]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix minor problems and update comments in pager.c.
authordan <dan@noemail.net>
Sat, 7 Aug 2010 16:17:48 +0000 (16:17 +0000)
committerdan <dan@noemail.net>
Sat, 7 Aug 2010 16:17:48 +0000 (16:17 +0000)
FossilOrigin-Name: 92e456374b052aceff356d10317b5b94fcdeaa5c

manifest
manifest.uuid
src/pager.c
src/wal.c
test/walmode.test

index 13283aff95f2e784f3d0f05f73d5403e6a90624a..6455d6683b871c14c8fbf4019371f6906256d5b9 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\sproblem\swherein\schanging\sthe\sjournal-mode\simmediately\safter\sleaving\sexclusive-locking\smode\scould\slead\sto\sthe\sdatabase\sbeing\sunlocked\swithout\sclearing\sthe\schangeCountDone\sflag.
-D 2010-08-07T09:31:14
+C Fix\sminor\sproblems\sand\supdate\scomments\sin\spager.c.
+D 2010-08-07T16:17:49
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -156,7 +156,7 @@ F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f
 F src/os_os2.c 72d0b2e562952a2464308c4ce5f7913ac10bef3e
 F src/os_unix.c ae5ca8a6031380708f3fec7be325233d49944914
 F src/os_win.c 51cb62f76262d961ea4249489383d714501315a7
-F src/pager.c 9621456e9fdbd134273a434efb2c873c4c4f2a9e
+F src/pager.c 3af4caaa32f26d537ff857ac30d3ac3ce7e46ea5
 F src/pager.h 80726162dc3942f59ab27b738fb667b9ba0a89d5
 F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58
 F src/pcache.c 1e9aa2dbc0845b52e1b51cc39753b6d1e041cb07
@@ -227,7 +227,7 @@ F src/vdbeblob.c 258a6010ba7a82b72b327fb24c55790655689256
 F src/vdbemem.c e5673f81a2381b35c60e73ef0a8502be2ab1041e
 F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
 F src/vtab.c 82200af3881fa4e1c9cf07cf31d98c09d437e3ab
-F src/wal.c 6e04bccccd75acf86725cc8cb4b107cd245e018c
+F src/wal.c ef5e37b8cf0b617b787d00eb9c63c803f1f790b1
 F src/wal.h 96669b645e27cd5a111ba59f0cae7743a207bc3c
 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
 F src/where.c 7db3e41c2a846f9deeb24f1bbb75461b4010b7b5
@@ -794,7 +794,7 @@ F test/walcrash.test e763841551d6b23677ccb419797c1589dcbdbaf5
 F test/walcrash2.test 019d60b89d96c1937adb2b30b850ac7e86e5a142
 F test/walfault.test 05c470688d742688e455dd56816bd6bcffa298f8
 F test/walhook.test ed00a40ba7255da22d6b66433ab61fab16a63483
-F test/walmode.test 5dc3008ef71988ecdd949ea16e5750e325b92b54
+F test/walmode.test 4ecd37284f245247f7935896ab66f6943f0432a0
 F test/walshared.test 985b4a3406b2b2dace1d52a42d26a11dd6900981
 F test/walslow.test d21625e2e99e11c032ce949e8a94661576548933
 F test/walthread.test a25a393c068a2b42b44333fa3fdaae9072f1617c
@@ -843,7 +843,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P b5d46f1ea08db2b88d2205bc283b9262ad970b55
-R 1c87633c0c4928fc4e767694680c3b36
+P 531abc808526d607768bf6f503268d4cc66ab169
+R 8bd570ff99007432bc59ff36d6f70bed
 U dan
-Z d18018a31ac0c912f6e4858813e6f216
+Z ab88a6e6bc1538b57c390502ab433fb7
index 33f193000c1ded26e594bea7bf0e4f7535501bbb..802595050ab00c959974a3572895a2ad5522a2be 100644 (file)
@@ -1 +1 @@
-531abc808526d607768bf6f503268d4cc66ab169
\ No newline at end of file
+92e456374b052aceff356d10317b5b94fcdeaa5c
\ No newline at end of file
index 765a64c34e5abc94d39e0584f242a93318ea3fe4..b68d3cbb8feb6895ccc4406f39193a90a13eeb35 100644 (file)
@@ -891,6 +891,7 @@ static char *print_pager_state(Pager *p){
       "Journal mode:  journal_mode=%s\n"
       "Backing store: tempFile=%d memDb=%d useJournal=%d\n"
       "Journal:       journalOff=%lld journalHdr=%lld\n"
+      "Size:          dbsize=%d dbOrigSize=%d dbFileSize=%d\n"
       , p->zFilename
       , p->eState==PAGER_OPEN            ? "OPEN" :
         p->eState==PAGER_READER          ? "READER" :
@@ -914,6 +915,7 @@ static char *print_pager_state(Pager *p){
         p->journalMode==PAGER_JOURNALMODE_WAL      ? "wal" : "?error?"
       , (int)p->tempFile, (int)p->memDb, (int)p->useJournal
       , p->journalOff, p->journalHdr
+      , (int)p->dbSize, (int)p->dbOrigSize, (int)p->dbFileSize
   );
 
   return zRet;
@@ -1520,7 +1522,6 @@ static int writeMasterJournal(Pager *pPager, const char *zMaster){
   u32 cksum = 0;                   /* Checksum of string zMaster */
 
   assert( pPager->setMaster==0 );
-  assert( !zMaster || pPager->journalMode!=PAGER_JOURNALMODE_WAL );
   assert( !pagerUseWal(pPager) );
 
   if( !zMaster 
@@ -5168,33 +5169,18 @@ static int pager_write(PgHdr *pPg){
       if( pPg->pgno<=pPager->dbOrigSize && isOpen(pPager->jfd) ){
         u32 cksum;
         char *pData2;
+        i64 iOff = pPager->journalOff;
 
         /* We should never write to the journal file the page that
         ** contains the database locks.  The following assert verifies
         ** that we do not. */
         assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
 
-        assert( pPager->journalHdr <= pPager->journalOff );
+        assert( pPager->journalHdr<=pPager->journalOff );
         CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
         cksum = pager_cksum(pPager, (u8*)pData2);
-        rc = write32bits(pPager->jfd, pPager->journalOff, pPg->pgno);
-        if( rc==SQLITE_OK ){
-          rc = sqlite3OsWrite(pPager->jfd, pData2, pPager->pageSize,
-                              pPager->journalOff + 4);
-          pPager->journalOff += pPager->pageSize+4;
-        }
-        if( rc==SQLITE_OK ){
-          rc = write32bits(pPager->jfd, pPager->journalOff, cksum);
-          pPager->journalOff += 4;
-        }
-        IOTRACE(("JOUT %p %d %lld %d\n", pPager, pPg->pgno, 
-                 pPager->journalOff, pPager->pageSize));
-        PAGER_INCR(sqlite3_pager_writej_count);
-        PAGERTRACE(("JOURNAL %d page %d needSync=%d hash(%08x)\n",
-             PAGERID(pPager), pPg->pgno, 
-             ((pPg->flags&PGHDR_NEED_SYNC)?1:0), pager_pagehash(pPg)));
 
-        /* Even if an IO or diskfull error occurred while journalling the
+        /* Even if an IO or diskfull error occurs while journalling the
         ** page in the block above, set the need-sync flag for the page.
         ** Otherwise, when the transaction is rolled back, the logic in
         ** playback_one_page() will think that the page needs to be restored
@@ -5203,13 +5189,21 @@ static int pager_write(PgHdr *pPg){
         */
         pPg->flags |= PGHDR_NEED_SYNC;
 
-        /* An error has occurred writing to the journal file. The 
-        ** transaction will be rolled back by the layer above.
-        */
-        if( rc!=SQLITE_OK ){
-          return rc;
-        }
+        rc = write32bits(pPager->jfd, iOff, pPg->pgno);
+        if( rc!=SQLITE_OK ) return rc;
+        rc = sqlite3OsWrite(pPager->jfd, pData2, pPager->pageSize, iOff+4);
+        if( rc!=SQLITE_OK ) return rc;
+        rc = write32bits(pPager->jfd, iOff+pPager->pageSize+4, cksum);
+        if( rc!=SQLITE_OK ) return rc;
+
+        IOTRACE(("JOUT %p %d %lld %d\n", pPager, pPg->pgno, 
+                 pPager->journalOff, pPager->pageSize));
+        PAGER_INCR(sqlite3_pager_writej_count);
+        PAGERTRACE(("JOURNAL %d page %d needSync=%d hash(%08x)\n",
+             PAGERID(pPager), pPg->pgno, 
+             ((pPg->flags&PGHDR_NEED_SYNC)?1:0), pager_pagehash(pPg)));
 
+        pPager->journalOff += 8 + pPager->pageSize;
         pPager->nRec++;
         assert( pPager->pInJournal!=0 );
         rc = sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
@@ -5335,7 +5329,7 @@ int sqlite3PagerWrite(DbPage *pDbPage){
     ** before any of them can be written out to the database file.
     */
     if( rc==SQLITE_OK && needSync ){
-      assert( !MEMDB && pPager->noSync==0 );
+      assert( !MEMDB );
       for(ii=0; ii<nPage; ii++){
         PgHdr *pPage = pager_lookup(pPager, pg1+ii);
         if( pPage ){
@@ -5790,47 +5784,30 @@ int sqlite3PagerCommitPhaseTwo(Pager *pPager){
 }
 
 /*
-** Rollback all changes. The database falls back to PAGER_SHARED mode.
+** If a write transaction is open, then all changes made within the 
+** transaction are reverted and the current write-transaction is closed.
+** The pager falls back to PAGER_READER state if successful, or PAGER_ERROR
+** state if an error occurs.
+**
+** If the pager is already in PAGER_ERROR state when this function is called,
+** it returns Pager.errCode immediately. No work is performed in this case.
 **
-** This function performs two tasks:
+** Otherwise, in rollback mode, this function performs two functions:
 **
 **   1) It rolls back the journal file, restoring all database file and 
 **      in-memory cache pages to the state they were in when the transaction
 **      was opened, and
+**
 **   2) It finalizes the journal file, so that it is not used for hot
 **      rollback at any point in the future.
 **
-** subject to the following qualifications:
-**
-** * If the journal file is not yet open when this function is called,
-**   then only (2) is performed. In this case there is no journal file
-**   to roll back.
-**
-** * If in an error state other than SQLITE_FULL, then task (1) is 
-**   performed. If successful, task (2). Regardless of the outcome
-**   of either, the error state error code is returned to the caller
-**   (i.e. either SQLITE_IOERR or SQLITE_CORRUPT).
-**
-** * If the pager is in PAGER_RESERVED state, then attempt (1). Whether
-**   or not (1) is successful, also attempt (2). If successful, return
-**   SQLITE_OK. Otherwise, enter the error state and return the first 
-**   error code encountered. 
-**
-**   In this case there is no chance that the database was written to. 
-**   So is safe to finalize the journal file even if the playback 
-**   (operation 1) failed. However the pager must enter the error state
-**   as the contents of the in-memory cache are now suspect.
-**
-** * Finally, if in PAGER_EXCLUSIVE state, then attempt (1). Only
-**   attempt (2) if (1) is successful. Return SQLITE_OK if successful,
-**   otherwise enter the error state and return the error code from the 
-**   failing operation.
-**
-**   In this case the database file may have been written to. So if the
-**   playback operation did not succeed it would not be safe to finalize
-**   the journal file. It needs to be left in the file-system so that
-**   some other process can use it to restore the database state (by
-**   hot-journal rollback).
+** Finalization of the journal file (task 2) is only performed if the 
+** rollback is successful.
+**
+** In WAL mode, all cache-entries containing data modified within the
+** current transaction are either expelled from the cache or reverted to
+** their pre-transaction state by re-reading data from the database or
+** WAL files. The WAL transaction is then closed.
 */
 int sqlite3PagerRollback(Pager *pPager){
   int rc = SQLITE_OK;                  /* Return code */
@@ -5849,11 +5826,12 @@ int sqlite3PagerRollback(Pager *pPager){
     rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, -1);
     rc2 = pager_end_transaction(pPager, pPager->setMaster);
     if( rc==SQLITE_OK ) rc = rc2;
-  }else if( !isOpen(pPager->jfd) ){
+  }else if( !isOpen(pPager->jfd) || pPager->eState==PAGER_WRITER_LOCKED ){
     rc = pager_end_transaction(pPager, 0);
   }else{
     rc = pager_playback(pPager, 0);
   }
+
   assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK );
   assert( rc==SQLITE_OK || rc==SQLITE_FULL || (rc&0xFF)==SQLITE_IOERR );
 
index be8c466428826b711f1a1866da3803dd079a391d..57d8e462df077401d8abab3f029594e772657a92 100644 (file)
--- a/src/wal.c
+++ b/src/wal.c
@@ -2044,6 +2044,7 @@ int sqlite3WalBeginReadTransaction(Wal *pWal, int *pChanged){
 ** read-lock.
 */
 void sqlite3WalEndReadTransaction(Wal *pWal){
+  sqlite3WalEndWriteTransaction(pWal);
   if( pWal->readLock>=0 ){
     walUnlockShared(pWal, WAL_READ_LOCK(pWal->readLock));
     pWal->readLock = -1;
index 1a54277418c9411d01338b2d01a4874e9447298e..2506c90e1e4624b7bc09be71e7c1c67134dfeff4 100644 (file)
@@ -377,4 +377,11 @@ sqlite3 db2 test.db2
 do_test walmode-8.19 { execsql { PRAGMA main.journal_mode } db2 }  {wal}
 db2 close
 
+do_execsql_test walmode-8.20 { PRAGMA journal_mode = DELETE } {delete}
+do_execsql_test walmode-8.21 { PRAGMA main.journal_mode }     {delete}
+do_execsql_test walmode-8.22 { PRAGMA two.journal_mode }      {delete}
+do_execsql_test walmode-8.21 { PRAGMA journal_mode = WAL }    {wal}
+do_execsql_test walmode-8.21 { PRAGMA main.journal_mode }     {wal}
+do_execsql_test walmode-8.22 { PRAGMA two.journal_mode }      {wal}
+
 finish_test