Fossil SCM

Update the built-in SQLite to the third beta for 3.32.0.

drh 2020-05-19 16:51 trunk
Commit a8098efebfa81f25a7c634d6e9ce01210c770b7925b1441dc1385b5a469f9030
2 files changed +43 -34 +1 -1
+43 -34
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
11621162
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11631163
** [sqlite_version()] and [sqlite_source_id()].
11641164
*/
11651165
#define SQLITE_VERSION "3.32.0"
11661166
#define SQLITE_VERSION_NUMBER 3032000
1167
-#define SQLITE_SOURCE_ID "2020-05-17 13:47:28 69e149f76853d196c8855fedfc98848b60fb116ac36bc08824b1a122469f8ece"
1167
+#define SQLITE_SOURCE_ID "2020-05-19 15:51:10 3117c1b5a9e348fd8d16ba9d03fdafaad8514567fb3403f72b86d6162ad40bde"
11681168
11691169
/*
11701170
** CAPI3REF: Run-Time Library Version Numbers
11711171
** KEYWORDS: sqlite3_version sqlite3_sourceid
11721172
**
@@ -46821,11 +46821,13 @@
4682146821
pFile->pVfs = pVfs;
4682246822
pFile->h = h;
4682346823
if( isReadonly ){
4682446824
pFile->ctrlFlags |= WINFILE_RDONLY;
4682546825
}
46826
- if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
46826
+ if( (flags & SQLITE_OPEN_MAIN_DB)
46827
+ && sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE)
46828
+ ){
4682746829
pFile->ctrlFlags |= WINFILE_PSOW;
4682846830
}
4682946831
pFile->lastErrno = NO_ERROR;
4683046832
pFile->zPath = zName;
4683146833
#if SQLITE_MAX_MMAP_SIZE>0
@@ -59957,29 +59959,47 @@
5995759959
5995859960
aOut[0] = s1;
5995959961
aOut[1] = s2;
5996059962
}
5996159963
59964
+/*
59965
+** If there is the possibility of concurrent access to the SHM file
59966
+** from multiple threads and/or processes, then do a memory barrier.
59967
+*/
5996259968
static void walShmBarrier(Wal *pWal){
5996359969
if( pWal->exclusiveMode!=WAL_HEAPMEMORY_MODE ){
5996459970
sqlite3OsShmBarrier(pWal->pDbFd);
5996559971
}
5996659972
}
5996759973
59974
+/*
59975
+** Add the SQLITE_NO_TSAN as part of the return-type of a function
59976
+** definition as a hint that the function contains constructs that
59977
+** might give false-positive TSAN warnings.
59978
+**
59979
+** See tag-20200519-1.
59980
+*/
59981
+#if defined(__clang__) && !defined(SQLITE_NO_TSAN)
59982
+# define SQLITE_NO_TSAN __attribute__((no_sanitize_thread))
59983
+#else
59984
+# define SQLITE_NO_TSAN
59985
+#endif
59986
+
5996859987
/*
5996959988
** Write the header information in pWal->hdr into the wal-index.
5997059989
**
5997159990
** The checksum on pWal->hdr is updated before it is written.
5997259991
*/
59973
-static void walIndexWriteHdr(Wal *pWal){
59992
+static SQLITE_NO_TSAN void walIndexWriteHdr(Wal *pWal){
5997459993
volatile WalIndexHdr *aHdr = walIndexHdr(pWal);
5997559994
const int nCksum = offsetof(WalIndexHdr, aCksum);
5997659995
5997759996
assert( pWal->writeLock );
5997859997
pWal->hdr.isInit = 1;
5997959998
pWal->hdr.iVersion = WALINDEX_MAX_VERSION;
5998059999
walChecksumBytes(1, (u8*)&pWal->hdr, nCksum, 0, pWal->hdr.aCksum);
60000
+ /* Possible TSAN false-positive. See tag-20200519-1 */
5998160001
memcpy((void*)&aHdr[1], (const void*)&pWal->hdr, sizeof(WalIndexHdr));
5998260002
walShmBarrier(pWal);
5998360003
memcpy((void*)&aHdr[0], (const void*)&pWal->hdr, sizeof(WalIndexHdr));
5998460004
}
5998560005
@@ -61165,36 +61185,17 @@
6116561185
** cannot be backfilled from the WAL.
6116661186
*/
6116761187
mxSafeFrame = pWal->hdr.mxFrame;
6116861188
mxPage = pWal->hdr.nPage;
6116961189
for(i=1; i<WAL_NREADER; i++){
61170
- /* Thread-sanitizer reports that the following is an unsafe read,
61171
- ** as some other thread may be in the process of updating the value
61172
- ** of the aReadMark[] slot. The assumption here is that if that is
61173
- ** happening, the other client may only be increasing the value,
61174
- ** not decreasing it. So assuming either that either the "old" or
61175
- ** "new" version of the value is read, and not some arbitrary value
61176
- ** that would never be written by a real client, things are still
61177
- ** safe.
61178
- **
61179
- ** Astute readers have pointed out that the assumption stated in the
61180
- ** last sentence of the previous paragraph is not guaranteed to be
61181
- ** true for all conforming systems. However, the assumption is true
61182
- ** for all compilers and architectures in common use today (circa
61183
- ** 2019-11-27) and the alternatives are both slow and complex, and
61184
- ** so we will continue to go with the current design for now. If this
61185
- ** bothers you, or if you really are running on a system where aligned
61186
- ** 32-bit reads and writes are not atomic, then you can simply avoid
61187
- ** the use of WAL mode, or only use WAL mode together with
61188
- ** PRAGMA locking_mode=EXCLUSIVE and all will be well.
61189
- */
61190
- u32 y = pInfo->aReadMark[i];
61190
+ u32 y = AtomicLoad(pInfo->aReadMark+i);
6119161191
if( mxSafeFrame>y ){
6119261192
assert( y<=pWal->hdr.mxFrame );
6119361193
rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
6119461194
if( rc==SQLITE_OK ){
61195
- pInfo->aReadMark[i] = (i==1 ? mxSafeFrame : READMARK_NOT_USED);
61195
+ u32 iMark = (i==1 ? mxSafeFrame : READMARK_NOT_USED);
61196
+ AtomicStore(pInfo->aReadMark+i, iMark);
6119661197
walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
6119761198
}else if( rc==SQLITE_BUSY ){
6119861199
mxSafeFrame = y;
6119961200
xBusy = 0;
6120061201
}else{
@@ -61208,11 +61209,11 @@
6120861209
rc = walIteratorInit(pWal, pInfo->nBackfill, &pIter);
6120961210
assert( rc==SQLITE_OK || pIter==0 );
6121061211
}
6121161212
6121261213
if( pIter
61213
- && (rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(0),1))==SQLITE_OK
61214
+ && (rc = walBusyLock(pWal,xBusy,pBusyArg,WAL_READ_LOCK(0),1))==SQLITE_OK
6121461215
){
6121561216
u32 nBackfill = pInfo->nBackfill;
6121661217
6121761218
pInfo->nBackfillAttempted = mxSafeFrame;
6121861219
@@ -61423,11 +61424,11 @@
6142361424
** and *pChanged is set to 1.
6142461425
**
6142561426
** If the checksum cannot be verified return non-zero. If the header
6142661427
** is read successfully and the checksum verified, return zero.
6142761428
*/
61428
-static int walIndexTryHdr(Wal *pWal, int *pChanged){
61429
+static SQLITE_NO_TSAN int walIndexTryHdr(Wal *pWal, int *pChanged){
6142961430
u32 aCksum[2]; /* Checksum on the header content */
6143061431
WalIndexHdr h1, h2; /* Two copies of the header content */
6143161432
WalIndexHdr volatile *aHdr; /* Header in shared memory */
6143261433
6143361434
/* The first page of the wal-index must be mapped at this point. */
@@ -61436,17 +61437,23 @@
6143661437
/* Read the header. This might happen concurrently with a write to the
6143761438
** same area of shared memory on a different CPU in a SMP,
6143861439
** meaning it is possible that an inconsistent snapshot is read
6143961440
** from the file. If this happens, return non-zero.
6144061441
**
61442
+ ** tag-20200519-1:
6144161443
** There are two copies of the header at the beginning of the wal-index.
6144261444
** When reading, read [0] first then [1]. Writes are in the reverse order.
6144361445
** Memory barriers are used to prevent the compiler or the hardware from
61444
- ** reordering the reads and writes.
61446
+ ** reordering the reads and writes. TSAN and similar tools can sometimes
61447
+ ** give false-positive warnings about these accesses because the tools do not
61448
+ ** account for the double-read and the memory barrier. The use of mutexes
61449
+ ** here would be problematic as the memory being accessed is potentially
61450
+ ** shared among multiple processes and not all mutex implementions work
61451
+ ** reliably in that environment.
6144561452
*/
6144661453
aHdr = walIndexHdr(pWal);
61447
- memcpy(&h1, (void *)&aHdr[0], sizeof(h1));
61454
+ memcpy(&h1, (void *)&aHdr[0], sizeof(h1)); /* Possible TSAN false-positive */
6144861455
walShmBarrier(pWal);
6144961456
memcpy(&h2, (void *)&aHdr[1], sizeof(h2));
6145061457
6145161458
if( memcmp(&h1, &h2, sizeof(h1))!=0 ){
6145261459
return 1; /* Dirty read */
@@ -62283,26 +62290,28 @@
6228362290
for(iHash=walFramePage(iLast); iHash>=iMinHash; iHash--){
6228462291
WalHashLoc sLoc; /* Hash table location */
6228562292
int iKey; /* Hash slot index */
6228662293
int nCollide; /* Number of hash collisions remaining */
6228762294
int rc; /* Error code */
62295
+ u32 iH;
6228862296
6228962297
rc = walHashGet(pWal, iHash, &sLoc);
6229062298
if( rc!=SQLITE_OK ){
6229162299
return rc;
6229262300
}
6229362301
nCollide = HASHTABLE_NSLOT;
62294
- for(iKey=walHash(pgno); sLoc.aHash[iKey]; iKey=walNextHash(iKey)){
62295
- u32 iH = sLoc.aHash[iKey];
62302
+ iKey = walHash(pgno);
62303
+ while( (iH = AtomicLoad(&sLoc.aHash[iKey]))!=0 ){
6229662304
u32 iFrame = iH + sLoc.iZero;
6229762305
if( iFrame<=iLast && iFrame>=pWal->minFrame && sLoc.aPgno[iH]==pgno ){
6229862306
assert( iFrame>iRead || CORRUPT_DB );
6229962307
iRead = iFrame;
6230062308
}
6230162309
if( (nCollide--)==0 ){
6230262310
return SQLITE_CORRUPT_BKPT;
6230362311
}
62312
+ iKey = walNextHash(iKey);
6230462313
}
6230562314
if( iRead ) break;
6230662315
}
6230762316
6230862317
#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
@@ -224738,11 +224747,11 @@
224738224747
int nArg, /* Number of args */
224739224748
sqlite3_value **apUnused /* Function arguments */
224740224749
){
224741224750
assert( nArg==0 );
224742224751
UNUSED_PARAM2(nArg, apUnused);
224743
- sqlite3_result_text(pCtx, "fts5: 2020-05-17 00:26:44 1313557b512297e7b75ed748894379b2022aecf696d5a58318e46a668321c1ff", -1, SQLITE_TRANSIENT);
224752
+ sqlite3_result_text(pCtx, "fts5: 2020-05-19 15:51:10 3117c1b5a9e348fd8d16ba9d03fdafaad8514567fb3403f72b86d6162ad40bde", -1, SQLITE_TRANSIENT);
224744224753
}
224745224754
224746224755
/*
224747224756
** Return true if zName is the extension on one of the shadow tables used
224748224757
** by this module.
@@ -229521,12 +229530,12 @@
229521229530
}
229522229531
#endif /* SQLITE_CORE */
229523229532
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
229524229533
229525229534
/************** End of stmt.c ************************************************/
229526
-#if __LINE__!=229526
229535
+#if __LINE__!=229535
229527229536
#undef SQLITE_SOURCE_ID
229528
-#define SQLITE_SOURCE_ID "2020-05-17 13:47:28 69e149f76853d196c8855fedfc98848b60fb116ac36bc08824b1a122469falt2"
229537
+#define SQLITE_SOURCE_ID "2020-05-19 15:51:10 3117c1b5a9e348fd8d16ba9d03fdafaad8514567fb3403f72b86d6162ad4alt2"
229529229538
#endif
229530229539
/* Return the source-id for this library */
229531229540
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
229532229541
/************************** End of sqlite3.c ******************************/
229533229542
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.32.0"
1166 #define SQLITE_VERSION_NUMBER 3032000
1167 #define SQLITE_SOURCE_ID "2020-05-17 13:47:28 69e149f76853d196c8855fedfc98848b60fb116ac36bc08824b1a122469f8ece"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -46821,11 +46821,13 @@
46821 pFile->pVfs = pVfs;
46822 pFile->h = h;
46823 if( isReadonly ){
46824 pFile->ctrlFlags |= WINFILE_RDONLY;
46825 }
46826 if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
 
 
46827 pFile->ctrlFlags |= WINFILE_PSOW;
46828 }
46829 pFile->lastErrno = NO_ERROR;
46830 pFile->zPath = zName;
46831 #if SQLITE_MAX_MMAP_SIZE>0
@@ -59957,29 +59959,47 @@
59957
59958 aOut[0] = s1;
59959 aOut[1] = s2;
59960 }
59961
 
 
 
 
59962 static void walShmBarrier(Wal *pWal){
59963 if( pWal->exclusiveMode!=WAL_HEAPMEMORY_MODE ){
59964 sqlite3OsShmBarrier(pWal->pDbFd);
59965 }
59966 }
59967
 
 
 
 
 
 
 
 
 
 
 
 
 
59968 /*
59969 ** Write the header information in pWal->hdr into the wal-index.
59970 **
59971 ** The checksum on pWal->hdr is updated before it is written.
59972 */
59973 static void walIndexWriteHdr(Wal *pWal){
59974 volatile WalIndexHdr *aHdr = walIndexHdr(pWal);
59975 const int nCksum = offsetof(WalIndexHdr, aCksum);
59976
59977 assert( pWal->writeLock );
59978 pWal->hdr.isInit = 1;
59979 pWal->hdr.iVersion = WALINDEX_MAX_VERSION;
59980 walChecksumBytes(1, (u8*)&pWal->hdr, nCksum, 0, pWal->hdr.aCksum);
 
59981 memcpy((void*)&aHdr[1], (const void*)&pWal->hdr, sizeof(WalIndexHdr));
59982 walShmBarrier(pWal);
59983 memcpy((void*)&aHdr[0], (const void*)&pWal->hdr, sizeof(WalIndexHdr));
59984 }
59985
@@ -61165,36 +61185,17 @@
61165 ** cannot be backfilled from the WAL.
61166 */
61167 mxSafeFrame = pWal->hdr.mxFrame;
61168 mxPage = pWal->hdr.nPage;
61169 for(i=1; i<WAL_NREADER; i++){
61170 /* Thread-sanitizer reports that the following is an unsafe read,
61171 ** as some other thread may be in the process of updating the value
61172 ** of the aReadMark[] slot. The assumption here is that if that is
61173 ** happening, the other client may only be increasing the value,
61174 ** not decreasing it. So assuming either that either the "old" or
61175 ** "new" version of the value is read, and not some arbitrary value
61176 ** that would never be written by a real client, things are still
61177 ** safe.
61178 **
61179 ** Astute readers have pointed out that the assumption stated in the
61180 ** last sentence of the previous paragraph is not guaranteed to be
61181 ** true for all conforming systems. However, the assumption is true
61182 ** for all compilers and architectures in common use today (circa
61183 ** 2019-11-27) and the alternatives are both slow and complex, and
61184 ** so we will continue to go with the current design for now. If this
61185 ** bothers you, or if you really are running on a system where aligned
61186 ** 32-bit reads and writes are not atomic, then you can simply avoid
61187 ** the use of WAL mode, or only use WAL mode together with
61188 ** PRAGMA locking_mode=EXCLUSIVE and all will be well.
61189 */
61190 u32 y = pInfo->aReadMark[i];
61191 if( mxSafeFrame>y ){
61192 assert( y<=pWal->hdr.mxFrame );
61193 rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
61194 if( rc==SQLITE_OK ){
61195 pInfo->aReadMark[i] = (i==1 ? mxSafeFrame : READMARK_NOT_USED);
 
61196 walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
61197 }else if( rc==SQLITE_BUSY ){
61198 mxSafeFrame = y;
61199 xBusy = 0;
61200 }else{
@@ -61208,11 +61209,11 @@
61208 rc = walIteratorInit(pWal, pInfo->nBackfill, &pIter);
61209 assert( rc==SQLITE_OK || pIter==0 );
61210 }
61211
61212 if( pIter
61213 && (rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(0),1))==SQLITE_OK
61214 ){
61215 u32 nBackfill = pInfo->nBackfill;
61216
61217 pInfo->nBackfillAttempted = mxSafeFrame;
61218
@@ -61423,11 +61424,11 @@
61423 ** and *pChanged is set to 1.
61424 **
61425 ** If the checksum cannot be verified return non-zero. If the header
61426 ** is read successfully and the checksum verified, return zero.
61427 */
61428 static int walIndexTryHdr(Wal *pWal, int *pChanged){
61429 u32 aCksum[2]; /* Checksum on the header content */
61430 WalIndexHdr h1, h2; /* Two copies of the header content */
61431 WalIndexHdr volatile *aHdr; /* Header in shared memory */
61432
61433 /* The first page of the wal-index must be mapped at this point. */
@@ -61436,17 +61437,23 @@
61436 /* Read the header. This might happen concurrently with a write to the
61437 ** same area of shared memory on a different CPU in a SMP,
61438 ** meaning it is possible that an inconsistent snapshot is read
61439 ** from the file. If this happens, return non-zero.
61440 **
 
61441 ** There are two copies of the header at the beginning of the wal-index.
61442 ** When reading, read [0] first then [1]. Writes are in the reverse order.
61443 ** Memory barriers are used to prevent the compiler or the hardware from
61444 ** reordering the reads and writes.
 
 
 
 
 
61445 */
61446 aHdr = walIndexHdr(pWal);
61447 memcpy(&h1, (void *)&aHdr[0], sizeof(h1));
61448 walShmBarrier(pWal);
61449 memcpy(&h2, (void *)&aHdr[1], sizeof(h2));
61450
61451 if( memcmp(&h1, &h2, sizeof(h1))!=0 ){
61452 return 1; /* Dirty read */
@@ -62283,26 +62290,28 @@
62283 for(iHash=walFramePage(iLast); iHash>=iMinHash; iHash--){
62284 WalHashLoc sLoc; /* Hash table location */
62285 int iKey; /* Hash slot index */
62286 int nCollide; /* Number of hash collisions remaining */
62287 int rc; /* Error code */
 
62288
62289 rc = walHashGet(pWal, iHash, &sLoc);
62290 if( rc!=SQLITE_OK ){
62291 return rc;
62292 }
62293 nCollide = HASHTABLE_NSLOT;
62294 for(iKey=walHash(pgno); sLoc.aHash[iKey]; iKey=walNextHash(iKey)){
62295 u32 iH = sLoc.aHash[iKey];
62296 u32 iFrame = iH + sLoc.iZero;
62297 if( iFrame<=iLast && iFrame>=pWal->minFrame && sLoc.aPgno[iH]==pgno ){
62298 assert( iFrame>iRead || CORRUPT_DB );
62299 iRead = iFrame;
62300 }
62301 if( (nCollide--)==0 ){
62302 return SQLITE_CORRUPT_BKPT;
62303 }
 
62304 }
62305 if( iRead ) break;
62306 }
62307
62308 #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
@@ -224738,11 +224747,11 @@
224738 int nArg, /* Number of args */
224739 sqlite3_value **apUnused /* Function arguments */
224740 ){
224741 assert( nArg==0 );
224742 UNUSED_PARAM2(nArg, apUnused);
224743 sqlite3_result_text(pCtx, "fts5: 2020-05-17 00:26:44 1313557b512297e7b75ed748894379b2022aecf696d5a58318e46a668321c1ff", -1, SQLITE_TRANSIENT);
224744 }
224745
224746 /*
224747 ** Return true if zName is the extension on one of the shadow tables used
224748 ** by this module.
@@ -229521,12 +229530,12 @@
229521 }
229522 #endif /* SQLITE_CORE */
229523 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
229524
229525 /************** End of stmt.c ************************************************/
229526 #if __LINE__!=229526
229527 #undef SQLITE_SOURCE_ID
229528 #define SQLITE_SOURCE_ID "2020-05-17 13:47:28 69e149f76853d196c8855fedfc98848b60fb116ac36bc08824b1a122469falt2"
229529 #endif
229530 /* Return the source-id for this library */
229531 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
229532 /************************** End of sqlite3.c ******************************/
229533
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.32.0"
1166 #define SQLITE_VERSION_NUMBER 3032000
1167 #define SQLITE_SOURCE_ID "2020-05-19 15:51:10 3117c1b5a9e348fd8d16ba9d03fdafaad8514567fb3403f72b86d6162ad40bde"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -46821,11 +46821,13 @@
46821 pFile->pVfs = pVfs;
46822 pFile->h = h;
46823 if( isReadonly ){
46824 pFile->ctrlFlags |= WINFILE_RDONLY;
46825 }
46826 if( (flags & SQLITE_OPEN_MAIN_DB)
46827 && sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE)
46828 ){
46829 pFile->ctrlFlags |= WINFILE_PSOW;
46830 }
46831 pFile->lastErrno = NO_ERROR;
46832 pFile->zPath = zName;
46833 #if SQLITE_MAX_MMAP_SIZE>0
@@ -59957,29 +59959,47 @@
59959
59960 aOut[0] = s1;
59961 aOut[1] = s2;
59962 }
59963
59964 /*
59965 ** If there is the possibility of concurrent access to the SHM file
59966 ** from multiple threads and/or processes, then do a memory barrier.
59967 */
59968 static void walShmBarrier(Wal *pWal){
59969 if( pWal->exclusiveMode!=WAL_HEAPMEMORY_MODE ){
59970 sqlite3OsShmBarrier(pWal->pDbFd);
59971 }
59972 }
59973
59974 /*
59975 ** Add the SQLITE_NO_TSAN as part of the return-type of a function
59976 ** definition as a hint that the function contains constructs that
59977 ** might give false-positive TSAN warnings.
59978 **
59979 ** See tag-20200519-1.
59980 */
59981 #if defined(__clang__) && !defined(SQLITE_NO_TSAN)
59982 # define SQLITE_NO_TSAN __attribute__((no_sanitize_thread))
59983 #else
59984 # define SQLITE_NO_TSAN
59985 #endif
59986
59987 /*
59988 ** Write the header information in pWal->hdr into the wal-index.
59989 **
59990 ** The checksum on pWal->hdr is updated before it is written.
59991 */
59992 static SQLITE_NO_TSAN void walIndexWriteHdr(Wal *pWal){
59993 volatile WalIndexHdr *aHdr = walIndexHdr(pWal);
59994 const int nCksum = offsetof(WalIndexHdr, aCksum);
59995
59996 assert( pWal->writeLock );
59997 pWal->hdr.isInit = 1;
59998 pWal->hdr.iVersion = WALINDEX_MAX_VERSION;
59999 walChecksumBytes(1, (u8*)&pWal->hdr, nCksum, 0, pWal->hdr.aCksum);
60000 /* Possible TSAN false-positive. See tag-20200519-1 */
60001 memcpy((void*)&aHdr[1], (const void*)&pWal->hdr, sizeof(WalIndexHdr));
60002 walShmBarrier(pWal);
60003 memcpy((void*)&aHdr[0], (const void*)&pWal->hdr, sizeof(WalIndexHdr));
60004 }
60005
@@ -61165,36 +61185,17 @@
61185 ** cannot be backfilled from the WAL.
61186 */
61187 mxSafeFrame = pWal->hdr.mxFrame;
61188 mxPage = pWal->hdr.nPage;
61189 for(i=1; i<WAL_NREADER; i++){
61190 u32 y = AtomicLoad(pInfo->aReadMark+i);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61191 if( mxSafeFrame>y ){
61192 assert( y<=pWal->hdr.mxFrame );
61193 rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
61194 if( rc==SQLITE_OK ){
61195 u32 iMark = (i==1 ? mxSafeFrame : READMARK_NOT_USED);
61196 AtomicStore(pInfo->aReadMark+i, iMark);
61197 walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
61198 }else if( rc==SQLITE_BUSY ){
61199 mxSafeFrame = y;
61200 xBusy = 0;
61201 }else{
@@ -61208,11 +61209,11 @@
61209 rc = walIteratorInit(pWal, pInfo->nBackfill, &pIter);
61210 assert( rc==SQLITE_OK || pIter==0 );
61211 }
61212
61213 if( pIter
61214 && (rc = walBusyLock(pWal,xBusy,pBusyArg,WAL_READ_LOCK(0),1))==SQLITE_OK
61215 ){
61216 u32 nBackfill = pInfo->nBackfill;
61217
61218 pInfo->nBackfillAttempted = mxSafeFrame;
61219
@@ -61423,11 +61424,11 @@
61424 ** and *pChanged is set to 1.
61425 **
61426 ** If the checksum cannot be verified return non-zero. If the header
61427 ** is read successfully and the checksum verified, return zero.
61428 */
61429 static SQLITE_NO_TSAN int walIndexTryHdr(Wal *pWal, int *pChanged){
61430 u32 aCksum[2]; /* Checksum on the header content */
61431 WalIndexHdr h1, h2; /* Two copies of the header content */
61432 WalIndexHdr volatile *aHdr; /* Header in shared memory */
61433
61434 /* The first page of the wal-index must be mapped at this point. */
@@ -61436,17 +61437,23 @@
61437 /* Read the header. This might happen concurrently with a write to the
61438 ** same area of shared memory on a different CPU in a SMP,
61439 ** meaning it is possible that an inconsistent snapshot is read
61440 ** from the file. If this happens, return non-zero.
61441 **
61442 ** tag-20200519-1:
61443 ** There are two copies of the header at the beginning of the wal-index.
61444 ** When reading, read [0] first then [1]. Writes are in the reverse order.
61445 ** Memory barriers are used to prevent the compiler or the hardware from
61446 ** reordering the reads and writes. TSAN and similar tools can sometimes
61447 ** give false-positive warnings about these accesses because the tools do not
61448 ** account for the double-read and the memory barrier. The use of mutexes
61449 ** here would be problematic as the memory being accessed is potentially
61450 ** shared among multiple processes and not all mutex implementions work
61451 ** reliably in that environment.
61452 */
61453 aHdr = walIndexHdr(pWal);
61454 memcpy(&h1, (void *)&aHdr[0], sizeof(h1)); /* Possible TSAN false-positive */
61455 walShmBarrier(pWal);
61456 memcpy(&h2, (void *)&aHdr[1], sizeof(h2));
61457
61458 if( memcmp(&h1, &h2, sizeof(h1))!=0 ){
61459 return 1; /* Dirty read */
@@ -62283,26 +62290,28 @@
62290 for(iHash=walFramePage(iLast); iHash>=iMinHash; iHash--){
62291 WalHashLoc sLoc; /* Hash table location */
62292 int iKey; /* Hash slot index */
62293 int nCollide; /* Number of hash collisions remaining */
62294 int rc; /* Error code */
62295 u32 iH;
62296
62297 rc = walHashGet(pWal, iHash, &sLoc);
62298 if( rc!=SQLITE_OK ){
62299 return rc;
62300 }
62301 nCollide = HASHTABLE_NSLOT;
62302 iKey = walHash(pgno);
62303 while( (iH = AtomicLoad(&sLoc.aHash[iKey]))!=0 ){
62304 u32 iFrame = iH + sLoc.iZero;
62305 if( iFrame<=iLast && iFrame>=pWal->minFrame && sLoc.aPgno[iH]==pgno ){
62306 assert( iFrame>iRead || CORRUPT_DB );
62307 iRead = iFrame;
62308 }
62309 if( (nCollide--)==0 ){
62310 return SQLITE_CORRUPT_BKPT;
62311 }
62312 iKey = walNextHash(iKey);
62313 }
62314 if( iRead ) break;
62315 }
62316
62317 #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
@@ -224738,11 +224747,11 @@
224747 int nArg, /* Number of args */
224748 sqlite3_value **apUnused /* Function arguments */
224749 ){
224750 assert( nArg==0 );
224751 UNUSED_PARAM2(nArg, apUnused);
224752 sqlite3_result_text(pCtx, "fts5: 2020-05-19 15:51:10 3117c1b5a9e348fd8d16ba9d03fdafaad8514567fb3403f72b86d6162ad40bde", -1, SQLITE_TRANSIENT);
224753 }
224754
224755 /*
224756 ** Return true if zName is the extension on one of the shadow tables used
224757 ** by this module.
@@ -229521,12 +229530,12 @@
229530 }
229531 #endif /* SQLITE_CORE */
229532 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
229533
229534 /************** End of stmt.c ************************************************/
229535 #if __LINE__!=229535
229536 #undef SQLITE_SOURCE_ID
229537 #define SQLITE_SOURCE_ID "2020-05-19 15:51:10 3117c1b5a9e348fd8d16ba9d03fdafaad8514567fb3403f72b86d6162ad4alt2"
229538 #endif
229539 /* Return the source-id for this library */
229540 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
229541 /************************** End of sqlite3.c ******************************/
229542
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.32.0"
127127
#define SQLITE_VERSION_NUMBER 3032000
128
-#define SQLITE_SOURCE_ID "2020-05-17 13:47:28 69e149f76853d196c8855fedfc98848b60fb116ac36bc08824b1a122469f8ece"
128
+#define SQLITE_SOURCE_ID "2020-05-19 15:51:10 3117c1b5a9e348fd8d16ba9d03fdafaad8514567fb3403f72b86d6162ad40bde"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
134134
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.32.0"
127 #define SQLITE_VERSION_NUMBER 3032000
128 #define SQLITE_SOURCE_ID "2020-05-17 13:47:28 69e149f76853d196c8855fedfc98848b60fb116ac36bc08824b1a122469f8ece"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
134
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.32.0"
127 #define SQLITE_VERSION_NUMBER 3032000
128 #define SQLITE_SOURCE_ID "2020-05-19 15:51:10 3117c1b5a9e348fd8d16ba9d03fdafaad8514567fb3403f72b86d6162ad40bde"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
134

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button