From: dan Date: Fri, 12 May 2017 18:52:27 +0000 (+0000) Subject: Require exclusive access to the db to wrap the wal file. Have "PRAGMA X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bf431367f3544b66b13ba8a329c6ef1dd8044ebd;p=thirdparty%2Fsqlite.git Require exclusive access to the db to wrap the wal file. Have "PRAGMA wal_checkpoint = restart" block for this. FossilOrigin-Name: cbf44ed9758d577e1450b53e645b73c9ca1ee29d2354ce6375c234a41a063400 --- diff --git a/manifest b/manifest index a23f43ff89..4a54d5acb2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\scausing\sa\slock\sto\sbe\sheld\spast\sthe\send\sof\sa\stransaction.\sUse\sa\nblocking\slock\sto\stake\sthe\sread-lock\son\spage\s1\staken\sby\sall\stransactions. -D 2017-05-10T16:18:05.140 +C Require\sexclusive\saccess\sto\sthe\sdb\sto\swrap\sthe\swal\sfile.\sHave\s"PRAGMA\nwal_checkpoint\s=\srestart"\sblock\sfor\sthis. +D 2017-05-12T18:52:27.743 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 6a8c838220f7c00820e1fc0ac1bccaaa8e5676067e1dbfa1bafa7a4ffecf8ae6 @@ -482,7 +482,7 @@ F src/vdbesort.c e72fe02a2121386ba767ede8942e9450878b8fc873abf3d1b6824485f092570 F src/vdbetrace.c 41963d5376f0349842b5fc4aaaaacd7d9cdc0834 F src/vtab.c 35b9bdc2b41de32a417141d12097bcc4e29a77ed7cdb8f836d1d2305d946b61b F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 -F src/wal.c b78eab7bb45f6c5b59ad90b7825adb2fe10cb3bc73295d2fcdaa61859f078301 +F src/wal.c c2c7289acf4e7c8222d53c7f4ddc0553c60b130c08ce7e6ff3c54a079afb11eb F src/wal.h 739d92494eb18b6d8f3e353e66c10eb8f94534bafd336ece9f3f60235317ea08 F src/walker.c b71a992b413b3a022572eccf29ef4b4890223791 F src/where.c c6352f15be5031907c68bcbde96cad1a6da20e9f4051d10168a59235de9a8566 @@ -1115,7 +1115,7 @@ F test/server1.test 46803bd3fe8b99b30dbc5ff38ffc756f5c13a118 F test/server2.test 11dda300ebef43b4abe0fdc086b6f51b964beddb529fb65bc1f026db5895c36e F test/server3.test c33343f2f6bc23f2b4e2f047c3d083579f0cfac2795e0f1eb226ab34758967c0 F test/servercrash.test 816c132b26af008067cab2913783f67006d4003e3988f3f3ee1075742f6e0a6c -F test/serverwal.test a162dd5105b0c1d6d68a12224aae06aba06812503396711fdc70f967b9f00f8d +F test/serverwal.test 2d066ba70db35e28f0115a57385cf606513c56d6e2861119c2defb7471e4e2d9 F test/session.test 78fa2365e93d3663a6e933f86e7afc395adf18be F test/shared.test 1da9dbad400cee0d93f252ccf76e1ae007a63746 F test/shared2.test 03eb4a8d372e290107d34b6ce1809919a698e879 @@ -1584,7 +1584,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4464ca1d686b5c457995cc885d4a8704e402ad387aa4cc37de199276b28cc08e -R 8af7c0b56c931c6427bbb46d22a2354a +P 2584df3d42ece69d37f31f3655cd0d4760914bea73d4f4ccb7f2a7aa47f80f49 +R 8621dc84bbe8eab1b9dea62b9019e55d U dan -Z 9c853b21d10daf349150cf7187819c31 +Z ad37dc40e7be8af9dbc4865f3cd7c6dc diff --git a/manifest.uuid b/manifest.uuid index cf91b36b8c..6621b47df9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2584df3d42ece69d37f31f3655cd0d4760914bea73d4f4ccb7f2a7aa47f80f49 \ No newline at end of file +cbf44ed9758d577e1450b53e645b73c9ca1ee29d2354ce6375c234a41a063400 \ No newline at end of file diff --git a/src/wal.c b/src/wal.c index 3a70b29946..6e5e512245 100644 --- a/src/wal.c +++ b/src/wal.c @@ -1909,6 +1909,9 @@ static int walCheckpoint( ** indicate that the log file contains zero valid frames. */ walRestartHdr(pWal, salt1); rc = sqlite3OsTruncate(pWal->pWalFd, 0); + }else if( walIsServer(pWal) ){ + assert( eMode==SQLITE_CHECKPOINT_RESTART ); + walRestartHdr(pWal, salt1); } walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); } @@ -3126,7 +3129,7 @@ int sqlite3WalFrames( /* See if it is possible to write these frames into the start of the ** log file, instead of appending to it at pWal->hdr.mxFrame. */ - if( SQLITE_OK!=(rc = walRestartLog(pWal)) ){ + if( walIsServer(pWal)==0 && SQLITE_OK!=(rc = walRestartLog(pWal)) ){ return rc; } @@ -3379,7 +3382,13 @@ int sqlite3WalCheckpoint( */ if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){ if( walIsServer(pWal) ){ - rc = sqlite3ServerLock(pWal->pServer, 0, 1, 1); + if( eMode>=SQLITE_CHECKPOINT_RESTART ){ + /* Exclusive lock on page 1. This is exclusive access to the db. */ + rc = sqlite3ServerLock(pWal->pServer, 1, 1, 1); + }else{ + /* Take the server write-lock ("page" 0) */ + rc = sqlite3ServerLock(pWal->pServer, 0, 1, 1); + } }else{ rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_WRITE_LOCK, 1); } @@ -3431,6 +3440,7 @@ int sqlite3WalCheckpoint( walUnlockExclusive(pWal, WAL_CKPT_LOCK, 1); pWal->ckptLock = 0; WALTRACE(("WAL%p: checkpoint %s\n", pWal, rc ? "failed" : "ok")); + if( walIsServer(pWal) ) sqlite3ServerEnd(pWal->pServer); return (rc==SQLITE_OK && eMode!=eMode2 ? SQLITE_BUSY : rc); } diff --git a/test/serverwal.test b/test/serverwal.test index abcd78b3be..2c442361c7 100644 --- a/test/serverwal.test +++ b/test/serverwal.test @@ -61,6 +61,7 @@ do_test 2.2 { execsql COMMIT db2 } {} db close +db2 close #------------------------------------------------------------------------- # That the wal file can be wrapped around. @@ -79,7 +80,7 @@ do_execsql_test 3.0 { do_test 3.1 { set N [file size test.db-wal] execsql { - PRAGMA wal_checkpoint; + PRAGMA wal_checkpoint = restart; INSERT INTO ttt VALUES(11, 12); INSERT INTO ttt VALUES(13, 14); } @@ -109,5 +110,29 @@ do_execsql_test 4.1 { PRAGMA integrity_check; } {ok ok} +reset_db +do_execsql_test 5.1 { + CREATE TABLE xyz(a); + PRAGMA journal_mode = wal; + INSERT INTO xyz VALUES(1); + INSERT INTO xyz VALUES(2); + INSERT INTO xyz VALUES(3); +} {wal} + +breakpoint + +do_test 5.2 { + sqlite3 db2 test.db + execsql { SELECT * FROM xyz } db2 +} {1 2 3} + +do_execsql_test 5.3 { + PRAGMA wal_checkpoint = restart +} {0 0 0} + +do_test 5.4 { + execsql { SELECT * FROM xyz } db2 +} {1 2 3} + finish_test