1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Further enhancements to threadtest3 stress tests.

FossilOrigin-Name: ba772cff602ca7c3c0c91451e701f52a872e7a14
This commit is contained in:
dan
2014-12-13 17:41:48 +00:00
parent 9bd3cc4681
commit 053542d72a
8 changed files with 299 additions and 60 deletions

View File

@ -1,5 +1,5 @@
C Add\sextra\stests\sto\sthreadtest4.c.\s\sFix\sa\sbenign\sdata\srace\saccessing\sthe\ntext\sencoding\susing\sENC(db). C Further\senhancements\sto\sthreadtest3\sstress\stests.
D 2014-12-12T23:17:54.003 D 2014-12-13T17:41:48.275
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 6c4f961fa91d0b4fa121946a19f9e5eac2f2f809 F Makefile.in 6c4f961fa91d0b4fa121946a19f9e5eac2f2f809
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -912,7 +912,7 @@ F test/thread2.test f35d2106452b77523b3a2b7d1dcde2e5ee8f9e46
F test/thread_common.tcl 334639cadcb9f912bf82aa73f49efd5282e6cadd F test/thread_common.tcl 334639cadcb9f912bf82aa73f49efd5282e6cadd
F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
F test/threadtest2.c ace893054fa134af3fc8d6e7cfecddb8e3acefb9 F test/threadtest2.c ace893054fa134af3fc8d6e7cfecddb8e3acefb9
F test/threadtest3.c bef2bde18b4e638b6cf4b119aa2076123ffdc425 F test/threadtest3.c 05d67ab8fd4ad82978a96200701a22af35faa097
F test/threadtest4.c c1e67136ceb6c7ec8184e56ac61db28f96bd2925 F test/threadtest4.c c1e67136ceb6c7ec8184e56ac61db28f96bd2925
F test/tkt-02a8e81d44.test 6c80d9c7514e2a42d4918bf87bf6bc54f379110c F test/tkt-02a8e81d44.test 6c80d9c7514e2a42d4918bf87bf6bc54f379110c
F test/tkt-26ff0c2d1e.test 888324e751512972c6e0d1a09df740d8f5aaf660 F test/tkt-26ff0c2d1e.test 888324e751512972c6e0d1a09df740d8f5aaf660
@ -1076,11 +1076,11 @@ F test/triggerB.test 56780c031b454abac2340dbb3b71ac5c56c3d7fe
F test/triggerC.test a68980c5955d62ee24be6f97129d824f199f9a4c F test/triggerC.test a68980c5955d62ee24be6f97129d824f199f9a4c
F test/triggerD.test 8e7f3921a92a5797d472732108109e44575fa650 F test/triggerD.test 8e7f3921a92a5797d472732108109e44575fa650
F test/triggerE.test 355e9c5cbaed5cd039a60baad1fb2197caeb8e52 F test/triggerE.test 355e9c5cbaed5cd039a60baad1fb2197caeb8e52
F test/tt3_checkpoint.c 415eccce672d681b297485fc20f44cdf0eac93af F test/tt3_checkpoint.c 5e63ee65ed5f87176e25a996480cb02c6caec8b4
F test/tt3_index.c 652630e6b6fc7a48adf2ead60de1ef48e1a34569 F test/tt3_index.c 39eec10a35f57672225be4d182862152896dee4a
F test/tt3_lookaside1.c 0b5b79ba37f21a1eb849cd4a54eed367f4d4aaaf F test/tt3_lookaside1.c 0377e202c3c2a50d688cb65ba203afeda6fafeb9
F test/tt3_stress.c e003a8486ba990c43dc9b8298f4b266cd10eb1c1 F test/tt3_stress.c edbb00ed1516535691040315e97cf32c62df22d0
F test/tt3_vacuum.c 6a66e52e2b39fc0cccb71db5a302411f34d09736 F test/tt3_vacuum.c 1753f45917699c9c1f66b64c717a717c9379f776
F test/types.test bf816ce73c7dfcfe26b700c19f97ef4050d194ff F test/types.test bf816ce73c7dfcfe26b700c19f97ef4050d194ff
F test/types2.test 3555aacf8ed8dc883356e59efc314707e6247a84 F test/types2.test 3555aacf8ed8dc883356e59efc314707e6247a84
F test/types3.test 99e009491a54f4dc02c06bdbc0c5eea56ae3e25a F test/types3.test 99e009491a54f4dc02c06bdbc0c5eea56ae3e25a
@ -1231,7 +1231,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P f6bf86f907cbff31bed3cbfc922c10c973575498 P d7bb7ea4ab97ad26f4c84c9b8dc2827010093803
R 97f096b77c750d9e694c3063635e4c8a R 5d62798e848b5017221fa2f718c6fa3d
U drh U dan
Z 4a2c4212438d559f2811b75a6a368836 Z 748bf95122bf9ac21f60dff7348c8009

View File

@ -1 +1 @@
d7bb7ea4ab97ad26f4c84c9b8dc2827010093803 ba772cff602ca7c3c0c91451e701f52a872e7a14

View File

@ -47,10 +47,13 @@
#define execsql_i64(x,y,...) (SEL(x), execsql_i64_x(x,y,__VA_ARGS__)) #define execsql_i64(x,y,...) (SEL(x), execsql_i64_x(x,y,__VA_ARGS__))
#define execsql_text(x,y,z,...) (SEL(x), execsql_text_x(x,y,z,__VA_ARGS__)) #define execsql_text(x,y,z,...) (SEL(x), execsql_text_x(x,y,z,__VA_ARGS__))
#define execsql(x,y,...) (SEL(x), (void)execsql_i64_x(x,y,__VA_ARGS__)) #define execsql(x,y,...) (SEL(x), (void)execsql_i64_x(x,y,__VA_ARGS__))
#define sql_script_printf(x,y,z,...) ( \
SEL(x), sql_script_printf_x(x,y,z,__VA_ARGS__) \
)
/* Thread functions */ /* Thread functions */
#define launch_thread(w,x,y,z) (SEL(w), launch_thread_x(w,x,y,z)) #define launch_thread(w,x,y,z) (SEL(w), launch_thread_x(w,x,y,z))
#define join_all_threads(y,z) (SEL(y), join_all_threads_x(y,z)) #define join_all_threads(y,z) (SEL(y), join_all_threads_x(y,z))
/* Timer functions */ /* Timer functions */
#define setstoptime(y,z) (SEL(y), setstoptime_x(y,z)) #define setstoptime(y,z) (SEL(y), setstoptime_x(y,z))
@ -64,6 +67,9 @@
#define filesize(y,z) (SEL(y), filesize_x(y,z)) #define filesize(y,z) (SEL(y), filesize_x(y,z))
#define filecopy(x,y,z) (SEL(x), filecopy_x(x,y,z)) #define filecopy(x,y,z) (SEL(x), filecopy_x(x,y,z))
#define PTR2INT(x) ((int)((intptr_t)x))
#define INT2PTR(x) ((void*)((intptr_t)x))
/* /*
** End of test code/infrastructure interface macros. ** End of test code/infrastructure interface macros.
*************************************************************************/ *************************************************************************/
@ -334,7 +340,7 @@ static void MD5Final(unsigned char digest[16], MD5Context *ctx){
MD5Transform(ctx->buf, (uint32 *)ctx->in); MD5Transform(ctx->buf, (uint32 *)ctx->in);
byteReverse((unsigned char *)ctx->buf, 4); byteReverse((unsigned char *)ctx->buf, 4);
memcpy(digest, ctx->buf, 16); memcpy(digest, ctx->buf, 16);
memset(ctx, 0, sizeof(ctx)); /* In case it is sensitive */ memset(ctx, 0, sizeof(*ctx)); /* In case it is sensitive */
} }
/* /*
@ -398,9 +404,6 @@ typedef struct Thread Thread;
/* Total number of errors in this process so far. */ /* Total number of errors in this process so far. */
static int nGlobalErr = 0; static int nGlobalErr = 0;
/* Set to true to run in "process" instead of "thread" mode. */
static int bProcessMode = 0;
struct Error { struct Error {
int rc; int rc;
int iLine; int iLine;
@ -421,10 +424,10 @@ struct Statement {
struct Thread { struct Thread {
int iTid; /* Thread number within test */ int iTid; /* Thread number within test */
int iArg; /* Integer argument passed by caller */ void* pArg; /* Pointer argument passed by caller */
pthread_t tid; /* Thread id */ pthread_t tid; /* Thread id */
char *(*xProc)(int, int); /* Thread main proc */ char *(*xProc)(int, void*); /* Thread main proc */
Thread *pNext; /* Next in this list of threads */ Thread *pNext; /* Next in this list of threads */
}; };
@ -506,8 +509,9 @@ static void opendb_x(
){ ){
if( pErr->rc==SQLITE_OK ){ if( pErr->rc==SQLITE_OK ){
int rc; int rc;
int flags = SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_URI;
if( bDelete ) unlink(zFile); if( bDelete ) unlink(zFile);
rc = sqlite3_open(zFile, &pDb->db); rc = sqlite3_open_v2(zFile, &pDb->db, flags, 0);
if( rc ){ if( rc ){
sqlite_error(pErr, pDb, "open"); sqlite_error(pErr, pDb, "open");
sqlite3_close(pDb->db); sqlite3_close(pDb->db);
@ -556,6 +560,22 @@ static void sql_script_x(
} }
} }
static void sql_script_printf_x(
Error *pErr, /* IN/OUT: Error code */
Sqlite *pDb, /* Database handle */
const char *zFormat, /* SQL printf format string */
... /* Printf args */
){
va_list ap; /* ... printf arguments */
va_start(ap, zFormat);
if( pErr->rc==SQLITE_OK ){
char *zSql = sqlite3_vmprintf(zFormat, ap);
pErr->rc = sqlite3_exec(pDb->db, zSql, 0, 0, &pErr->zErr);
sqlite3_free(zSql);
}
va_end(ap);
}
static Statement *getSqlStatement( static Statement *getSqlStatement(
Error *pErr, /* IN/OUT: Error code */ Error *pErr, /* IN/OUT: Error code */
Sqlite *pDb, /* Database handle */ Sqlite *pDb, /* Database handle */
@ -624,11 +644,9 @@ static i64 execsql_i64_x(
if( pErr->rc==SQLITE_OK ){ if( pErr->rc==SQLITE_OK ){
sqlite3_stmt *pStmt; /* SQL statement to execute */ sqlite3_stmt *pStmt; /* SQL statement to execute */
va_list ap; /* ... arguments */ va_list ap; /* ... arguments */
int i; /* Used to iterate through parameters */
va_start(ap, pDb); va_start(ap, pDb);
pStmt = getAndBindSqlStatement(pErr, pDb, ap); pStmt = getAndBindSqlStatement(pErr, pDb, ap);
if( pStmt ){ if( pStmt ){
int rc;
int first = 1; int first = 1;
while( SQLITE_ROW==sqlite3_step(pStmt) ){ while( SQLITE_ROW==sqlite3_step(pStmt) ){
if( first && sqlite3_column_count(pStmt)>0 ){ if( first && sqlite3_column_count(pStmt)>0 ){
@ -663,11 +681,9 @@ static char * execsql_text_x(
if( pErr->rc==SQLITE_OK ){ if( pErr->rc==SQLITE_OK ){
sqlite3_stmt *pStmt; /* SQL statement to execute */ sqlite3_stmt *pStmt; /* SQL statement to execute */
va_list ap; /* ... arguments */ va_list ap; /* ... arguments */
int i; /* Used to iterate through parameters */
va_start(ap, iSlot); va_start(ap, iSlot);
pStmt = getAndBindSqlStatement(pErr, pDb, ap); pStmt = getAndBindSqlStatement(pErr, pDb, ap);
if( pStmt ){ if( pStmt ){
int rc;
int first = 1; int first = 1;
while( SQLITE_ROW==sqlite3_step(pStmt) ){ while( SQLITE_ROW==sqlite3_step(pStmt) ){
if( first && sqlite3_column_count(pStmt)>0 ){ if( first && sqlite3_column_count(pStmt)>0 ){
@ -693,14 +709,13 @@ static void integrity_check_x(
){ ){
if( pErr->rc==SQLITE_OK ){ if( pErr->rc==SQLITE_OK ){
Statement *pStatement; /* Statement to execute */ Statement *pStatement; /* Statement to execute */
int rc; /* Return code */
char *zErr = 0; /* Integrity check error */ char *zErr = 0; /* Integrity check error */
pStatement = getSqlStatement(pErr, pDb, "PRAGMA integrity_check"); pStatement = getSqlStatement(pErr, pDb, "PRAGMA integrity_check");
if( pStatement ){ if( pStatement ){
sqlite3_stmt *pStmt = pStatement->pStmt; sqlite3_stmt *pStmt = pStatement->pStmt;
while( SQLITE_ROW==sqlite3_step(pStmt) ){ while( SQLITE_ROW==sqlite3_step(pStmt) ){
const char *z = sqlite3_column_text(pStmt, 0); const char *z = (const char*)sqlite3_column_text(pStmt, 0);
if( strcmp(z, "ok") ){ if( strcmp(z, "ok") ){
if( zErr==0 ){ if( zErr==0 ){
zErr = sqlite3_mprintf("%s", z); zErr = sqlite3_mprintf("%s", z);
@ -721,14 +736,14 @@ static void integrity_check_x(
static void *launch_thread_main(void *pArg){ static void *launch_thread_main(void *pArg){
Thread *p = (Thread *)pArg; Thread *p = (Thread *)pArg;
return (void *)p->xProc(p->iTid, p->iArg); return (void *)p->xProc(p->iTid, p->pArg);
} }
static void launch_thread_x( static void launch_thread_x(
Error *pErr, /* IN/OUT: Error code */ Error *pErr, /* IN/OUT: Error code */
Threadset *pThreads, /* Thread set */ Threadset *pThreads, /* Thread set */
char *(*xProc)(int, int), /* Proc to run */ char *(*xProc)(int, void*), /* Proc to run */
int iArg /* Argument passed to thread proc */ void *pArg /* Argument passed to thread proc */
){ ){
if( pErr->rc==SQLITE_OK ){ if( pErr->rc==SQLITE_OK ){
int iTid = ++pThreads->iMaxTid; int iTid = ++pThreads->iMaxTid;
@ -738,7 +753,7 @@ static void launch_thread_x(
p = (Thread *)sqlite3_malloc(sizeof(Thread)); p = (Thread *)sqlite3_malloc(sizeof(Thread));
memset(p, 0, sizeof(Thread)); memset(p, 0, sizeof(Thread));
p->iTid = iTid; p->iTid = iTid;
p->iArg = iArg; p->pArg = pArg;
p->xProc = xProc; p->xProc = xProc;
rc = pthread_create(&p->tid, NULL, launch_thread_main, (void *)p); rc = pthread_create(&p->tid, NULL, launch_thread_main, (void *)p);
@ -895,7 +910,7 @@ static int timetostop_x(
#define WALTHREAD1_NTHREAD 10 #define WALTHREAD1_NTHREAD 10
#define WALTHREAD3_NTHREAD 6 #define WALTHREAD3_NTHREAD 6
static char *walthread1_thread(int iTid, int iArg){ static char *walthread1_thread(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
int nIter = 0; /* Iterations so far */ int nIter = 0; /* Iterations so far */
@ -934,7 +949,7 @@ static char *walthread1_thread(int iTid, int iArg){
return sqlite3_mprintf("%d iterations", nIter); return sqlite3_mprintf("%d iterations", nIter);
} }
static char *walthread1_ckpt_thread(int iTid, int iArg){ static char *walthread1_ckpt_thread(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
int nCkpt = 0; /* Checkpoints so far */ int nCkpt = 0; /* Checkpoints so far */
@ -977,10 +992,11 @@ static void walthread1(int nMs){
print_and_free_err(&err); print_and_free_err(&err);
} }
static char *walthread2_thread(int iTid, int iArg){ static char *walthread2_thread(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
int anTrans[2] = {0, 0}; /* Number of WAL and Rollback transactions */ int anTrans[2] = {0, 0}; /* Number of WAL and Rollback transactions */
int iArg = PTR2INT(pArg);
const char *zJournal = "PRAGMA journal_mode = WAL"; const char *zJournal = "PRAGMA journal_mode = WAL";
if( iArg ){ zJournal = "PRAGMA journal_mode = DELETE"; } if( iArg ){ zJournal = "PRAGMA journal_mode = DELETE"; }
@ -1026,17 +1042,18 @@ static void walthread2(int nMs){
setstoptime(&err, nMs); setstoptime(&err, nMs);
launch_thread(&err, &threads, walthread2_thread, 0); launch_thread(&err, &threads, walthread2_thread, 0);
launch_thread(&err, &threads, walthread2_thread, 0); launch_thread(&err, &threads, walthread2_thread, 0);
launch_thread(&err, &threads, walthread2_thread, 1); launch_thread(&err, &threads, walthread2_thread, (void*)1);
launch_thread(&err, &threads, walthread2_thread, 1); launch_thread(&err, &threads, walthread2_thread, (void*)1);
join_all_threads(&err, &threads); join_all_threads(&err, &threads);
print_and_free_err(&err); print_and_free_err(&err);
} }
static char *walthread3_thread(int iTid, int iArg){ static char *walthread3_thread(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
i64 iNextWrite; /* Next value this thread will write */ i64 iNextWrite; /* Next value this thread will write */
int iArg = PTR2INT(pArg);
opendb(&err, &db, "test.db", 0); opendb(&err, &db, "test.db", 0);
sql_script(&err, &db, "PRAGMA wal_autocheckpoint = 10"); sql_script(&err, &db, "PRAGMA wal_autocheckpoint = 10");
@ -1087,14 +1104,14 @@ static void walthread3(int nMs){
setstoptime(&err, nMs); setstoptime(&err, nMs);
for(i=0; i<WALTHREAD3_NTHREAD; i++){ for(i=0; i<WALTHREAD3_NTHREAD; i++){
launch_thread(&err, &threads, walthread3_thread, i); launch_thread(&err, &threads, walthread3_thread, INT2PTR(i));
} }
join_all_threads(&err, &threads); join_all_threads(&err, &threads);
print_and_free_err(&err); print_and_free_err(&err);
} }
static char *walthread4_reader_thread(int iTid, int iArg){ static char *walthread4_reader_thread(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
@ -1108,7 +1125,7 @@ static char *walthread4_reader_thread(int iTid, int iArg){
return 0; return 0;
} }
static char *walthread4_writer_thread(int iTid, int iArg){ static char *walthread4_writer_thread(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
i64 iRow = 1; i64 iRow = 1;
@ -1148,7 +1165,7 @@ static void walthread4(int nMs){
print_and_free_err(&err); print_and_free_err(&err);
} }
static char *walthread5_thread(int iTid, int iArg){ static char *walthread5_thread(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
i64 nRow; i64 nRow;
@ -1280,7 +1297,7 @@ static void cgt_pager_1(int nMs){
** is an attempt to find a bug reported to us. ** is an attempt to find a bug reported to us.
*/ */
static char *dynamic_triggers_1(int iTid, int iArg){ static char *dynamic_triggers_1(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
int nDrop = 0; int nDrop = 0;
@ -1331,7 +1348,7 @@ static char *dynamic_triggers_1(int iTid, int iArg){
return sqlite3_mprintf("%d created, %d dropped", nCreate, nDrop); return sqlite3_mprintf("%d created, %d dropped", nCreate, nDrop);
} }
static char *dynamic_triggers_2(int iTid, int iArg){ static char *dynamic_triggers_2(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
i64 iVal = 0; i64 iVal = 0;
@ -1382,9 +1399,9 @@ static void dynamic_triggers(int nMs){
sqlite3_enable_shared_cache(1); sqlite3_enable_shared_cache(1);
launch_thread(&err, &threads, dynamic_triggers_2, 0); launch_thread(&err, &threads, dynamic_triggers_2, 0);
launch_thread(&err, &threads, dynamic_triggers_2, 0); launch_thread(&err, &threads, dynamic_triggers_2, 0);
sqlite3_enable_shared_cache(0);
sleep(2); sleep(2);
sqlite3_enable_shared_cache(0);
launch_thread(&err, &threads, dynamic_triggers_2, 0); launch_thread(&err, &threads, dynamic_triggers_2, 0);
launch_thread(&err, &threads, dynamic_triggers_1, 0); launch_thread(&err, &threads, dynamic_triggers_1, 0);
@ -1425,6 +1442,7 @@ int main(int argc, char **argv){
{ lookaside1, "lookaside1", 10000 }, { lookaside1, "lookaside1", 10000 },
{ vacuum1, "vacuum1", 10000 }, { vacuum1, "vacuum1", 10000 },
{ stress1, "stress1", 10000 }, { stress1, "stress1", 10000 },
{ stress2, "stress2", 10000 },
}; };
int i; int i;
@ -1443,6 +1461,7 @@ int main(int argc, char **argv){
} }
} }
sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
sqlite3_config(SQLITE_CONFIG_MULTITHREAD); sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
for(i=0; i<sizeof(aTest)/sizeof(aTest[0]); i++){ for(i=0; i<sizeof(aTest)/sizeof(aTest[0]); i++){

View File

@ -66,7 +66,7 @@ static int checkpoint_starvation_walhook(
return SQLITE_OK; return SQLITE_OK;
} }
static char *checkpoint_starvation_reader(int iTid, int iArg){ static char *checkpoint_starvation_reader(int iTid, void *pArg){
Error err = {0}; Error err = {0};
Sqlite db = {0}; Sqlite db = {0};

View File

@ -14,7 +14,7 @@
*/ */
static char *create_drop_index_thread(int iTid, int iArg){ static char *create_drop_index_thread(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */

View File

@ -18,7 +18,7 @@
** that is suspected to exist at time of writing. ** that is suspected to exist at time of writing.
*/ */
static char *lookaside1_thread_reader(int iTid, int iArg){ static char *lookaside1_thread_reader(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
@ -43,7 +43,7 @@ static char *lookaside1_thread_reader(int iTid, int iArg){
return sqlite3_mprintf("ok"); return sqlite3_mprintf("ok");
} }
static char *lookaside1_thread_writer(int iTid, int iArg){ static char *lookaside1_thread_writer(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */

View File

@ -17,7 +17,7 @@
/* /*
** Thread 1. CREATE and DROP a table. ** Thread 1. CREATE and DROP a table.
*/ */
static char *stress_thread_1(int iTid, int iArg){ static char *stress_thread_1(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
@ -36,7 +36,7 @@ static char *stress_thread_1(int iTid, int iArg){
/* /*
** Thread 2. Open and close database connections. ** Thread 2. Open and close database connections.
*/ */
static char *stress_thread_2(int iTid, int iArg){ static char *stress_thread_2(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
while( !timetostop(&err) ){ while( !timetostop(&err) ){
@ -52,7 +52,7 @@ static char *stress_thread_2(int iTid, int iArg){
/* /*
** Thread 3. Attempt many small SELECT statements. ** Thread 3. Attempt many small SELECT statements.
*/ */
static char *stress_thread_3(int iTid, int iArg){ static char *stress_thread_3(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
@ -75,11 +75,13 @@ static char *stress_thread_3(int iTid, int iArg){
/* /*
** Thread 5. Attempt INSERT statements. ** Thread 5. Attempt INSERT statements.
*/ */
static char *stress_thread_4(int iTid, int iArg){ static char *stress_thread_4(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
int i1 = 0; int i1 = 0;
int i2 = 0; int i2 = 0;
int iArg = PTR2INT(pArg);
opendb(&err, &db, "test.db", 0); opendb(&err, &db, "test.db", 0);
while( !timetostop(&err) ){ while( !timetostop(&err) ){
if( iArg ){ if( iArg ){
@ -103,9 +105,10 @@ static char *stress_thread_4(int iTid, int iArg){
/* /*
** Thread 6. Attempt DELETE operations. ** Thread 6. Attempt DELETE operations.
*/ */
static char *stress_thread_5(int iTid, int iArg){ static char *stress_thread_5(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
int iArg = PTR2INT(pArg);
int i1 = 0; int i1 = 0;
int i2 = 0; int i2 = 0;
@ -131,12 +134,9 @@ static char *stress_thread_5(int iTid, int iArg){
static void stress1(int nMs){ static void stress1(int nMs){
Error err = {0}; Error err = {0};
Sqlite db = {0};
Threadset threads = {0}; Threadset threads = {0};
setstoptime(&err, nMs); setstoptime(&err, nMs);
sqlite3_enable_shared_cache(1); sqlite3_enable_shared_cache(1);
launch_thread(&err, &threads, stress_thread_1, 0); launch_thread(&err, &threads, stress_thread_1, 0);
@ -152,10 +152,230 @@ static void stress1(int nMs){
launch_thread(&err, &threads, stress_thread_4, 0); launch_thread(&err, &threads, stress_thread_4, 0);
launch_thread(&err, &threads, stress_thread_5, 0); launch_thread(&err, &threads, stress_thread_5, 0);
launch_thread(&err, &threads, stress_thread_5, 1); launch_thread(&err, &threads, stress_thread_5, (void*)1);
join_all_threads(&err, &threads); join_all_threads(&err, &threads);
sqlite3_enable_shared_cache(0); sqlite3_enable_shared_cache(0);
print_and_free_err(&err); print_and_free_err(&err);
} }
/**************************************************************************
***************************************************************************
** Start of test case "stress2"
*/
/*
** 1. CREATE TABLE statements.
** 2. DROP TABLE statements.
** 3. Small SELECT statements.
** 4. Big SELECT statements.
** 5. Small INSERT statements.
** 6. Big INSERT statements.
** 7. Small UPDATE statements.
** 8. Big UPDATE statements.
** 9. Small DELETE statements.
** 10. Big DELETE statements.
** 11. VACUUM.
** 14. Integrity-check.
** 17. Switch the journal mode from delete to wal and back again.
** 19. Open and close database connections rapidly.
*/
#define STRESS2_TABCNT 5
static void stress2_workload1(Error *pErr, Sqlite *pDb, int i){
int iTab = (i % STRESS2_TABCNT);
sql_script_printf(pErr, pDb,
"CREATE TABLE IF NOT EXISTS t%d(x PRIMARY KEY, y, z);", iTab
);
}
static void stress2_workload2(Error *pErr, Sqlite *pDb, int i){
int iTab = (i % STRESS2_TABCNT);
sql_script_printf(pErr, pDb, "DROP TABLE IF EXISTS t%d;", iTab);
}
static void stress2_workload3(Error *pErr, Sqlite *pDb, int i){
int iTab = (i % STRESS2_TABCNT);
sql_script_printf(pErr, pDb, "SELECT * FROM t%d WHERE z = 'small'", iTab);
}
static void stress2_workload4(Error *pErr, Sqlite *pDb, int i){
int iTab = (i % STRESS2_TABCNT);
sql_script_printf(pErr, pDb, "SELECT * FROM t%d WHERE z = 'big'", iTab);
}
static void stress2_workload5(Error *pErr, Sqlite *pDb, int i){
int iTab = (i % STRESS2_TABCNT);
sql_script_printf(pErr, pDb,
"INSERT INTO t%d VALUES(random(), hex(randomblob(57)), 'small');", iTab
);
}
static void stress2_workload6(Error *pErr, Sqlite *pDb, int i){
int iTab = (i % STRESS2_TABCNT);
sql_script_printf(pErr, pDb,
"INSERT INTO t%d VALUES(random(), hex(randomblob(2000)), 'big');", iTab
);
}
static void stress2_workload7(Error *pErr, Sqlite *pDb, int i){
int iTab = (i % STRESS2_TABCNT);
sql_script_printf(pErr, pDb,
"UPDATE t%d SET y = hex(randomblob(57)) "
"WHERE (x %% 5)==(%d %% 5) AND z='small';"
,iTab, i
);
}
static void stress2_workload8(Error *pErr, Sqlite *pDb, int i){
int iTab = (i % STRESS2_TABCNT);
sql_script_printf(pErr, pDb,
"UPDATE t%d SET y = hex(randomblob(2000)) "
"WHERE (x %% 5)==(%d %% 5) AND z='big';"
,iTab, i
);
}
static void stress2_workload9(Error *pErr, Sqlite *pDb, int i){
int iTab = (i % STRESS2_TABCNT);
sql_script_printf(pErr, pDb,
"DELETE FROM t%d WHERE (x %% 5)==(%d %% 5) AND z='small';"
,iTab, i
);
}
static void stress2_workload10(Error *pErr, Sqlite *pDb, int i){
int iTab = (i % STRESS2_TABCNT);
sql_script_printf(pErr, pDb,
"DELETE FROM t%d WHERE (x %% 5)==(%d %% 5) AND z='big';"
,iTab, i
);
}
static void stress2_workload11(Error *pErr, Sqlite *pDb, int i){
sql_script(pErr, pDb, "VACUUM");
}
static void stress2_workload14(Error *pErr, Sqlite *pDb, int i){
sql_script(pErr, pDb, "PRAGMA integrity_check");
}
static void stress2_workload17(Error *pErr, Sqlite *pDb, int i){
sql_script_printf(pErr, pDb,
"PRAGMA journal_mode = %q", (i%2) ? "delete" : "wal"
);
}
static char *stress2_workload19(int iTid, void *pArg){
Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */
const char *zDb = (const char*)pArg;
while( !timetostop(&err) ){
opendb(&err, &db, zDb, 0);
sql_script(&err, &db, "SELECT * FROM sqlite_master;");
clear_error(&err, SQLITE_LOCKED);
closedb(&err, &db);
}
print_and_free_err(&err);
return sqlite3_mprintf("ok");
}
typedef struct Stress2Ctx Stress2Ctx;
struct Stress2Ctx {
const char *zDb;
void (*xProc)(Error*, Sqlite*, int);
};
static char *stress2_thread_wrapper(int iTid, void *pArg){
Stress2Ctx *pCtx = (Stress2Ctx*)pArg;
Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */
int i1 = 0;
int i2 = 0;
opendb(&err, &db, pCtx->zDb, 0);
while( !timetostop(&err) ){
pCtx->xProc(&err, &db, i1);
i2 += (err.rc==SQLITE_OK);
clear_error(&err, SQLITE_LOCKED);
clear_error(&err, SQLITE_ERROR);
i1++;
}
print_and_free_err(&err);
return sqlite3_mprintf("ok %d/%d", i2, i1);
}
static void stress2_launch_thread_loop(
Error *pErr, /* IN/OUT: Error code */
Threadset *pThreads, /* Thread set */
const char *zDb, /* Database name */
void (*x)(Error*,Sqlite*,int) /* Run this until error or timeout */
){
Stress2Ctx *pCtx = sqlite3_malloc(sizeof(Stress2Ctx));
pCtx->zDb = zDb;
pCtx->xProc = x;
launch_thread(pErr, pThreads, stress2_thread_wrapper, (void*)pCtx);
}
static void stress2(int nMs){
struct Stress2Task {
void (*x)(Error*,Sqlite*,int);
} aTask[] = {
{ stress2_workload1 },
{ stress2_workload2 },
{ stress2_workload3 },
{ stress2_workload4 },
{ stress2_workload5 },
{ stress2_workload6 },
{ stress2_workload7 },
{ stress2_workload8 },
{ stress2_workload9 },
{ stress2_workload10 },
{ stress2_workload11 },
{ stress2_workload14 },
{ stress2_workload17 },
};
const char *azDb[] = {
"test.db",
"file::memory:?cache=shared"
};
int j;
for(j=0; j<sizeof(azDb)/sizeof(azDb[0]); j++){
int i;
Error err = {0};
Sqlite db = {0};
Threadset threads = {0};
const char *zDb = azDb[j];
/* To make sure the db file is empty before commencing */
opendb(&err, &db, zDb, 1);
closedb(&err, &db);
setstoptime(&err, nMs);
sqlite3_enable_shared_cache(1);
for(i=0; i<sizeof(aTask)/sizeof(aTask[0]); i++){
stress2_launch_thread_loop(&err, &threads, zDb, aTask[i].x);
}
launch_thread(&err, &threads, stress2_workload19, (void*)zDb);
launch_thread(&err, &threads, stress2_workload19, (void*)zDb);
join_all_threads(&err, &threads);
sqlite3_enable_shared_cache(0);
print_and_free_err(&err);
if( j==0 ){
printf("Running stress2 (again, with in-memory db) for %d seconds...\n",
nMs / 1000
);
}
}
}

View File

@ -20,7 +20,7 @@
*/ */
static char *vacuum1_thread_writer(int iTid, int iArg){ static char *vacuum1_thread_writer(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
opendb(&err, &db, "test.db", 0); opendb(&err, &db, "test.db", 0);
@ -49,7 +49,7 @@ static char *vacuum1_thread_writer(int iTid, int iArg){
return sqlite3_mprintf("ok"); return sqlite3_mprintf("ok");
} }
static char *vacuum1_thread_vacuumer(int iTid, int iArg){ static char *vacuum1_thread_vacuumer(int iTid, void *pArg){
Error err = {0}; /* Error code and message */ Error err = {0}; /* Error code and message */
Sqlite db = {0}; /* SQLite database connection */ Sqlite db = {0}; /* SQLite database connection */
opendb(&err, &db, "test.db", 0); opendb(&err, &db, "test.db", 0);