/ Check-in [34f56f8a]
Login

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

Overview
Comment:Add tests cases for recovery in wal2 mode.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wal2
Files: files | file ages | folders
SHA3-256: 34f56f8a4239781071edf6317723d0a7333249551c2c1ce7ed39fc116d53d780
User & Date: dan 2018-12-13 16:26:43
Wiki:wal2
Context
2018-12-14
19:53
Add further tests for wal2 mode. check-in: 54e628f9 user: dan tags: wal2
2018-12-13
16:26
Add tests cases for recovery in wal2 mode. check-in: 34f56f8a user: dan tags: wal2
2018-12-12
20:39
Add new test file wal2big.test. check-in: e3e50bcd user: dan tags: wal2
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/wal.c.

  1652   1652     if( rc==SQLITE_OK ){
  1653   1653       volatile WalCkptInfo *pInfo;
  1654   1654   
  1655   1655       if( isOpen(pWal->apWalFd[1]) ){
  1656   1656         /* The case where *-wal2 may follow *-wal */
  1657   1657         if( nCkpt2<=0x0F && nCkpt2==nCkpt1+1 ){
  1658   1658           if( sqlite3Get4byte((u8*)(&pWal->hdr.aSalt[0]))==hdr.aFrameCksum[0]
  1659         -            && sqlite3Get4byte((u8*)(&pWal->hdr.aSalt[1]))==hdr.aFrameCksum[1]
  1660         -          ){
         1659  +         && sqlite3Get4byte((u8*)(&pWal->hdr.aSalt[1]))==hdr.aFrameCksum[1]
         1660  +        ){
  1661   1661             walidxSetFile(&pWal->hdr, 1);
  1662   1662             walidxSetMxFrame(&pWal->hdr, 1, pWal->hdr.mxFrame);
  1663   1663             walidxSetMxFrame(&pWal->hdr, 0, hdr.mxFrame);
  1664   1664           }else{
  1665   1665             pWal->hdr = hdr;
  1666   1666           }
  1667   1667         }else
................................................................................
  1711   1711       /* If more than one frame was recovered from the log file, report an
  1712   1712       ** event via sqlite3_log(). This is to help with identifying performance
  1713   1713       ** problems caused by applications routinely shutting down without
  1714   1714       ** checkpointing the log file.  */
  1715   1715       if( pWal->hdr.nPage ){
  1716   1716         if( isWalMode2(pWal) ){
  1717   1717           sqlite3_log(SQLITE_NOTICE_RECOVER_WAL,
  1718         -            "recovered (%d,%d) frames from WAL files %s[2] (%s mode)",
         1718  +            "recovered (%d,%d) frames from WAL files %s[2] (wal2 mode)",
  1719   1719               walidxGetMxFrame(&pWal->hdr, 0), walidxGetMxFrame(&pWal->hdr, 1), 
  1720         -            pWal->zWalName, isWalMode2(pWal) ? "wal2" : "wal"
         1720  +            pWal->zWalName
  1721   1721           );
  1722   1722         }else{
  1723   1723           sqlite3_log(SQLITE_NOTICE_RECOVER_WAL,
  1724   1724               "recovered %d frames from WAL file %s",
  1725   1725               pWal->hdr.mxFrame, pWal->zWalName
  1726   1726           );
  1727   1727         }

Changes to test/wal2big.test.

    39     39   do_execsql_test 1.1 {
    40     40     WITH s(i) AS (
    41     41       SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<200000
    42     42     )
    43     43     INSERT INTO t1 SELECT random(), random(), random() FROM s;
    44     44   }
    45     45   
    46         -do_test 1.1 {
           46  +do_test 1.2 {
    47     47     list [expr [file size test.db-wal]>10000000] \
    48     48          [expr [file size test.db-wal2]>10000000]
    49     49   } {1 1}
    50     50   
    51         -do_test 1.2 {
           51  +do_test 1.3 {
    52     52     sqlite3 db2 test.db
    53     53     execsql {
    54     54       SELECT count(*) FROM t1;
    55     55       PRAGMA integrity_check;
    56     56     } db2
    57     57   } {400000 ok}
           58  +
           59  +do_test 1.4 {
           60  +  db2 close
           61  +  forcecopy test.db test.db2
           62  +  forcecopy test.db-wal test.db2-wal
           63  +  forcecopy test.db-wal2 test.db2-wal2
           64  +  sqlite3 db2 test.db2
           65  +  execsql {
           66  +    SELECT count(*) FROM t1;
           67  +    PRAGMA integrity_check;
           68  +  }
           69  +} {400000 ok}
    58     70   
    59     71   finish_test

Added test/wal2recover.test.

            1  +# 2018 December 13
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this file is testing the operation of the library in
           13  +# "PRAGMA journal_mode=WAL2" mode.
           14  +#
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +source $testdir/lock_common.tcl
           19  +source $testdir/malloc_common.tcl
           20  +source $testdir/wal_common.tcl
           21  +
           22  +set testprefix wal2recover
           23  +ifcapable !wal {finish_test ; return }
           24  +
           25  +proc db_copy {from to} {
           26  +  forcecopy $from $to
           27  +  forcecopy ${from}-wal ${to}-wal
           28  +  forcecopy ${from}-wal2 ${to}-wal2
           29  +}
           30  +
           31  +do_execsql_test 1.0 {
           32  +  CREATE TABLE t1(a, b, c);
           33  +  CREATE INDEX t1a ON t1(a);
           34  +  CREATE INDEX t1b ON t1(b);
           35  +  CREATE INDEX t1c ON t1(c);
           36  +  PRAGMA journal_mode = wal2;
           37  +  PRAGMA journal_size_limit = 15000;
           38  +  PRAGMA wal_autocheckpoint = 0;
           39  +} {wal2 15000 0}
           40  +
           41  +do_test 1.1 {
           42  +  for {set i 1} {$i <= 1000} {incr i} {
           43  +    execsql { INSERT INTO t1 VALUES(random(), random(), random()) }
           44  +    db_copy test.db test.db2
           45  +    sqlite3 db2 test.db
           46  +    set res [execsql {
           47  +      SELECT count(*) FROM t1;
           48  +      PRAGMA integrity_check;
           49  +    } db2]
           50  +    db2 close
           51  +    if {$res != [list $i ok]} {
           52  +      error "failure on iteration $i"
           53  +    }
           54  +  }
           55  +  set {} {}
           56  +} {}
           57  +
           58  +#--------------------------------------------------------------------------
           59  +reset_db
           60  +do_execsql_test 2.0 {
           61  +  CREATE TABLE t1(x UNIQUE);
           62  +  CREATE TABLE t2(x UNIQUE);
           63  +  PRAGMA journal_mode = wal2;
           64  +  PRAGMA journal_size_limit = 10000;
           65  +  PRAGMA wal_autocheckpoint = 0;
           66  +  BEGIN;
           67  +    INSERT INTO t1 VALUES(randomblob(4000));
           68  +    INSERT INTO t1 VALUES(randomblob(4000));
           69  +    INSERT INTO t1 VALUES(randomblob(4000));
           70  +  COMMIT;
           71  +  BEGIN;
           72  +    INSERT INTO t2 VALUES(randomblob(4000));
           73  +    INSERT INTO t2 VALUES(randomblob(4000));
           74  +    INSERT INTO t2 VALUES(randomblob(4000));
           75  +  COMMIT;
           76  +} {wal2 10000 0}
           77  +do_test 2.0.1 {
           78  +  list [file size test.db] [file size test.db-wal] [file size test.db-wal2]
           79  +} {5120 28328 28328}
           80  +
           81  +# Test recovery with both wal files intact.
           82  +#
           83  +do_test 2.1 {
           84  +  db_copy test.db test.db2
           85  +  sqlite3 db2 test.db2
           86  +  execsql {
           87  +    SELECT count(*) FROM t1;
           88  +    SELECT count(*) FROM t2;
           89  +    PRAGMA integrity_check;
           90  +  } db2
           91  +} {3 3 ok}
           92  +
           93  +do_test 2.2 {
           94  +  db2 close
           95  +  db_copy test.db test.db2
           96  +  hexio_write test.db2-wal 16 12345678
           97  +  sqlite3 db2 test.db2
           98  +  execsql {
           99  +    SELECT count(*) FROM t1;
          100  +    SELECT count(*) FROM t2;
          101  +  } db2
          102  +} {0 3}
          103  +
          104  +do_test 2.3 {
          105  +  db2 close
          106  +  db_copy test.db test.db2
          107  +  hexio_write test.db2-wal2 16 12345678
          108  +  sqlite3 db2 test.db2
          109  +  execsql {
          110  +    SELECT count(*) FROM t1;
          111  +    SELECT count(*) FROM t2;
          112  +    PRAGMA integrity_check;
          113  +  } db2
          114  +} {3 0 ok}
          115  +
          116  +do_test 2.4 {
          117  +  db2 close
          118  +  db_copy test.db test.db2
          119  +  forcecopy test.db-wal test.db2-wal2
          120  +  sqlite3 db2 test.db2
          121  +  execsql {
          122  +    SELECT count(*) FROM t1;
          123  +    SELECT count(*) FROM t2;
          124  +    PRAGMA integrity_check;
          125  +  } db2
          126  +} {3 0 ok}
          127  +
          128  +do_test 2.5 {
          129  +  db2 close
          130  +  db_copy test.db test.db2
          131  +  forcecopy test.db-wal  test.db2-wal2
          132  +  forcecopy test.db-wal2  test.db2-wal
          133  +  sqlite3 db2 test.db2
          134  +  execsql {
          135  +    SELECT count(*) FROM t1;
          136  +    SELECT count(*) FROM t2;
          137  +    PRAGMA integrity_check;
          138  +  } db2
          139  +} {3 3 ok}
          140  +
          141  +do_test 2.6 {
          142  +  db2 close
          143  +  db_copy test.db test.db2
          144  +  forcecopy test.db-wal test.db2-wal2
          145  +  close [open test.db-wal w]
          146  +  sqlite3 db2 test.db2
          147  +  execsql {
          148  +    SELECT count(*) FROM t1;
          149  +    SELECT count(*) FROM t2;
          150  +    PRAGMA integrity_check;
          151  +  } db2
          152  +} {3 0 ok}
          153  +
          154  +do_test 2.7 {
          155  +  db2 close
          156  +  db_copy test.db test.db2
          157  +  forcedelete test.db2-wal
          158  +  sqlite3 db2 test.db2
          159  +  execsql {
          160  +    SELECT count(*) FROM t1;
          161  +    SELECT count(*) FROM t2;
          162  +    PRAGMA integrity_check;
          163  +  } db2
          164  +} {0 0 ok}
          165  +
          166  +finish_test
          167  +