mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Fix a but in the WAL checkpoint code causing SQLite to use an inconsistent cache in a subsequent transaction.
FossilOrigin-Name: d1cadeed4eea20d8892726cc8c69f4f3f57d0cd4
This commit is contained in:
@ -918,5 +918,50 @@ foreach code [list {
|
||||
db close
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Check a fun corruption case has been fixed.
|
||||
#
|
||||
# The problem was that after performing a checkpoint using a connection
|
||||
# that had an out-of-date pager-cache, the next time the connection was
|
||||
# used it did not realize the cache was out-of-date and proceeded to
|
||||
# operate with an inconsistent cache. Leading to corruption.
|
||||
#
|
||||
|
||||
catch { db close }
|
||||
catch { db2 close }
|
||||
catch { db3 close }
|
||||
file delete -force test.db test.db-wal
|
||||
sqlite3 db test.db
|
||||
sqlite3 db2 test.db
|
||||
|
||||
do_test wal-14 {
|
||||
execsql {
|
||||
PRAGMA journal_mode = WAL;
|
||||
CREATE TABLE t1(a PRIMARY KEY, b);
|
||||
INSERT INTO t1 VALUES(randomblob(10), randomblob(100));
|
||||
INSERT INTO t1 SELECT randomblob(10), randomblob(100) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(10), randomblob(100) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(10), randomblob(100) FROM t1;
|
||||
}
|
||||
|
||||
db2 eval {
|
||||
INSERT INTO t1 SELECT randomblob(10), randomblob(100);
|
||||
INSERT INTO t1 SELECT randomblob(10), randomblob(100);
|
||||
INSERT INTO t1 SELECT randomblob(10), randomblob(100);
|
||||
INSERT INTO t1 SELECT randomblob(10), randomblob(100);
|
||||
}
|
||||
|
||||
# After executing the "PRAGMA checkpoint", connection [db] was being
|
||||
# left with an inconsistent cache. Running the CREATE INDEX statement
|
||||
# in this state led to database corruption.
|
||||
catchsql {
|
||||
PRAGMA checkpoint;
|
||||
CREATE INDEX i1 on t1(b);
|
||||
}
|
||||
|
||||
db2 eval { PRAGMA integrity_check }
|
||||
} {ok}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
|
Reference in New Issue
Block a user