/ Check-in [8156b57a]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Add testcase macros to ensure that large-file cases are tested in WAL.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8156b57ac33161ae6dd8a9413127ecce3c9eae83
User & Date: drh 2010-07-07 13:43:19
Context
2010-07-07
13:58
Fix minor issue in xAccess() method for Windows. check-in: 4bfd46f1 user: shaneh tags: trunk
13:54
Make sure the schema is loaded before preparing a "PRAGMA journal_mode" command. This helps it return meaningful results when it is the first command executed by a new database connection. check-in: ef126e77 user: dan tags: trunk
13:43
Add testcase macros to ensure that large-file cases are tested in WAL. check-in: 8156b57a user: drh tags: trunk
11:43
Run some fts3 tests as part of the "wal" permutation. check-in: 8657455a user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/sqliteInt.h.

   268    268   # define ALWAYS(X)      ((X)?1:(assert(0),0))
   269    269   # define NEVER(X)       ((X)?(assert(0),1):0)
   270    270   #else
   271    271   # define ALWAYS(X)      (X)
   272    272   # define NEVER(X)       (X)
   273    273   #endif
   274    274   
          275  +/*
          276  +** Return true (non-zero) if the input is a integer that is too large
          277  +** to fit in 32-bits.  This macro is used inside of various testcase()
          278  +** macros to verify that we have tested SQLite for large-file support.
          279  +*/
          280  +#define IS_BIG_INT(X)  (((X)&(i64)0xffffffff)!=0)
          281  +
   275    282   /*
   276    283   ** The macro unlikely() is a hint that surrounds a boolean
   277    284   ** expression that is usually false.  Macro likely() surrounds
   278    285   ** a boolean expression that is usually true.  GCC is able to
   279    286   ** use these hints to generate better code, sometimes.
   280    287   */
   281    288   #if defined(__GNUC__) && 0

Changes to src/wal.c.

  1568   1568       /* Sync the WAL to disk */
  1569   1569       if( sync_flags ){
  1570   1570         rc = sqlite3OsSync(pWal->pWalFd, sync_flags);
  1571   1571       }
  1572   1572   
  1573   1573       /* Iterate through the contents of the WAL, copying data to the db file. */
  1574   1574       while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
         1575  +      i64 iOffset;
  1575   1576         assert( walFramePgno(pWal, iFrame)==iDbpage );
  1576   1577         if( iFrame<=nBackfill || iFrame>mxSafeFrame ) continue;
  1577         -      rc = sqlite3OsRead(pWal->pWalFd, zBuf, szPage, 
  1578         -          walFrameOffset(iFrame, szPage) + WAL_FRAME_HDRSIZE
  1579         -      );
  1580         -      if( rc==SQLITE_OK ){
  1581         -        i64 iOffset = (i64)(iDbpage-1)*szPage;
  1582         -        testcase( iOffset > (((i64)1)<<32) );
  1583         -        rc = sqlite3OsWrite(pWal->pDbFd, zBuf, szPage, iOffset);
  1584         -      }
         1578  +      iOffset = walFrameOffset(iFrame, szPage) + WAL_FRAME_HDRSIZE;
         1579  +      /* testcase( IS_BIG_INT(iOffset) ); -- would require a 4GB WAL file */
         1580  +      rc = sqlite3OsRead(pWal->pWalFd, zBuf, szPage, iOffset);
         1581  +      if( rc!=SQLITE_OK ) break;
         1582  +      iOffset = (iDbpage-1)*(i64)szPage;
         1583  +      testcase( IS_BIG_INT(iOffset) );
         1584  +      rc = sqlite3OsWrite(pWal->pDbFd, zBuf, szPage, iOffset);
         1585  +      if( rc!=SQLITE_OK ) break;
  1585   1586       }
  1586   1587   
  1587   1588       /* If work was actually accomplished... */
  1588   1589       if( rc==SQLITE_OK ){
  1589   1590         if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){
  1590         -        rc = sqlite3OsTruncate(pWal->pDbFd, ((i64)pWal->hdr.nPage*(i64)szPage));
         1591  +        i64 szDb = pWal->hdr.nPage*(i64)szPage;
         1592  +        testcase( IS_BIG_INT(szDb) );
         1593  +        rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
  1591   1594           if( rc==SQLITE_OK && sync_flags ){
  1592   1595             rc = sqlite3OsSync(pWal->pDbFd, sync_flags);
  1593   1596           }
  1594   1597         }
  1595   1598         if( rc==SQLITE_OK ){
  1596   1599           pInfo->nBackfill = mxSafeFrame;
  1597   1600         }
................................................................................
  2121   2124   
  2122   2125     /* If iRead is non-zero, then it is the log frame number that contains the
  2123   2126     ** required page. Read and return data from the log file.
  2124   2127     */
  2125   2128     if( iRead ){
  2126   2129       i64 iOffset = walFrameOffset(iRead, pWal->hdr.szPage) + WAL_FRAME_HDRSIZE;
  2127   2130       *pInWal = 1;
         2131  +    testcase( IS_BIG_INT(iOffset) );
  2128   2132       return sqlite3OsRead(pWal->pWalFd, pOut, nOut, iOffset);
  2129   2133     }
  2130   2134   
  2131   2135     *pInWal = 0;
  2132   2136     return SQLITE_OK;
  2133   2137   }
  2134   2138   
................................................................................
  2412   2416     /* Write the log file. */
  2413   2417     for(p=pList; p; p=p->pDirty){
  2414   2418       u32 nDbsize;                  /* Db-size field for frame header */
  2415   2419       i64 iOffset;                  /* Write offset in log file */
  2416   2420       void *pData;
  2417   2421      
  2418   2422       iOffset = walFrameOffset(++iFrame, szPage);
         2423  +    testcase( IS_BIG_INT(iOffset) );
  2419   2424       
  2420   2425       /* Populate and write the frame header */
  2421   2426       nDbsize = (isCommit && p->pDirty==0) ? nTruncate : 0;
  2422   2427   #if defined(SQLITE_HAS_CODEC)
  2423   2428       if( (pData = sqlite3PagerCodec(p))==0 ) return SQLITE_NOMEM;
  2424   2429   #else
  2425   2430       pData = p->pData;
................................................................................
  2451   2456         void *pData;
  2452   2457   #if defined(SQLITE_HAS_CODEC)
  2453   2458         if( (pData = sqlite3PagerCodec(pLast))==0 ) return SQLITE_NOMEM;
  2454   2459   #else
  2455   2460         pData = pLast->pData;
  2456   2461   #endif
  2457   2462         walEncodeFrame(pWal, pLast->pgno, nTruncate, pData, aFrame);
         2463  +      testcase( IS_BIG_INT(iOffset) );
  2458   2464         rc = sqlite3OsWrite(pWal->pWalFd, aFrame, sizeof(aFrame), iOffset);
  2459   2465         if( rc!=SQLITE_OK ){
  2460   2466           return rc;
  2461   2467         }
  2462   2468         iOffset += WAL_FRAME_HDRSIZE;
  2463   2469         rc = sqlite3OsWrite(pWal->pWalFd, pData, szPage, iOffset); 
  2464   2470         if( rc!=SQLITE_OK ){