Fix a race condition to do with very large index keys in shared-cache mode.

FossilOrigin-Name: fc157dd7f18c94b7ae5f155e1b4a5d7714b7da8c
This commit is contained in:
dan
2014-12-11 16:38:18 +00:00
parent 0a3520c0f4
commit 857536623a
7 changed files with 119 additions and 16 deletions
+2
View File
@@ -1398,6 +1398,7 @@ static void dynamic_triggers(int nMs){
#include "tt3_checkpoint.c"
#include "tt3_index.c"
#include "tt3_lookaside1.c"
int main(int argc, char **argv){
struct ThreadTest {
@@ -1419,6 +1420,7 @@ int main(int argc, char **argv){
{ checkpoint_starvation_2, "checkpoint_starvation_2", 10000 },
{ create_drop_index_1, "create_drop_index_1", 10000 },
{ lookaside1, "lookaside1", 10000 },
};
int i;
+1 -1
View File
@@ -67,8 +67,8 @@ static void create_drop_index_1(int nMs){
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);
sqlite3_enable_shared_cache(0);
print_and_free_err(&err);
}
+99
View File
@@ -0,0 +1,99 @@
/*
** 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.
**
*************************************************************************
**
** lookaside1
*/
/*
** The test in this file attempts to expose a specific race condition
** that is suspected to exist at time of writing.
*/
static char *lookaside1_thread_reader(int iTid, int iArg){
Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */
opendb(&err, &db, "test.db", 0);
while( !timetostop(&err) ){
sqlite3_stmt *pStmt = 0;
int rc;
sqlite3_prepare_v2(db.db, "SELECT 1 FROM t1", -1, &pStmt, 0);
while( sqlite3_step(pStmt)==SQLITE_ROW ){
execsql(&err, &db, "SELECT length(x||y||z) FROM t2");
}
rc = sqlite3_finalize(pStmt);
if( err.rc==SQLITE_OK && rc!=SQLITE_OK ){
sqlite_error(&err, &db, "finalize");
}
}
closedb(&err, &db);
print_and_free_err(&err);
return sqlite3_mprintf("ok");
}
static char *lookaside1_thread_writer(int iTid, int iArg){
Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */
opendb(&err, &db, "test.db", 0);
do{
sql_script(&err, &db,
"BEGIN;"
"UPDATE t3 SET i=i+1 WHERE x=1;"
"ROLLBACK;"
);
}while( !timetostop(&err) );
closedb(&err, &db);
print_and_free_err(&err);
return sqlite3_mprintf("ok");
}
static void lookaside1(int nMs){
Error err = {0};
Sqlite db = {0};
Threadset threads = {0};
opendb(&err, &db, "test.db", 1);
sql_script(&err, &db,
"CREATE TABLE t1(x PRIMARY KEY) WITHOUT ROWID;"
"WITH data(x,y) AS ("
" SELECT 1, quote(randomblob(750)) UNION ALL "
" SELECT x*2, y||y FROM data WHERE x<5) "
"INSERT INTO t1 SELECT y FROM data;"
"CREATE TABLE t3(x PRIMARY KEY,i) WITHOUT ROWID;"
"INSERT INTO t3 VALUES(1, 1);"
"CREATE TABLE t2(x,y,z);"
"INSERT INTO t2 VALUES(randomblob(50), randomblob(50), randomblob(50));"
);
closedb(&err, &db);
setstoptime(&err, nMs);
sqlite3_enable_shared_cache(1);
launch_thread(&err, &threads, lookaside1_thread_reader, 0);
launch_thread(&err, &threads, lookaside1_thread_reader, 0);
launch_thread(&err, &threads, lookaside1_thread_reader, 0);
launch_thread(&err, &threads, lookaside1_thread_reader, 0);
launch_thread(&err, &threads, lookaside1_thread_reader, 0);
launch_thread(&err, &threads, lookaside1_thread_writer, 0);
join_all_threads(&err, &threads);
sqlite3_enable_shared_cache(0);
print_and_free_err(&err);
}