Add some assert() statements to querySharedCacheTableLock(). (CVS 6421)
FossilOrigin-Name: 3e3b5e861aeff2e4ef568c422236fdf7fa22bed3
This commit is contained in:
parent
faa68dbb7d
commit
5b413d785f
15
manifest
15
manifest
@ -1,5 +1,5 @@
|
||||
C add\sa\ssanity\scheck\sto\smake\ssure\sthe\sconfigure\sscript\sand\sVERSION\sfile\sare\salways\sin\ssync\s(CVS\s6420)
|
||||
D 2009-04-01T07:38:31
|
||||
C Add\ssome\sassert()\sstatements\sto\squerySharedCacheTableLock().\s(CVS\s6421)
|
||||
D 2009-04-01T09:41:54
|
||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||
F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
@ -103,7 +103,7 @@ F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
|
||||
F src/backup.c 0082d0e5a63f04e88faee0dff0a7d63d3e92a78d
|
||||
F src/bitvec.c 44f7059ac1f874d364b34af31b9617e52223ba75
|
||||
F src/btmutex.c 341502bc496dc0840dcb00cde65680fb0e85c3ab
|
||||
F src/btree.c 304c18b7e3d6e921764cede594c36e755200ce08
|
||||
F src/btree.c afb15be98c01b07528072dd6e18b7f644859ada0
|
||||
F src/btree.h e302c5747494067cd4f5763000fbe7bca767d816
|
||||
F src/btreeInt.h df64030d632f8c8ac217ed52e8b6b3eacacb33a5
|
||||
F src/build.c 72357fd75ef036d0afbf1756edab6d62c56fcf4b
|
||||
@ -532,6 +532,7 @@ F test/shared.test 3b448dc0f7a9356e641894ed81c27599f39d809d
|
||||
F test/shared2.test 8973e41e008acbbd8d1b191b91a23cd472f058e8
|
||||
F test/shared3.test 9c880afc081d797da514ef64bccf36f3fce2f09c
|
||||
F test/shared4.test d0fadacb50bb6981b2fb9dc6d1da30fa1edddf83
|
||||
F test/shared6.test 9c155088d28bcaa5d87c52b6406ef5d0e7086e8e
|
||||
F test/shared_err.test 91e26ec4f3fbe07951967955585137e2f18993de
|
||||
F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
|
||||
F test/sidedelete.test f0ad71abe6233e3b153100f3b8d679b19a488329
|
||||
@ -713,7 +714,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
|
||||
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
P ce683cbd329eab45abb6f97f677f560b0fd1cdb6
|
||||
R 2718bfb20c645bac2c120cb851c22c61
|
||||
U vapier
|
||||
Z ee7f3525d69da1abde020f897f014028
|
||||
P 1b9da6d73f603e66d078463c3571dda86ceedfb3
|
||||
R 14b12ad716bad78f9281344d4310ecc6
|
||||
U danielk1977
|
||||
Z 50c3252197be65f8aa74e6bb679653bc
|
||||
|
@ -1 +1 @@
|
||||
1b9da6d73f603e66d078463c3571dda86ceedfb3
|
||||
3e3b5e861aeff2e4ef568c422236fdf7fa22bed3
|
23
src/btree.c
23
src/btree.c
@ -9,7 +9,7 @@
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** $Id: btree.c,v 1.582 2009/03/30 18:50:05 danielk1977 Exp $
|
||||
** $Id: btree.c,v 1.583 2009/04/01 09:41:54 danielk1977 Exp $
|
||||
**
|
||||
** This file implements a external (disk-based) database using BTrees.
|
||||
** See the header comment on "btreeInt.h" for additional information.
|
||||
@ -103,6 +103,13 @@ static int querySharedCacheTableLock(Btree *p, Pgno iTab, u8 eLock){
|
||||
assert( eLock==READ_LOCK || eLock==WRITE_LOCK );
|
||||
assert( p->db!=0 );
|
||||
|
||||
/* If requesting a write-lock, then the Btree must have an open write
|
||||
** transaction on this file. And, obviously, for this to be so there
|
||||
** must be an open write transaction on the file itself.
|
||||
*/
|
||||
assert( eLock==READ_LOCK || (p==pBt->pWriter && p->inTrans==TRANS_WRITE) );
|
||||
assert( eLock==READ_LOCK || pBt->inTransaction==TRANS_WRITE );
|
||||
|
||||
/* This is a no-op if the shared-cache is not enabled */
|
||||
if( !p->sharable ){
|
||||
return SQLITE_OK;
|
||||
@ -138,8 +145,18 @@ static int querySharedCacheTableLock(Btree *p, Pgno iTab, u8 eLock){
|
||||
iTab==MASTER_ROOT
|
||||
){
|
||||
for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
|
||||
if( pIter->pBtree!=p && pIter->iTable==iTab &&
|
||||
(pIter->eLock!=eLock || eLock!=READ_LOCK) ){
|
||||
/* The condition (pIter->eLock!=eLock) in the following if(...)
|
||||
** statement is a simplification of:
|
||||
**
|
||||
** (eLock==WRITE_LOCK || pIter->eLock==WRITE_LOCK)
|
||||
**
|
||||
** since we know that if eLock==WRITE_LOCK, then no other connection
|
||||
** may hold a WRITE_LOCK on any table in this file (since there can
|
||||
** only be a single writer).
|
||||
*/
|
||||
assert( pIter->eLock==READ_LOCK || pIter->eLock==WRITE_LOCK );
|
||||
assert( eLock==READ_LOCK || pIter->pBtree==p || pIter->eLock==READ_LOCK);
|
||||
if( pIter->pBtree!=p && pIter->iTable==iTab && pIter->eLock!=eLock ){
|
||||
sqlite3ConnectionBlocked(p->db, pIter->pBtree->db);
|
||||
if( eLock==WRITE_LOCK ){
|
||||
assert( p==pBt->pWriter );
|
||||
|
138
test/shared6.test
Normal file
138
test/shared6.test
Normal file
@ -0,0 +1,138 @@
|
||||
# 2009 April 01
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# $Id: shared6.test,v 1.1 2009/04/01 09:41:54 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
ifcapable !shared_cache { finish_test ; return }
|
||||
|
||||
do_test shared7-1.1.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b);
|
||||
CREATE TABLE t2(c, d);
|
||||
CREATE TABLE t3(e, f);
|
||||
}
|
||||
} {}
|
||||
do_test shared7-1.1.2 {
|
||||
set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
|
||||
sqlite3_enable_shared_cache
|
||||
} {1}
|
||||
|
||||
do_test shared7-1.1.3 {
|
||||
sqlite3 db1 test.db
|
||||
sqlite3 db2 test.db
|
||||
} {}
|
||||
|
||||
# Exclusive shared-cache locks. Test the following:
|
||||
#
|
||||
# 1.2.1: If [db1] has an exclusive lock, [db2] cannot read.
|
||||
# 1.2.2: If [db1] has an exclusive lock, [db1] can read.
|
||||
# 1.2.3: If [db1] has a non-exclusive write-lock, [db2] can read.
|
||||
#
|
||||
do_test shared7-1.2.1 {
|
||||
execsql { SELECT * FROM t1 } db2 ;# Cache a compiled statement
|
||||
execsql { BEGIN EXCLUSIVE } db1
|
||||
catchsql { SELECT * FROM t1 } db2 ;# Execute the cached compiled statement
|
||||
} {1 {database table is locked}}
|
||||
do_test shared7-1.2.2 {
|
||||
execsql { SELECT * FROM t1 } db1
|
||||
} {}
|
||||
do_test shared7-1.2.3 {
|
||||
execsql {
|
||||
COMMIT;
|
||||
BEGIN;
|
||||
INSERT INTO t2 VALUES(3, 4);
|
||||
} db1
|
||||
execsql { SELECT * FROM t1 } db2
|
||||
} {}
|
||||
do_test shared7-1.2.X {
|
||||
execsql { COMMIT } db1
|
||||
} {}
|
||||
|
||||
# Regular shared-cache locks. Verify the following:
|
||||
#
|
||||
# 1.3.1: If [db1] has a write-lock on t1, [db1] can read from t1.
|
||||
# 1.3.2: If [db1] has a write-lock on t1, [db2] can read from t2.
|
||||
# 1.3.3: If [db1] has a write-lock on t1, [db2] cannot read from t1.
|
||||
# 1.3.4: If [db1] has a write-lock on t1, [db2] cannot write to t1.
|
||||
# 1.3.5: If [db1] has a read-lock on t1, [db2] can read from t1.
|
||||
# 1.3.6: If [db1] has a read-lock on t1, [db2] cannot write to t1.
|
||||
#
|
||||
do_test shared7-1.3.1 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
INSERT INTO t1 VALUES(1, 2);
|
||||
} db1
|
||||
execsql { SELECT * FROM t1 } db1
|
||||
} {1 2}
|
||||
do_test shared7-1.3.2 {
|
||||
execsql { SELECT * FROM t2 } db2
|
||||
} {3 4}
|
||||
do_test shared7-1.3.3 {
|
||||
catchsql { SELECT * FROM t1 } db2
|
||||
} {1 {database table is locked: t1}}
|
||||
do_test shared7-1.3.4 {
|
||||
catchsql { INSERT INTO t2 VALUES(1, 2) } db2
|
||||
} {1 {database table is locked}}
|
||||
do_test shared7-1.3.5 {
|
||||
execsql {
|
||||
COMMIT;
|
||||
BEGIN;
|
||||
SELECT * FROM t1;
|
||||
} db1
|
||||
execsql { SELECT * FROM t1 } db2
|
||||
} {1 2}
|
||||
do_test shared7-1.3.5 {
|
||||
catchsql { INSERT INTO t1 VALUES(5, 6) } db2
|
||||
} {1 {database table is locked: t1}}
|
||||
do_test shared7-1.3.X {
|
||||
execsql { COMMIT } db1
|
||||
} {}
|
||||
|
||||
# Read-uncommitted mode.
|
||||
#
|
||||
# For these tests, connection [db2] is in read-uncommitted mode.
|
||||
#
|
||||
# 1.4.1: If [db1] has a write-lock on t1, [db2] can still read from t1.
|
||||
# 1.4.2: If [db1] has a write-lock on the db schema (sqlite_master table),
|
||||
# [db2] cannot read from the schema.
|
||||
# 1.4.3: If [db1] has a read-lock on t1, [db2] cannot write to t1.
|
||||
#
|
||||
do_test shared7-1.4.1 {
|
||||
execsql { PRAGMA read_uncommitted = 1 } db2
|
||||
execsql {
|
||||
BEGIN;
|
||||
INSERT INTO t1 VALUES(5, 6);
|
||||
} db1
|
||||
execsql { SELECT * FROM t1 } db2
|
||||
} {1 2 5 6}
|
||||
do_test shared7-1.4.2 {
|
||||
execsql { CREATE TABLE t4(a, b) } db1
|
||||
catchsql { SELECT * FROM t1 } db2
|
||||
} {1 {database table is locked}}
|
||||
do_test shared7-1.4.3 {
|
||||
execsql {
|
||||
COMMIT;
|
||||
BEGIN;
|
||||
SELECT * FROM t1;
|
||||
} db1
|
||||
catchsql { INSERT INTO t1 VALUES(7, 8) } db2
|
||||
} {1 {database table is locked: t1}}
|
||||
|
||||
do_test shared7-1.X {
|
||||
db1 close
|
||||
db2 close
|
||||
} {}
|
||||
|
||||
sqlite3_enable_shared_cache $::enable_shared_cache
|
||||
finish_test
|
||||
|
Loading…
x
Reference in New Issue
Block a user