/ Check-in [874bc884]
Login

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

Overview
Comment:Change pager_truncate() to a different method for extending files while also ensuring that writes are page-size and page-aligned.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 874bc8844f6494cdbf700bd884dee67d40f11fc0
User & Date: drh 2011-01-28 15:46:14
Context
2011-01-28
17:02
Bogus release candidate. Closed-Leaf check-in: 38ca1daa user: drh tags: mistake
16:45
Add test script pagerfault3.test. No changes to code or existing tests. check-in: 682fe41e user: dan tags: trunk
15:46
Change pager_truncate() to a different method for extending files while also ensuring that writes are page-size and page-aligned. check-in: 874bc884 user: drh tags: trunk
15:07
When extending a database file, do so by writing one or more page-size chunks of data to the file, instead of just a single byte to the end. check-in: 58577135 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

  2473   2473     assert( pPager->eState!=PAGER_ERROR );
  2474   2474     assert( pPager->eState!=PAGER_READER );
  2475   2475     
  2476   2476     if( isOpen(pPager->fd) 
  2477   2477      && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN) 
  2478   2478     ){
  2479   2479       i64 currentSize, newSize;
         2480  +    int szPage = pPager->pageSize;
  2480   2481       assert( pPager->eLock==EXCLUSIVE_LOCK );
  2481   2482       /* TODO: Is it safe to use Pager.dbFileSize here? */
  2482   2483       rc = sqlite3OsFileSize(pPager->fd, &currentSize);
  2483         -    newSize = pPager->pageSize*(i64)nPage;
         2484  +    newSize = szPage*(i64)nPage;
  2484   2485       if( rc==SQLITE_OK && currentSize!=newSize ){
  2485   2486         if( currentSize>newSize ){
  2486   2487           rc = sqlite3OsTruncate(pPager->fd, newSize);
  2487   2488         }else{
  2488   2489           char *pTmp = pPager->pTmpSpace;
  2489         -        memset(pTmp, 0, pPager->pageSize);
  2490         -        while( currentSize<newSize ){
  2491         -          rc = sqlite3OsWrite(pPager->fd, pTmp, pPager->pageSize, currentSize);
  2492         -          currentSize += pPager->pageSize;
  2493         -        }
         2490  +        memset(pTmp, 0, szPage);
         2491  +        testcase( (newSize-szPage) <  currentSize );
         2492  +        testcase( (newSize-szPage) == currentSize );
         2493  +        testcase( (newSize-szPage) >  currentSize );
         2494  +        rc = sqlite3OsWrite(pPager->fd, pTmp, szPage, newSize-szPage);
  2494   2495         }
  2495   2496         if( rc==SQLITE_OK ){
  2496   2497           pPager->dbFileSize = nPage;
  2497   2498         }
  2498   2499       }
  2499   2500     }
  2500   2501     return rc;