1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Return SQLITE_BUSY (not SQLITE_BUSY_SNAPSHOT) if sqlite3_snapshot_open() fails to obtain the shared checkpointer lock.

FossilOrigin-Name: 5343060bcc6c99029f731f8020d2cba3f405f207
This commit is contained in:
dan
2015-12-10 19:11:34 +00:00
parent 7d15979420
commit a7aeb39836
4 changed files with 70 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
C Add\stests\sto\sensure\sthat\san\ssqlite3_snapshot_open()\sclient\scannot\sbe\stricked\sinto\sreading\sa\scorrupt\ssnapshot\seven\sif\sanother\sprocess\sfails\smid-checkpoint. C Return\sSQLITE_BUSY\s(not\sSQLITE_BUSY_SNAPSHOT)\sif\ssqlite3_snapshot_open()\sfails\sto\sobtain\sthe\sshared\scheckpointer\slock.
D 2015-12-10T18:06:21.050 D 2015-12-10T19:11:34.013
F Makefile.in 28bcd6149e050dff35d4dcfd97e890cd387a499d F Makefile.in 28bcd6149e050dff35d4dcfd97e890cd387a499d
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc e8fdca1cb89a1b58b5f4d3a130ea9a3d28cb314d F Makefile.msc e8fdca1cb89a1b58b5f4d3a130ea9a3d28cb314d
@@ -415,7 +415,7 @@ F src/vdbesort.c a7ec02da4494c59dfd071126dd3726be5a11459d
F src/vdbetrace.c 8befe829faff6d9e6f6e4dee5a7d3f85cc85f1a0 F src/vdbetrace.c 8befe829faff6d9e6f6e4dee5a7d3f85cc85f1a0
F src/vtab.c 2a8b44aa372c33f6154208e7a7f6c44254549806 F src/vtab.c 2a8b44aa372c33f6154208e7a7f6c44254549806
F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb
F src/wal.c 32ee7dc4b689321d1650fba2e937ddc3bccfb06f F src/wal.c 94576d273e7feeae598188ebec641906a5b93a2f
F src/wal.h 907943dfdef10b583e81906679a347e0ec6f1b1b F src/wal.h 907943dfdef10b583e81906679a347e0ec6f1b1b
F src/walker.c 2e14d17f592d176b6dc879c33fbdec4fbccaa2ba F src/walker.c 2e14d17f592d176b6dc879c33fbdec4fbccaa2ba
F src/where.c b18edbb9e5afabb77f4f27550c471c5c824e0fe7 F src/where.c b18edbb9e5afabb77f4f27550c471c5c824e0fe7
@@ -1020,7 +1020,7 @@ F test/skipscan2.test d1d1450952b7275f0b0a3a981f0230532743951a
F test/skipscan3.test ec5bab3f81c7038b43450e7b3062e04a198bdbb5 F test/skipscan3.test ec5bab3f81c7038b43450e7b3062e04a198bdbb5
F test/skipscan5.test 67817a4b6857c47e0e33ba3e506da6f23ef68de2 F test/skipscan5.test 67817a4b6857c47e0e33ba3e506da6f23ef68de2
F test/skipscan6.test 5866039d03a56f5bd0b3d172a012074a1d90a15b F test/skipscan6.test 5866039d03a56f5bd0b3d172a012074a1d90a15b
F test/snapshot.test 5631669a133c96aaa228f7233989f6d2d069fb02 F test/snapshot.test 184c7ed21f204a5bd909246560edfac308467609
F test/snapshot_fault.test 06472056c516be4610834de4688ea3357e8bde01 F test/snapshot_fault.test 06472056c516be4610834de4688ea3357e8bde01
F test/soak.test 0b5b6375c9f4110c828070b826b3b4b0bb65cd5f F test/soak.test 0b5b6375c9f4110c828070b826b3b4b0bb65cd5f
F test/softheap1.test 843cd84db9891b2d01b9ab64cef3e9020f98d087 F test/softheap1.test 843cd84db9891b2d01b9ab64cef3e9020f98d087
@@ -1410,7 +1410,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 8084eae0bc4f6513b1147fb890a6b2813f1c0a09 P b908048b6cfa1ee2fe1f7a17bae475ddd9d0376c
R b7a6ff87063d246e894cc3fd88f3e89f R 1311c20224293debd3e251bf775d0f5c
U dan U dan
Z 1fe7db1e51b0eef5aa529631bb7527d1 Z ae2ff3e1ce7fc4e495f8fcae9626097f

View File

@@ -1 +1 @@
b908048b6cfa1ee2fe1f7a17bae475ddd9d0376c 5343060bcc6c99029f731f8020d2cba3f405f207

View File

@@ -2432,23 +2432,26 @@ int sqlite3WalBeginReadTransaction(Wal *pWal, int *pChanged){
** before checking pInfo->nBackfillAttempted. */ ** before checking pInfo->nBackfillAttempted. */
rc = walLockShared(pWal, WAL_CKPT_LOCK); rc = walLockShared(pWal, WAL_CKPT_LOCK);
/* Check that the wal file has not been wrapped. Assuming that it has if( rc==SQLITE_OK ){
** not, also check that no checkpointer has attempted to checkpoint /* Check that the wal file has not been wrapped. Assuming that it has
** any frames beyond pSnapshot->mxFrame. If either of these conditions ** not, also check that no checkpointer has attempted to checkpoint any
** are true, return SQLTIE_BUSY_SNAPSHOT. Otherwise, overwrite pWal->hdr ** frames beyond pSnapshot->mxFrame. If either of these conditions are
** with *pSnapshot and set *pChanged as appropriate for opening the ** true, return SQLITE_BUSY_SNAPSHOT. Otherwise, overwrite pWal->hdr
** snapshot. */ ** with *pSnapshot and set *pChanged as appropriate for opening the
if( memcmp(pSnapshot->aSalt, pWal->hdr.aSalt, sizeof(pWal->hdr.aSalt))==0 ** snapshot. */
&& pSnapshot->mxFrame>=pInfo->nBackfillAttempted if( !memcmp(pSnapshot->aSalt, pWal->hdr.aSalt, sizeof(pWal->hdr.aSalt))
){ && pSnapshot->mxFrame>=pInfo->nBackfillAttempted
memcpy(&pWal->hdr, pSnapshot, sizeof(WalIndexHdr)); ){
*pChanged = bChanged; memcpy(&pWal->hdr, pSnapshot, sizeof(WalIndexHdr));
}else{ *pChanged = bChanged;
rc = SQLITE_BUSY_SNAPSHOT; }else{
rc = SQLITE_BUSY_SNAPSHOT;
}
/* Release the shared CKPT lock obtained above. */
walUnlockShared(pWal, WAL_CKPT_LOCK);
} }
/* Release the shared CKPT lock obtained above. */
walUnlockShared(pWal, WAL_CKPT_LOCK);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
sqlite3WalEndReadTransaction(pWal); sqlite3WalEndReadTransaction(pWal);

View File

@@ -246,5 +246,49 @@ do_test 4.2.4 {
sqlite3_snapshot_free $snapshot sqlite3_snapshot_free $snapshot
} {} } {}
#-------------------------------------------------------------------------
# Check that SQLITE_BUSY is returned if a checkpoint is running when
# sqlite3_snapshot_open() is called.
#
reset_db
db close
testvfs tvfs
sqlite3 db test.db -vfs tvfs
do_execsql_test 5.1 {
PRAGMA journal_mode = wal;
CREATE TABLE x1(x, xx, xxx);
INSERT INTO x1 VALUES('z', 'zz', 'zzz');
BEGIN;
SELECT * FROM x1;
} {wal z zz zzz}
do_test 5.2 {
set ::snapshot [sqlite3_snapshot_get db main]
sqlite3 db2 test.db -vfs tvfs
execsql {
INSERT INTO x1 VALUES('a', 'aa', 'aaa');
COMMIT;
}
} {}
set t53 0
proc write_callback {args} {
breakpoint
do_test 5.3.[incr ::t53] {
execsql BEGIN
list [catch { sqlite3_snapshot_open db main $::snapshot } msg] $msg
} {1 SQLITE_BUSY}
catchsql COMMIT
}
tvfs filter xWrite
tvfs script write_callback
db2 eval { PRAGMA wal_checkpoint }
db close
db2 close
tvfs delete
sqlite3_snapshot_free $snapshot
finish_test finish_test