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

Handle the race condition that may occur if another process connects and then

checkpoints and truncates the wal file while a readonly-shm client is building
its heap-memory wal-index.

FossilOrigin-Name: 5a6703fc3f2174b3e9a624c7272ae013b73c42d6c97ffa62b58553efdb54e3bc
This commit is contained in:
dan
2017-11-07 21:15:07 +00:00
parent f12ba66cf8
commit 08ecefc5b1
4 changed files with 70 additions and 14 deletions

View File

@@ -2071,6 +2071,12 @@ static int walIndexTryHdr(Wal *pWal, int *pChanged){
return 0;
}
/*
** This is the value that walTryBeginRead returns when it needs to
** be retried.
*/
#define WAL_RETRY (-1)
/*
** Read the wal-index header from the wal-index and into pWal->hdr.
** If the wal-header appears to be corrupt, try to reconstruct the
@@ -2149,6 +2155,9 @@ static int walIndexReadHdr(Wal *pWal, int *pChanged){
if( pWal->bUnlocked ){
if( rc!=SQLITE_OK ){
walIndexClose(pWal, 0);
pWal->bUnlocked = 0;
assert( pWal->nWiData>0 && pWal->apWiData[0]==0 );
if( rc==SQLITE_IOERR_SHORT_READ ) rc = WAL_RETRY;
}
pWal->exclusiveMode = WAL_NORMAL_MODE;
}
@@ -2156,12 +2165,6 @@ static int walIndexReadHdr(Wal *pWal, int *pChanged){
return rc;
}
/*
** This is the value that walTryBeginRead returns when it needs to
** be retried.
*/
#define WAL_RETRY (-1)
/*
** Open an "unlocked" transaction. An unlocked transaction is a read
** transaction used by a read-only client in cases where the *-shm