1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

A different fix to [fc62af4523]. When changing from journal_mode=PERSIST or TRINCATE to some other rollback mode, delete the journal file only if a RESERVED lock can be obtained on the database file first.

FossilOrigin-Name: b9b11855e8a9522309dd30e5256bb67d67e1353a
This commit is contained in:
dan
2010-06-17 16:44:21 +00:00
parent b70f82a7a5
commit 731bf5bcf8
6 changed files with 58 additions and 24 deletions

View File

@@ -5898,6 +5898,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( state<PAGER_SHARED ){
rc = sqlite3PagerSharedLock(pPager);
}
if( pPager->state==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 */