Add part of the btree layer of the shared-cache feature. (CVS 2848)
FossilOrigin-Name: 2afcad990190af97d1ad0010f211a5ca8f0fd745
This commit is contained in:
+2
-1
@@ -13,7 +13,7 @@
|
||||
# file format change that may be used in the future to implement
|
||||
# "ALTER TABLE ... ADD COLUMN".
|
||||
#
|
||||
# $Id: alter3.test,v 1.6 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
# $Id: alter3.test,v 1.7 2005/12/30 16:28:02 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -360,6 +360,7 @@ do_test alter3-8.1 {
|
||||
CREATE TABLE t4(c1);
|
||||
}
|
||||
} {}
|
||||
set ::sql ""
|
||||
do_test alter3-8.2 {
|
||||
set cols c1
|
||||
for {set i 2} {$i < 100} {incr i} {
|
||||
|
||||
+2
-3
@@ -12,13 +12,12 @@
|
||||
# focus of this script is testing the ATTACH and DETACH commands
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: attach2.test,v 1.33 2005/12/06 17:19:12 danielk1977 Exp $
|
||||
# $Id: attach2.test,v 1.34 2005/12/30 16:28:02 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
|
||||
# Ticket #354
|
||||
#
|
||||
# Databases test.db and test2.db contain identical schemas. Make
|
||||
@@ -157,7 +156,7 @@ proc lock_status {testnum db expected_result} {
|
||||
# If the database was compiled with OMIT_TEMPDB set, then
|
||||
# the lock_status list will not contain an entry for the temp
|
||||
# db. But the test code doesn't know this, so it's easiest
|
||||
# to filter it out here.
|
||||
# to filter it out of the $expected_result list here.
|
||||
ifcapable !tempdb {
|
||||
set expected_result [concat \
|
||||
[lrange $expected_result 0 1] \
|
||||
|
||||
+18
-3
@@ -9,7 +9,10 @@
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# $Id: malloc5.test,v 1.2 2005/12/20 09:19:38 danielk1977 Exp $
|
||||
# This file contains test cases focused on the two memory-management APIs,
|
||||
# sqlite3_soft_heap_limit() and sqlite3_release_memory().
|
||||
#
|
||||
# $Id: malloc5.test,v 1.3 2005/12/30 16:28:02 danielk1977 Exp $
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# NOTES ON EXPECTED BEHAVIOUR
|
||||
@@ -19,6 +22,13 @@
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Only run these tests if memory debugging is turned on.
|
||||
if {[info command sqlite_malloc_stat]==""} {
|
||||
puts "Skipping malloc tests: not compiled with -DSQLITE_MEMDEBUG..."
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
do_test malloc5-1.1 {
|
||||
# Simplest possible test. Call [db release_memory] when there is exactly
|
||||
# one unused page in a single pager cache. This test case set's the
|
||||
@@ -159,6 +169,11 @@ sqlite_malloc_outstanding -clearmaxbytes
|
||||
# and tests to see that this limit is not exceeded at any point during
|
||||
# transaction execution.
|
||||
#
|
||||
# Before executing malloc5-4.* we save the value of the current soft heap
|
||||
# limit in variable ::soft_limit. The original value is restored after
|
||||
# running the tests.
|
||||
#
|
||||
set ::soft_limit [db soft_heap_limit -1]
|
||||
do_test malloc5-4.1 {
|
||||
execsql {BEGIN;}
|
||||
execsql {DELETE FROM abc;}
|
||||
@@ -188,8 +203,8 @@ do_test malloc5-4.3 {
|
||||
}
|
||||
} [list 20000 [expr int(20000.0 * 4999.5)] [expr int(20000.0 * 4999.5)]]
|
||||
|
||||
# Unset the soft-heap-limit value.
|
||||
db soft_heap_limit -1
|
||||
# Restore the soft heap limit.
|
||||
db soft_heap_limit $::soft_limit
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
+19
-1
@@ -6,7 +6,25 @@
|
||||
#***********************************************************************
|
||||
# This file runs all tests.
|
||||
#
|
||||
# $Id: quick.test,v 1.38 2005/12/15 10:11:32 danielk1977 Exp $
|
||||
# $Id: quick.test,v 1.39 2005/12/30 16:28:02 danielk1977 Exp $
|
||||
|
||||
proc lshift {lvar} {
|
||||
upvar $lvar l
|
||||
set ret [lindex $l 0]
|
||||
set l [lrange $l 1 end]
|
||||
return $ret
|
||||
}
|
||||
while {[set arg [lshift argv]] != ""} {
|
||||
switch -- $arg {
|
||||
-sharedpagercache {
|
||||
sqlite3_enable_shared_cache 1
|
||||
}
|
||||
default {
|
||||
set argv [linsert $argv 0 $arg]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
# 2005 December 30
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the SELECT statement.
|
||||
#
|
||||
# $Id: shared.test,v 1.1 2005/12/30 16:28:02 danielk1977 Exp $
|
||||
|
||||
set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
db close
|
||||
|
||||
ifcapable !shared_cache {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Test organization:
|
||||
#
|
||||
# shared-1.*: Simple test to verify basic sanity of table level locking when
|
||||
# two connections share a pager cache.
|
||||
# shared-2.*: Test that a read transaction can co-exist with a
|
||||
# write-transaction, including a simple test to ensure the
|
||||
# external locking protocol is still working.
|
||||
#
|
||||
|
||||
do_test shared-1.1 {
|
||||
# Open a second database on the file test.db. It should use the same pager
|
||||
# cache and schema as the original connection. Verify that only 1 file is
|
||||
# opened.
|
||||
sqlite3 db2 test.db
|
||||
sqlite3 db test.db
|
||||
set ::sqlite_open_file_count
|
||||
} {1}
|
||||
do_test shared-1.2 {
|
||||
# Add a table and a single row of data via the first connection.
|
||||
# Ensure that the second connection can see them.
|
||||
execsql {
|
||||
CREATE TABLE abc(a, b, c);
|
||||
INSERT INTO abc VALUES(1, 2, 3);
|
||||
} db
|
||||
execsql {
|
||||
SELECT * FROM abc;
|
||||
} db2
|
||||
} {1 2 3}
|
||||
do_test shared-1.3 {
|
||||
# Have the first connection begin a transaction and obtain a read-lock
|
||||
# on table abc. This should not prevent the second connection from
|
||||
# querying abc.
|
||||
execsql {
|
||||
BEGIN;
|
||||
SELECT * FROM abc;
|
||||
}
|
||||
execsql {
|
||||
SELECT * FROM abc;
|
||||
} db2
|
||||
} {1 2 3}
|
||||
do_test shared-1.4 {
|
||||
# Try to insert a row into abc via connection 2. This should fail because
|
||||
# of the read-lock connection 1 is holding on table abc (obtained in the
|
||||
# previous test case).
|
||||
catchsql {
|
||||
INSERT INTO abc VALUES(4, 5, 6);
|
||||
} db2
|
||||
} {1 {database is locked}}
|
||||
do_test shared-1.5 {
|
||||
# Using connection 2 (the one without the open transaction), create a
|
||||
# new table and add a row to it. This is permitted as the transaction
|
||||
# started by connection 1 is currently a read transaction.
|
||||
execsql {
|
||||
CREATE TABLE def(d, e, f);
|
||||
INSERT INTO def VALUES('I', 'II', 'III');
|
||||
} db2
|
||||
} {}
|
||||
do_test shared-1.6 {
|
||||
# Upgrade connection 1's transaction to a write transaction. Insert
|
||||
# a row into table def - the table just created by connection 2.
|
||||
#
|
||||
# Connection 1 is able to see table def, even though it was created
|
||||
# "after" the connection 1 transaction was started. This is because no
|
||||
# lock was established on the sqlite_master table.
|
||||
|
||||
# Todo: Remove this. Because the implementation does not include
|
||||
# shared-schemas yet, we need to run some query (that will fail at
|
||||
# OP_VerifyCookie) so that connection 1 picks up the schema change
|
||||
# made via connection 2. Otherwise the sqlite3_prepare("INSERT INTO def...")
|
||||
# below will fail.
|
||||
execsql {
|
||||
SELECT * FROM sqlite_master;
|
||||
}
|
||||
|
||||
execsql {
|
||||
INSERT INTO def VALUES('IV', 'V', 'VI');
|
||||
}
|
||||
} {}
|
||||
do_test shared-1.7 {
|
||||
# Read from the sqlite_master table with connection 1 (inside the
|
||||
# transaction). Then test that we can no longer create a table
|
||||
# with connection 2. This is because of the read-lock on sqlite_master.
|
||||
execsql {
|
||||
SELECT * FROM sqlite_master;
|
||||
}
|
||||
catchsql {
|
||||
CREATE TABLE ghi(g, h, i);
|
||||
} db2
|
||||
} {1 {database is locked}}
|
||||
do_test shared-1.8 {
|
||||
# Check that connection 2 can read the sqlite_master table. Then
|
||||
# create a table using connection 1 (this should write-lock the
|
||||
# sqlite_master table). Then try to read sqlite_master again using
|
||||
# connection 2 and verify that the write-lock prevents this.
|
||||
execsql {
|
||||
SELECT * FROM sqlite_master;
|
||||
} db2
|
||||
execsql {
|
||||
CREATE TABLE ghi(g, h, i);
|
||||
}
|
||||
catchsql {
|
||||
SELECT * FROM sqlite_master;
|
||||
} db2
|
||||
} {1 {database is locked}}
|
||||
do_test shared-1.9 {
|
||||
# Commit the connection 1 transaction.
|
||||
execsql {
|
||||
COMMIT;
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test shared-2.1 {
|
||||
# Open connection db3 to the database. Use a different path to the same
|
||||
# file so that db3 does *not* share the same pager cache as db and db2
|
||||
# (there should be two open file handles).
|
||||
sqlite3 db3 ./test.db
|
||||
set ::sqlite_open_file_count
|
||||
} {2}
|
||||
do_test shared-2.2 {
|
||||
# Start read transactions on db and db2 (the shared pager cache). Ensure
|
||||
# db3 cannot write to the database.
|
||||
execsql {
|
||||
BEGIN;
|
||||
SELECT * FROM abc;
|
||||
}
|
||||
execsql {
|
||||
BEGIN;
|
||||
SELECT * FROM abc;
|
||||
} db2
|
||||
catchsql {
|
||||
INSERT INTO abc VALUES(1, 2, 3);
|
||||
} db2
|
||||
} {1 {database is locked}}
|
||||
do_test shared-2.3 {
|
||||
# Turn db's transaction into a write-transaction. db3 should still be
|
||||
# able to read from table def (but will not see the new row). Connection
|
||||
# db2 should not be able to read def (because of the write-lock).
|
||||
|
||||
# Todo: The failed "INSERT INTO abc ..." statement in the above test
|
||||
# has started a write-transaction on db2 (should this be so?). This
|
||||
# would prevent connection db from starting a write-transaction. So roll the
|
||||
# db2 transaction back and replace it with a new read transaction.
|
||||
execsql {
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
SELECT * FROM abc;
|
||||
} db2
|
||||
|
||||
execsql {
|
||||
INSERT INTO def VALUES('VII', 'VIII', 'IX');
|
||||
}
|
||||
concat [
|
||||
catchsql { SELECT * FROM def; } db3
|
||||
] [
|
||||
catchsql { SELECT * FROM def; } db2
|
||||
]
|
||||
} {0 {I II III IV V VI} 1 {database is locked}}
|
||||
do_test shared-2.4 {
|
||||
# Commit the open transaction on db. db2 still holds a read-transaction.
|
||||
# This should prevent db3 from writing to the database, but not from
|
||||
# reading.
|
||||
execsql {
|
||||
COMMIT;
|
||||
}
|
||||
concat [
|
||||
catchsql { SELECT * FROM def; } db3
|
||||
] [
|
||||
catchsql { INSERT INTO def VALUES('X', 'XI', 'XII'); } db3
|
||||
]
|
||||
} {0 {I II III IV V VI VII VIII IX} 1 {database is locked}}
|
||||
|
||||
|
||||
catch {db close}
|
||||
catch {db2 close}
|
||||
catch {db3 close}
|
||||
|
||||
finish_test
|
||||
sqlite3_enable_shared_cache $::enable_shared_cache
|
||||
|
||||
+14
-10
@@ -11,7 +11,7 @@
|
||||
# This file implements some common TCL routines used for regression
|
||||
# testing the SQLite library
|
||||
#
|
||||
# $Id: tester.tcl,v 1.54 2005/12/09 14:39:05 danielk1977 Exp $
|
||||
# $Id: tester.tcl,v 1.55 2005/12/30 16:28:02 danielk1977 Exp $
|
||||
|
||||
# Make sure tclsqlite3 was compiled correctly. Abort now with an
|
||||
# error message if not.
|
||||
@@ -440,6 +440,7 @@ proc copy_file {from to} {
|
||||
#
|
||||
proc check_for_leaks {} {
|
||||
set ret [list]
|
||||
set cnt 0
|
||||
foreach alloc [sqlite_malloc_outstanding] {
|
||||
foreach {nBytes file iLine userstring backtrace} $alloc {}
|
||||
set stack [list]
|
||||
@@ -447,18 +448,21 @@ proc check_for_leaks {} {
|
||||
|
||||
# The first command in this block will probably fail on windows. This
|
||||
# means there will be no stack dump available.
|
||||
catch {
|
||||
set stuff [eval "exec addr2line -e ./testfixture -f $backtrace"]
|
||||
foreach {func line} $stuff {
|
||||
if {$func != "??" || $line != "??:0"} {
|
||||
regexp {.*/(.*)} $line dummy line
|
||||
lappend stack "${func}() $line"
|
||||
} else {
|
||||
if {[lindex $stack end] != "..."} {
|
||||
lappend stack "..."
|
||||
if {$cnt < 25} {
|
||||
catch {
|
||||
set stuff [eval "exec addr2line -e ./testfixture -f $backtrace"]
|
||||
foreach {func line} $stuff {
|
||||
if {$func != "??" || $line != "??:0"} {
|
||||
regexp {.*/(.*)} $line dummy line
|
||||
lappend stack "${func}() $line"
|
||||
} else {
|
||||
if {[lindex $stack end] != "..."} {
|
||||
lappend stack "..."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
incr cnt
|
||||
}
|
||||
|
||||
if {!$skip} {
|
||||
|
||||
+3
-1
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is database locks.
|
||||
#
|
||||
# $Id: trans.test,v 1.26 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
# $Id: trans.test,v 1.27 2005/12/30 16:28:02 danielk1977 Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -97,6 +97,7 @@ do_test trans-3.2 {
|
||||
SELECT a FROM two ORDER BY a;
|
||||
} altdb
|
||||
} {0 {1 5 10}}
|
||||
|
||||
do_test trans-3.3 {
|
||||
catchsql {
|
||||
SELECT a FROM one ORDER BY a;
|
||||
@@ -135,6 +136,7 @@ do_test trans-3.9 {
|
||||
do_test trans-3.10 {
|
||||
execsql {END TRANSACTION}
|
||||
} {}
|
||||
|
||||
do_test trans-3.11 {
|
||||
set v [catch {execsql {
|
||||
SELECT a FROM two ORDER BY a;
|
||||
|
||||
Reference in New Issue
Block a user