Fix a problem with rolling back to a savepoint opened before the writer decided to wrap the log file.

FossilOrigin-Name: 6b4aed6aae7dc9e92807d27375cbe1e83c15841b
This commit is contained in:
dan 2010-06-02 18:59:03 +00:00
parent 10ec894c3a
commit 6e6bd5658f
5 changed files with 56 additions and 13 deletions

View File

@ -1,5 +1,5 @@
C If\san\serror\soccurs\swhile\swriting\sframes\sto\sthe\slog\sto\scommit\sa\stransaction,\sdo\snot\smark\sthe\spages\sas\sclean\sin\sthe\scache.\sOtherwise,\sthe\ssubsequent\srollback\sdoes\snot\sroll\sthem\sback\s(leaving\sthe\sclient\sto\scontinue\swith\sa\scache\sthat\smakes\sit\sappear\sthat\sthe\stransaction\swas\scommitted\s-\sinconsistent\swith\sthe\sdatabase\son\sdisk).
D 2010-06-02T17:15:25
C Fix\sa\sproblem\swith\srolling\sback\sto\sa\ssavepoint\sopened\sbefore\sthe\swriter\sdecided\sto\swrap\sthe\slog\sfile.
D 2010-06-02T18:59:03
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in a5cad1f8f3e021356bfcc6c77dc16f6f1952bbc3
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -224,8 +224,8 @@ F src/vdbeblob.c 5327132a42a91e8b7acfb60b9d2c3b1c5c863e0e
F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1
F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
F src/vtab.c a0f8a40274e4261696ef57aa806de2776ab72cda
F src/wal.c 125cc67e8e5c091ef78f3a499524701bcddbb8f4
F src/wal.h 1c1c9feb629b7f4afcbe0b47f80f47c5551d3a02
F src/wal.c 82da8997bccdf229edc192aede6e00a3454321e4
F src/wal.h 4ace25262452d17e7d3ec970c89ee17794004008
F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
F src/where.c 75fee9e255b62f773fcadd1d1f25b6f63ac7a356
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@ -761,7 +761,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 a54d9be9e82eede1653f7998723ead8ce8a1a580
F test/wal.test bfec61450b47cdf09f7d2269f9e9967683b8b0fc
F test/wal2.test a2146846c4dd940252f18ec1e00431346286bcb3
F test/walbak.test e7650a26eb4b8abeca9b145b1af1e63026dde432
F test/walcksum.test 4efa8fb88c32bed8288ea4385a9cc113a5c8f0bf
@ -815,7 +815,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P b3109f85bde0b24bfbcfe6c0f7bbe973be196c1d
R 830ef9967206d6e34b488a57bc115b0c
P cb571c1b71a37b3a10d640987c77a6eec508235d
R 958f6d0fb0d51651adb74690506f1284
U dan
Z 189de0d7978aa94a58fbada93d61bb5d
Z 8958cafc220d9bcfdae765c6216ea4c7

View File

@ -1 +1 @@
cb571c1b71a37b3a10d640987c77a6eec508235d
6b4aed6aae7dc9e92807d27375cbe1e83c15841b

View File

@ -2110,6 +2110,7 @@ void sqlite3WalSavepoint(Wal *pWal, u32 *aWalData){
aWalData[0] = pWal->hdr.mxFrame;
aWalData[1] = pWal->hdr.aFrameCksum[0];
aWalData[2] = pWal->hdr.aFrameCksum[1];
aWalData[3] = pWal->nCkpt;
}
/*
@ -2120,9 +2121,19 @@ void sqlite3WalSavepoint(Wal *pWal, u32 *aWalData){
*/
int sqlite3WalSavepointUndo(Wal *pWal, u32 *aWalData){
int rc = SQLITE_OK;
assert( pWal->writeLock );
assert( aWalData[0]<=pWal->hdr.mxFrame );
assert( pWal->writeLock );
assert( aWalData[3]!=pWal->nCkpt || aWalData[0]<=pWal->hdr.mxFrame );
if( aWalData[3]!=pWal->nCkpt ){
/* This savepoint was opened immediately after the write-transaction
** was started. Right after that, the writer decided to wrap around
** to the start of the log. Update the savepoint values to match.
*/
aWalData[0] = 0;
aWalData[3] = pWal->nCkpt;
}
if( aWalData[0]<pWal->hdr.mxFrame ){
rc = walIndexMap(pWal, walMappingSize(pWal->hdr.mxFrame));
pWal->hdr.mxFrame = aWalData[0];
@ -2130,9 +2141,10 @@ int sqlite3WalSavepointUndo(Wal *pWal, u32 *aWalData){
pWal->hdr.aFrameCksum[1] = aWalData[2];
if( rc==SQLITE_OK ){
walCleanupHash(pWal);
walIndexUnmap(pWal);
}
}
walIndexUnmap(pWal);
return rc;
}

View File

@ -36,7 +36,7 @@
# define sqlite3WalCallback(z) 0
#else
#define WAL_SAVEPOINT_NDATA 3
#define WAL_SAVEPOINT_NDATA 4
/* Connection to a write-ahead log (WAL) file.
** There is one object of this type for each pager.

View File

@ -1460,5 +1460,36 @@ 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
execsql {
PRAGMA journal_mode = WAL;
CREATE TABLE t1(a, b);
INSERT INTO t1 VALUES(1, 2);
INSERT INTO t1 VALUES(3, 4);
INSERT INTO t1 VALUES(5, 6);
INSERT INTO t1 VALUES(7, 8);
INSERT INTO t1 VALUES(9, 10);
INSERT INTO t1 VALUES(11, 12);
}
} {wal}
do_test wal-21.2 {
execsql {
PRAGMA cache_size = 10;
PRAGMA wal_checkpoint;
BEGIN;
SAVEPOINT s;
INSERT INTO t1 SELECT randomblob(900), randomblob(900) FROM t1;
ROLLBACK TO s;
COMMIT;
SELECT * FROM t1;
}
} {1 2 3 4 5 6 7 8 9 10 11 12}
do_test wal-21.3 {
execsql { PRAGMA integrity_check }
} {ok}
finish_test