/ Check-in [35e6ac18]
Login

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

Overview
Comment:When copying a rollback mode database over a WAL database using the backup API, leave the destination database in WAL mode (instead of switching it to rollback mode). Fix for [af95b8c609].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 35e6ac18e3d030095da57fff87a288939e9be93f
User & Date: dan 2011-08-23 11:47:06
Context
2011-08-23
12:50
Merge the PAGECACHE_BLOCKALLOC changes into trunk. check-in: 768c1846 user: drh tags: trunk
11:47
When copying a rollback mode database over a WAL database using the backup API, leave the destination database in WAL mode (instead of switching it to rollback mode). Fix for [af95b8c609]. check-in: 35e6ac18 user: dan tags: trunk
00:01
Remove a branch that is always true. check-in: a6568192 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/backup.c.

   414    414        && (rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1))==SQLITE_OK
   415    415       ){
   416    416         int nDestTruncate;
   417    417     
   418    418         if( p->pDestDb ){
   419    419           sqlite3ResetInternalSchema(p->pDestDb, -1);
   420    420         }
          421  +
          422  +      if( destMode==PAGER_JOURNALMODE_WAL ){
          423  +        /* This call cannot fail. The success of the BtreeUpdateMeta() 
          424  +        ** method above indicates that a write transaction has been opened 
          425  +        ** and page 1 is already dirty. Therefore this always succeeds.
          426  +        */
          427  +        TESTONLY(int rc2 =) sqlite3BtreeSetVersion(p->pDest, 2);
          428  +        assert( rc2==SQLITE_OK );
          429  +      }
   421    430   
   422    431         /* Set nDestTruncate to the final number of pages in the destination
   423    432         ** database. The complication here is that the destination page
   424    433         ** size may be different to the source page size. 
   425    434         **
   426    435         ** If the source page size is smaller than the destination page size, 
   427    436         ** round up. In this case the call to sqlite3OsTruncate() below will

Changes to src/btree.c.

  8145   8145   ** "write version" (single byte at byte offset 19) fields in the database
  8146   8146   ** header to iVersion.
  8147   8147   */
  8148   8148   int sqlite3BtreeSetVersion(Btree *pBtree, int iVersion){
  8149   8149     BtShared *pBt = pBtree->pBt;
  8150   8150     int rc;                         /* Return code */
  8151   8151    
  8152         -  assert( pBtree->inTrans==TRANS_NONE );
  8153   8152     assert( iVersion==1 || iVersion==2 );
  8154   8153   
  8155   8154     /* If setting the version fields to 1, do not automatically open the
  8156   8155     ** WAL connection, even if the version fields are currently set to 2.
  8157   8156     */
  8158   8157     pBt->doNotUseWAL = (u8)(iVersion==1);
  8159   8158   

Changes to test/walbak.test.

    75     75   do_test walbak-1.5 {
    76     76     list [file size test.db] [file size test.db-wal]
    77     77   } [list 1024 [wal_file_size 6 1024]]
    78     78   do_test walbak-1.6 {
    79     79     execsql { PRAGMA wal_checkpoint }
    80     80     list [file size test.db] [file size test.db-wal]
    81     81   } [list [expr 3*1024] [wal_file_size 6 1024]]
           82  +do_test walbak-1.6.1 {
           83  +  hexio_read test.db 18 2
           84  +} {0202}
    82     85   do_test walbak-1.7 {
    83     86     execsql { 
    84     87       CREATE TABLE t2(a, b);
    85     88       INSERT INTO t2 SELECT * FROM t1;
    86     89       DROP TABLE t1;
    87     90     }
    88     91     list [file size test.db] [file size test.db-wal]
................................................................................
   266    269   
   267    270     do_test walbak-3.$tn.4 {
   268    271       sqlite3_backup B db main db2 main
   269    272       B step 10000
   270    273       B finish
   271    274       execsql { SELECT * FROM t1 }
   272    275     } {1 2 3 4 5 6 7 8}
          276  +
          277  +  # Check that [db] is still in WAL mode.
          278  +  do_test walbak-3.$tn.5 {
          279  +    execsql { PRAGMA journal_mode }
          280  +  } {wal}
          281  +  do_test walbak-3.$tn.6 {
          282  +    execsql { PRAGMA wal_checkpoint }
          283  +    hexio_read test.db 18 2
          284  +  } {0202}
          285  +
          286  +  # If it was not an in-memory database, check that [db2] is still in
          287  +  # rollback mode.
          288  +  if {[file exists test.db2]} {
          289  +    do_test walbak-3.$tn.7 {
          290  +      execsql { PRAGMA journal_mode } db2
          291  +    } {wal}
          292  +    do_test walbak-3.$tn.8 {
          293  +      execsql { PRAGMA wal_checkpoint }
          294  +      hexio_read test.db 18 2
          295  +    } {0202}
          296  +  }
   273    297   
   274    298     db  close
   275    299     db2 close
   276    300   }
          301  +
          302  +#-------------------------------------------------------------------------
          303  +# Test that the following holds when a backup operation is run:
          304  +#
          305  +#   Source  |  Destination inital  |  Destination final
          306  +#   ---------------------------------------------------
          307  +#   Rollback   Rollback               Rollback
          308  +#   Rollback   WAL                    WAL
          309  +#   WAL        Rollback               WAL
          310  +#   WAL        WAL                    WAL
          311  +#
          312  +foreach {tn src dest dest_final} {
          313  +  1   delete    delete    delete
          314  +  2   delete    wal       wal
          315  +  3   wal       delete    wal
          316  +  4   wal       wal       wal
          317  +} {
          318  +  catch { db close } 
          319  +  catch { db2 close } 
          320  +  forcedelete test.db test.db2
          321  +
          322  +  do_test walbak-4.$tn.1 {
          323  +    sqlite3 db test.db
          324  +    db eval "PRAGMA journal_mode = $src"
          325  +    db eval {
          326  +      CREATE TABLE t1(a, b);
          327  +      INSERT INTO t1 VALUES('I', 'II');
          328  +      INSERT INTO t1 VALUES('III', 'IV');
          329  +    }
          330  +
          331  +    sqlite3 db2 test.db2
          332  +    db2 eval "PRAGMA journal_mode = $dest"
          333  +    db2 eval {
          334  +      CREATE TABLE t2(x, y);
          335  +      INSERT INTO t2 VALUES('1', '2');
          336  +      INSERT INTO t2 VALUES('3', '4');
          337  +    }
          338  +  } {}
          339  +
          340  +  do_test walbak-4.$tn.2 { execsql { PRAGMA journal_mode } db  } $src
          341  +  do_test walbak-4.$tn.3 { execsql { PRAGMA journal_mode } db2 } $dest
          342  +
          343  +  do_test walbak-4.$tn.4 { db backup test.db2 } {}
          344  +  do_test walbak-4.$tn.5 {
          345  +    execsql { SELECT * FROM t1 } db2
          346  +  } {I II III IV}
          347  +  do_test walbak-4.$tn.5 { execsql { PRAGMA journal_mode } db2 } $dest_final
          348  +
          349  +
          350  +  db2 close
          351  +  do_test walbak-4.$tn.6 { file exists test.db2-wal } 0
          352  +  sqlite3 db2 test.db2
          353  +  do_test walbak-4.$tn.7 { execsql { PRAGMA journal_mode } db2 } $dest_final
          354  +}
   277    355   
   278    356   
   279    357   finish_test