/ Check-in [a6716fcd]
Login

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

Overview
Comment:Add further tests for the code added on this branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | readonly-wal-recovery
Files: files | file ages | folders
SHA3-256: a6716fcde38b28b8a03b40f9d16f78a57ec20f60cf391ff553692641cb7f0d3f
User & Date: dan 2017-11-04 21:06:35
Context
2017-11-06
19:49
Add further test cases for the new code on this branch. And a couple of fixes. check-in: 71af9acb user: dan tags: readonly-wal-recovery
2017-11-04
21:06
Add further tests for the code added on this branch. check-in: a6716fcd user: dan tags: readonly-wal-recovery
18:10
In cases where a readonly_shm client cannot take the DMS lock on the *-shm file, have it parse the wal file and create a wal-index to access it in heap memory. check-in: 18b26843 user: dan tags: readonly-wal-recovery
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/wal.c.

  2249   2249     aFrame = (u8 *)sqlite3_malloc64(szFrame);
  2250   2250     if( aFrame==0 ){
  2251   2251       rc = SQLITE_NOMEM_BKPT;
  2252   2252       goto begin_unlocked_out;
  2253   2253     }
  2254   2254     aData = &aFrame[WAL_FRAME_HDRSIZE];
  2255   2255   
         2256  +  /* Check to see if a complete transaction has been appended to the
         2257  +  ** wal file since the heap-memory wal-index was created. If so, the
         2258  +  ** heap-memory wal-index is discarded and WAL_RETRY returned to
         2259  +  ** the caller.  */
  2256   2260     aSaveCksum[0] = pWal->hdr.aFrameCksum[0];
  2257   2261     aSaveCksum[1] = pWal->hdr.aFrameCksum[1];
  2258   2262     for(iOffset=walFrameOffset(pWal->hdr.mxFrame+1, pWal->hdr.szPage); 
  2259   2263         iOffset+szFrame<=szWal; 
  2260   2264         iOffset+=szFrame
  2261   2265     ){
  2262   2266       u32 pgno;                   /* Database page number for frame */
................................................................................
  2272   2276           ** So retry opening this read transaction.  */
  2273   2277           rc = WAL_RETRY;
  2274   2278         }
  2275   2279         break;
  2276   2280       }
  2277   2281       if( !walDecodeFrame(pWal, &pgno, &nTruncate, aData, aFrame) ) break;
  2278   2282   
  2279         -    /* If nTruncate is non-zero, this is a commit record. */
         2283  +    /* If nTruncate is non-zero, then a complete transaction has been
         2284  +    ** appended to this wal file. Set rc to WAL_RETRY and break out of
         2285  +    ** the loop.  */
  2280   2286       if( nTruncate ){
  2281   2287         rc = WAL_RETRY;
  2282   2288         break;
  2283   2289       }
  2284   2290     }
  2285   2291     pWal->hdr.aFrameCksum[0] = aSaveCksum[0];
  2286   2292     pWal->hdr.aFrameCksum[1] = aSaveCksum[1];

Changes to test/walro2.test.

    11     11   #
    12     12   # This file contains tests for using WAL databases in read-only mode.
    13     13   #
    14     14   
    15     15   set testdir [file dirname $argv0]
    16     16   source $testdir/tester.tcl
    17     17   source $testdir/lock_common.tcl
    18         -set ::testprefix walro
           18  +source $testdir/wal_common.tcl
           19  +set ::testprefix walro2
    19     20   
    20     21   # These tests are only going to work on unix.
    21     22   #
    22     23   if {$::tcl_platform(platform) != "unix"} {
    23     24     finish_test
    24     25     return
    25     26   }
................................................................................
   116    117       sql3 { SELECT * FROM t1 }
   117    118     } {a b c d e f g h}
   118    119     do_test 2.3.2 {
   119    120       sql3 { INSERT INTO t1 VALUES('i', 'j') }
   120    121       code3 { db3 close }
   121    122       sql1 { COMMIT } 
   122    123     } {}
   123         -  breakpoint
   124    124     do_test 2.3.3 {
   125    125       sql1 { SELECT * FROM t1 }
   126    126     } {a b c d e f g h i j}
          127  +
          128  +
          129  +  #-----------------------------------------------------------------------
          130  +  # 3.1.*: That a readonly_shm connection can read a database file if both
          131  +  #        the *-wal and *-shm files are zero bytes in size.
          132  +  #
          133  +  # 3.2.*: That it flushes the cache if, between transactions on a db with a
          134  +  #        zero byte *-wal file, some other connection modifies the db, then
          135  +  #        does "PRAGMA wal_checkpoint=truncate" to truncate the wal file
          136  +  #        back to zero bytes in size.
          137  +  #
          138  +  # 3.3.*: That, if between transactions some other process wraps the wal
          139  +  #        file, the readonly_shm client reruns recovery.
          140  +  #
          141  +  catch { code1 { db close } }
          142  +  catch { code2 { db2 close } }
          143  +  catch { code3 { db3 close } }
          144  +  do_test 3.1.0 {
          145  +    list [file exists test.db-wal] [file exists test.db-shm]
          146  +  } {0 0}
          147  +  do_test 3.1.1 {
          148  +    close [open test.db-wal w]
          149  +    close [open test.db-shm w]
          150  +    code1 {
          151  +      sqlite3 db file:test.db?readonly_shm=1
          152  +    }
          153  +    sql1 { SELECT * FROM t1 }
          154  +  } {a b c d e f g h}
          155  +
          156  +  do_test 3.2.0 {
          157  +    list [file size test.db-wal] [file size test.db-shm]
          158  +  } {0 0}
          159  +  do_test 3.2.1 {
          160  +    code2 { sqlite3 db2 test.db }
          161  +    sql2 { INSERT INTO t1 VALUES(1, 2) ; PRAGMA wal_checkpoint=truncate }
          162  +    code2 { db2 close }
          163  +    sql1 { SELECT * FROM t1 }
          164  +  } {a b c d e f g h 1 2}
          165  +  do_test 3.2.2 {
          166  +    list [file size test.db-wal] [file size test.db-shm]
          167  +  } {0 32768}
          168  +
          169  +  do_test 3.3.0 {
          170  +    code2 { sqlite3 db2 test.db }
          171  +    sql2 { 
          172  +      INSERT INTO t1 VALUES(3, 4);
          173  +      INSERT INTO t1 VALUES(5, 6);
          174  +      INSERT INTO t1 VALUES(7, 8);
          175  +      INSERT INTO t1 VALUES(9, 10);
          176  +    }
          177  +    code2 { db2 close }
          178  +    code1 { db close }
          179  +    list [file size test.db-wal] [file size test.db-shm]
          180  +  } [list [wal_file_size 4 1024] 32768]
          181  +  do_test 3.3.1 {
          182  +    code1 { sqlite3 db file:test.db?readonly_shm=1 }
          183  +    sql1 { SELECT * FROM t1 }
          184  +  } {a b c d e f g h 1 2 3 4 5 6 7 8 9 10}
          185  +  do_test 3.3.2 {
          186  +    code2 { sqlite3 db2 test.db }
          187  +    sql2 { 
          188  +      PRAGMA wal_checkpoint; 
          189  +      DELETE FROM t1;
          190  +      INSERT INTO t1 VALUES('i', 'ii');
          191  +    }
          192  +    code2 { db2 close }
          193  +    list [file size test.db-wal] [file size test.db-shm]
          194  +  } [list [wal_file_size 4 1024] 32768]
          195  +  do_test 3.3.3 {
          196  +    sql1 { SELECT * FROM t1 }
          197  +  } {i ii}
          198  +
   127    199   }
   128    200   
   129    201   finish_test