mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Merge the latest trunk enhancements into the bedrock branch.
FossilOrigin-Name: d5289de411cd6cb9d56b4d5d34ad9616ee125f0c1900310e1259a82466955738
This commit is contained in:
18
src/wal.c
18
src/wal.c
@@ -804,6 +804,7 @@ struct Wal {
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_SNAPSHOT
|
||||
WalIndexHdr *pSnapshot; /* Start transaction here if not NULL */
|
||||
int bGetSnapshot; /* Transaction opened for sqlite3_get_snapshot() */
|
||||
#endif
|
||||
int bClosing; /* Set to true at start of sqlite3WalClose() */
|
||||
int bWal2; /* bWal2 flag passed to WalOpen() */
|
||||
@@ -3765,7 +3766,7 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int *pCnt){
|
||||
u32 mxFrame; /* Wal frame to lock to */
|
||||
if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame
|
||||
#ifdef SQLITE_ENABLE_SNAPSHOT
|
||||
&& (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0)
|
||||
&& ((pWal->bGetSnapshot==0 && pWal->pSnapshot==0) || pWal->hdr.mxFrame==0)
|
||||
#endif
|
||||
){
|
||||
/* The WAL has been completely backfilled (or it is empty).
|
||||
@@ -5719,7 +5720,20 @@ void sqlite3WalSnapshotOpen(
|
||||
Wal *pWal,
|
||||
sqlite3_snapshot *pSnapshot
|
||||
){
|
||||
pWal->pSnapshot = (WalIndexHdr*)pSnapshot;
|
||||
if( pSnapshot && ((WalIndexHdr*)pSnapshot)->iVersion==0 ){
|
||||
/* iVersion==0 means that this is a call to sqlite3_snapshot_get(). In
|
||||
** this case set the bGetSnapshot flag so that if the call to
|
||||
** sqlite3_snapshot_get() is about to read transaction on this wal
|
||||
** file, it does not take read-lock 0 if the wal file has been completely
|
||||
** checkpointed. Taking read-lock 0 would work, but then it would be
|
||||
** possible for a subsequent writer to destroy the snapshot even while
|
||||
** this connection is holding its read-transaction open. This is contrary
|
||||
** to user expectations, so we avoid it by not taking read-lock 0. */
|
||||
pWal->bGetSnapshot = 1;
|
||||
}else{
|
||||
pWal->pSnapshot = (WalIndexHdr*)pSnapshot;
|
||||
pWal->bGetSnapshot = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user