SQLite

Check-in [3ec976e015]
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
Timelines: family | ancestors | descendants | both | apple-osx
Files: files | file ages | folders
SHA3-256: 3ec976e01550d7fb4fb76cc4896c13c86f66a141060f5fe59319434dc6119116
User & Date: dan 2017-11-28 13:48:42.669
Context
2017-11-30
07:56
Merge latest trunk changes, including the fixes for test file walprotocol.test. (check-in: b425b99811 user: dan tags: apple-osx)
2017-11-28
13:48
Merge the snapshots-always-lock-the-wal-file change into this branch. (check-in: 3ec976e015 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: b81a31495b user: dan tags: trunk)
08:08
Merge latest trunk changes, including the SQLITE_ENABLE_MULTITHREADED_CHECKS feature, into this branch. (check-in: 1fd1034935 user: dan tags: apple-osx)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/wal.c.
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
  }

  assert( pWal->nWiData>0 );
  assert( pWal->apWiData[0]!=0 );
  pInfo = walCkptInfo(pWal);
  if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame
#ifdef SQLITE_ENABLE_SNAPSHOT
   && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0
     || 0==memcmp(&pWal->hdr, pWal->pSnapshot, sizeof(WalIndexHdr)))
#endif
  ){
    /* The WAL has been completely backfilled (or it is empty).
    ** and can be safely ignored.
    */
    rc = walLockShared(pWal, WAL_READ_LOCK(0));
    walShmBarrier(pWal);







|
<







2498
2499
2500
2501
2502
2503
2504
2505

2506
2507
2508
2509
2510
2511
2512
  }

  assert( pWal->nWiData>0 );
  assert( pWal->apWiData[0]!=0 );
  pInfo = walCkptInfo(pWal);
  if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame
#ifdef SQLITE_ENABLE_SNAPSHOT
   && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0)

#endif
  ){
    /* The WAL has been completely backfilled (or it is empty).
    ** and can be safely ignored.
    */
    rc = walLockShared(pWal, WAL_READ_LOCK(0));
    walShmBarrier(pWal);
Added test/snapshot3.test.








































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# 2016 September 23
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The focus
# of this file is the sqlite3_snapshot_xxx() APIs.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
ifcapable !snapshot {finish_test; return}
set testprefix snapshot3

# This test does not work with the inmemory_journal permutation. The reason
# is that each connection opened as part of this permutation executes
# "PRAGMA journal_mode=memory", which fails if the database is in wal mode
# and there are one or more existing connections.
if {[permutation]=="inmemory_journal"} {
  finish_test
  return
}

#-------------------------------------------------------------------------
# This block of tests verifies that it is not possible to wrap the wal
# file - using a writer or a "PRAGMA wal_checkpoint = TRUNCATE" - while
# there is an open snapshot transaction (transaction opened using
# sqlite3_snapshot_open()).
#
do_execsql_test 1.0 {
  CREATE TABLE t1(y);
  PRAGMA journal_mode = wal;
  INSERT INTO t1 VALUES(1);
  INSERT INTO t1 VALUES(2);
  INSERT INTO t1 VALUES(3);
  INSERT INTO t1 VALUES(4);
} {wal}

do_test 1.1 {
  sqlite3 db2 test.db
  sqlite3 db3 test.db

  execsql {SELECT * FROM sqlite_master} db2
  execsql {SELECT * FROM sqlite_master} db3

  db2 trans { set snap [sqlite3_snapshot_get_blob db2 main] }
  db2 eval { SELECT * FROM t1 }
} {1 2 3 4}

do_test 1.2 {
  execsql BEGIN db2
  sqlite3_snapshot_open_blob db2 main $snap
  db2 eval { SELECT * FROM t1 }
} {1 2 3 4}

do_test 1.2 {
  execsql END db2
  execsql { PRAGMA wal_checkpoint }

  execsql BEGIN db2
  sqlite3_snapshot_open_blob db2 main $snap
  db2 eval { SELECT * FROM t1 }
} {1 2 3 4}

set sz [file size test.db-wal]
do_test 1.3 {
  execsql { PRAGMA wal_checkpoint = truncate }
  file size test.db-wal
} $sz

do_test 1.4 {
  execsql BEGIN db3
  list [catch { sqlite3_snapshot_open_blob db3 main $snap } msg] $msg
} {0 {}}

do_test 1.5 {
  db3 eval { SELECT * FROM t1; END }
} {1 2 3 4}

do_test 1.6 {
  db2 eval { SELECT * FROM t1; END }
} {1 2 3 4}

do_test 1.7 {
  execsql { PRAGMA wal_checkpoint = truncate }
  file size test.db-wal
} 0

do_test 1.8 {
  execsql BEGIN db3
  list [catch { sqlite3_snapshot_open_blob db3 main $snap } msg] $msg
} {1 SQLITE_BUSY_SNAPSHOT}

finish_test