/ Check-in [1dde96c9]
Login

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

Overview
Comment:For improved clarity of presentation, refactor some of the code associated with ZERO_DAMAGE and sector-size.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | statvfs
Files: files | file ages | folders
SHA1: 1dde96c9ee88af1c4e37c2e65acb7c0fe6a20e2a
User & Date: drh 2011-12-17 20:02:11
Context
2011-12-19
00:31
Some fixes to the test suite so that it works with ZERO_DAMAGE set to true. Still lots more problems remain. check-in: 41891b23 user: drh tags: statvfs
2011-12-17
20:02
For improved clarity of presentation, refactor some of the code associated with ZERO_DAMAGE and sector-size. check-in: 1dde96c9 user: drh tags: statvfs
19:49
Add SQLITE_IOCAP_ZERO_DAMAGE and enable it for both unix and windows. Use this device characteristic to reduce the required work in journaling. A side effect is that this changes the default page exists back to 1024 even with the use of statvfs(). check-in: a0be6ea4 user: drh tags: statvfs
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

  2524   2524   ** we minimize the sector size.  For backwards compatibility of the
  2525   2525   ** rollback journal file format, we cannot reduce the effective sector
  2526   2526   ** size below 512.
  2527   2527   */
  2528   2528   static void setSectorSize(Pager *pPager){
  2529   2529     assert( isOpen(pPager->fd) || pPager->tempFile );
  2530   2530   
  2531         -  if( !pPager->tempFile
  2532         -   && (sqlite3OsDeviceCharacteristics(pPager->fd)&SQLITE_IOCAP_ZERO_DAMAGE)==0
         2531  +  if( pPager->tempFile
         2532  +   || (sqlite3OsDeviceCharacteristics(pPager->fd)&SQLITE_IOCAP_ZERO_DAMAGE)!=0
  2533   2533     ){
  2534   2534       /* Sector size doesn't matter for temporary files. Also, the file
  2535   2535       ** may not have been opened yet, in which case the OsSectorSize()
  2536         -    ** call will segfault.
  2537         -    */
         2536  +    ** call will segfault. */
         2537  +    pPager->sectorSize = 512;
         2538  +  }else{
  2538   2539       pPager->sectorSize = sqlite3OsSectorSize(pPager->fd);
  2539         -  }
  2540         -  if( pPager->sectorSize<32 ){
  2541         -    pPager->sectorSize = 512;
  2542         -  }
  2543         -  if( pPager->sectorSize>MAX_SECTOR_SIZE ){
  2544         -    assert( MAX_SECTOR_SIZE>=512 );
  2545         -    pPager->sectorSize = MAX_SECTOR_SIZE;
         2540  +    if( pPager->sectorSize<32 ){
         2541  +      pPager->sectorSize = 512;
         2542  +    }
         2543  +    if( pPager->sectorSize>MAX_SECTOR_SIZE ){
         2544  +      assert( MAX_SECTOR_SIZE>=512 );
         2545  +      pPager->sectorSize = MAX_SECTOR_SIZE;
         2546  +    }
  2546   2547     }
  2547   2548   }
  2548   2549   
  2549   2550   /*
  2550   2551   ** Playback the journal and thus restore the database file to
  2551   2552   ** the state it was in before we started making changes.  
  2552   2553   **

Changes to src/wal.c.

   421    421     u8 syncFlags;              /* Flags to use to sync header writes */
   422    422     u8 exclusiveMode;          /* Non-zero if connection is in exclusive mode */
   423    423     u8 writeLock;              /* True if in a write transaction */
   424    424     u8 ckptLock;               /* True if holding a checkpoint lock */
   425    425     u8 readOnly;               /* WAL_RDWR, WAL_RDONLY, or WAL_SHM_RDONLY */
   426    426     u8 truncateOnCommit;       /* True to truncate WAL file on commit */
   427    427     u8 noSyncHeader;           /* Avoid WAL header fsyncs if true */
   428         -  u8 noPadding;              /* No need to pad transactions to sector size */
          428  +  u8 padToSectorBoundary;    /* Pad transactions out to the next sector */
   429    429     WalIndexHdr hdr;           /* Wal-index header for current transaction */
   430    430     const char *zWalName;      /* Name of WAL file */
   431    431     u32 nCkpt;                 /* Checkpoint sequence counter in the wal-header */
   432    432   #ifdef SQLITE_DEBUG
   433    433     u8 lockError;              /* True if a locking error has occurred */
   434    434   #endif
   435    435   };
................................................................................
  1291   1291   
  1292   1292     pRet->pVfs = pVfs;
  1293   1293     pRet->pWalFd = (sqlite3_file *)&pRet[1];
  1294   1294     pRet->pDbFd = pDbFd;
  1295   1295     pRet->readLock = -1;
  1296   1296     pRet->mxWalSize = mxWalSize;
  1297   1297     pRet->zWalName = zWalName;
         1298  +  pRet->padToSectorBoundary = 1;
  1298   1299     pRet->exclusiveMode = (bNoShm ? WAL_HEAPMEMORY_MODE: WAL_NORMAL_MODE);
  1299   1300   
  1300   1301     /* Open file handle on the write-ahead log file. */
  1301   1302     flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL);
  1302   1303     rc = sqlite3OsOpen(pVfs, zWalName, pRet->pWalFd, flags, &flags);
  1303   1304     if( rc==SQLITE_OK && flags&SQLITE_OPEN_READONLY ){
  1304   1305       pRet->readOnly = WAL_RDONLY;
................................................................................
  1307   1308     if( rc!=SQLITE_OK ){
  1308   1309       walIndexClose(pRet, 0);
  1309   1310       sqlite3OsClose(pRet->pWalFd);
  1310   1311       sqlite3_free(pRet);
  1311   1312     }else{
  1312   1313       int iDC = sqlite3OsDeviceCharacteristics(pRet->pWalFd);
  1313   1314       if( iDC & SQLITE_IOCAP_SEQUENTIAL ){ pRet->noSyncHeader = 1; }
  1314         -    if( iDC & SQLITE_IOCAP_ZERO_DAMAGE ){ pRet->noPadding = 1; }
         1315  +    if( iDC & SQLITE_IOCAP_ZERO_DAMAGE ){ pRet->padToSectorBoundary = 0; }
  1315   1316       *ppWal = pRet;
  1316   1317       WALTRACE(("WAL%d: opened\n", pRet));
  1317   1318     }
  1318   1319     return rc;
  1319   1320   }
  1320   1321   
  1321   1322   /*
................................................................................
  2778   2779         return rc;
  2779   2780       }
  2780   2781       pLast = p;
  2781   2782     }
  2782   2783   
  2783   2784     /* Sync the log file if the 'isSync' flag was specified. */
  2784   2785     if( isCommit && (sync_flags & WAL_SYNC_TRANSACTIONS)!=0 ){
  2785         -    if( !pWal->noPadding ){
         2786  +    if( pWal->padToSectorBoundary ){
  2786   2787         i64 iSegment = sqlite3OsSectorSize(pWal->pWalFd);
  2787   2788         i64 iOffset = walFrameOffset(iFrame+1, szPage);
  2788   2789     
  2789   2790         assert( iSegment>0 );
  2790   2791     
  2791   2792         iSegment = (((iOffset+iSegment-1)/iSegment) * iSegment);
  2792   2793         while( iOffset<iSegment ){