diff options
author | dan <dan@noemail.net> | 2010-04-30 15:49:27 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2010-04-30 15:49:27 +0000 |
commit | a7ad518ef02e9e9ce1c3bb190e2895389916d23f (patch) | |
tree | 72e6b2b777544328d9e3b0b2c0b6d2c2ad327997 /src | |
parent | 6045461eee8c9921e1b4155e211e6d944cec41eb (diff) | |
download | sqlite-a7ad518ef02e9e9ce1c3bb190e2895389916d23f.tar.gz sqlite-a7ad518ef02e9e9ce1c3bb190e2895389916d23f.zip |
When closing a WAL connection, attempt an exclusive lock on the database file. If the lock is obtained, checkpoint the database and delete the wal and wal-index files.
FossilOrigin-Name: c05e7dca172719f33e245c08d0c0e8ab47e5a537
Diffstat (limited to 'src')
-rw-r--r-- | src/wal.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -785,8 +785,35 @@ int sqlite3WalClose( ){ int rc = SQLITE_OK; if( pWal ){ + int isDelete = 0; /* True to unlink wal and wal-index files */ + + /* If an EXCLUSIVE lock can be obtained on the database file (using the + ** ordinary, rollback-mode locking methods, this guarantees that the + ** connection associated with this log file is the only connection to + ** the database. In this case checkpoint the database and unlink both + ** the wal and wal-index files. + ** + ** The EXCLUSIVE lock is not released before returning. + */ + rc = sqlite3OsLock(pFd, SQLITE_LOCK_EXCLUSIVE); + if( rc==SQLITE_OK ){ + rc = walCheckpoint(pWal, pFd, sync_flags, zBuf); + if( rc==SQLITE_OK ){ + isDelete = 1; + } + walIndexUnmap(pWal); + } + pWal->pVfs->xShmClose(pWal->pWIndex); sqlite3OsClose(pWal->pFd); + if( isDelete ){ + int nWal; + char *zWal = &((char *)pWal->pFd)[pWal->pVfs->szOsFile]; + sqlite3OsDelete(pWal->pVfs, zWal, 0); + nWal = sqlite3Strlen30(zWal); + memcpy(&zWal[nWal], "-index", 7); + pWal->pVfs->xShmDelete(pWal->pVfs, zWal); + } sqlite3_free(pWal); } return rc; |