From be5c10477c17f0fe4916181b449e7575a96d5fec Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 17 Jun 2010 17:05:53 +0000 Subject: [PATCH] Apply [b9b11855e8] (the alternate fix to [fc62af4523]) to the trunk. FossilOrigin-Name: 9a949a3a5c32b8bfbb94e10e18d050ec80a25553 --- manifest | 28 +++++++++------------------- manifest.uuid | 2 +- src/pager.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/vdbe.c | 7 ++----- test/jrnlmode.test | 4 ++-- 5 files changed, 56 insertions(+), 27 deletions(-) diff --git a/manifest b/manifest index 1ed3a6b60a..eeefca1a8d 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,5 @@ ------BEGIN PGP SIGNED MESSAGE----- -Hash: SHA1 - -C Fix\sthe\stkt-fc62af4523.test\sto\swork\saround\snon-randomness\sof\sthe\nrandomblob()\sfunction\swhen\sin\stesting\smode. -D 2010-06-17T16:08:54 +C Apply\s[b9b11855e8]\s(the\salternate\sfix\sto\s[fc62af4523])\sto\sthe\strunk. +D 2010-06-17T17:05:54 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in a5cad1f8f3e021356bfcc6c77dc16f6f1952bbc3 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -159,7 +156,7 @@ F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f F src/os_os2.c 665876d5eec7585226b0a1cf5e18098de2b2da19 F src/os_unix.c ae173c9f6afaa58b2833a1c95c6cd32021755c42 F src/os_win.c dfde7d33c446e89dd9a277c036f2c4cc564b3138 -F src/pager.c b5584c5e75e463b4a136e26858d555e83ca97b44 +F src/pager.c 4fe451d68950002eb985e6325d666ab54956a37f F src/pager.h ca1f23c0cf137ac26f8908df2427c8b308361efd F src/parse.y ace5c7a125d9f2a410e431ee3209034105045f7e F src/pcache.c 1e9aa2dbc0845b52e1b51cc39753b6d1e041cb07 @@ -220,7 +217,7 @@ F src/update.c 9859f2056c7739a1db0d9774ccb6c2f0cee6d1de F src/utf.c 1baeeac91707a4df97ccc6141ec0f808278af685 F src/util.c 32aebf04c10e51ad3977a928b7416bed671b620b F src/vacuum.c 241a8386727c1497eba4955933356dfba6ff8c9f -F src/vdbe.c 8a910a19981b8f670f4d67b5b0673459de50ccba +F src/vdbe.c e115585b14d2cc4128cb53a7e42f207750e80f55 F src/vdbe.h 471f6a3dcec4817ca33596fe7f6654d56c0e75f3 F src/vdbeInt.h 19ebc8c2a2e938340051ee65af3f377fb99102d1 F src/vdbeapi.c dc3138f10afbc95ed3c21dd25abb154504b1db9d @@ -469,7 +466,7 @@ F test/join4.test 1a352e4e267114444c29266ce79e941af5885916 F test/join5.test 86675fc2919269aa923c84dd00ee4249b97990fe F test/join6.test bf82cf3f979e9eade83ad0d056a66c5ed71d1901 F test/journal1.test 36f2d1bb9bf03f790f43fbdb439e44c0657fab19 -F test/jrnlmode.test cd0c9c5b2555f3d5bb72ed8aa8d0ad16ecf77e7c +F test/jrnlmode.test 76f94d61528c5ff32102a12f8cf34f4cc36f7849 F test/jrnlmode2.test fe79ea1f0375c926b8de0362ddf94f34a64135fd F test/jrnlmode3.test cfcdb12b90e640a23b92785a002d96c0624c8710 F test/keyword1.test a2400977a2e4fde43bf33754c2929fda34dbca05 @@ -826,14 +823,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 1ec74591a93e8b27ad3ac739914a48a91972e82c -R f22efcb25274595c63db494b4fd0d5e3 -U drh -Z 5de72be9b8f0adddcd3189b98a437ea2 ------BEGIN PGP SIGNATURE----- -Version: GnuPG v1.4.6 (GNU/Linux) - -iD8DBQFMGkiZoxKgR168RlERAqWGAJwJQXBZXrZmTaB1vIkV/5uryay3cACbBcij -ZJYGkT2oDVKZ+q0ThWu3qBk= -=rpt5 ------END PGP SIGNATURE----- +P 7c3a86b9c7e2a35ce755c32b38e911e79d843fad +R 1e4481b965cd36ec30ba83a04296f9cc +U dan +Z b00e14e0e21b5f60f6931c141403c159 diff --git a/manifest.uuid b/manifest.uuid index ac9c423d57..97d2603404 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7c3a86b9c7e2a35ce755c32b38e911e79d843fad \ No newline at end of file +9a949a3a5c32b8bfbb94e10e18d050ec80a25553 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index ad1e1e1378..c875dd9dfa 100644 --- a/src/pager.c +++ b/src/pager.c @@ -5877,6 +5877,48 @@ int sqlite3PagerSetJournalMode(Pager *pPager, int eMode){ /* Change the journal mode. */ pPager->journalMode = (u8)eMode; + + /* When transistioning from TRUNCATE or PERSIST to any other journal + ** mode except WAL (and we are not in locking_mode=EXCLUSIVE) then + ** delete the journal file. + */ + assert( (PAGER_JOURNALMODE_TRUNCATE & 5)==1 ); + assert( (PAGER_JOURNALMODE_PERSIST & 5)==1 ); + assert( (PAGER_JOURNALMODE_DELETE & 5)==0 ); + assert( (PAGER_JOURNALMODE_MEMORY & 5)==4 ); + assert( (PAGER_JOURNALMODE_OFF & 5)==0 ); + assert( (PAGER_JOURNALMODE_WAL & 5)==5 ); + + assert( isOpen(pPager->fd) || pPager->exclusiveMode ); + if( !pPager->exclusiveMode && (eOld & 5)==1 && (eMode & 1)==0 ){ + + /* In this case we would like to delete the journal file. If it is + ** not possible, then that is not a problem. Deleting the journal file + ** here is an optimization only. + ** + ** Before deleting the journal file, obtain a RESERVED lock on the + ** database file. This ensures that the journal file is not deleted + ** while it is in use by some other client. + */ + int rc = SQLITE_OK; + int state = pPager->state; + if( statestate==PAGER_SHARED ){ + assert( rc==SQLITE_OK ); + rc = sqlite3OsLock(pPager->fd, RESERVED_LOCK); + } + if( rc==SQLITE_OK ){ + sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0); + } + if( rc==SQLITE_OK && state==PAGER_SHARED ){ + sqlite3OsUnlock(pPager->fd, SHARED_LOCK); + }else if( state==PAGER_UNLOCK ){ + pager_unlock(pPager); + } + assert( state==pPager->state ); + } } /* Return the new journal mode */ diff --git a/src/vdbe.c b/src/vdbe.c index 14785d35d5..6803beafd3 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -5251,9 +5251,6 @@ case OP_JournalMode: { /* out2-prerelease */ }else if( rc==SQLITE_BUSY && pOp->p5==0 ){ goto abort_due_to_error; } - }else{ - sqlite3PagerSetJournalMode(pPager, PAGER_JOURNALMODE_DELETE); - rc = SQLITE_OK; } /* Open a transaction on the database file. Regardless of the journal @@ -5261,8 +5258,7 @@ case OP_JournalMode: { /* out2-prerelease */ */ assert( sqlite3BtreeIsInTrans(pBt)==0 ); if( rc==SQLITE_OK ){ - rc = sqlite3BtreeSetVersion(pBt, - (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1)); + rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1)); if( rc==SQLITE_BUSY && pOp->p5==0 ) goto abort_due_to_error; } if( rc==SQLITE_BUSY ){ @@ -5274,6 +5270,7 @@ case OP_JournalMode: { /* out2-prerelease */ #endif /* ifndef SQLITE_OMIT_WAL */ eNew = sqlite3PagerSetJournalMode(pPager, eNew); + pOut = &aMem[pOp->p2]; pOut->flags = MEM_Str|MEM_Static|MEM_Term; pOut->z = (char *)sqlite3JournalModename(eNew); diff --git a/test/jrnlmode.test b/test/jrnlmode.test index 2a6338fc9e..fd3e59f12d 100644 --- a/test/jrnlmode.test +++ b/test/jrnlmode.test @@ -484,7 +484,7 @@ ifcapable pragma { INSERT INTO t4 VALUES(3, 4); } file exists test.db-journal - } {1} + } {0} do_test jrnlmode-6.7 { execsql { COMMIT; @@ -493,7 +493,7 @@ ifcapable pragma { } {1 2 3 4} do_test jrnlmode-6.8 { file exists test.db-journal - } {1} + } {0} do_test jrnlmode-6.9 { execsql { PRAGMA journal_mode = DELETE;