diff options
author | dan <dan@noemail.net> | 2010-05-31 16:41:53 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2010-05-31 16:41:53 +0000 |
commit | d0aa34277fdfe83d8dda08ec9fddf4511f8fe914 (patch) | |
tree | 6277b9876b10c4db23cb8a8f79f93a8a7edaf4b1 /src/wal.c | |
parent | 3dee6da9949ad367cdd827f0fe255e53f4bb9ccc (diff) | |
download | sqlite-d0aa34277fdfe83d8dda08ec9fddf4511f8fe914.tar.gz sqlite-d0aa34277fdfe83d8dda08ec9fddf4511f8fe914.zip |
Avoid dropping the checkpoint lock after a recovery run as a precursor to a checkpoint operation.
FossilOrigin-Name: cc25cfa04630a43c1de26f2dbdacbe46c110a2b5
Diffstat (limited to 'src/wal.c')
-rw-r--r-- | src/wal.c | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -264,7 +264,7 @@ struct WalIndexHdr { u32 iChange; /* Counter incremented each transaction */ u16 bigEndCksum; /* True if checksums in WAL are big-endian */ u16 szPage; /* Database page size in bytes */ - u32 mxFrame; /* Index of last valid frame in the WAL */ + u32 mxFrame; /* Index of last valid frame in the WAL */ u32 nPage; /* Size of database in pages */ u32 aFrameCksum[2]; /* Checksum of last frame in log */ u32 aSalt[2]; /* Two salt values copied from WAL header */ @@ -953,8 +953,22 @@ static int walIndexRecover(Wal *pWal){ int rc; /* Return Code */ i64 nSize; /* Size of log file */ u32 aFrameCksum[2] = {0, 0}; - - rc = walLockExclusive(pWal, WAL_ALL_BUT_WRITE, SQLITE_SHM_NLOCK-1); + int iLock; /* Lock offset to lock for checkpoint */ + int nLock; /* Number of locks to hold */ + + /* Obtain an exclusive lock on all byte in the locking range not already + ** locked by the caller. The caller is guaranteed to have locked the + ** WAL_WRITE_LOCK byte, and may have also locked the WAL_CKPT_LOCK byte. + ** If successful, the same bytes that are locked here are unlocked before + ** this function returns. + */ + assert( pWal->ckptLock==1 || pWal->ckptLock==0 ); + assert( WAL_ALL_BUT_WRITE==WAL_WRITE_LOCK+1 ); + assert( WAL_CKPT_LOCK==WAL_ALL_BUT_WRITE ); + assert( pWal->writeLock ); + iLock = WAL_ALL_BUT_WRITE + pWal->ckptLock; + nLock = SQLITE_SHM_NLOCK - iLock; + rc = walLockExclusive(pWal, iLock, nLock); if( rc ){ return rc; } @@ -1060,7 +1074,7 @@ finished: recovery_error: WALTRACE(("WAL%p: recovery %s\n", pWal, rc ? "failed" : "ok")); - walUnlockExclusive(pWal, WAL_ALL_BUT_WRITE, SQLITE_SHM_NLOCK-1); + walUnlockExclusive(pWal, iLock, nLock); return rc; } |