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:
18
src/wal.c
18
src/wal.c
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user