mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Merge the KeyInfo cache mutex fix from trunk.
FossilOrigin-Name: f0940c73bd13cb49a3d229ce2517736324392cfb
This commit is contained in:
26
manifest
26
manifest
@@ -1,5 +1,5 @@
|
||||
C Merge\sthe\sfix\sfor\sthe\sshared-cache\sKeyInfo\scache\sbug\sfrom\strunk.
|
||||
D 2014-12-05T20:05:10.426
|
||||
C Merge\sthe\sKeyInfo\scache\smutex\sfix\sfrom\strunk.
|
||||
D 2014-12-09T14:54:26.273
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in 0869fe2a3b7853f048a945fd9cdf671a329b7351
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@@ -184,13 +184,13 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
|
||||
F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786
|
||||
F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
|
||||
F src/alter.c ba266a779bc7ce10e52e59e7d3dc79fa342e8fdb
|
||||
F src/analyze.c f7d774356ba5a14e7ad4fb637681af16875ad88f
|
||||
F src/analyze.c 7a2986e6ea8247e5f21aca3d0b584598f58d84fe
|
||||
F src/attach.c f4e94df2d1826feda65eb0939f7f6f5f923a0ad9
|
||||
F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240
|
||||
F src/backup.c 7ddee9c7d505e07e959a575b18498f17c71e53ea
|
||||
F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb
|
||||
F src/btmutex.c 49ca66250c7dfa844a4d4cb8272b87420d27d3a5
|
||||
F src/btree.c 44b58cd798a32579816ce274e415de262df9843d
|
||||
F src/btree.c ea6692ce58bfba55b12c75d2947fec0906d1ef7a
|
||||
F src/btree.h e31a3a3ebdedb1caf9bda3ad5dbab3db9b780f6e
|
||||
F src/btreeInt.h 3363e18fd76f69a27a870b25221b2345b3fd4d21
|
||||
F src/build.c 67bb05b1077e0cdaccb2e36bfcbe7a5df9ed31e8
|
||||
@@ -212,7 +212,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d
|
||||
F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e
|
||||
F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770
|
||||
F src/loadext.c de741e66e5ddc1598d904d7289239696e40ed994
|
||||
F src/main.c d13290bb1592cd7651a3b416a99850c652337e32
|
||||
F src/main.c 6614381d96520d7c73d0fb2eb5291533a6b04d16
|
||||
F src/malloc.c 740db54387204c9a2eb67c6d98e68b08e9ef4eab
|
||||
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
|
||||
F src/mem1.c faf615aafd8be74a71494dfa027c113ea5c6615f
|
||||
@@ -255,7 +255,7 @@ F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
|
||||
F src/status.c 81712116e826b0089bb221b018929536b2b5406f
|
||||
F src/table.c f142bba7903e93ca8d113a5b8877a108ad1a27dc
|
||||
F src/tclsqlite.c 05be57620509060e85064b9495256c05d56e76b0
|
||||
F src/test1.c c24d7f67252348d756773a6dbe23a61b4552f709
|
||||
F src/test1.c ebb8cd3c94a2ac8851b7b0b1349284e73a8b4c7a
|
||||
F src/test2.c 98049e51a17dc62606a99a9eb95ee477f9996712
|
||||
F src/test3.c 1c0e5d6f080b8e33c1ce8b3078e7013fdbcd560c
|
||||
F src/test4.c 9b32d22f5f150abe23c1830e2057c4037c45b3df
|
||||
@@ -315,13 +315,13 @@ F src/vdbeapi.c 3d4d2a2b24055ce2cb029fa73067c56616264b51
|
||||
F src/vdbeaux.c ccf6b7ca6c7361bdb71d12385b4cff70b395486c
|
||||
F src/vdbeblob.c cb7359c2d99df92c35cdaedc12af6d4f83854cb7
|
||||
F src/vdbemem.c 96e41193b4affd9ebc0eea2fa628879dac88c744
|
||||
F src/vdbesort.c 42c166f7ca78cb643c7f4e4bdfa83c59d363d1a6
|
||||
F src/vdbesort.c db015e20a77b25eca4d1e125815f4998a3ca1354
|
||||
F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010
|
||||
F src/vtab.c c08ec66f45919eaa726bf88aa53eb08379d607f9
|
||||
F src/wal.c 847692349eb6e1fb8543dbc97e69ddbfa4cc7ea7
|
||||
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
|
||||
F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804
|
||||
F src/where.c 8877b55e6803eaa856254875bca8d12fff3681cf
|
||||
F src/where.c e914fdb9159bb36af4a673193bbda08aaf9e5a73
|
||||
F src/whereInt.h d3633e9b592103241b74b0ec76185f3e5b8b62e0
|
||||
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
||||
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
||||
@@ -495,6 +495,7 @@ F test/e_update.test 312cb8f5ccfe41515a6bb092f8ea562a9bd54d52
|
||||
F test/e_uri.test 5ae33760fb2039c61aa2d90886f1664664173585
|
||||
F test/e_vacuum.test 5bfbdc21b65c0abf24398d0ba31dc88d93ca77a9
|
||||
F test/e_wal.test 0967f0b8f1dfda871dc7b9b5574198f1f4f7d69a
|
||||
F test/e_walckpt.test 18de8fca6b74f29bf7d24a2e267eec749b8fec50
|
||||
F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea
|
||||
F test/enc2.test 83437a79ba1545a55fb549309175c683fb334473
|
||||
F test/enc3.test 90683ad0e6ea587b9d5542ca93568af9a9858c40
|
||||
@@ -928,7 +929,7 @@ F test/thread2.test f35d2106452b77523b3a2b7d1dcde2e5ee8f9e46
|
||||
F test/thread_common.tcl 334639cadcb9f912bf82aa73f49efd5282e6cadd
|
||||
F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
|
||||
F test/threadtest2.c ace893054fa134af3fc8d6e7cfecddb8e3acefb9
|
||||
F test/threadtest3.c 0ed13e09690f6204d7455fac3b0e8ece490f6eef
|
||||
F test/threadtest3.c fca8d360b470405ae3ed431b5cb4cdf031f85a74
|
||||
F test/tkt-02a8e81d44.test 6c80d9c7514e2a42d4918bf87bf6bc54f379110c
|
||||
F test/tkt-26ff0c2d1e.test 888324e751512972c6e0d1a09df740d8f5aaf660
|
||||
F test/tkt-2a5629202f.test 0521bd25658428baa26665aa53ffed9367d33af2
|
||||
@@ -1092,6 +1093,7 @@ F test/triggerC.test a68980c5955d62ee24be6f97129d824f199f9a4c
|
||||
F test/triggerD.test 8e7f3921a92a5797d472732108109e44575fa650
|
||||
F test/triggerE.test 355e9c5cbaed5cd039a60baad1fb2197caeb8e52
|
||||
F test/tt3_checkpoint.c 415eccce672d681b297485fc20f44cdf0eac93af
|
||||
F test/tt3_index.c 2e7f3151a0ae522f031e8e2761ca2bda63f4d221
|
||||
F test/types.test bf816ce73c7dfcfe26b700c19f97ef4050d194ff
|
||||
F test/types2.test 3555aacf8ed8dc883356e59efc314707e6247a84
|
||||
F test/types3.test 99e009491a54f4dc02c06bdbc0c5eea56ae3e25a
|
||||
@@ -1242,7 +1244,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
|
||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
|
||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||
P c9f20eb2fbba0868df85ebb98877f9bb969be8a4 fdb667335c2250239a66143aec4235325dec8274
|
||||
R 5f307fe542c2e256cd3ca2580b7cd173
|
||||
P 5a73da6a3083926a3dafd28c0604122296dc9184 b05340fe3cd5f1676a55023228dc8d1a92de5936
|
||||
R 2816a79c9fe6d224099c23041d3622b2
|
||||
U drh
|
||||
Z d2fac6b276a39da7118e93eb39e0e62a
|
||||
Z 5d345254f96163549bdbecca703eb3ee
|
||||
|
@@ -1 +1 @@
|
||||
5a73da6a3083926a3dafd28c0604122296dc9184
|
||||
f0940c73bd13cb49a3d229ce2517736324392cfb
|
@@ -1596,7 +1596,7 @@ static void initAvgEq(Index *pIdx){
|
||||
i64 nSum100 = 0; /* Number of terms contributing to sumEq */
|
||||
i64 nDist100; /* Number of distinct values in index */
|
||||
|
||||
if( pIdx->aiRowEst==0 || pIdx->aiRowEst[iCol+1]==0 ){
|
||||
if( !pIdx->aiRowEst || iCol>=pIdx->nKeyCol || pIdx->aiRowEst[iCol+1]==0 ){
|
||||
nRow = pFinal->anLt[iCol];
|
||||
nDist100 = (i64)100 * pFinal->anDLt[iCol];
|
||||
nSample--;
|
||||
|
14
src/btree.c
14
src/btree.c
@@ -6785,7 +6785,7 @@ static int balance_nonroot(
|
||||
|
||||
/* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer
|
||||
** that is more than 6 times the database page size. */
|
||||
assert( szScratch<=6*pBt->pageSize );
|
||||
assert( szScratch<=6*(int)pBt->pageSize );
|
||||
apCell = sqlite3ScratchMalloc( szScratch );
|
||||
if( apCell==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
@@ -6859,7 +6859,11 @@ static int balance_nonroot(
|
||||
}else{
|
||||
assert( leafCorrection==4 );
|
||||
if( szCell[nCell]<4 ){
|
||||
/* Do not allow any cells smaller than 4 bytes. */
|
||||
/* Do not allow any cells smaller than 4 bytes. If a smaller cell
|
||||
** does exist, pad it with 0x00 bytes. */
|
||||
assert( szCell[nCell]==3 );
|
||||
assert( apCell[nCell]==&pTemp[iSpace1-3] );
|
||||
pTemp[iSpace1++] = 0x00;
|
||||
szCell[nCell] = 4;
|
||||
}
|
||||
}
|
||||
@@ -7094,7 +7098,11 @@ static int balance_nonroot(
|
||||
** if sibling page iOld had the same page number as pNew, and if
|
||||
** pCell really was a part of sibling page iOld (not a divider or
|
||||
** overflow cell), we can skip updating the pointer map entries. */
|
||||
if( pNew->pgno!=aPgno[iOld] || pCell<aOld || pCell>=&aOld[usableSize] ){
|
||||
if( iOld>=nNew
|
||||
|| pNew->pgno!=aPgno[iOld]
|
||||
|| pCell<aOld
|
||||
|| pCell>=&aOld[usableSize]
|
||||
){
|
||||
if( !leafCorrection ){
|
||||
ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc);
|
||||
}
|
||||
|
@@ -1034,11 +1034,13 @@ void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){
|
||||
if( pDb->pBt ){
|
||||
if( pDb->pSchema ){
|
||||
/* Must clear the KeyInfo cache. See ticket [e4a18565a36884b00edf] */
|
||||
sqlite3BtreeEnter(pDb->pBt);
|
||||
for(i=sqliteHashFirst(&pDb->pSchema->idxHash); i; i=sqliteHashNext(i)){
|
||||
Index *pIdx = sqliteHashData(i);
|
||||
sqlite3KeyInfoUnref(pIdx->pKeyInfo);
|
||||
pIdx->pKeyInfo = 0;
|
||||
}
|
||||
sqlite3BtreeLeave(pDb->pBt);
|
||||
}
|
||||
sqlite3BtreeClose(pDb->pBt);
|
||||
pDb->pBt = 0;
|
||||
@@ -2809,7 +2811,9 @@ static int openDatabase(
|
||||
sqlite3Error(db, rc);
|
||||
goto opendb_out;
|
||||
}
|
||||
sqlite3BtreeEnter(db->aDb[0].pBt);
|
||||
db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
|
||||
sqlite3BtreeLeave(db->aDb[0].pBt);
|
||||
db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
|
||||
|
||||
/* The default safety_level for the main database is 'full'; for the temp
|
||||
|
10
src/test1.c
10
src/test1.c
@@ -5704,15 +5704,17 @@ static int test_wal_checkpoint_v2(
|
||||
if( objc==4 ){
|
||||
zDb = Tcl_GetString(objv[3]);
|
||||
}
|
||||
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db)
|
||||
|| Tcl_GetIndexFromObj(interp, objv[2], aMode, "mode", 0, &eMode)
|
||||
){
|
||||
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) || (
|
||||
TCL_OK!=Tcl_GetIntFromObj(0, objv[2], &eMode)
|
||||
&& TCL_OK!=Tcl_GetIndexFromObj(interp, objv[2], aMode, "mode", 0, &eMode)
|
||||
)){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
rc = sqlite3_wal_checkpoint_v2(db, zDb, eMode, &nLog, &nCkpt);
|
||||
if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
|
||||
Tcl_SetResult(interp, (char *)sqlite3_errmsg(db), TCL_VOLATILE);
|
||||
const char *zErrCode = sqlite3ErrName(rc);
|
||||
Tcl_AppendResult(interp, zErrCode, " - ", (char *)sqlite3_errmsg(db), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
|
@@ -450,7 +450,9 @@ struct SorterRecord {
|
||||
|
||||
/* The minimum PMA size is set to this value multiplied by the database
|
||||
** page size in bytes. */
|
||||
#define SORTER_MIN_WORKING 10
|
||||
#ifndef SQLITE_SORTER_PMASZ
|
||||
# define SQLITE_SORTER_PMASZ 250
|
||||
#endif
|
||||
|
||||
/* Maximum number of PMAs that a single MergeEngine can merge */
|
||||
#define SORTER_MAX_MERGE_COUNT 16
|
||||
@@ -849,9 +851,9 @@ int sqlite3VdbeSorterInit(
|
||||
}
|
||||
|
||||
if( !sqlite3TempInMemory(db) ){
|
||||
pSorter->mnPmaSize = SORTER_MIN_WORKING * pgsz;
|
||||
pSorter->mnPmaSize = SQLITE_SORTER_PMASZ * pgsz;
|
||||
mxCache = db->aDb[0].pSchema->cache_size;
|
||||
if( mxCache<SORTER_MIN_WORKING ) mxCache = SORTER_MIN_WORKING;
|
||||
if( mxCache<SQLITE_SORTER_PMASZ ) mxCache = SQLITE_SORTER_PMASZ;
|
||||
pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_MXPMASIZE);
|
||||
|
||||
/* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
|
||||
|
@@ -2948,7 +2948,7 @@ static void addScanStatus(
|
||||
){
|
||||
const char *zObj = 0;
|
||||
WhereLoop *pLoop = pLvl->pWLoop;
|
||||
if( (pLoop->wsFlags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
|
||||
if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 && pLoop->u.btree.pIndex!=0 ){
|
||||
zObj = pLoop->u.btree.pIndex->zName;
|
||||
}else{
|
||||
zObj = pSrclist->a[pLvl->iFrom].zName;
|
||||
|
488
test/e_walckpt.test
Normal file
488
test/e_walckpt.test
Normal file
@@ -0,0 +1,488 @@
|
||||
# 2014 December 04
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
source $testdir/lock_common.tcl
|
||||
source $testdir/wal_common.tcl
|
||||
set testprefix e_walckpt
|
||||
|
||||
# The following two commands are used to determine if any of the files
|
||||
# "test.db", "test.db2" and "test.db3" are modified by a test case.
|
||||
#
|
||||
# The [save_db_hashes] command saves a hash of the current contents of
|
||||
# all three files in global variables. The [compare_db_hashes] compares
|
||||
# the current contents with the saved hashes and returns a list of the
|
||||
# files that have changed.
|
||||
#
|
||||
proc save_db_hashes {} {
|
||||
global H
|
||||
foreach f {test.db test.db2 test.db3} {
|
||||
set H($f) 0
|
||||
catch { set H($f) [md5file $f] }
|
||||
}
|
||||
}
|
||||
proc compare_db_hashes {} {
|
||||
global H
|
||||
set ret [list]
|
||||
foreach f {test.db test.db2 test.db3} {
|
||||
set expect 0
|
||||
catch { set expect [md5file $f] }
|
||||
if {$H($f) != $expect} { lappend ret $f }
|
||||
}
|
||||
set ret
|
||||
}
|
||||
|
||||
|
||||
# The following tests are run 3 times, each using a different method of
|
||||
# invoking a checkpoint:
|
||||
#
|
||||
# 1) Using sqlite3_wal_checkpoint_v2()
|
||||
# 2) Using "PRAGMA wal_checkpoint"
|
||||
# 3) Using sqlite3_wal_checkpoint() in place of checkpoint_v2(PASSIVE)
|
||||
#
|
||||
# Cases (2) and (3) are to show that the following statements are
|
||||
# correct, respectively:
|
||||
#
|
||||
# EVIDENCE-OF: R-36706-10507 The PRAGMA wal_checkpoint command can be
|
||||
# used to invoke this interface from SQL.
|
||||
#
|
||||
# EVIDENCE-OF: R-41613-20553 The sqlite3_wal_checkpoint(D,X) is
|
||||
# equivalent to
|
||||
# sqlite3_wal_checkpoint_v2(D,X,SQLITE_CHECKPOINT_PASSIVE,0,0).
|
||||
#
|
||||
foreach {tn script} {
|
||||
1 {
|
||||
proc checkpoint {db mode args} {
|
||||
eval sqlite3_wal_checkpoint_v2 [list $db] [list $mode] $args
|
||||
}
|
||||
}
|
||||
|
||||
2 {
|
||||
proc checkpoint {db mode args} {
|
||||
set sql "PRAGMA wal_checkpoint = $mode"
|
||||
if {[llength $args] && [lindex $args 0]!=""} {
|
||||
set sql "PRAGMA [lindex $args 0].wal_checkpoint = $mode"
|
||||
}
|
||||
set rc [catch { $db eval $sql } msg]
|
||||
if {$rc} {
|
||||
regsub {database} $msg {database:} msg
|
||||
error "[sqlite3_errcode $db] - $msg"
|
||||
}
|
||||
set msg
|
||||
}
|
||||
}
|
||||
|
||||
3 {
|
||||
proc checkpoint {db mode args} {
|
||||
if {$mode == "passive"} {
|
||||
set rc [eval sqlite3_wal_checkpoint [list $db] $args]
|
||||
if {$rc != "SQLITE_OK"} {
|
||||
error "$rc - [sqlite3_errmsg $db]"
|
||||
}
|
||||
} else {
|
||||
eval sqlite3_wal_checkpoint_v2 [list $db] [list $mode] $args
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} {
|
||||
|
||||
eval $script
|
||||
|
||||
reset_db
|
||||
forcedelete test.db2 test.db3 test.db4
|
||||
execsql {
|
||||
ATTACH 'test.db2' AS aux;
|
||||
ATTACH 'test.db3' AS aux2;
|
||||
ATTACH 'test.db4' AS aux3;
|
||||
CREATE TABLE t1(x);
|
||||
CREATE TABLE aux.t2(x);
|
||||
CREATE TABLE aux2.t3(x);
|
||||
CREATE TABLE aux3.t4(x);
|
||||
PRAGMA main.journal_mode = WAL;
|
||||
PRAGMA aux.journal_mode = WAL;
|
||||
PRAGMA aux2.journal_mode = WAL;
|
||||
/* Leave aux4 in rollback mode */
|
||||
}
|
||||
|
||||
# EVIDENCE-OF: R-49787-09095 The sqlite3_wal_checkpoint_v2(D,X,M,L,C)
|
||||
# interface runs a checkpoint operation on database X of database
|
||||
# connection D in mode M. Status information is written back into
|
||||
# integers pointed to by L and C.
|
||||
#
|
||||
# Tests 1, 2 and 3 below verify the "on database X" part of the
|
||||
# above. Other parts of this requirement are tested below.
|
||||
#
|
||||
# EVIDENCE-OF: R-00653-06026 If parameter zDb is NULL or points to a
|
||||
# zero length string, then the specified operation is attempted on all
|
||||
# WAL databases attached to database connection db.
|
||||
#
|
||||
# Tests 4 and 5 below test this.
|
||||
#
|
||||
foreach {tn2 zDb dblist} {
|
||||
1 main test.db
|
||||
2 aux test.db2
|
||||
3 aux2 test.db3
|
||||
4 "" {test.db test.db2 test.db3}
|
||||
5 - {test.db test.db2 test.db3}
|
||||
6 temp {}
|
||||
} {
|
||||
do_test $tn.1.$tn2 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(1);
|
||||
INSERT INTO t2 VALUES(2);
|
||||
INSERT INTO t3 VALUES(3);
|
||||
}
|
||||
save_db_hashes
|
||||
|
||||
if {$zDb == "-"} {
|
||||
checkpoint db passive
|
||||
} else {
|
||||
checkpoint db passive $zDb
|
||||
}
|
||||
|
||||
compare_db_hashes
|
||||
} $dblist
|
||||
}
|
||||
|
||||
# EVIDENCE-OF: R-38207-48996 If zDb is not NULL (or a zero length
|
||||
# string) and is not the name of any attached database, SQLITE_ERROR is
|
||||
# returned to the caller.
|
||||
do_test $tn.2.1 {
|
||||
list [catch { checkpoint db passive notadb } msg] $msg
|
||||
} {1 {SQLITE_ERROR - unknown database: notadb}}
|
||||
|
||||
# EVIDENCE-OF: R-14303-42483 If database zDb is the name of an attached
|
||||
# database that is not in WAL mode, SQLITE_OK is returned and both
|
||||
# *pnLog and *pnCkpt set to -1.
|
||||
#
|
||||
if {$tn==3} {
|
||||
# With sqlite3_wal_checkpoint() the two output variables cannot be
|
||||
# tested. So just test that no error is returned when attempting to
|
||||
# checkpoint a db in rollback mode.
|
||||
do_test $tn.2.2.a { checkpoint db passive aux3 } {}
|
||||
} else {
|
||||
do_test $tn.2.2.b { checkpoint db passive aux3 } {0 -1 -1}
|
||||
}
|
||||
|
||||
# EVIDENCE-OF: R-62028-47212 All calls obtain an exclusive "checkpoint"
|
||||
# lock on the database file.
|
||||
db close
|
||||
testvfs tvfs
|
||||
tvfs filter xShmLock
|
||||
tvfs script filelock
|
||||
proc filelock {method file handle details} {
|
||||
# Test for an exclusive checkpoint lock. A checkpoint lock locks a
|
||||
# single byte starting at offset 1.
|
||||
if {$details == "1 1 lock exclusive"} { set ::seen_checkpoint_lock 1 }
|
||||
}
|
||||
sqlite3 db test.db -vfs tvfs
|
||||
do_test $tn.3.1 {
|
||||
execsql { INSERT INTO t1 VALUES('xyz') }
|
||||
unset -nocomplain ::seen_checkpoint_lock
|
||||
checkpoint db passive
|
||||
set ::seen_checkpoint_lock
|
||||
} {1}
|
||||
db close
|
||||
tvfs delete
|
||||
reset_db
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# EVIDENCE-OF: R-10421-19736 If any other process is running a
|
||||
# checkpoint operation at the same time, the lock cannot be obtained and
|
||||
# SQLITE_BUSY is returned.
|
||||
#
|
||||
# EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured,
|
||||
# it will not be invoked in this case.
|
||||
#
|
||||
testvfs tvfs
|
||||
tvfs filter xWrite
|
||||
sqlite3 db test.db -vfs tvfs
|
||||
sqlite3 db2 test.db -vfs tvfs
|
||||
|
||||
do_test $tn.3.2.1 {
|
||||
db2 eval {
|
||||
PRAGMA journal_mode = WAL;
|
||||
CREATE TABLE t1(x, y);
|
||||
INSERT INTO t1 VALUES(1,2);
|
||||
INSERT INTO t1 VALUES(3,4);
|
||||
INSERT INTO t1 VALUES(5,6);
|
||||
}
|
||||
file size test.db-wal
|
||||
} [wal_file_size 5 1024]
|
||||
|
||||
|
||||
# Connection [db] runs a checkpoint. During this checkpoint, each
|
||||
# time it calls xWrite() to write a page into the database file, we
|
||||
# attempt to start a checkpoint using [db2]. According to the
|
||||
# first requirement being tested, this should return SQLITE_BUSY. According
|
||||
# to the second, the busy-handler belonging to [db2] should not be
|
||||
# invoked.
|
||||
#
|
||||
set ::write_count 0
|
||||
set ::write_errors [list]
|
||||
proc busy_callback {args} {
|
||||
lappend ::write_errors "busy handler called!"
|
||||
}
|
||||
proc write_callback {args} {
|
||||
set rc [catch {checkpoint db2 passive} msg]
|
||||
if {0==[regexp "database is locked" $msg] && $msg!="1 -1 -1"} {
|
||||
lappend ::write_errors "$rc $msg"
|
||||
}
|
||||
incr ::write_count
|
||||
}
|
||||
db2 busy busy_callback
|
||||
tvfs script write_callback
|
||||
|
||||
do_test $tn.3.2.2 {
|
||||
db eval {SELECT * FROM sqlite_master}
|
||||
checkpoint db full
|
||||
set ::write_count
|
||||
} {2}
|
||||
|
||||
do_test $tn.3.2.3 {
|
||||
set ::write_errors
|
||||
} {}
|
||||
|
||||
db close
|
||||
db2 close
|
||||
tvfs delete
|
||||
|
||||
proc busy_handler {mode busy_handler_mode n} {
|
||||
incr ::busy_handler_counter
|
||||
switch -- $busy_handler_mode {
|
||||
1 {
|
||||
# Do nothing. Do not block.
|
||||
return 1
|
||||
}
|
||||
|
||||
2 {
|
||||
# Close first the reader, then later the writer.
|
||||
if {$n==5} { catch {db2 eval commit} }
|
||||
if {$n==10} { catch {db3 eval commit} }
|
||||
return 0
|
||||
}
|
||||
|
||||
3 {
|
||||
# Close first the writer, then later the reader.
|
||||
if {$n==5} { catch {db2 eval commit} }
|
||||
if {$n==10} { catch {db3 eval commit} }
|
||||
return 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach {mode busy_handler_mode} {
|
||||
passive 1
|
||||
full 1
|
||||
full 2
|
||||
full 3
|
||||
} {
|
||||
|
||||
set ::sync_counter 0
|
||||
|
||||
proc tvfs_callback {method args} {
|
||||
set tail [file tail [lindex $args 0]]
|
||||
if {$method == "xSync" && $tail == "test.db"} {
|
||||
incr ::sync_counter
|
||||
}
|
||||
|
||||
if {$method == "xWrite" && $tail=="test.db"} {
|
||||
if {$::write_ok < 0} {
|
||||
set ::write_ok [expr ![catch {db5 eval { BEGIN IMMEDIATE }}]]
|
||||
catch { db5 eval ROLLBACK }
|
||||
}
|
||||
if {$::read_ok < 0} {
|
||||
set ::read_ok [expr ![catch {db5 eval { SELECT * FROM t1 }}]]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch { db close }
|
||||
forcedelete test.db
|
||||
testvfs tvfs
|
||||
sqlite3 db test.db -vfs tvfs
|
||||
#tvfs filter xSync
|
||||
tvfs script tvfs_callback
|
||||
|
||||
do_execsql_test $tn.4.$mode.0 {
|
||||
CREATE TABLE t1(a, b);
|
||||
CREATE TABLE t2(a, b);
|
||||
PRAGMA journal_mode = wal;
|
||||
INSERT INTO t1 VALUES(1, 2);
|
||||
INSERT INTO t1 VALUES(3, 4);
|
||||
INSERT INTO t1 VALUES(5, 6);
|
||||
} {wal}
|
||||
|
||||
# Open a reader on the current database snapshot.
|
||||
do_test $tn.4.$mode.1 {
|
||||
sqlite3 db2 test.db -vfs tvfs
|
||||
execsql {
|
||||
BEGIN;
|
||||
SELECT * FROM t1 UNION ALL SELECT * FROM t2;
|
||||
} db2
|
||||
} {1 2 3 4 5 6}
|
||||
|
||||
# Open a writer. Write a transaction. Then begin, but do not commit,
|
||||
# a second transaction.
|
||||
do_test $tn.4.$mode.2 {
|
||||
sqlite3 db3 test.db -vfs tvfs
|
||||
execsql {
|
||||
INSERT INTO t2 VALUES(7, 8);
|
||||
BEGIN;
|
||||
INSERT INTO t2 VALUES(9, 10);
|
||||
SELECT * FROM t1 UNION ALL SELECT * FROM t2;
|
||||
} db3
|
||||
} {1 2 3 4 5 6 7 8 9 10}
|
||||
|
||||
sqlite3 db5 test.db -vfs tvfs
|
||||
|
||||
# Register a busy-handler with connection [db].
|
||||
#
|
||||
db busy [list busy_handler $mode $busy_handler_mode]
|
||||
set ::sync_counter 0
|
||||
set ::busy_handler_counter 0
|
||||
set ::read_ok -1
|
||||
set ::write_ok -1
|
||||
|
||||
do_test $tn.4.$mode.3 {
|
||||
checkpoint db $mode main
|
||||
set {} {}
|
||||
} {}
|
||||
|
||||
if { $mode=="passive" } {
|
||||
# EVIDENCE-OF: R-16333-64433 Checkpoint as many frames as possible
|
||||
# without waiting for any database readers or writers to finish, then
|
||||
# sync the database file if all frames in the log were checkpointed.
|
||||
#
|
||||
# "As many frames as possible" means all but the last two transactions
|
||||
# (the two that write to table t2, of which the scond is unfinished).
|
||||
# So copying the db file only we see the t1 change, but not the t2
|
||||
# modifications.
|
||||
#
|
||||
# The busy handler is not invoked (see below) and the db reader and
|
||||
# writer are still active - so the checkpointer did not wait for either
|
||||
# readers or writers. As a result the checkpoint was not finished and
|
||||
# so the db file is not synced.
|
||||
#
|
||||
# EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
|
||||
# in the SQLITE_CHECKPOINT_PASSIVE mode.
|
||||
#
|
||||
# It's not. Test case "$tn.4.$mode.6".
|
||||
#
|
||||
do_test $tn.4.$mode.4 {
|
||||
forcecopy test.db abc.db
|
||||
sqlite3 db4 abc.db
|
||||
db4 eval { SELECT * FROM t1 UNION ALL SELECT * FROM t2 }
|
||||
} {1 2 3 4 5 6}
|
||||
do_test $tn.4.$mode.5 { set ::sync_counter } 0
|
||||
do_test $tn.4.$mode.6 { set ::busy_handler_counter } 0
|
||||
db4 close
|
||||
|
||||
db2 eval COMMIT
|
||||
db3 eval COMMIT
|
||||
|
||||
# EVIDENCE-OF: R-65499-53765 On the other hand, passive mode might leave
|
||||
# the checkpoint unfinished if there are concurrent readers or writers.
|
||||
#
|
||||
# The reader and writer have now dropped their locks. And so a
|
||||
# checkpoint now is able to checkpoint more frames. Showing that the
|
||||
# attempt above was left "unfinished".
|
||||
#
|
||||
# Also, because the checkpoint finishes this time, the db is synced.
|
||||
# Which is part of R-16333-64433 above.
|
||||
#
|
||||
do_test $tn.4.$mode.7 {
|
||||
checkpoint db $mode main
|
||||
forcecopy test.db abc.db
|
||||
sqlite3 db4 abc.db
|
||||
db4 eval { SELECT * FROM t1 UNION ALL SELECT * FROM t2 }
|
||||
} {1 2 3 4 5 6 7 8 9 10}
|
||||
do_test $tn.4.$mode.6 { set ::sync_counter } 1
|
||||
do_test $tn.4.$mode.7 { set ::busy_handler_counter } 0
|
||||
db4 close
|
||||
}
|
||||
|
||||
if { $mode=="full" } {
|
||||
if {$busy_handler_mode==2 || $busy_handler_mode==3} {
|
||||
# EVIDENCE-OF: R-59171-47567 This mode blocks (it invokes the
|
||||
# busy-handler callback) until there is no database writer and all
|
||||
# readers are reading from the most recent database snapshot.
|
||||
#
|
||||
# Show that both the reader and writer have finished:
|
||||
#
|
||||
do_test $tn.4.$mode.7 {
|
||||
list [catchsql COMMIT db2] [catchsql COMMIT db3]
|
||||
} [list \
|
||||
{1 {cannot commit - no transaction is active}} \
|
||||
{1 {cannot commit - no transaction is active}} \
|
||||
]
|
||||
|
||||
# EVIDENCE-OF: R-29177-48281 It then checkpoints all frames in the log
|
||||
# file and syncs the database file.
|
||||
#
|
||||
do_test $tn.4.$mode.8 {
|
||||
forcecopy test.db abc.db
|
||||
sqlite3 db4 abc.db
|
||||
db4 eval { SELECT * FROM t1 UNION ALL SELECT * FROM t2 }
|
||||
} {1 2 3 4 5 6 7 8 9 10}
|
||||
do_test $tn.4.$mode.9 { set ::sync_counter } 1
|
||||
db4 close
|
||||
|
||||
# EVIDENCE-OF: R-51867-44713 This mode blocks new database writers
|
||||
# while it is pending, but new database readers are allowed to continue
|
||||
# unimpeded.
|
||||
do_test $tn.4.$mode.10 {
|
||||
list $::write_ok $::read_ok
|
||||
} {0 1}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
db2 close
|
||||
db3 close
|
||||
db5 close
|
||||
}
|
||||
|
||||
db close
|
||||
tvfs delete
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# EVIDENCE-OF: R-03996-12088 The M parameter must be a valid checkpoint
|
||||
# mode:
|
||||
#
|
||||
# Valid checkpoint modes are 0, 1, 2 and 3.
|
||||
#
|
||||
sqlite3 db test.db
|
||||
foreach {tn mode res} {
|
||||
0 -1001 {1 {SQLITE_MISUSE - not an error}}
|
||||
1 -1 {1 {SQLITE_MISUSE - not an error}}
|
||||
2 0 {0 {0 -1 -1}}
|
||||
3 1 {0 {0 -1 -1}}
|
||||
4 2 {0 {0 -1 -1}}
|
||||
5 3 {0 {0 -1 -1}}
|
||||
6 4 {1 {SQLITE_MISUSE - not an error}}
|
||||
7 114 {1 {SQLITE_MISUSE - not an error}}
|
||||
8 1000000 {1 {SQLITE_MISUSE - not an error}}
|
||||
} {
|
||||
do_test 4.$tn {
|
||||
list [catch "sqlite3_wal_checkpoint_v2 db $mode" msg] $msg
|
||||
} $res
|
||||
}
|
||||
|
||||
|
||||
finish_test
|
@@ -1394,7 +1394,10 @@ static void dynamic_triggers(int nMs){
|
||||
print_and_free_err(&err);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "tt3_checkpoint.c"
|
||||
#include "tt3_index.c"
|
||||
|
||||
int main(int argc, char **argv){
|
||||
struct ThreadTest {
|
||||
@@ -1414,6 +1417,8 @@ int main(int argc, char **argv){
|
||||
|
||||
{ checkpoint_starvation_1, "checkpoint_starvation_1", 10000 },
|
||||
{ checkpoint_starvation_2, "checkpoint_starvation_2", 10000 },
|
||||
|
||||
{ create_drop_index_1, "create_drop_index_1", 10000 },
|
||||
};
|
||||
|
||||
int i;
|
||||
|
74
test/tt3_index.c
Normal file
74
test/tt3_index.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
** 2014 December 9
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** create_drop_index_1
|
||||
*/
|
||||
|
||||
|
||||
static char *create_drop_index_thread(int iTid, int iArg){
|
||||
Error err = {0}; /* Error code and message */
|
||||
Sqlite db = {0}; /* SQLite database connection */
|
||||
|
||||
while( !timetostop(&err) ){
|
||||
opendb(&err, &db, "test.db", 0);
|
||||
|
||||
sql_script(&err, &db,
|
||||
|
||||
"DROP INDEX IF EXISTS i1;"
|
||||
"DROP INDEX IF EXISTS i2;"
|
||||
"DROP INDEX IF EXISTS i3;"
|
||||
"DROP INDEX IF EXISTS i4;"
|
||||
|
||||
"CREATE INDEX IF NOT EXISTS i1 ON t1(a);"
|
||||
"CREATE INDEX IF NOT EXISTS i2 ON t1(b);"
|
||||
"CREATE INDEX IF NOT EXISTS i3 ON t1(c);"
|
||||
"CREATE INDEX IF NOT EXISTS i4 ON t1(d);"
|
||||
|
||||
"SELECT * FROM t1 ORDER BY a;"
|
||||
"SELECT * FROM t1 ORDER BY b;"
|
||||
"SELECT * FROM t1 ORDER BY c;"
|
||||
"SELECT * FROM t1 ORDER BY d;"
|
||||
);
|
||||
|
||||
closedb(&err, &db);
|
||||
}
|
||||
|
||||
print_and_free_err(&err);
|
||||
return sqlite3_mprintf("ok");
|
||||
}
|
||||
|
||||
static void create_drop_index_1(int nMs){
|
||||
Error err = {0};
|
||||
Sqlite db = {0};
|
||||
Threadset threads = {0};
|
||||
|
||||
opendb(&err, &db, "test.db", 1);
|
||||
sql_script(&err, &db,
|
||||
"CREATE TABLE t1(a, b, c, d);"
|
||||
"WITH data(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM data WHERE x<100) "
|
||||
"INSERT INTO t1 SELECT x,x,x,x FROM data;"
|
||||
);
|
||||
closedb(&err, &db);
|
||||
|
||||
setstoptime(&err, nMs);
|
||||
|
||||
sqlite3_enable_shared_cache(1);
|
||||
launch_thread(&err, &threads, create_drop_index_thread, 0);
|
||||
launch_thread(&err, &threads, create_drop_index_thread, 0);
|
||||
launch_thread(&err, &threads, create_drop_index_thread, 0);
|
||||
launch_thread(&err, &threads, create_drop_index_thread, 0);
|
||||
launch_thread(&err, &threads, create_drop_index_thread, 0);
|
||||
sqlite3_enable_shared_cache(0);
|
||||
|
||||
join_all_threads(&err, &threads);
|
||||
print_and_free_err(&err);
|
||||
}
|
Reference in New Issue
Block a user