Merge in changes that cause the first sector of the WAL file to be synced

when the WAL restarts.  This is a fix for the power-loss corruption
problem described in ticket [ff5be73dee086]

FossilOrigin-Name: 44ca4d123385d759c11919865525c998c2e35bdb
This commit is contained in:
drh
2011-12-17 13:45:28 +00:00
7 changed files with 140 additions and 54 deletions
+29 -21
View File
@@ -1176,9 +1176,9 @@ if {$::tcl_platform(platform) == "unix"} {
# Test that "PRAGMA checkpoint_fullsync" appears to be working.
#
foreach {tn sql reslist} {
1 { } {8 0 3 0 5 0}
2 { PRAGMA checkpoint_fullfsync = 1 } {8 4 3 2 5 2}
3 { PRAGMA checkpoint_fullfsync = 0 } {8 0 3 0 5 0}
1 { } {10 0 4 0 6 0}
2 { PRAGMA checkpoint_fullfsync = 1 } {10 4 4 2 6 2}
3 { PRAGMA checkpoint_fullfsync = 0 } {10 0 4 0 6 0}
} {
faultsim_delete_and_reopen
@@ -1192,12 +1192,12 @@ foreach {tn sql reslist} {
do_execsql_test wal2-14.$tn.2 {
PRAGMA wal_autocheckpoint = 10;
CREATE TABLE t1(a, b); -- 2 wal syncs
INSERT INTO t1 VALUES(1, 2); -- 1 wal sync
INSERT INTO t1 VALUES(1, 2); -- 2 wal sync
PRAGMA wal_checkpoint; -- 1 wal sync, 1 db sync
BEGIN;
INSERT INTO t1 VALUES(3, 4);
INSERT INTO t1 VALUES(5, 6);
COMMIT; -- 1 wal sync
COMMIT; -- 2 wal sync
PRAGMA wal_checkpoint; -- 1 wal sync, 1 db sync
} {10 0 5 5 0 2 2}
@@ -1233,22 +1233,22 @@ catch { db close }
# PRAGMA fullfsync
# PRAGMA synchronous
#
foreach {tn settings commit_sync ckpt_sync} {
1 {0 0 off} {0 0} {0 0}
2 {0 0 normal} {0 0} {2 0}
3 {0 0 full} {1 0} {2 0}
foreach {tn settings restart_sync commit_sync ckpt_sync} {
1 {0 0 off} {0 0} {0 0} {0 0}
2 {0 0 normal} {1 0} {0 0} {2 0}
3 {0 0 full} {2 0} {1 0} {2 0}
4 {0 1 off} {0 0} {0 0}
5 {0 1 normal} {0 0} {0 2}
6 {0 1 full} {0 1} {0 2}
4 {0 1 off} {0 0} {0 0} {0 0}
5 {0 1 normal} {0 1} {0 0} {0 2}
6 {0 1 full} {0 2} {0 1} {0 2}
7 {1 0 off} {0 0} {0 0}
8 {1 0 normal} {0 0} {0 2}
9 {1 0 full} {1 0} {0 2}
7 {1 0 off} {0 0} {0 0} {0 0}
8 {1 0 normal} {1 0} {0 0} {0 2}
9 {1 0 full} {2 0} {1 0} {0 2}
10 {1 1 off} {0 0} {0 0}
11 {1 1 normal} {0 0} {0 2}
12 {1 1 full} {0 1} {0 2}
10 {1 1 off} {0 0} {0 0} {0 0}
11 {1 1 normal} {0 1} {0 0} {0 2}
12 {1 1 full} {0 2} {0 1} {0 2}
} {
forcedelete test.db
@@ -1262,27 +1262,35 @@ foreach {tn settings commit_sync ckpt_sync} {
sqlite3 db test.db
do_execsql_test 15.$tn.1 "
CREATE TABLE t1(x);
PRAGMA wal_autocheckpoint = OFF;
PRAGMA journal_mode = WAL;
PRAGMA checkpoint_fullfsync = [lindex $settings 0];
PRAGMA fullfsync = [lindex $settings 1];
PRAGMA synchronous = [lindex $settings 2];
" {wal}
" {0 wal}
do_test 15.$tn.2 {
set sync(normal) 0
set sync(full) 0
execsql { INSERT INTO t1 VALUES('abc') }
list $::sync(normal) $::sync(full)
} $commit_sync
} $restart_sync
do_test 15.$tn.3 {
set sync(normal) 0
set sync(full) 0
execsql { INSERT INTO t1 VALUES('abc') }
list $::sync(normal) $::sync(full)
} $commit_sync
do_test 15.$tn.4 {
set sync(normal) 0
set sync(full) 0
execsql { INSERT INTO t1 VALUES('def') }
list $::sync(normal) $::sync(full)
} $commit_sync
do_test 15.$tn.4 {
do_test 15.$tn.5 {
set sync(normal) 0
set sync(full) 0
execsql { PRAGMA wal_checkpoint }
+1
View File
@@ -217,6 +217,7 @@ foreach {tn syncmode synccount} {
execsql "PRAGMA synchronous = $syncmode"
execsql { PRAGMA journal_mode = WAL }
execsql { CREATE TABLE filler(a,b,c); }
set ::syncs [list]
T filter xSync