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

If a reader attempts to upgrade to a writer, but is not reading the most recent database snapshot, return SQLITE_BUSY.

FossilOrigin-Name: 837d82a92977cbfa0963411daf8160d286a7ed32
This commit is contained in:
dan
2010-04-30 15:24:43 +00:00
parent 5530b764a8
commit 6045461eee
3 changed files with 26 additions and 18 deletions

View File

@@ -1009,6 +1009,24 @@ int sqlite3WalWriteLock(Wal *pWal, int op){
if( op ){
assert( pWal->lockState == SQLITE_SHM_READ );
rc = walSetLock(pWal, SQLITE_SHM_WRITE);
/* If this connection is not reading the most recent database snapshot,
** it is not possible to write to the database. In this case release
** the write locks and return SQLITE_BUSY.
*/
if( rc==SQLITE_OK ){
rc = walIndexMap(pWal, -1);
if( rc==SQLITE_OK
&& memcmp(&pWal->hdr, pWal->pWiData, sizeof(WalIndexHdr))
){
rc = SQLITE_BUSY;
}
walIndexUnmap(pWal);
if( rc!=SQLITE_OK ){
walSetLock(pWal, SQLITE_SHM_READ);
}
}
}else if( pWal->lockState==SQLITE_SHM_WRITE ){
rc = walSetLock(pWal, SQLITE_SHM_READ);
}