1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-27 20:41:58 +03:00

Add a version number to the wal-index header. If SQLite encounters a version number in either the wal or wal-index files that it does not understand, the operation is abandoned and SQLITE_CANTOPEN returned.

FossilOrigin-Name: 8d0f8a7f70d6fb42369411a934b30f8c8ca8322f
This commit is contained in:
dan
2010-06-23 15:55:43 +00:00
parent b316cb22de
commit 10f5a50e57
13 changed files with 324 additions and 152 deletions

View File

@ -17,6 +17,7 @@ set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/lock_common.tcl
source $testdir/malloc_common.tcl
source $testdir/wal_common.tcl
ifcapable !wal {finish_test ; return }
@ -41,10 +42,6 @@ proc sqlite3_wal {args} {
[lindex $args 0] function blob blob
}
proc log_file_size {nFrame pgsz} {
expr {24 + ($pgsz+24)*$nFrame}
}
proc log_deleted {logfile} {
return [expr [file exists $logfile]==0]
}
@ -87,7 +84,7 @@ do_test wal-1.1 {
do_test wal-1.2 {
# There are now two pages in the log.
file size test.db-wal
} [log_file_size 2 1024]
} [wal_file_size 2 1024]
do_test wal-1.3 {
execsql { SELECT * FROM sqlite_master }
@ -366,11 +363,11 @@ do_test wal-7.1 {
INSERT INTO t1 VALUES(1, 2);
}
list [file size test.db] [file size test.db-wal]
} [list 1024 [log_file_size 3 1024]]
} [list 1024 [wal_file_size 3 1024]]
do_test wal-7.2 {
execsql { PRAGMA wal_checkpoint }
list [file size test.db] [file size test.db-wal]
} [list 2048 [log_file_size 3 1024]]
} [list 2048 [wal_file_size 3 1024]]
# Execute some transactions in auto-vacuum mode to test database file
# truncation.
@ -685,11 +682,11 @@ do_test wal-11.1 {
do_test wal-11.2 {
execsql { PRAGMA wal_checkpoint }
list [expr [file size test.db]/1024] [file size test.db-wal]
} [list 3 [log_file_size 3 1024]]
} [list 3 [wal_file_size 3 1024]]
do_test wal-11.3 {
execsql { INSERT INTO t1 VALUES( blob(900) ) }
list [expr [file size test.db]/1024] [file size test.db-wal]
} [list 3 [log_file_size 4 1024]]
} [list 3 [wal_file_size 4 1024]]
do_test wal-11.4 {
execsql {
@ -700,7 +697,7 @@ do_test wal-11.4 {
INSERT INTO t1 SELECT blob(900) FROM t1; -- 16
}
list [expr [file size test.db]/1024] [file size test.db-wal]
} [list 3 [log_file_size 32 1024]]
} [list 3 [wal_file_size 32 1024]]
do_test wal-11.5 {
execsql {
SELECT count(*) FROM t1;
@ -710,7 +707,7 @@ do_test wal-11.5 {
do_test wal-11.6 {
execsql COMMIT
list [expr [file size test.db]/1024] [file size test.db-wal]
} [list 3 [log_file_size 41 1024]]
} [list 3 [wal_file_size 41 1024]]
do_test wal-11.7 {
execsql {
SELECT count(*) FROM t1;
@ -720,7 +717,7 @@ do_test wal-11.7 {
do_test wal-11.8 {
execsql { PRAGMA wal_checkpoint }
list [expr [file size test.db]/1024] [file size test.db-wal]
} [list 37 [log_file_size 41 1024]]
} [list 37 [wal_file_size 41 1024]]
do_test wal-11.9 {
db close
list [expr [file size test.db]/1024] [log_deleted test.db-wal]
@ -734,7 +731,7 @@ do_test wal-11.10 {
SELECT count(*) FROM t1;
}
list [expr [file size test.db]/1024] [file size test.db-wal]
} [list 37 [log_file_size 37 1024]]
} [list 37 [wal_file_size 37 1024]]
do_test wal-11.11 {
execsql {
SELECT count(*) FROM t1;
@ -744,7 +741,7 @@ do_test wal-11.11 {
} {32 16}
do_test wal-11.12 {
list [expr [file size test.db]/1024] [file size test.db-wal]
} [list 37 [log_file_size 37 1024]]
} [list 37 [wal_file_size 37 1024]]
do_test wal-11.13 {
execsql {
INSERT INTO t1 VALUES( blob(900) );
@ -754,7 +751,7 @@ do_test wal-11.13 {
} {17 ok}
do_test wal-11.14 {
list [expr [file size test.db]/1024] [file size test.db-wal]
} [list 37 [log_file_size 37 1024]]
} [list 37 [wal_file_size 37 1024]]
#-------------------------------------------------------------------------
@ -771,7 +768,7 @@ do_test wal-12.1 {
INSERT INTO t1 VALUES('A', 1);
}
list [expr [file size test.db]/1024] [file size test.db-wal]
} [list 1 [log_file_size 5 1024]]
} [list 1 [wal_file_size 5 1024]]
do_test wal-12.2 {
db close
sqlite3 db test.db
@ -865,7 +862,7 @@ do_test wal-13.2.2 {
execsql { SELECT count(*) FROM t2 }
} [expr int(pow(2, 16))]
do_test wal-13.2.3 {
expr [file size test.db-wal] > [log_file_size 33000 1024]
expr [file size test.db-wal] > [wal_file_size 33000 1024]
} 1
do_multiclient_test tn {
@ -1067,20 +1064,20 @@ foreach {tn ckpt_cmd ckpt_res ckpt_main ckpt_aux} {
}
list [file size test.db] [file size test.db-wal]
} [list [expr 1*1024] [log_file_size 10 1024]]
} [list [expr 1*1024] [wal_file_size 10 1024]]
do_test wal-16.$tn.3 {
list [file size test2.db] [file size test2.db-wal]
} [list [expr 1*1024] [log_file_size 16 1024]]
} [list [expr 1*1024] [wal_file_size 16 1024]]
do_test wal-16.$tn.4 [list eval $ckpt_cmd] $ckpt_res
do_test wal-16.$tn.5 {
list [file size test.db] [file size test.db-wal]
} [list [expr ($ckpt_main ? 7 : 1)*1024] [log_file_size 10 1024]]
} [list [expr ($ckpt_main ? 7 : 1)*1024] [wal_file_size 10 1024]]
do_test wal-16.$tn.6 {
list [file size test2.db] [file size test2.db-wal]
} [list [expr ($ckpt_aux ? 7 : 1)*1024] [log_file_size 16 1024]]
} [list [expr ($ckpt_aux ? 7 : 1)*1024] [wal_file_size 16 1024]]
catch { db close }
}
@ -1094,7 +1091,7 @@ foreach {tn ckpt_cmd ckpt_res ckpt_main ckpt_aux} {
# a transaction that modifies 171 pages. In synchronous=NORMAL mode, this
# produces a log file of:
#
# 24 + (24+512)*171 = 90312 bytes.
# 32 + (24+512)*171 = 90312 bytes.
#
# Slightly larger than 11*8192 = 90112 bytes.
#
@ -1106,15 +1103,15 @@ foreach {tn ckpt_cmd ckpt_res ckpt_main ckpt_aux} {
#
set old_pending_byte [sqlite3_test_control_pending_byte 0x10000000]
catch { db close }
foreach {tn sectorsize logsize} {
1 128 92216
2 256 92216
3 512 92216
4 1024 92216
5 2048 92216
6 4096 94360
7 8192 98648
} {
foreach {tn sectorsize logsize} "
1 128 [wal_file_size 172 512]
2 256 [wal_file_size 172 512]
3 512 [wal_file_size 172 512]
4 1024 [wal_file_size 172 512]
5 2048 [wal_file_size 172 512]
6 4096 [wal_file_size 176 512]
7 8192 [wal_file_size 184 512]
" {
file delete -force test.db test.db-wal test.db-journal
sqlite3_simulate_device -sectorsize $sectorsize
sqlite3 db test.db -vfs devsym
@ -1181,7 +1178,7 @@ do_test wal-18.0 {
file copy -force test.db-wal testX.db-wal
db close
list [file size testX.db] [file size testX.db-wal]
} [list [expr 3*1024] [log_file_size 6 1024]]
} [list [expr 3*1024] [wal_file_size 6 1024]]
unset -nocomplain nFrame result
foreach {nFrame result} {
@ -1280,6 +1277,8 @@ foreach {tn pgsz works} {
set c1 0
set c2 0
logcksum c1 c2 $walhdr
append walhdr [binary format II $c1 $c2]
logcksum c1 c2 [string range $framehdr 0 7]
logcksum c1 c2 $framebody
set framehdr [binary format IIIIII $pg 5 22 23 $c1 $c2]
@ -1292,7 +1291,7 @@ foreach {tn pgsz works} {
close $fd
file size test.db-wal
} [log_file_size 1 $pgsz]
} [wal_file_size 1 $pgsz]
do_test wal-18.2.$tn.$pg.5 {
sqlite3 db test.db
@ -1414,10 +1413,9 @@ integrity_check wal-20.5
catch { db2 close }
catch { db close }
file delete -force test.db test.db-wal test.db-journal
do_test wal-21.1 {
sqlite3 db test.db
faultsim_delete_and_reopen
execsql {
PRAGMA journal_mode = WAL;
CREATE TABLE t1(a, b);