From: dan Date: Mon, 7 Mar 2022 18:42:02 +0000 (+0000) Subject: Add multi-threaded test for the features on this branch. Fix a misuse of xShmLock(). X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=64710113396e4bb5360532990342ef64d50ef6b9;p=thirdparty%2Fsqlite.git Add multi-threaded test for the features on this branch. Fix a misuse of xShmLock(). FossilOrigin-Name: 1ec05168c9fe9c09586da795e9db841647c30825f32a2f2c811186fac57760e1 --- diff --git a/main.mk b/main.mk index 0943e97556..ef232c0897 100644 --- a/main.mk +++ b/main.mk @@ -992,6 +992,7 @@ THREADTEST3_SRC = $(TOP)/test/threadtest3.c \ $(TOP)/test/tt3_index.c \ $(TOP)/test/tt3_vacuum.c \ $(TOP)/test/tt3_stress.c \ + $(TOP)/test/tt3_bcwal2.c \ $(TOP)/test/tt3_lookaside1.c threadtest3$(EXE): sqlite3.o $(THREADTEST3_SRC) $(TOP)/src/test_multiplex.c diff --git a/manifest b/manifest index 5a9359f6b9..d05abeaecc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\sversion\s3.38.0\sinto\sthe\sbegin-concurrent-pnu-wal2\sbranch. -D 2022-02-22T19:56:17.371 +C Add\smulti-threaded\stest\sfor\sthe\sfeatures\son\sthis\sbranch.\sFix\sa\smisuse\sof\sxShmLock(). +D 2022-03-07T18:42:02.586 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -480,7 +480,7 @@ F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 -F main.mk 0fedddc3a494b25ef95821c4aea660698002db7bc95560539d9035e5cbaad462 +F main.mk a4cd0654947e8477d993a47fe46547b6e45150a91873f540fc59622bbd340676 F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 @@ -643,7 +643,7 @@ F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf8 F src/vdbevtab.c f99b275366c5fc5e2d99f734729880994ab9500bdafde7fae3b02d562b9d323c F src/vtab.c e0eaf5b8f7f8929088485a76bea2ff6124adb12e0eb5c0997287ff5e0e4c0517 F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 -F src/wal.c 151479223abeaf4f9a4210f243a9a9ab4cccaa062855028a8c375b711b1d0611 +F src/wal.c 8d7c4c78e403062d31a9c88638cfd1403849830517a9a4973a3db5d82ddd233d F src/wal.h 7a733af13b966ecb81872ce397e862116b3575ea53245b90b139a2873ee87825 F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b F src/where.c 0d75d7514764726409ea945520fe9fb515e7d9ae52a5a3c0a136142cfaa19087 @@ -1501,7 +1501,7 @@ F test/thread2.test f35d2106452b77523b3a2b7d1dcde2e5ee8f9e46 F test/thread_common.tcl 334639cadcb9f912bf82aa73f49efd5282e6cadd F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b F test/threadtest2.c a70a8e94bef23339d34226eb9521015ef99f4df8 -F test/threadtest3.c 655bff6c0895ec03f014126aa65e808fac9aae8c5a7a7da58a510cbe8b43b781 +F test/threadtest3.c e947b396444f7992a942cd8db0f01589ede90dd250ec802fe800cc90bbee21e3 F test/threadtest4.c c1e67136ceb6c7ec8184e56ac61db28f96bd2925 F test/threadtest5.c 9b4d782c58d8915d7e955ff8051f3d03628bda0d33b82971ea8c0f2f2808c421 F test/time-wordcount.sh 8e0b0f8109367827ad5d58f5cc849705731e4b90 @@ -1675,6 +1675,7 @@ F test/triggerF.test 5d76f0a8c428ff87a4d5ed52da06f6096a2c787a1e21b846111dfac4123 F test/triggerG.test 2b816093c91ba73c733cfa8aedcc210ad819d72a98b1da30768a3c56505233e9 F test/triggerupfrom.test d1f9e56090408115c522bee626cc33a2f3370f627a5e341d832589d72e3aa271 F test/trustschema1.test 4e970aef0bfe0cee139703cc7209d0e0f07725d999b180ba50770f49edef1494 +F test/tt3_bcwal2.c 8351577477ce58c3b21a1772c28e73ec58538c44be4a183ff7485d6814bd5385 F test/tt3_checkpoint.c ac7ca661d739280c89d9c253897df64a59a49369bd1247207ac0f655b622579d F test/tt3_core.c 8cd89ead95410f70e7fb02c79f1e040f9c5ad5cf F test/tt3_index.c 39eec10a35f57672225be4d182862152896dee4a @@ -1976,8 +1977,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1336d2f23fcee5bc969cd5ca9e3be1458915e79365e21566ca2ba438f6df260b de24c8ee41007bc6d25d25856b64d8bdc4581666bca53eb031530b0e498fb0fe -R ed6fa4c6d23cf4452713e16d348242ba -U drh -Z 73a286234d6208b714874fee1540117c +P 8387e4f3af552322ed412e21948437bffc4cc237c5c5a80b558b8d395de4999d +R 6af6b1abf1d4ffdc878b758de226a211 +U dan +Z a11eedd12ffbcfd58984dea6de671b52 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4a519a28ab..8ea1e2ec3a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8387e4f3af552322ed412e21948437bffc4cc237c5c5a80b558b8d395de4999d \ No newline at end of file +1ec05168c9fe9c09586da795e9db841647c30825f32a2f2c811186fac57760e1 \ No newline at end of file diff --git a/src/wal.c b/src/wal.c index 85a2093d8b..8e038fad09 100644 --- a/src/wal.c +++ b/src/wal.c @@ -4499,7 +4499,12 @@ static int walRestartLog(Wal *pWal){ nWalSize = MAX(nWalSize, 1); } - if( walidxGetMxFrame(&pWal->hdr, iApp)>=nWalSize ){ + assert( 1==WAL_LOCK_PART1 ); + assert( 4==WAL_LOCK_PART2 ); + assert( 1+(iApp*3)==WAL_LOCK_PART1 || 1+(iApp*3)==WAL_LOCK_PART2 ); + if( pWal->readLock==1+(iApp*3) + && walidxGetMxFrame(&pWal->hdr, iApp)>=nWalSize + ){ volatile WalCkptInfo *pInfo = walCkptInfo(pWal); u32 mxFrame = walidxGetMxFrame(&pWal->hdr, !iApp); if( mxFrame==0 || pInfo->nBackfill ){ diff --git a/test/threadtest3.c b/test/threadtest3.c index 3a12c5889b..da8effc67d 100644 --- a/test/threadtest3.c +++ b/test/threadtest3.c @@ -1494,6 +1494,8 @@ static void dynamic_triggers(int nMs){ #include "tt3_stress.c" #include "tt3_shared.c" +#include "tt3_bcwal2.c" + int main(int argc, char **argv){ struct ThreadTest { void (*xTest)(int); /* Routine for running this test */ @@ -1518,6 +1520,8 @@ int main(int argc, char **argv){ { stress1, "stress1", 10000 }, { stress2, "stress2", 60000 }, { shared1, "shared1", 10000 }, + + { bcwal2_1, "bcwal2_1", 100000 }, }; static char *substArgv[] = { 0, "*", 0 }; int i, iArg; diff --git a/test/tt3_bcwal2.c b/test/tt3_bcwal2.c new file mode 100644 index 0000000000..d0e3fab4d4 --- /dev/null +++ b/test/tt3_bcwal2.c @@ -0,0 +1,122 @@ +/* +** 2011-02-02 +** +** 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 is part of the test program "threadtest3". Despite being a C +** file it is not compiled separately, but included by threadtest3.c using +** the #include directive normally used with header files. +** +** This file contains the implementation of test cases: +** +** bcwal2_1 +*/ + +static char *bcwal2_1_checkpointer(int iTid, void *pArg){ + Error err = {0}; /* Error code and message */ + Sqlite db = {0}; /* SQLite database connection */ + int nIter = 0; + + opendb(&err, &db, "test.db", 0); + while( !timetostop(&err) ){ + sql_script(&err, &db, "PRAGMA wal_checkpoint;"); + nIter++; + } + closedb(&err, &db); + + print_and_free_err(&err); + return sqlite3_mprintf("%d iterations", nIter); +} + +static char *bcwal2_1_integrity(int iTid, void *pArg){ + Error err = {0}; /* Error code and message */ + Sqlite db = {0}; /* SQLite database connection */ + int nIter = 0; + + opendb(&err, &db, "test.db", 0); + while( !timetostop(&err) ){ + // integrity_check(&err, &db); + sql_script(&err, &db, "SELECT * FROM t1;"); + nIter++; + } + closedb(&err, &db); + + print_and_free_err(&err); + return sqlite3_mprintf("%d integrity-checks", nIter); +} + +static char *bcwal2_1_writer(int iTid, void *pArg){ + Error err = {0}; /* Error code and message */ + Sqlite db = {0}; /* SQLite database connection */ + int nWrite = 0; /* Writes so far */ + int nBusy = 0; /* Busy errors so far */ + sqlite3_mutex *pMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_APP1); + + opendb(&err, &db, "test.db", 0); + while( !timetostop(&err) ){ + + sql_script(&err, &db, + "PRAGMA wal_autocheckpoint = 0;" + "BEGIN CONCURRENT;" + " REPLACE INTO t1 VALUES( abs(random() % 100000), " + " hex(randomblob( abs( random() % 200 ) + 50 ))" + " );" + ); + + if( err.rc==SQLITE_OK ){ + sqlite3_mutex_enter(pMutex); + sql_script(&err, &db, "COMMIT"); + sqlite3_mutex_leave(pMutex); + if( err.rc==SQLITE_OK ){ + nWrite++; + }else{ + clear_error(&err, SQLITE_BUSY); + sql_script(&err, &db, "ROLLBACK"); + nBusy++; + } + + assert( err.rc!=SQLITE_OK || sqlite3_get_autocommit(db.db)==1 ); + } + } + closedb(&err, &db); + + print_and_free_err(&err); + return sqlite3_mprintf("%d successful writes, %d busy", nWrite, nBusy); +} + +static void bcwal2_1(int nMs){ + Error err = {0}; + Sqlite db = {0}; + Threadset threads = {0}; + + opendb(&err, &db, "test.db", 1); + sql_script(&err, &db, + "PRAGMA page_size = 1024;" + "PRAGMA journal_mode = wal2;" + "CREATE TABLE t1(ii INTEGER PRIMARY KEY, tt TEXT);" + "CREATE INDEX t1tt ON t1(tt);" + ); + + setstoptime(&err, nMs); + + launch_thread(&err, &threads, bcwal2_1_writer, 0); + launch_thread(&err, &threads, bcwal2_1_writer, 0); + launch_thread(&err, &threads, bcwal2_1_writer, 0); + launch_thread(&err, &threads, bcwal2_1_integrity, 0); + launch_thread(&err, &threads, bcwal2_1_checkpointer, 0); + + join_all_threads(&err, &threads); + + /* Do a final integrity-check on the db */ + integrity_check(&err, &db); + closedb(&err, &db); + + print_and_free_err(&err); +} +