mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Code formatting changes to make trunk more like wal2.
FossilOrigin-Name: 8f725472b0fe62359a4cd3237b43d7b834e042d8ce425abde06e3ed6c62dbafa
This commit is contained in:
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Changes\sfor\sbetter\salignment\swith\sthe\swal2\sbranch.
|
C Code\sformatting\schanges\sto\smake\strunk\smore\slike\swal2.
|
||||||
D 2024-12-16T13:25:49.902
|
D 2024-12-16T18:04:39.151
|
||||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||||
F LICENSE.md e108e1e69ae8e8a59e93c455654b8ac9356a11720d3345df2a4743e9590fb20d
|
F LICENSE.md e108e1e69ae8e8a59e93c455654b8ac9356a11720d3345df2a4743e9590fb20d
|
||||||
@@ -858,7 +858,7 @@ F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf8
|
|||||||
F src/vdbevtab.c fc46b9cbd759dc013f0b3724549cc0d71379183c667df3a5988f7e2f1bd485f3
|
F src/vdbevtab.c fc46b9cbd759dc013f0b3724549cc0d71379183c667df3a5988f7e2f1bd485f3
|
||||||
F src/vtab.c 316cd48e9320660db3047cd306cd056e4361180cebb4d0f10a39244e10c11422
|
F src/vtab.c 316cd48e9320660db3047cd306cd056e4361180cebb4d0f10a39244e10c11422
|
||||||
F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
|
F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
|
||||||
F src/wal.c fcbc36c31df200daa4ed398923ab55a02dbbed9ce22a8a31c5d9bf447a130126
|
F src/wal.c 4e6181d8780ab0af2e1388d0754cbe6f2f04593d2b1ab6c41699a89942fd8997
|
||||||
F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452
|
F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452
|
||||||
F src/walker.c d5006d6b005e4ea7302ad390957a8d41ed83faa177e412f89bc5600a7462a014
|
F src/walker.c d5006d6b005e4ea7302ad390957a8d41ed83faa177e412f89bc5600a7462a014
|
||||||
F src/where.c 9ad3dea8003a8913da6a4ca8322e2fe30773f46e88a0d4fbf9db13bdb999efa2
|
F src/where.c 9ad3dea8003a8913da6a4ca8322e2fe30773f46e88a0d4fbf9db13bdb999efa2
|
||||||
@@ -2202,8 +2202,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
|
|||||||
F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
|
F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
|
||||||
F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139
|
F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139
|
||||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||||
P ae580443d210811c12209866112fc8b0b83281e24945504b748a17d93ad84062
|
P 4fab85b3d0d1cad2d185f2456de7ddf281badf8561cc051e10e16655441dcc84
|
||||||
R dc9095f065111bf3b125973079f69b6b
|
R 9aaaecad314aea90d45c80b60798b57a
|
||||||
U drh
|
U drh
|
||||||
Z 26e0562f544e2adce22ef893d4b0b579
|
Z 2a765bcb487b40c3fb2da87580a07616
|
||||||
# Remove this line to create a well-formed Fossil manifest.
|
# Remove this line to create a well-formed Fossil manifest.
|
||||||
|
@@ -1 +1 @@
|
|||||||
4fab85b3d0d1cad2d185f2456de7ddf281badf8561cc051e10e16655441dcc84
|
8f725472b0fe62359a4cd3237b43d7b834e042d8ce425abde06e3ed6c62dbafa
|
||||||
|
262
src/wal.c
262
src/wal.c
@@ -2986,11 +2986,7 @@ static int walBeginShmUnreliable(Wal *pWal, int *pChanged){
|
|||||||
*/
|
*/
|
||||||
static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int *pCnt){
|
static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int *pCnt){
|
||||||
volatile WalCkptInfo *pInfo; /* Checkpoint information in wal-index */
|
volatile WalCkptInfo *pInfo; /* Checkpoint information in wal-index */
|
||||||
u32 mxReadMark; /* Largest aReadMark[] value */
|
|
||||||
int mxI; /* Index of largest aReadMark[] value */
|
|
||||||
int i; /* Loop counter */
|
|
||||||
int rc = SQLITE_OK; /* Return code */
|
int rc = SQLITE_OK; /* Return code */
|
||||||
u32 mxFrame; /* Wal frame to lock to */
|
|
||||||
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
|
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
|
||||||
int nBlockTmout = 0;
|
int nBlockTmout = 0;
|
||||||
#endif
|
#endif
|
||||||
@@ -3096,141 +3092,147 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int *pCnt){
|
|||||||
assert( pWal->apWiData[0]!=0 );
|
assert( pWal->apWiData[0]!=0 );
|
||||||
pInfo = walCkptInfo(pWal);
|
pInfo = walCkptInfo(pWal);
|
||||||
SEH_INJECT_FAULT;
|
SEH_INJECT_FAULT;
|
||||||
if( !useWal && AtomicLoad(&pInfo->nBackfill)==pWal->hdr.mxFrame
|
{
|
||||||
|
u32 mxReadMark; /* Largest aReadMark[] value */
|
||||||
|
int mxI; /* Index of largest aReadMark[] value */
|
||||||
|
int i; /* Loop counter */
|
||||||
|
u32 mxFrame; /* Wal frame to lock to */
|
||||||
|
if( !useWal && AtomicLoad(&pInfo->nBackfill)==pWal->hdr.mxFrame
|
||||||
#ifdef SQLITE_ENABLE_SNAPSHOT
|
#ifdef SQLITE_ENABLE_SNAPSHOT
|
||||||
&& ((pWal->bGetSnapshot==0 && pWal->pSnapshot==0) || pWal->hdr.mxFrame==0)
|
&& ((pWal->bGetSnapshot==0 && pWal->pSnapshot==0) || pWal->hdr.mxFrame==0)
|
||||||
#endif
|
#endif
|
||||||
){
|
){
|
||||||
/* The WAL has been completely backfilled (or it is empty).
|
/* The WAL has been completely backfilled (or it is empty).
|
||||||
** and can be safely ignored.
|
** and can be safely ignored.
|
||||||
*/
|
*/
|
||||||
rc = walLockShared(pWal, WAL_READ_LOCK(0));
|
rc = walLockShared(pWal, WAL_READ_LOCK(0));
|
||||||
walShmBarrier(pWal);
|
walShmBarrier(pWal);
|
||||||
if( rc==SQLITE_OK ){
|
|
||||||
if( memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr)) ){
|
|
||||||
/* It is not safe to allow the reader to continue here if frames
|
|
||||||
** may have been appended to the log before READ_LOCK(0) was obtained.
|
|
||||||
** When holding READ_LOCK(0), the reader ignores the entire log file,
|
|
||||||
** which implies that the database file contains a trustworthy
|
|
||||||
** snapshot. Since holding READ_LOCK(0) prevents a checkpoint from
|
|
||||||
** happening, this is usually correct.
|
|
||||||
**
|
|
||||||
** However, if frames have been appended to the log (or if the log
|
|
||||||
** is wrapped and written for that matter) before the READ_LOCK(0)
|
|
||||||
** is obtained, that is not necessarily true. A checkpointer may
|
|
||||||
** have started to backfill the appended frames but crashed before
|
|
||||||
** it finished. Leaving a corrupt image in the database file.
|
|
||||||
*/
|
|
||||||
walUnlockShared(pWal, WAL_READ_LOCK(0));
|
|
||||||
return WAL_RETRY;
|
|
||||||
}
|
|
||||||
pWal->readLock = 0;
|
|
||||||
return SQLITE_OK;
|
|
||||||
}else if( rc!=SQLITE_BUSY ){
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we get this far, it means that the reader will want to use
|
|
||||||
** the WAL to get at content from recent commits. The job now is
|
|
||||||
** to select one of the aReadMark[] entries that is closest to
|
|
||||||
** but not exceeding pWal->hdr.mxFrame and lock that entry.
|
|
||||||
*/
|
|
||||||
mxReadMark = 0;
|
|
||||||
mxI = 0;
|
|
||||||
mxFrame = pWal->hdr.mxFrame;
|
|
||||||
#ifdef SQLITE_ENABLE_SNAPSHOT
|
|
||||||
if( pWal->pSnapshot && pWal->pSnapshot->mxFrame<mxFrame ){
|
|
||||||
mxFrame = pWal->pSnapshot->mxFrame;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
for(i=1; i<WAL_NREADER; i++){
|
|
||||||
u32 thisMark = AtomicLoad(pInfo->aReadMark+i); SEH_INJECT_FAULT;
|
|
||||||
if( mxReadMark<=thisMark && thisMark<=mxFrame ){
|
|
||||||
assert( thisMark!=READMARK_NOT_USED );
|
|
||||||
mxReadMark = thisMark;
|
|
||||||
mxI = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( (pWal->readOnly & WAL_SHM_RDONLY)==0
|
|
||||||
&& (mxReadMark<mxFrame || mxI==0)
|
|
||||||
){
|
|
||||||
for(i=1; i<WAL_NREADER; i++){
|
|
||||||
rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
|
|
||||||
if( rc==SQLITE_OK ){
|
if( rc==SQLITE_OK ){
|
||||||
AtomicStore(pInfo->aReadMark+i,mxFrame);
|
if( memcmp((void *)walIndexHdr(pWal), &pWal->hdr,sizeof(WalIndexHdr)) ){
|
||||||
mxReadMark = mxFrame;
|
/* It is not safe to allow the reader to continue here if frames
|
||||||
mxI = i;
|
** may have been appended to the log before READ_LOCK(0) was obtained.
|
||||||
walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
|
** When holding READ_LOCK(0), the reader ignores the entire log file,
|
||||||
break;
|
** which implies that the database file contains a trustworthy
|
||||||
|
** snapshot. Since holding READ_LOCK(0) prevents a checkpoint from
|
||||||
|
** happening, this is usually correct.
|
||||||
|
**
|
||||||
|
** However, if frames have been appended to the log (or if the log
|
||||||
|
** is wrapped and written for that matter) before the READ_LOCK(0)
|
||||||
|
** is obtained, that is not necessarily true. A checkpointer may
|
||||||
|
** have started to backfill the appended frames but crashed before
|
||||||
|
** it finished. Leaving a corrupt image in the database file.
|
||||||
|
*/
|
||||||
|
walUnlockShared(pWal, WAL_READ_LOCK(0));
|
||||||
|
return WAL_RETRY;
|
||||||
|
}
|
||||||
|
pWal->readLock = 0;
|
||||||
|
return SQLITE_OK;
|
||||||
}else if( rc!=SQLITE_BUSY ){
|
}else if( rc!=SQLITE_BUSY ){
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if( mxI==0 ){
|
/* If we get this far, it means that the reader will want to use
|
||||||
assert( rc==SQLITE_BUSY || (pWal->readOnly & WAL_SHM_RDONLY)!=0 );
|
** the WAL to get at content from recent commits. The job now is
|
||||||
return rc==SQLITE_BUSY ? WAL_RETRY : SQLITE_READONLY_CANTINIT;
|
** to select one of the aReadMark[] entries that is closest to
|
||||||
}
|
** but not exceeding pWal->hdr.mxFrame and lock that entry.
|
||||||
|
*/
|
||||||
(void)walEnableBlockingMs(pWal, nBlockTmout);
|
mxReadMark = 0;
|
||||||
rc = walLockShared(pWal, WAL_READ_LOCK(mxI));
|
mxI = 0;
|
||||||
walDisableBlocking(pWal);
|
mxFrame = pWal->hdr.mxFrame;
|
||||||
if( rc ){
|
#ifdef SQLITE_ENABLE_SNAPSHOT
|
||||||
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
|
if( pWal->pSnapshot && pWal->pSnapshot->mxFrame<mxFrame ){
|
||||||
if( rc==SQLITE_BUSY_TIMEOUT ){
|
mxFrame = pWal->pSnapshot->mxFrame;
|
||||||
*pCnt |= WAL_RETRY_BLOCKED_MASK;
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
assert( rc!=SQLITE_BUSY_TIMEOUT );
|
|
||||||
#endif
|
#endif
|
||||||
assert( (rc&0xFF)!=SQLITE_BUSY||rc==SQLITE_BUSY||rc==SQLITE_BUSY_TIMEOUT );
|
for(i=1; i<WAL_NREADER; i++){
|
||||||
return (rc&0xFF)==SQLITE_BUSY ? WAL_RETRY : rc;
|
u32 thisMark = AtomicLoad(pInfo->aReadMark+i); SEH_INJECT_FAULT;
|
||||||
}
|
if( mxReadMark<=thisMark && thisMark<=mxFrame ){
|
||||||
/* Now that the read-lock has been obtained, check that neither the
|
assert( thisMark!=READMARK_NOT_USED );
|
||||||
** value in the aReadMark[] array or the contents of the wal-index
|
mxReadMark = thisMark;
|
||||||
** header have changed.
|
mxI = i;
|
||||||
**
|
}
|
||||||
** It is necessary to check that the wal-index header did not change
|
}
|
||||||
** between the time it was read and when the shared-lock was obtained
|
if( (pWal->readOnly & WAL_SHM_RDONLY)==0
|
||||||
** on WAL_READ_LOCK(mxI) was obtained to account for the possibility
|
&& (mxReadMark<mxFrame || mxI==0)
|
||||||
** that the log file may have been wrapped by a writer, or that frames
|
){
|
||||||
** that occur later in the log than pWal->hdr.mxFrame may have been
|
for(i=1; i<WAL_NREADER; i++){
|
||||||
** copied into the database by a checkpointer. If either of these things
|
rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
|
||||||
** happened, then reading the database with the current value of
|
if( rc==SQLITE_OK ){
|
||||||
** pWal->hdr.mxFrame risks reading a corrupted snapshot. So, retry
|
AtomicStore(pInfo->aReadMark+i,mxFrame);
|
||||||
** instead.
|
mxReadMark = mxFrame;
|
||||||
**
|
mxI = i;
|
||||||
** Before checking that the live wal-index header has not changed
|
walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
|
||||||
** since it was read, set Wal.minFrame to the first frame in the wal
|
break;
|
||||||
** file that has not yet been checkpointed. This client will not need
|
}else if( rc!=SQLITE_BUSY ){
|
||||||
** to read any frames earlier than minFrame from the wal file - they
|
return rc;
|
||||||
** can be safely read directly from the database file.
|
}
|
||||||
**
|
}
|
||||||
** Because a ShmBarrier() call is made between taking the copy of
|
}
|
||||||
** nBackfill and checking that the wal-header in shared-memory still
|
if( mxI==0 ){
|
||||||
** matches the one cached in pWal->hdr, it is guaranteed that the
|
assert( rc==SQLITE_BUSY || (pWal->readOnly & WAL_SHM_RDONLY)!=0 );
|
||||||
** checkpointer that set nBackfill was not working with a wal-index
|
return rc==SQLITE_BUSY ? WAL_RETRY : SQLITE_READONLY_CANTINIT;
|
||||||
** header newer than that cached in pWal->hdr. If it were, that could
|
}
|
||||||
** cause a problem. The checkpointer could omit to checkpoint
|
|
||||||
** a version of page X that lies before pWal->minFrame (call that version
|
(void)walEnableBlockingMs(pWal, nBlockTmout);
|
||||||
** A) on the basis that there is a newer version (version B) of the same
|
rc = walLockShared(pWal, WAL_READ_LOCK(mxI));
|
||||||
** page later in the wal file. But if version B happens to like past
|
walDisableBlocking(pWal);
|
||||||
** frame pWal->hdr.mxFrame - then the client would incorrectly assume
|
if( rc ){
|
||||||
** that it can read version A from the database file. However, since
|
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
|
||||||
** we can guarantee that the checkpointer that set nBackfill could not
|
if( rc==SQLITE_BUSY_TIMEOUT ){
|
||||||
** see any pages past pWal->hdr.mxFrame, this problem does not come up.
|
*pCnt |= WAL_RETRY_BLOCKED_MASK;
|
||||||
*/
|
}
|
||||||
pWal->minFrame = AtomicLoad(&pInfo->nBackfill)+1; SEH_INJECT_FAULT;
|
#else
|
||||||
walShmBarrier(pWal);
|
assert( rc!=SQLITE_BUSY_TIMEOUT );
|
||||||
if( AtomicLoad(pInfo->aReadMark+mxI)!=mxReadMark
|
#endif
|
||||||
|| memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr))
|
assert((rc&0xFF)!=SQLITE_BUSY||rc==SQLITE_BUSY||rc==SQLITE_BUSY_TIMEOUT);
|
||||||
){
|
return (rc&0xFF)==SQLITE_BUSY ? WAL_RETRY : rc;
|
||||||
walUnlockShared(pWal, WAL_READ_LOCK(mxI));
|
}
|
||||||
return WAL_RETRY;
|
/* Now that the read-lock has been obtained, check that neither the
|
||||||
}else{
|
** value in the aReadMark[] array or the contents of the wal-index
|
||||||
assert( mxReadMark<=pWal->hdr.mxFrame );
|
** header have changed.
|
||||||
pWal->readLock = (i16)mxI;
|
**
|
||||||
|
** It is necessary to check that the wal-index header did not change
|
||||||
|
** between the time it was read and when the shared-lock was obtained
|
||||||
|
** on WAL_READ_LOCK(mxI) was obtained to account for the possibility
|
||||||
|
** that the log file may have been wrapped by a writer, or that frames
|
||||||
|
** that occur later in the log than pWal->hdr.mxFrame may have been
|
||||||
|
** copied into the database by a checkpointer. If either of these things
|
||||||
|
** happened, then reading the database with the current value of
|
||||||
|
** pWal->hdr.mxFrame risks reading a corrupted snapshot. So, retry
|
||||||
|
** instead.
|
||||||
|
**
|
||||||
|
** Before checking that the live wal-index header has not changed
|
||||||
|
** since it was read, set Wal.minFrame to the first frame in the wal
|
||||||
|
** file that has not yet been checkpointed. This client will not need
|
||||||
|
** to read any frames earlier than minFrame from the wal file - they
|
||||||
|
** can be safely read directly from the database file.
|
||||||
|
**
|
||||||
|
** Because a ShmBarrier() call is made between taking the copy of
|
||||||
|
** nBackfill and checking that the wal-header in shared-memory still
|
||||||
|
** matches the one cached in pWal->hdr, it is guaranteed that the
|
||||||
|
** checkpointer that set nBackfill was not working with a wal-index
|
||||||
|
** header newer than that cached in pWal->hdr. If it were, that could
|
||||||
|
** cause a problem. The checkpointer could omit to checkpoint
|
||||||
|
** a version of page X that lies before pWal->minFrame (call that version
|
||||||
|
** A) on the basis that there is a newer version (version B) of the same
|
||||||
|
** page later in the wal file. But if version B happens to like past
|
||||||
|
** frame pWal->hdr.mxFrame - then the client would incorrectly assume
|
||||||
|
** that it can read version A from the database file. However, since
|
||||||
|
** we can guarantee that the checkpointer that set nBackfill could not
|
||||||
|
** see any pages past pWal->hdr.mxFrame, this problem does not come up.
|
||||||
|
*/
|
||||||
|
pWal->minFrame = AtomicLoad(&pInfo->nBackfill)+1; SEH_INJECT_FAULT;
|
||||||
|
walShmBarrier(pWal);
|
||||||
|
if( AtomicLoad(pInfo->aReadMark+mxI)!=mxReadMark
|
||||||
|
|| memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr))
|
||||||
|
){
|
||||||
|
walUnlockShared(pWal, WAL_READ_LOCK(mxI));
|
||||||
|
return WAL_RETRY;
|
||||||
|
}else{
|
||||||
|
assert( mxReadMark<=pWal->hdr.mxFrame );
|
||||||
|
pWal->readLock = (i16)mxI;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user