Further tests and changes related to switching between WAL and rollback modes.
FossilOrigin-Name: 1236318477787a612f02cc98caf2931bd2e99d94
This commit is contained in:
parent
b978002743
commit
ede6eb8d1d
18
manifest
18
manifest
@ -1,5 +1,5 @@
|
||||
C Tests\sfor\s(and\schanges\sto)\sthe\scode\sto\sswitch\sbetween\sWAL\sand\srollback\smodes.
|
||||
D 2010-04-21T18:37:57
|
||||
C Further\stests\sand\schanges\srelated\sto\sswitching\sbetween\sWAL\sand\srollback\smodes.
|
||||
D 2010-04-22T06:27:05
|
||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||
F Makefile.in 4f2f967b7e58a35bb74fb7ec8ae90e0f4ca7868b
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
@ -109,7 +109,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
|
||||
F src/backup.c e86634da8c48357a759694c9c7c471125cd8d5a8
|
||||
F src/bitvec.c 06ad2c36a9c3819c0b9cbffec7b15f58d5d834e0
|
||||
F src/btmutex.c 96a12f50f7a17475155971a241d85ec5171573ff
|
||||
F src/btree.c fcfff21fb259fc5f09d8ae65478c3240553f4cd9
|
||||
F src/btree.c f87ed73ef82bccb1e5dd63d6a4919272d3354c8a
|
||||
F src/btree.h dd83041eda10c17daf023257c1fc883b5f71f85a
|
||||
F src/btreeInt.h b0c87f6725b06a0aa194a6d25d54b16ce9d6e291
|
||||
F src/build.c 11100b66fb97638d2d874c1d34d8db90650bb1d7
|
||||
@ -154,7 +154,7 @@ F src/os_common.h 240c88b163b02c21a9f21f87d49678a0aa21ff30
|
||||
F src/os_os2.c 75a8c7b9a00a2cf1a65f9fa4afbc27d46634bb2f
|
||||
F src/os_unix.c 5bf0015cebe2f21635da2af983c348eb88b3b4c1
|
||||
F src/os_win.c 1c7453c2df4dab26d90ff6f91272aea18bcf7053
|
||||
F src/pager.c f20f9090456b2f4aa3c5174e390a3cfd61bd3cc1
|
||||
F src/pager.c 06fb9b8b7c5283c62f5258e098d6d1649dde7635
|
||||
F src/pager.h cee4487ab4f0911dd9f22a40e3cd55afdb7ef444
|
||||
F src/parse.y ace5c7a125d9f2a410e431ee3209034105045f7e
|
||||
F src/pcache.c ace8f6a5ecd4711cc66a1b23053be7109bd437cf
|
||||
@ -214,7 +214,7 @@ F src/update.c c0dc6b75ad28b76b619042d934f337b02acee208
|
||||
F src/utf.c 1baeeac91707a4df97ccc6141ec0f808278af685
|
||||
F src/util.c 32aebf04c10e51ad3977a928b7416bed671b620b
|
||||
F src/vacuum.c b1d542c8919d4d11119f78069e1906a1ad07e0ee
|
||||
F src/vdbe.c 4d99d175264ef5b2ac57b19396f2b78199539e22
|
||||
F src/vdbe.c 09e88e8b01b413271b5ccd8c902c424cd563e342
|
||||
F src/vdbe.h 471f6a3dcec4817ca33596fe7f6654d56c0e75f3
|
||||
F src/vdbeInt.h 19ebc8c2a2e938340051ee65af3f377fb99102d1
|
||||
F src/vdbeapi.c 466044df5bc916f778833e927165fd02cdef6086
|
||||
@ -761,7 +761,7 @@ F test/vtab_shared.test 0eff9ce4f19facbe0a3e693f6c14b80711a4222d
|
||||
F test/wal.test fd0e5914599b205172dae33c765368a75feb2462
|
||||
F test/walcrash.test f022cee7eb7baa5fb898726120a6a4073dd831d1
|
||||
F test/walhook.test 76a559e262f0715c470bade4a8d8333035f8ee47
|
||||
F test/walmode.test 004da14c0d6be8314bba076d2d89c16458b6f849
|
||||
F test/walmode.test c2f4e30ad64910b2d8faf6cf4e940b3f201b41df
|
||||
F test/walslow.test 38076d5fad49e3678027be0f8110e6a32d531dc2
|
||||
F test/walthread.test 27e44ee6fd02f1f494a24f999c97086af3ab739d
|
||||
F test/where.test de337a3fe0a459ec7c93db16a519657a90552330
|
||||
@ -807,7 +807,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||
P 33cabf271b8f4dda508a610bf59964273fe2cb84
|
||||
R ce8d5df20a1a383d4fb608ef1b16a4c8
|
||||
P 9f4f933f2c6596064fcfc7fb5add87e8c5b57448
|
||||
R cdccc9135123b3edc2fcb17c83fbd857
|
||||
U dan
|
||||
Z 9951e081ef8379216185ea5ef99b745d
|
||||
Z 891f9ffc6892beb06734f78c0f8e5711
|
||||
|
@ -1 +1 @@
|
||||
9f4f933f2c6596064fcfc7fb5add87e8c5b57448
|
||||
1236318477787a612f02cc98caf2931bd2e99d94
|
@ -8004,7 +8004,7 @@ int sqlite3BtreeSetVersion(Btree *pBtree, int iVersion){
|
||||
if( rc==SQLITE_OK ){
|
||||
u8 *aData = pBt->pPage1->aData;
|
||||
if( aData[18]!=(u8)iVersion || aData[19]!=(u8)iVersion ){
|
||||
rc = sqlite3BtreeBeginTrans(pBtree, 1);
|
||||
rc = sqlite3BtreeBeginTrans(pBtree, 2);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
|
||||
if( rc==SQLITE_OK ){
|
||||
|
36
src/pager.c
36
src/pager.c
@ -3732,18 +3732,13 @@ static int hasHotJournal(Pager *pPager, int *pExists){
|
||||
** an SQLite error code.
|
||||
**
|
||||
** The caller must hold a SHARED lock on the database file to call this
|
||||
** function.
|
||||
** function. Because an EXCLUSIVE lock on the db file is required to delete
|
||||
** a WAL, this ensures there is no race condition between the xAccess()
|
||||
** below and an xDelete() being executed by some other connection.
|
||||
*/
|
||||
static int pagerHasWAL(Pager *pPager, int *pExists){
|
||||
int rc; /* Return code */
|
||||
|
||||
/* Check that a SHARED lock is held on the database file. Because an
|
||||
** EXCLUSIVE lock on the db file is required to delete a WAL, this
|
||||
** ensures there is no race condition between the xAccess() below and
|
||||
** an xDelete() being executed by some other connection.
|
||||
*/
|
||||
assert( pPager->state>=PAGER_SHARED );
|
||||
|
||||
if( !pPager->tempFile ){
|
||||
char *zLog = sqlite3_mprintf("%s-wal", pPager->zFilename);
|
||||
if( !zLog ){
|
||||
@ -5755,12 +5750,29 @@ int sqlite3PagerOpenLog(Pager *pPager, int *pisOpen){
|
||||
*/
|
||||
int sqlite3PagerCloseLog(Pager *pPager){
|
||||
int rc = SQLITE_OK;
|
||||
if( pPager->pLog ){
|
||||
|
||||
/* Try to obtain an EXCLUSIVE lock on the database file. */
|
||||
assert( pPager->journalMode==PAGER_JOURNALMODE_WAL );
|
||||
|
||||
/* If the log file is not already open, but does exist in the file-system,
|
||||
** it may need to be checkpointed before the connection can switch to
|
||||
** rollback mode. Open it now so this can happen.
|
||||
*/
|
||||
if( !pPager->pLog ){
|
||||
int logexists = 0;
|
||||
rc = sqlite3OsLock(pPager->fd, SQLITE_LOCK_SHARED);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = pagerHasWAL(pPager, &logexists);
|
||||
}
|
||||
if( rc==SQLITE_OK && logexists ){
|
||||
rc = sqlite3LogOpen(pPager->pVfs, pPager->zFilename, &pPager->pLog);
|
||||
}
|
||||
}
|
||||
|
||||
/* Checkpoint and close the log. Because an EXCLUSIVE lock is held on
|
||||
** the database file, the log and log-summary files will be deleted.
|
||||
*/
|
||||
if( rc==SQLITE_OK && pPager->pLog ){
|
||||
rc = sqlite3OsLock(pPager->fd, SQLITE_LOCK_EXCLUSIVE);
|
||||
|
||||
/* If the EXCLUSIVE lock was obtained, checkpoint and close the log. */
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3LogClose(pPager->pLog, pPager->fd,
|
||||
(pPager->noSync ? 0 : pPager->sync_flags),
|
||||
|
@ -5244,11 +5244,12 @@ case OP_JournalMode: {
|
||||
);
|
||||
}else{
|
||||
|
||||
/* If leaving WAL mode, close the log file. If successful, the call to
|
||||
** PagerCloseLog() checkpoints and deletes the write-ahead-log file.
|
||||
** An EXCLUSIVE lock is still held on the database file after returning.
|
||||
*/
|
||||
if( eOld==PAGER_JOURNALMODE_WAL ){
|
||||
/* If leaving WAL mode, close the log file. If successful, the call
|
||||
** to PagerCloseLog() checkpoints and deletes the write-ahead-log
|
||||
** file. An EXCLUSIVE lock may still be held on the database file
|
||||
** after a successful return.
|
||||
*/
|
||||
rc = sqlite3PagerCloseLog(pPager);
|
||||
if( rc!=SQLITE_OK ) goto abort_due_to_error;
|
||||
sqlite3PagerJournalMode(pPager, eNew);
|
||||
|
@ -72,6 +72,8 @@ do_test walmode-3.2 {
|
||||
list $sqlite_sync_count [file exists test.db-wal] [file size test.db-wal]
|
||||
} {0 1 0}
|
||||
|
||||
# Test that changing back to journal_mode=persist works.
|
||||
#
|
||||
do_test walmode-4.1 {
|
||||
execsql { INSERT INTO t1 VALUES(1, 2) }
|
||||
execsql { PRAGMA journal_mode = persist }
|
||||
@ -91,5 +93,55 @@ do_test walmode-4.5 {
|
||||
list [file exists test.db-journal] [file exists test.db-wal]
|
||||
} {1 0}
|
||||
|
||||
# Test that nothing goes wrong if a connection is prevented from changing
|
||||
# from WAL to rollback mode because a second connection has the database
|
||||
# open. Or from rollback to WAL.
|
||||
#
|
||||
do_test walmode-4.1 {
|
||||
sqlite3 db2 test.db
|
||||
execsql { PRAGMA main.journal_mode } db2
|
||||
} {delete}
|
||||
do_test walmode-4.2 {
|
||||
execsql { PRAGMA main.journal_mode = wal } db
|
||||
} {wal}
|
||||
do_test walmode-4.3 {
|
||||
execsql { SELECT * FROM t1 } db2
|
||||
} {1 2}
|
||||
do_test walmode-4.4 {
|
||||
catchsql { PRAGMA journal_mode = delete } db
|
||||
} {1 {database is locked}}
|
||||
do_test walmode-4.5 {
|
||||
execsql { PRAGMA main.journal_mode } db
|
||||
} {wal}
|
||||
do_test walmode-4.6 {
|
||||
db2 close
|
||||
execsql { PRAGMA journal_mode = delete } db
|
||||
} {delete}
|
||||
do_test walmode-4.7 {
|
||||
execsql { PRAGMA main.journal_mode } db
|
||||
} {delete}
|
||||
do_test walmode-4.8 {
|
||||
list [file exists test.db-journal] [file exists test.db-wal]
|
||||
} {0 0}
|
||||
do_test walmode-4.9 {
|
||||
sqlite3 db2 test.db
|
||||
execsql {
|
||||
BEGIN;
|
||||
SELECT * FROM t1;
|
||||
} db2
|
||||
} {1 2}
|
||||
do_test walmode-4.11 {
|
||||
execsql { PRAGMA main.journal_mode } db
|
||||
} {delete}
|
||||
do_test walmode-4.10 {
|
||||
catchsql { PRAGMA main.journal_mode = wal } db
|
||||
} {1 {database is locked}}
|
||||
do_test walmode-4.11 {
|
||||
execsql { PRAGMA main.journal_mode } db
|
||||
} {delete}
|
||||
|
||||
|
||||
catch { db close }
|
||||
catch { db2 close }
|
||||
finish_test
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user