When committing a WAL transaction, do not write any pages to the WAL file with page numbers greater than the size of the database image in pages.

FossilOrigin-Name: 311d0b613d9cfa2dbcbb9ef2450041b1fd48770a
This commit is contained in:
dan 2011-04-05 16:09:08 +00:00
parent 0d8bba982d
commit ce8e5ffe1c
4 changed files with 73 additions and 9 deletions

View File

@ -1,5 +1,5 @@
C Fix\sa\sdocumentation\stypo.
D 2011-04-05T14:22:48.053
C When\scommitting\sa\sWAL\stransaction,\sdo\snot\swrite\sany\spages\sto\sthe\sWAL\sfile\swith\spage\snumbers\sgreater\sthan\sthe\ssize\sof\sthe\sdatabase\simage\sin\spages.
D 2011-04-05T16:09:08.127
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -164,7 +164,7 @@ F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f
F src/os_os2.c 2596fd2d5d0976c6c0c628d0c3c7c4e7a724f4cf
F src/os_unix.c 32414676594a0a26cfccd7e02656230a3406eee7
F src/os_win.c 24d72407a90551969744cf9bcbb1b4c72c5fa845
F src/pager.c 6aa906b60a59664ba58d3f746164bb010d407ce1
F src/pager.c 055239dcdfe12b3f5d97f6f01f85da01e2d6d912
F src/pager.h 3f8c783de1d4706b40b1ac15b64f5f896bcc78d1
F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58
F src/pcache.c 09d38c44ab275db581f7a2f6ff8b9bc7f8c0faaa
@ -860,7 +860,7 @@ F test/vtabE.test 7c4693638d7797ce2eda17af74292b97e705cc61
F test/vtab_alter.test 9e374885248f69e251bdaacf480b04a197f125e5
F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8
F test/vtab_shared.test 0eff9ce4f19facbe0a3e693f6c14b80711a4222d
F test/wal.test 973a4747a69247a43cc03292c44f59cc76f4df65
F test/wal.test 084b086913a205eab4dde4b9a9cf8c781a576bb8
F test/wal2.test e561a8c6fdd1c2cd1876f3e39757934e7b7361f8
F test/wal3.test 5c396cc22497244d627306f4c1d360167353f8dd
F test/wal4.test 3404b048fa5e10605facaf70384e6d2943412e30
@ -926,7 +926,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 5db4511d8a77b74be3503a7c34257ef6b07541f5
R f66ac9973277650bde436573608ca94f
U drh
Z c91a504724af14c0a00d31f50ea2afef
P d25c17ef6e2b916923489dccaaa018a2d6525401
R c888a09e2325a742237e83457c23e497
U dan
Z 881050430264f599344995b52c518cce

View File

@ -1 +1 @@
d25c17ef6e2b916923489dccaaa018a2d6525401
311d0b613d9cfa2dbcbb9ef2450041b1fd48770a

View File

@ -2972,6 +2972,19 @@ static int pagerWalFrames(
}
#endif
if( isCommit ){
/* If a WAL transaction is being committed, there is no point in writing
** any pages with page numbers greater than nTruncate into the WAL file.
** They will never be read by any client. So remove them from the pDirty
** list here. */
PgHdr *p;
PgHdr **ppNext = &pList;
for(p=pList; (*ppNext = p); p=p->pDirty){
if( p->pgno<=nTruncate ) ppNext = &p->pDirty;
}
assert( pList );
}
if( pList->pgno==1 ) pager_write_changecounter(pList);
rc = sqlite3WalFrames(pPager->pWal,
pPager->pageSize, pList, nTruncate, isCommit, syncFlags
@ -2984,6 +2997,7 @@ static int pagerWalFrames(
}
#ifdef SQLITE_CHECK_PAGES
pList = sqlite3PcacheDirtyList(pPager->pPCache);
for(p=pList; p; p=p->pDirty){
pager_set_pagehash(p);
}

View File

@ -19,6 +19,8 @@ source $testdir/lock_common.tcl
source $testdir/malloc_common.tcl
source $testdir/wal_common.tcl
set testprefix wal
ifcapable !wal {finish_test ; return }
proc reopen_db {} {
@ -1504,6 +1506,54 @@ do_test wal-23.4 {
set ::log
} [list SQLITE_OK "Recovered $nPage frames from WAL file $walfile"]
ifcapable autovacuum {
# This block tests that if the size of a database is reduced by a
# transaction (because of an incremental or auto-vacuum), that no
# data is written to the WAL file for the truncated pages as part
# of the commit. e.g. if a transaction reduces the size of a database
# to N pages, data for page N+1 should not be written to the WAL file
# when committing the transaction. At one point such data was being
# written.
#
catch {db close}
forcedelete test.db
sqlite3 db test.db
do_execsql_test 24.1 {
PRAGMA auto_vacuum = 2;
PRAGMA journal_mode = WAL;
PRAGMA page_size = 1024;
CREATE TABLE t1(x);
INSERT INTO t1 VALUES(randomblob(5000));
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
} {wal}
do_execsql_test 24.2 {
DELETE FROM t1;
PRAGMA wal_checkpoint;
} {0 109 109}
do_test 24.3 {
db close
sqlite3 db test.db
file exists test.db-wal
} 0
do_test 24.4 {
file size test.db
} [expr 84 * 1024]
do_test 24.5 {
execsql {
PRAGMA incremental_vacuum;
PRAGMA wal_checkpoint;
}
file size test.db
} [expr 3 * 1024]
do_test 24.6 {
file size test.db-wal
} 2128
}
db close
sqlite3_shutdown
test_sqlite3_log