/ Check-in [58884b6c]
Login

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

Overview
Comment:Another change to test_journal.c to account for (6817). Again, only test code has changed. (CVS 6819)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:58884b6c50f927c5606d857b2865d788a5147060
User & Date: danielk1977 2009-06-26 10:39:36
Context
2009-06-26
12:15
Fix the new pager.c changes so that they compile with IOTRACE defined. Fix an out-of-order variable definition in vdbeaux.c. (CVS 6820) check-in: ac145028 user: drh tags: trunk
10:39
Another change to test_journal.c to account for (6817). Again, only test code has changed. (CVS 6819) check-in: 58884b6c user: danielk1977 tags: trunk
09:01
Update test_journal.c to account for (6817). Changes to test code only. (CVS 6818) check-in: 542ee8cc user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test_journal.c.

    11     11   ******************************************************************************
    12     12   **
    13     13   ** This file contains code for a VFS layer that acts as a wrapper around
    14     14   ** an existing VFS. The code in this file attempts to verify that SQLite
    15     15   ** correctly populates and syncs a journal file before writing to a
    16     16   ** corresponding database file.
    17     17   **
    18         -** $Id: test_journal.c,v 1.16 2009/06/26 09:01:28 danielk1977 Exp $
           18  +** $Id: test_journal.c,v 1.17 2009/06/26 10:39:36 danielk1977 Exp $
    19     19   */
    20     20   #if SQLITE_TEST          /* This file is used for testing only */
    21     21   
    22     22   #include "sqlite3.h"
    23     23   #include "sqliteInt.h"
    24     24   
    25     25   /*
................................................................................
   214    214     sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PRNG));
   215    215   }
   216    216   static void leaveJtMutex(void){
   217    217     sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PRNG));
   218    218   }
   219    219   
   220    220   extern int sqlite3_io_error_pending;
   221         -static void stop_ioerr_simulation(int *piSave){
          221  +extern int sqlite3_io_error_hit;
          222  +static void stop_ioerr_simulation(int *piSave, int *piSave2){
   222    223     *piSave = sqlite3_io_error_pending;
          224  +  *piSave2 = sqlite3_io_error_hit;
   223    225     sqlite3_io_error_pending = -1;
          226  +  sqlite3_io_error_hit = 0;
   224    227   }
   225         -static void start_ioerr_simulation(int iSave){
          228  +static void start_ioerr_simulation(int iSave, int iSave2){
   226    229     sqlite3_io_error_pending = iSave;
          230  +  sqlite3_io_error_hit = iSave2;
   227    231   }
   228    232   
   229    233   /*
   230    234   ** The jt_file pointed to by the argument may or may not be a file-handle
   231    235   ** open on a main database file. If it is, and a transaction is currently
   232    236   ** opened on the file, then discard all transaction related data.
   233    237   */
................................................................................
   362    366     pJournal->iMaxOff = 0;
   363    367   
   364    368     if( !pMain->pWritable || !pMain->aCksum || !aData ){
   365    369       rc = SQLITE_IOERR_NOMEM;
   366    370     }else if( pMain->nPage>0 ){
   367    371       u32 iTrunk;
   368    372       int iSave;
          373  +    int iSave2;
   369    374   
   370         -    stop_ioerr_simulation(&iSave);
          375  +    stop_ioerr_simulation(&iSave, &iSave2);
   371    376   
   372    377       /* Read the database free-list. Add the page-number for each free-list
   373    378       ** leaf to the jt_file.pWritable bitvec.
   374    379       */
   375    380       rc = sqlite3OsRead(p, aData, pMain->nPagesize, 0);
   376    381       iTrunk = decodeUint32(&aData[32]);
   377    382       while( rc==SQLITE_OK && iTrunk>0 ){
................................................................................
   394    399           i64 iOff = (i64)(pMain->nPagesize) * (i64)ii;
   395    400           if( iOff==PENDING_BYTE ) continue;
   396    401           rc = sqlite3OsRead(pMain->pReal, aData, pMain->nPagesize, iOff);
   397    402           pMain->aCksum[ii] = genCksum(aData, pMain->nPagesize);
   398    403         }
   399    404       }
   400    405   
   401         -    start_ioerr_simulation(iSave);
          406  +    start_ioerr_simulation(iSave, iSave2);
   402    407     }
   403    408   
   404    409     sqlite3_free(aData);
   405    410     return rc;
   406    411   }
   407    412   
   408         -/*
   409         -** Write data to an jt-file.
   410         -*/
   411         -static int jtWrite(
   412         -  sqlite3_file *pFile, 
   413         -  const void *zBuf, 
   414         -  int iAmt, 
   415         -  sqlite_int64 iOfst
   416         -){
   417         -  jt_file *p = (jt_file *)pFile;
   418         -  if( p->flags&SQLITE_OPEN_MAIN_JOURNAL ){
   419         -    if( iOfst==0 ){
   420         -      jt_file *pMain = locateDatabaseHandle(p->zName);
   421         -      assert( pMain );
   422         -  
   423         -      if( iAmt==28 ){
   424         -        /* Zeroing the first journal-file header. This is the end of a
   425         -        ** transaction. */
   426         -        closeTransaction(pMain);
   427         -      }else if( iAmt!=12 ){
   428         -        /* Writing the first journal header to a journal file. This happens
   429         -        ** when a transaction is first started.  */
   430         -        int rc;
   431         -        u8 *z = (u8 *)zBuf;
   432         -        pMain->nPage = decodeUint32(&z[16]);
   433         -        pMain->nPagesize = decodeUint32(&z[24]);
   434         -        if( SQLITE_OK!=(rc=openTransaction(pMain, p)) ){
   435         -          return rc;
   436         -        }
   437         -      }
   438         -    }
   439         -    if( p->iMaxOff<(iOfst + iAmt) ){
   440         -      p->iMaxOff = iOfst + iAmt;
   441         -    }
   442         -  }
   443         -
   444         -  if( p->flags&SQLITE_OPEN_MAIN_DB && p->pWritable ){
   445         -    if( iAmt<p->nPagesize 
   446         -     && p->nPagesize%iAmt==0 
   447         -     && iOfst>=(PENDING_BYTE+512) 
   448         -     && iOfst+iAmt<=PENDING_BYTE+p->nPagesize
   449         -    ){
   450         -      /* No-op. This special case is hit when the backup code is copying a
   451         -      ** to a database with a larger page-size than the source database and
   452         -      ** it needs to fill in the non-locking-region part of the original
   453         -      ** pending-byte page.
   454         -      */
   455         -    }else{
   456         -      u32 pgno = iOfst/p->nPagesize + 1;
   457         -      assert( (iAmt==1||iAmt==p->nPagesize) && ((iOfst+iAmt)%p->nPagesize)==0 );
   458         -      assert( pgno<=p->nPage || p->nSync>0 );
   459         -      assert( pgno>p->nPage || sqlite3BitvecTest(p->pWritable, pgno) );
   460         -    }
   461         -  }
   462         -
   463         -  return sqlite3OsWrite(p->pReal, zBuf, iAmt, iOfst);
   464         -}
   465         -
   466         -/*
   467         -** Truncate an jt-file.
   468         -*/
   469         -static int jtTruncate(sqlite3_file *pFile, sqlite_int64 size){
   470         -  jt_file *p = (jt_file *)pFile;
   471         -  if( p->flags&SQLITE_OPEN_MAIN_JOURNAL && size==0 ){
   472         -    /* Truncating a journal file. This is the end of a transaction. */
   473         -    jt_file *pMain = locateDatabaseHandle(p->zName);
   474         -    closeTransaction(pMain);
   475         -  }
   476         -  if( p->flags&SQLITE_OPEN_MAIN_DB && p->pWritable ){
   477         -    u32 pgno;
   478         -    u32 locking_page = (u32)(PENDING_BYTE/p->nPagesize+1);
   479         -    for(pgno=size/p->nPagesize+1; pgno<=p->nPage; pgno++){
   480         -      assert( pgno==locking_page || sqlite3BitvecTest(p->pWritable, pgno) );
   481         -    }
   482         -  }
   483         -  return sqlite3OsTruncate(p->pReal, size);
   484         -}
   485         -
   486    413   /*
   487    414   ** The first argument to this function is a handle open on a journal file.
   488    415   ** This function reads the journal file and adds the page number for each
   489    416   ** page in the journal to the Bitvec object passed as the second argument.
   490    417   */
   491    418   static int readJournalFile(jt_file *p, jt_file *pMain){
   492    419     int rc = SQLITE_OK;
   493    420     unsigned char zBuf[28];
   494    421     sqlite3_file *pReal = p->pReal;
   495    422     sqlite3_int64 iOff = 0;
   496    423     sqlite3_int64 iSize = p->iMaxOff;
   497    424     unsigned char *aPage;
   498    425     int iSave;
          426  +  int iSave2;
   499    427   
   500    428     aPage = sqlite3_malloc(pMain->nPagesize);
   501    429     if( !aPage ){
   502    430       return SQLITE_IOERR_NOMEM;
   503    431     }
   504    432   
   505         -  stop_ioerr_simulation(&iSave);
          433  +  stop_ioerr_simulation(&iSave, &iSave2);
   506    434   
   507    435     while( rc==SQLITE_OK && iOff<iSize ){
   508    436       u32 nRec, nPage, nSector, nPagesize;
   509    437       u32 ii;
   510    438   
   511    439       /* Read and decode the next journal-header from the journal file. */
   512    440       rc = sqlite3OsRead(pReal, zBuf, 28, iOff);
................................................................................
   551    479         }
   552    480       }
   553    481   
   554    482       iOff = ((iOff + (nSector-1)) / nSector) * nSector;
   555    483     }
   556    484   
   557    485   finish_rjf:
   558         -  start_ioerr_simulation(iSave);
          486  +  start_ioerr_simulation(iSave, iSave2);
   559    487     sqlite3_free(aPage);
   560    488     if( rc==SQLITE_IOERR_SHORT_READ ){
   561    489       rc = SQLITE_OK;
   562    490     }
   563    491     return rc;
   564    492   }
   565    493   
          494  +
          495  +/*
          496  +** Write data to an jt-file.
          497  +*/
          498  +static int jtWrite(
          499  +  sqlite3_file *pFile, 
          500  +  const void *zBuf, 
          501  +  int iAmt, 
          502  +  sqlite_int64 iOfst
          503  +){
          504  +  int rc;
          505  +  jt_file *p = (jt_file *)pFile;
          506  +  if( p->flags&SQLITE_OPEN_MAIN_JOURNAL ){
          507  +    if( iOfst==0 ){
          508  +      jt_file *pMain = locateDatabaseHandle(p->zName);
          509  +      assert( pMain );
          510  +  
          511  +      if( iAmt==28 ){
          512  +        /* Zeroing the first journal-file header. This is the end of a
          513  +        ** transaction. */
          514  +        closeTransaction(pMain);
          515  +      }else if( iAmt!=12 ){
          516  +        /* Writing the first journal header to a journal file. This happens
          517  +        ** when a transaction is first started.  */
          518  +        u8 *z = (u8 *)zBuf;
          519  +        pMain->nPage = decodeUint32(&z[16]);
          520  +        pMain->nPagesize = decodeUint32(&z[24]);
          521  +        if( SQLITE_OK!=(rc=openTransaction(pMain, p)) ){
          522  +          return rc;
          523  +        }
          524  +      }
          525  +    }
          526  +    if( p->iMaxOff<(iOfst + iAmt) ){
          527  +      p->iMaxOff = iOfst + iAmt;
          528  +    }
          529  +  }
          530  +
          531  +  if( p->flags&SQLITE_OPEN_MAIN_DB && p->pWritable ){
          532  +    if( iAmt<p->nPagesize 
          533  +     && p->nPagesize%iAmt==0 
          534  +     && iOfst>=(PENDING_BYTE+512) 
          535  +     && iOfst+iAmt<=PENDING_BYTE+p->nPagesize
          536  +    ){
          537  +      /* No-op. This special case is hit when the backup code is copying a
          538  +      ** to a database with a larger page-size than the source database and
          539  +      ** it needs to fill in the non-locking-region part of the original
          540  +      ** pending-byte page.
          541  +      */
          542  +    }else{
          543  +      u32 pgno = iOfst/p->nPagesize + 1;
          544  +      assert( (iAmt==1||iAmt==p->nPagesize) && ((iOfst+iAmt)%p->nPagesize)==0 );
          545  +      assert( pgno<=p->nPage || p->nSync>0 );
          546  +      assert( pgno>p->nPage || sqlite3BitvecTest(p->pWritable, pgno) );
          547  +    }
          548  +  }
          549  +
          550  +  rc = sqlite3OsWrite(p->pReal, zBuf, iAmt, iOfst);
          551  +  if( (p->flags&SQLITE_OPEN_MAIN_JOURNAL) && iAmt==12 ){
          552  +    jt_file *pMain = locateDatabaseHandle(p->zName);
          553  +    int rc2 = readJournalFile(p, pMain);
          554  +    if( rc==SQLITE_OK ) rc = rc2;
          555  +  }
          556  +  return rc;
          557  +}
          558  +
          559  +/*
          560  +** Truncate an jt-file.
          561  +*/
          562  +static int jtTruncate(sqlite3_file *pFile, sqlite_int64 size){
          563  +  jt_file *p = (jt_file *)pFile;
          564  +  if( p->flags&SQLITE_OPEN_MAIN_JOURNAL && size==0 ){
          565  +    /* Truncating a journal file. This is the end of a transaction. */
          566  +    jt_file *pMain = locateDatabaseHandle(p->zName);
          567  +    closeTransaction(pMain);
          568  +  }
          569  +  if( p->flags&SQLITE_OPEN_MAIN_DB && p->pWritable ){
          570  +    u32 pgno;
          571  +    u32 locking_page = (u32)(PENDING_BYTE/p->nPagesize+1);
          572  +    for(pgno=size/p->nPagesize+1; pgno<=p->nPage; pgno++){
          573  +      assert( pgno==locking_page || sqlite3BitvecTest(p->pWritable, pgno) );
          574  +    }
          575  +  }
          576  +  return sqlite3OsTruncate(p->pReal, size);
          577  +}
          578  +
   566    579   /*
   567    580   ** Sync an jt-file.
   568    581   */
   569    582   static int jtSync(sqlite3_file *pFile, int flags){
   570    583     jt_file *p = (jt_file *)pFile;
   571    584   
   572    585     if( p->flags&SQLITE_OPEN_MAIN_JOURNAL ){