/ Check-in [629108c8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Make the pager less vulnerable to problems caused by shifting sector sizes when rolling back a hot journal.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 629108c8e5376f989cd66e11437949a54c33a5b8
User & Date: drh 2012-01-11 15:47:42
References
2012-01-20
15:05
Cherrypick the fix from [629108c8e5376f989] into the nx-devkit branch. check-in: d7374568 user: drh tags: nx-devkit
Context
2012-01-11
16:16
Remove code made unreachable by the enhancement of the previous check-in. check-in: 9e31a275 user: drh tags: trunk
15:47
Make the pager less vulnerable to problems caused by shifting sector sizes when rolling back a hot journal. check-in: 629108c8 user: drh tags: trunk
11:20
Fix the sqlite3_quota_file() function in test_quota.c so that it adds the second nul-terminator to all file names that will be passed to a VFS xOpen method. check-in: 3013f9a6 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

  2482   2482       assert( pPager->eLock==EXCLUSIVE_LOCK );
  2483   2483       /* TODO: Is it safe to use Pager.dbFileSize here? */
  2484   2484       rc = sqlite3OsFileSize(pPager->fd, &currentSize);
  2485   2485       newSize = szPage*(i64)nPage;
  2486   2486       if( rc==SQLITE_OK && currentSize!=newSize ){
  2487   2487         if( currentSize>newSize ){
  2488   2488           rc = sqlite3OsTruncate(pPager->fd, newSize);
  2489         -      }else{
         2489  +      }else if( (currentSize+szPage)<=newSize ){
  2490   2490           char *pTmp = pPager->pTmpSpace;
  2491   2491           memset(pTmp, 0, szPage);
  2492   2492           testcase( (newSize-szPage) <  currentSize );
  2493   2493           testcase( (newSize-szPage) == currentSize );
  2494   2494           testcase( (newSize-szPage) >  currentSize );
  2495   2495           rc = sqlite3OsWrite(pPager->fd, pTmp, szPage, newSize-szPage);
  2496   2496         }
................................................................................
  3084   3084       assert( isOpen(pPager->fd) || pPager->tempFile );
  3085   3085       if( isOpen(pPager->fd) ){
  3086   3086         int rc = sqlite3OsFileSize(pPager->fd, &n);
  3087   3087         if( rc!=SQLITE_OK ){
  3088   3088           return rc;
  3089   3089         }
  3090   3090       }
  3091         -    nPage = (Pgno)(n / pPager->pageSize);
         3091  +    nPage = (Pgno)((n+pPager->pageSize-1) / pPager->pageSize);
  3092   3092       if( nPage==0 && n>0 ){
  3093   3093         nPage = 1;
  3094   3094       }
  3095   3095     }
  3096   3096   
  3097   3097     /* If the current number of pages in the file is greater than the
  3098   3098     ** configured maximum pager number, increase the allowed limit so
................................................................................
  3518   3518       if( rc==SQLITE_OK ){
  3519   3519         pNew = (char *)sqlite3PageMalloc(pageSize);
  3520   3520         if( !pNew ) rc = SQLITE_NOMEM;
  3521   3521       }
  3522   3522   
  3523   3523       if( rc==SQLITE_OK ){
  3524   3524         pager_reset(pPager);
  3525         -      pPager->dbSize = (Pgno)(nByte/pageSize);
         3525  +      pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
  3526   3526         pPager->pageSize = pageSize;
  3527   3527         sqlite3PageFree(pPager->pTmpSpace);
  3528   3528         pPager->pTmpSpace = pNew;
  3529   3529         sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
  3530   3530       }
  3531   3531     }
  3532   3532