/ Check-in [3ec976e0]
Login

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

Overview
Comment:Merge the snapshots-always-lock-the-wal-file change into this branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | apple-osx
Files: files | file ages | folders
SHA3-256: 3ec976e01550d7fb4fb76cc4896c13c86f66a141060f5fe59319434dc6119116
User & Date: dan 2017-11-28 13:48:42
Context
2017-11-30
07:56
Merge latest trunk changes, including the fixes for test file walprotocol.test. check-in: b425b998 user: dan tags: apple-osx
2017-11-28
13:48
Merge the snapshots-always-lock-the-wal-file change into this branch. check-in: 3ec976e0 user: dan tags: apple-osx
13:39
Lock the wal file for all snapshot transactions, even if they would not otherwise require this, preventing checkpointers and writers from wrapping the wal file. This means that if one connection has an open snapshot transaction it is guaranteed that a second connection can open a transaction on the same snapshot. check-in: b81a3149 user: dan tags: trunk
08:08
Merge latest trunk changes, including the SQLITE_ENABLE_MULTITHREADED_CHECKS feature, into this branch. check-in: 1fd10349 user: dan tags: apple-osx
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/wal.c.

  2498   2498     }
  2499   2499   
  2500   2500     assert( pWal->nWiData>0 );
  2501   2501     assert( pWal->apWiData[0]!=0 );
  2502   2502     pInfo = walCkptInfo(pWal);
  2503   2503     if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame
  2504   2504   #ifdef SQLITE_ENABLE_SNAPSHOT
  2505         -   && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0
  2506         -     || 0==memcmp(&pWal->hdr, pWal->pSnapshot, sizeof(WalIndexHdr)))
         2505  +   && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0)
  2507   2506   #endif
  2508   2507     ){
  2509   2508       /* The WAL has been completely backfilled (or it is empty).
  2510   2509       ** and can be safely ignored.
  2511   2510       */
  2512   2511       rc = walLockShared(pWal, WAL_READ_LOCK(0));
  2513   2512       walShmBarrier(pWal);

Added test/snapshot3.test.

            1  +# 2016 September 23
            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 focus
           12  +# of this file is the sqlite3_snapshot_xxx() APIs.
           13  +#
           14  +
           15  +set testdir [file dirname $argv0]
           16  +source $testdir/tester.tcl
           17  +ifcapable !snapshot {finish_test; return}
           18  +set testprefix snapshot3
           19  +
           20  +# This test does not work with the inmemory_journal permutation. The reason
           21  +# is that each connection opened as part of this permutation executes
           22  +# "PRAGMA journal_mode=memory", which fails if the database is in wal mode
           23  +# and there are one or more existing connections.
           24  +if {[permutation]=="inmemory_journal"} {
           25  +  finish_test
           26  +  return
           27  +}
           28  +
           29  +#-------------------------------------------------------------------------
           30  +# This block of tests verifies that it is not possible to wrap the wal
           31  +# file - using a writer or a "PRAGMA wal_checkpoint = TRUNCATE" - while
           32  +# there is an open snapshot transaction (transaction opened using
           33  +# sqlite3_snapshot_open()).
           34  +#
           35  +do_execsql_test 1.0 {
           36  +  CREATE TABLE t1(y);
           37  +  PRAGMA journal_mode = wal;
           38  +  INSERT INTO t1 VALUES(1);
           39  +  INSERT INTO t1 VALUES(2);
           40  +  INSERT INTO t1 VALUES(3);
           41  +  INSERT INTO t1 VALUES(4);
           42  +} {wal}
           43  +
           44  +do_test 1.1 {
           45  +  sqlite3 db2 test.db
           46  +  sqlite3 db3 test.db
           47  +
           48  +  execsql {SELECT * FROM sqlite_master} db2
           49  +  execsql {SELECT * FROM sqlite_master} db3
           50  +
           51  +  db2 trans { set snap [sqlite3_snapshot_get_blob db2 main] }
           52  +  db2 eval { SELECT * FROM t1 }
           53  +} {1 2 3 4}
           54  +
           55  +do_test 1.2 {
           56  +  execsql BEGIN db2
           57  +  sqlite3_snapshot_open_blob db2 main $snap
           58  +  db2 eval { SELECT * FROM t1 }
           59  +} {1 2 3 4}
           60  +
           61  +do_test 1.2 {
           62  +  execsql END db2
           63  +  execsql { PRAGMA wal_checkpoint }
           64  +
           65  +  execsql BEGIN db2
           66  +  sqlite3_snapshot_open_blob db2 main $snap
           67  +  db2 eval { SELECT * FROM t1 }
           68  +} {1 2 3 4}
           69  +
           70  +set sz [file size test.db-wal]
           71  +do_test 1.3 {
           72  +  execsql { PRAGMA wal_checkpoint = truncate }
           73  +  file size test.db-wal
           74  +} $sz
           75  +
           76  +do_test 1.4 {
           77  +  execsql BEGIN db3
           78  +  list [catch { sqlite3_snapshot_open_blob db3 main $snap } msg] $msg
           79  +} {0 {}}
           80  +
           81  +do_test 1.5 {
           82  +  db3 eval { SELECT * FROM t1; END }
           83  +} {1 2 3 4}
           84  +
           85  +do_test 1.6 {
           86  +  db2 eval { SELECT * FROM t1; END }
           87  +} {1 2 3 4}
           88  +
           89  +do_test 1.7 {
           90  +  execsql { PRAGMA wal_checkpoint = truncate }
           91  +  file size test.db-wal
           92  +} 0
           93  +
           94  +do_test 1.8 {
           95  +  execsql BEGIN db3
           96  +  list [catch { sqlite3_snapshot_open_blob db3 main $snap } msg] $msg
           97  +} {1 SQLITE_BUSY_SNAPSHOT}
           98  +
           99  +finish_test
          100  +