Fossil SCM
Update to the latest SQLite with the new WAL file format containing version numbers.
Commit
e0bdd5afce4400944950e59f936d73b6d18efffa
Parent
34178e2771d036b…
2 files changed
+117
-40
+1
-1
+117
-40
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -636,11 +636,11 @@ | ||
| 636 | 636 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 637 | 637 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 638 | 638 | */ |
| 639 | 639 | #define SQLITE_VERSION "3.7.0" |
| 640 | 640 | #define SQLITE_VERSION_NUMBER 3007000 |
| 641 | -#define SQLITE_SOURCE_ID "2010-06-23 15:18:12 51ef43b9f7db8fabf73d9c8a76dae6c275e50d58" | |
| 641 | +#define SQLITE_SOURCE_ID "2010-06-24 10:50:18 7aac9ad6dd14b1c56eb8e4750ac769c6197c30bd" | |
| 642 | 642 | |
| 643 | 643 | /* |
| 644 | 644 | ** CAPI3REF: Run-Time Library Version Numbers |
| 645 | 645 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 646 | 646 | ** |
| @@ -25586,11 +25586,11 @@ | ||
| 25586 | 25586 | }; |
| 25587 | 25587 | |
| 25588 | 25588 | /* |
| 25589 | 25589 | ** Constants used for locking |
| 25590 | 25590 | */ |
| 25591 | -#define UNIX_SHM_BASE ((18+SQLITE_SHM_NLOCK)*4) /* first lock byte */ | |
| 25591 | +#define UNIX_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */ | |
| 25592 | 25592 | #define UNIX_SHM_DMS (UNIX_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */ |
| 25593 | 25593 | |
| 25594 | 25594 | /* |
| 25595 | 25595 | ** Apply posix advisory locks for all bytes from ofst through ofst+n-1. |
| 25596 | 25596 | ** |
| @@ -30017,11 +30017,11 @@ | ||
| 30017 | 30017 | }; |
| 30018 | 30018 | |
| 30019 | 30019 | /* |
| 30020 | 30020 | ** Constants used for locking |
| 30021 | 30021 | */ |
| 30022 | -#define WIN_SHM_BASE ((18+SQLITE_SHM_NLOCK)*4) /* first lock byte */ | |
| 30022 | +#define WIN_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */ | |
| 30023 | 30023 | #define WIN_SHM_DMS (WIN_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */ |
| 30024 | 30024 | |
| 30025 | 30025 | /* |
| 30026 | 30026 | ** Apply advisory locks for all n bytes beginning at ofst. |
| 30027 | 30027 | */ |
| @@ -34840,11 +34840,11 @@ | ||
| 34840 | 34840 | ** structure, the second the error-code about to be returned by a pager |
| 34841 | 34841 | ** API function. The value returned is a copy of the second argument |
| 34842 | 34842 | ** to this function. |
| 34843 | 34843 | ** |
| 34844 | 34844 | ** If the second argument is SQLITE_IOERR, SQLITE_CORRUPT, or SQLITE_FULL |
| 34845 | -** the error becomes persistent. Until the persisten error is cleared, | |
| 34845 | +** the error becomes persistent. Until the persistent error is cleared, | |
| 34846 | 34846 | ** subsequent API calls on this Pager will immediately return the same |
| 34847 | 34847 | ** error code. |
| 34848 | 34848 | ** |
| 34849 | 34849 | ** A persistent error indicates that the contents of the pager-cache |
| 34850 | 34850 | ** cannot be trusted. This state can be cleared by completely discarding |
| @@ -37092,13 +37092,11 @@ | ||
| 37092 | 37092 | ** reusing pPg. |
| 37093 | 37093 | ** |
| 37094 | 37094 | ** Similarly, if the pager has already entered the error state, do not |
| 37095 | 37095 | ** try to write the contents of pPg to disk. |
| 37096 | 37096 | */ |
| 37097 | - if( NEVER(pPager->errCode) | |
| 37098 | - || (pPager->doNotSync && pPg->flags&PGHDR_NEED_SYNC) | |
| 37099 | - ){ | |
| 37097 | + if( pPager->errCode || (pPager->doNotSync && pPg->flags&PGHDR_NEED_SYNC) ){ | |
| 37100 | 37098 | return SQLITE_OK; |
| 37101 | 37099 | } |
| 37102 | 37100 | |
| 37103 | 37101 | /* Sync the journal file if required. */ |
| 37104 | 37102 | if( pPg->flags&PGHDR_NEED_SYNC ){ |
| @@ -38649,11 +38647,11 @@ | ||
| 38649 | 38647 | |
| 38650 | 38648 | /* The dbOrigSize is never set if journal_mode=OFF */ |
| 38651 | 38649 | assert( pPager->journalMode!=PAGER_JOURNALMODE_OFF || pPager->dbOrigSize==0 ); |
| 38652 | 38650 | |
| 38653 | 38651 | /* If a prior error occurred, report that error again. */ |
| 38654 | - if( NEVER(pPager->errCode) ) return pPager->errCode; | |
| 38652 | + if( pPager->errCode ) return pPager->errCode; | |
| 38655 | 38653 | |
| 38656 | 38654 | PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n", |
| 38657 | 38655 | pPager->zFilename, zMaster, pPager->dbSize)); |
| 38658 | 38656 | |
| 38659 | 38657 | if( MEMDB && pPager->dbModified ){ |
| @@ -38879,11 +38877,11 @@ | ||
| 38879 | 38877 | ** performed. If successful, task (2). Regardless of the outcome |
| 38880 | 38878 | ** of either, the error state error code is returned to the caller |
| 38881 | 38879 | ** (i.e. either SQLITE_IOERR or SQLITE_CORRUPT). |
| 38882 | 38880 | ** |
| 38883 | 38881 | ** * If the pager is in PAGER_RESERVED state, then attempt (1). Whether |
| 38884 | -** or not (1) is succussful, also attempt (2). If successful, return | |
| 38882 | +** or not (1) is successful, also attempt (2). If successful, return | |
| 38885 | 38883 | ** SQLITE_OK. Otherwise, enter the error state and return the first |
| 38886 | 38884 | ** error code encountered. |
| 38887 | 38885 | ** |
| 38888 | 38886 | ** In this case there is no chance that the database was written to. |
| 38889 | 38887 | ** So is safe to finalize the journal file even if the playback |
| @@ -39708,23 +39706,25 @@ | ||
| 39708 | 39706 | ** frames can overwrite the old ones. A WAL always grows from beginning |
| 39709 | 39707 | ** toward the end. Checksums and counters attached to each frame are |
| 39710 | 39708 | ** used to determine which frames within the WAL are valid and which |
| 39711 | 39709 | ** are leftovers from prior checkpoints. |
| 39712 | 39710 | ** |
| 39713 | -** The WAL header is 24 bytes in size and consists of the following six | |
| 39711 | +** The WAL header is 32 bytes in size and consists of the following eight | |
| 39714 | 39712 | ** big-endian 32-bit unsigned integer values: |
| 39715 | 39713 | ** |
| 39716 | 39714 | ** 0: Magic number. 0x377f0682 or 0x377f0683 |
| 39717 | 39715 | ** 4: File format version. Currently 3007000 |
| 39718 | 39716 | ** 8: Database page size. Example: 1024 |
| 39719 | 39717 | ** 12: Checkpoint sequence number |
| 39720 | 39718 | ** 16: Salt-1, random integer incremented with each checkpoint |
| 39721 | 39719 | ** 20: Salt-2, a different random integer changing with each ckpt |
| 39720 | +** 24: Checksum-1 (first part of checksum for first 24 bytes of header). | |
| 39721 | +** 28: Checksum-2 (second part of checksum for first 24 bytes of header). | |
| 39722 | 39722 | ** |
| 39723 | 39723 | ** Immediately following the wal-header are zero or more frames. Each |
| 39724 | 39724 | ** frame consists of a 24-byte frame-header followed by a <page-size> bytes |
| 39725 | -** of page data. The frame-header is broken into 6 big-endian 32-bit unsigned | |
| 39725 | +** of page data. The frame-header is six big-endian 32-bit unsigned | |
| 39726 | 39726 | ** integer values, as follows: |
| 39727 | 39727 | ** |
| 39728 | 39728 | ** 0: Page number. |
| 39729 | 39729 | ** 4: For commit records, the size of the database image in pages |
| 39730 | 39730 | ** after the commit. For all other records, zero. |
| @@ -39755,10 +39755,15 @@ | ||
| 39755 | 39755 | ** |
| 39756 | 39756 | ** for i from 0 to n-1 step 2: |
| 39757 | 39757 | ** s0 += x[i] + s1; |
| 39758 | 39758 | ** s1 += x[i+1] + s0; |
| 39759 | 39759 | ** endfor |
| 39760 | +** | |
| 39761 | +** Note that s0 and s1 are both weighted checksums using fibonacci weights | |
| 39762 | +** in reverse order (the largest fibonacci weight occurs on the first element | |
| 39763 | +** of the sequence being summed.) The s1 value spans all 32-bit | |
| 39764 | +** terms of the sequence whereas s0 omits the final term. | |
| 39760 | 39765 | ** |
| 39761 | 39766 | ** On a checkpoint, the WAL is first VFS.xSync-ed, then valid content of the |
| 39762 | 39767 | ** WAL is transferred into the database, then the database is VFS.xSync-ed. |
| 39763 | 39768 | ** The VFS.xSync operations serve as write barriers - all writes launched |
| 39764 | 39769 | ** before the xSync must complete before any write that launches after the |
| @@ -39922,10 +39927,25 @@ | ||
| 39922 | 39927 | # define WALTRACE(X) if(sqlite3WalTrace) sqlite3DebugPrintf X |
| 39923 | 39928 | #else |
| 39924 | 39929 | # define WALTRACE(X) |
| 39925 | 39930 | #endif |
| 39926 | 39931 | |
| 39932 | +/* | |
| 39933 | +** The maximum (and only) versions of the wal and wal-index formats | |
| 39934 | +** that may be interpreted by this version of SQLite. | |
| 39935 | +** | |
| 39936 | +** If a client begins recovering a WAL file and finds that (a) the checksum | |
| 39937 | +** values in the wal-header are correct and (b) the version field is not | |
| 39938 | +** WAL_MAX_VERSION, recovery fails and SQLite returns SQLITE_CANTOPEN. | |
| 39939 | +** | |
| 39940 | +** Similarly, if a client successfully reads a wal-index header (i.e. the | |
| 39941 | +** checksum test is successful) and finds that the version field is not | |
| 39942 | +** WALINDEX_MAX_VERSION, then no read-transaction is opened and SQLite | |
| 39943 | +** returns SQLITE_CANTOPEN. | |
| 39944 | +*/ | |
| 39945 | +#define WAL_MAX_VERSION 3007000 | |
| 39946 | +#define WALINDEX_MAX_VERSION 3007000 | |
| 39927 | 39947 | |
| 39928 | 39948 | /* |
| 39929 | 39949 | ** Indices of various locking bytes. WAL_NREADER is the number |
| 39930 | 39950 | ** of available reader locks and should be at least 3. |
| 39931 | 39951 | */ |
| @@ -39948,10 +39968,12 @@ | ||
| 39948 | 39968 | ** |
| 39949 | 39969 | ** The actual header in the wal-index consists of two copies of this |
| 39950 | 39970 | ** object. |
| 39951 | 39971 | */ |
| 39952 | 39972 | struct WalIndexHdr { |
| 39973 | + u32 iVersion; /* Wal-index version */ | |
| 39974 | + u32 unused; /* Unused (padding) field */ | |
| 39953 | 39975 | u32 iChange; /* Counter incremented each transaction */ |
| 39954 | 39976 | u8 isInit; /* 1 when initialized */ |
| 39955 | 39977 | u8 bigEndCksum; /* True if checksums in WAL are big-endian */ |
| 39956 | 39978 | u16 szPage; /* Database page size in bytes */ |
| 39957 | 39979 | u32 mxFrame; /* Index of last valid frame in the WAL */ |
| @@ -40027,12 +40049,13 @@ | ||
| 40027 | 40049 | #define WALINDEX_HDR_SIZE (WALINDEX_LOCK_OFFSET+WALINDEX_LOCK_RESERVED) |
| 40028 | 40050 | |
| 40029 | 40051 | /* Size of header before each frame in wal */ |
| 40030 | 40052 | #define WAL_FRAME_HDRSIZE 24 |
| 40031 | 40053 | |
| 40032 | -/* Size of write ahead log header */ | |
| 40033 | -#define WAL_HDRSIZE 24 | |
| 40054 | +/* Size of write ahead log header, including checksum. */ | |
| 40055 | +/* #define WAL_HDRSIZE 24 */ | |
| 40056 | +#define WAL_HDRSIZE 32 | |
| 40034 | 40057 | |
| 40035 | 40058 | /* WAL magic value. Either this value, or the same value with the least |
| 40036 | 40059 | ** significant bit also set (WAL_MAGIC | 0x00000001) is stored in 32-bit |
| 40037 | 40060 | ** big-endian format in the first 4 bytes of a WAL file. |
| 40038 | 40061 | ** |
| @@ -40256,10 +40279,11 @@ | ||
| 40256 | 40279 | volatile WalIndexHdr *aHdr = walIndexHdr(pWal); |
| 40257 | 40280 | const int nCksum = offsetof(WalIndexHdr, aCksum); |
| 40258 | 40281 | |
| 40259 | 40282 | assert( pWal->writeLock ); |
| 40260 | 40283 | pWal->hdr.isInit = 1; |
| 40284 | + pWal->hdr.iVersion = WALINDEX_MAX_VERSION; | |
| 40261 | 40285 | walChecksumBytes(1, (u8*)&pWal->hdr, nCksum, 0, pWal->hdr.aCksum); |
| 40262 | 40286 | memcpy((void *)&aHdr[1], (void *)&pWal->hdr, sizeof(WalIndexHdr)); |
| 40263 | 40287 | sqlite3OsShmBarrier(pWal->pDbFd); |
| 40264 | 40288 | memcpy((void *)&aHdr[0], (void *)&pWal->hdr, sizeof(WalIndexHdr)); |
| 40265 | 40289 | } |
| @@ -40705,10 +40729,11 @@ | ||
| 40705 | 40729 | u8 *aData; /* Pointer to data part of aFrame buffer */ |
| 40706 | 40730 | int iFrame; /* Index of last frame read */ |
| 40707 | 40731 | i64 iOffset; /* Next offset to read from log file */ |
| 40708 | 40732 | int szPage; /* Page size according to the log */ |
| 40709 | 40733 | u32 magic; /* Magic value read from WAL header */ |
| 40734 | + u32 version; /* Magic value read from WAL header */ | |
| 40710 | 40735 | |
| 40711 | 40736 | /* Read in the WAL header. */ |
| 40712 | 40737 | rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0); |
| 40713 | 40738 | if( rc!=SQLITE_OK ){ |
| 40714 | 40739 | goto recovery_error; |
| @@ -40730,13 +40755,28 @@ | ||
| 40730 | 40755 | } |
| 40731 | 40756 | pWal->hdr.bigEndCksum = (magic&0x00000001); |
| 40732 | 40757 | pWal->szPage = szPage; |
| 40733 | 40758 | pWal->nCkpt = sqlite3Get4byte(&aBuf[12]); |
| 40734 | 40759 | memcpy(&pWal->hdr.aSalt, &aBuf[16], 8); |
| 40760 | + | |
| 40761 | + /* Verify that the WAL header checksum is correct */ | |
| 40735 | 40762 | walChecksumBytes(pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN, |
| 40736 | - aBuf, WAL_HDRSIZE, 0, pWal->hdr.aFrameCksum | |
| 40763 | + aBuf, WAL_HDRSIZE-2*4, 0, pWal->hdr.aFrameCksum | |
| 40737 | 40764 | ); |
| 40765 | + if( pWal->hdr.aFrameCksum[0]!=sqlite3Get4byte(&aBuf[24]) | |
| 40766 | + || pWal->hdr.aFrameCksum[1]!=sqlite3Get4byte(&aBuf[28]) | |
| 40767 | + ){ | |
| 40768 | + goto finished; | |
| 40769 | + } | |
| 40770 | + | |
| 40771 | + /* Verify that the version number on the WAL format is one that | |
| 40772 | + ** are able to understand */ | |
| 40773 | + version = sqlite3Get4byte(&aBuf[4]); | |
| 40774 | + if( version!=WAL_MAX_VERSION ){ | |
| 40775 | + rc = SQLITE_CANTOPEN_BKPT; | |
| 40776 | + goto finished; | |
| 40777 | + } | |
| 40738 | 40778 | |
| 40739 | 40779 | /* Malloc a buffer to read frames into. */ |
| 40740 | 40780 | szFrame = szPage + WAL_FRAME_HDRSIZE; |
| 40741 | 40781 | aFrame = (u8 *)sqlite3_malloc(szFrame); |
| 40742 | 40782 | if( !aFrame ){ |
| @@ -41297,30 +41337,24 @@ | ||
| 41297 | 41337 | return 0; |
| 41298 | 41338 | } |
| 41299 | 41339 | |
| 41300 | 41340 | /* |
| 41301 | 41341 | ** Read the wal-index header from the wal-index and into pWal->hdr. |
| 41302 | -** If the wal-header appears to be corrupt, try to recover the log | |
| 41303 | -** before returning. | |
| 41342 | +** If the wal-header appears to be corrupt, try to reconstruct the | |
| 41343 | +** wal-index from the WAL before returning. | |
| 41304 | 41344 | ** |
| 41305 | 41345 | ** Set *pChanged to 1 if the wal-index header value in pWal->hdr is |
| 41306 | 41346 | ** changed by this opertion. If pWal->hdr is unchanged, set *pChanged |
| 41307 | 41347 | ** to 0. |
| 41308 | 41348 | ** |
| 41309 | -** This routine also maps the wal-index content into memory and assigns | |
| 41310 | -** ownership of that mapping to the current thread. In some implementations, | |
| 41311 | -** only one thread at a time can hold a mapping of the wal-index. Hence, | |
| 41312 | -** the caller should strive to invoke walIndexUnmap() as soon as possible | |
| 41313 | -** after this routine returns. | |
| 41314 | -** | |
| 41315 | 41349 | ** If the wal-index header is successfully read, return SQLITE_OK. |
| 41316 | 41350 | ** Otherwise an SQLite error code. |
| 41317 | 41351 | */ |
| 41318 | 41352 | static int walIndexReadHdr(Wal *pWal, int *pChanged){ |
| 41319 | 41353 | int rc; /* Return code */ |
| 41320 | 41354 | int badHdr; /* True if a header read failed */ |
| 41321 | - volatile u32 *page0; | |
| 41355 | + volatile u32 *page0; /* Chunk of wal-index containing header */ | |
| 41322 | 41356 | |
| 41323 | 41357 | /* Ensure that page 0 of the wal-index (the page that contains the |
| 41324 | 41358 | ** wal-index header) is mapped. Return early if an error occurs here. |
| 41325 | 41359 | */ |
| 41326 | 41360 | assert( pChanged ); |
| @@ -41331,11 +41365,11 @@ | ||
| 41331 | 41365 | assert( page0 || pWal->writeLock==0 ); |
| 41332 | 41366 | |
| 41333 | 41367 | /* If the first page of the wal-index has been mapped, try to read the |
| 41334 | 41368 | ** wal-index header immediately, without holding any lock. This usually |
| 41335 | 41369 | ** works, but may fail if the wal-index header is corrupt or currently |
| 41336 | - ** being modified by another user. | |
| 41370 | + ** being modified by another thread or process. | |
| 41337 | 41371 | */ |
| 41338 | 41372 | badHdr = (page0 ? walIndexTryHdr(pWal, pChanged) : 1); |
| 41339 | 41373 | |
| 41340 | 41374 | /* If the first attempt failed, it might have been due to a race |
| 41341 | 41375 | ** with a writer. So get a WRITE lock and try again. |
| @@ -41355,10 +41389,18 @@ | ||
| 41355 | 41389 | } |
| 41356 | 41390 | } |
| 41357 | 41391 | pWal->writeLock = 0; |
| 41358 | 41392 | walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1); |
| 41359 | 41393 | } |
| 41394 | + | |
| 41395 | + /* If the header is read successfully, check the version number to make | |
| 41396 | + ** sure the wal-index was not constructed with some future format that | |
| 41397 | + ** this version of SQLite cannot understand. | |
| 41398 | + */ | |
| 41399 | + if( badHdr==0 && pWal->hdr.iVersion!=WALINDEX_MAX_VERSION ){ | |
| 41400 | + rc = SQLITE_CANTOPEN_BKPT; | |
| 41401 | + } | |
| 41360 | 41402 | |
| 41361 | 41403 | return rc; |
| 41362 | 41404 | } |
| 41363 | 41405 | |
| 41364 | 41406 | /* |
| @@ -41370,13 +41412,33 @@ | ||
| 41370 | 41412 | /* |
| 41371 | 41413 | ** Attempt to start a read transaction. This might fail due to a race or |
| 41372 | 41414 | ** other transient condition. When that happens, it returns WAL_RETRY to |
| 41373 | 41415 | ** indicate to the caller that it is safe to retry immediately. |
| 41374 | 41416 | ** |
| 41375 | -** On success return SQLITE_OK. On a permantent failure (such an | |
| 41417 | +** On success return SQLITE_OK. On a permanent failure (such an | |
| 41376 | 41418 | ** I/O error or an SQLITE_BUSY because another process is running |
| 41377 | 41419 | ** recovery) return a positive error code. |
| 41420 | +** | |
| 41421 | +** The useWal parameter is true to force the use of the WAL and disable | |
| 41422 | +** the case where the WAL is bypassed because it has been completely | |
| 41423 | +** checkpointed. If useWal==0 then this routine calls walIndexReadHdr() | |
| 41424 | +** to make a copy of the wal-index header into pWal->hdr. If the | |
| 41425 | +** wal-index header has changed, *pChanged is set to 1 (as an indication | |
| 41426 | +** to the caller that the local paget cache is obsolete and needs to be | |
| 41427 | +** flushed.) When useWal==1, the wal-index header is assumed to already | |
| 41428 | +** be loaded and the pChanged parameter is unused. | |
| 41429 | +** | |
| 41430 | +** The caller must set the cnt parameter to the number of prior calls to | |
| 41431 | +** this routine during the current read attempt that returned WAL_RETRY. | |
| 41432 | +** This routine will start taking more aggressive measures to clear the | |
| 41433 | +** race conditions after multiple WAL_RETRY returns, and after an excessive | |
| 41434 | +** number of errors will ultimately return SQLITE_PROTOCOL. The | |
| 41435 | +** SQLITE_PROTOCOL return indicates that some other process has gone rogue | |
| 41436 | +** and is not honoring the locking protocol. There is a vanishingly small | |
| 41437 | +** chance that SQLITE_PROTOCOL could be returned because of a run of really | |
| 41438 | +** bad luck when there is lots of contention for the wal-index, but that | |
| 41439 | +** possibility is so small that it can be safely neglected, we believe. | |
| 41378 | 41440 | ** |
| 41379 | 41441 | ** On success, this routine obtains a read lock on |
| 41380 | 41442 | ** WAL_READ_LOCK(pWal->readLock). The pWal->readLock integer is |
| 41381 | 41443 | ** in the range 0 <= pWal->readLock < WAL_NREADER. If pWal->readLock==(-1) |
| 41382 | 41444 | ** that means the Wal does not hold any read lock. The reader must not |
| @@ -41383,10 +41445,12 @@ | ||
| 41383 | 41445 | ** access any database page that is modified by a WAL frame up to and |
| 41384 | 41446 | ** including frame number aReadMark[pWal->readLock]. The reader will |
| 41385 | 41447 | ** use WAL frames up to and including pWal->hdr.mxFrame if pWal->readLock>0 |
| 41386 | 41448 | ** Or if pWal->readLock==0, then the reader will ignore the WAL |
| 41387 | 41449 | ** completely and get all content directly from the database file. |
| 41450 | +** If the useWal parameter is 1 then the WAL will never be ignored and | |
| 41451 | +** this routine will always set pWal->readLock>0 on success. | |
| 41388 | 41452 | ** When the read transaction is completed, the caller must release the |
| 41389 | 41453 | ** lock on WAL_READ_LOCK(pWal->readLock) and set pWal->readLock to -1. |
| 41390 | 41454 | ** |
| 41391 | 41455 | ** This routine uses the nBackfill and aReadMark[] fields of the header |
| 41392 | 41456 | ** to select a particular WAL_READ_LOCK() that strives to let the |
| @@ -41427,13 +41491,13 @@ | ||
| 41427 | 41491 | rc = WAL_RETRY; |
| 41428 | 41492 | }else if( rc==SQLITE_BUSY ){ |
| 41429 | 41493 | rc = SQLITE_BUSY_RECOVERY; |
| 41430 | 41494 | } |
| 41431 | 41495 | } |
| 41432 | - } | |
| 41433 | - if( rc!=SQLITE_OK ){ | |
| 41434 | - return rc; | |
| 41496 | + if( rc!=SQLITE_OK ){ | |
| 41497 | + return rc; | |
| 41498 | + } | |
| 41435 | 41499 | } |
| 41436 | 41500 | |
| 41437 | 41501 | pInfo = walCkptInfo(pWal); |
| 41438 | 41502 | if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame ){ |
| 41439 | 41503 | /* The WAL has been completely backfilled (or it is empty). |
| @@ -41605,13 +41669,13 @@ | ||
| 41605 | 41669 | /* This routine is only be called from within a read transaction. */ |
| 41606 | 41670 | assert( pWal->readLock>=0 || pWal->lockError ); |
| 41607 | 41671 | |
| 41608 | 41672 | /* If the "last page" field of the wal-index header snapshot is 0, then |
| 41609 | 41673 | ** no data will be read from the wal under any circumstances. Return early |
| 41610 | - ** in this case to avoid the walIndexMap/Unmap overhead. Likewise, if | |
| 41611 | - ** pWal->readLock==0, then the WAL is ignored by the reader so | |
| 41612 | - ** return early, as if the WAL were empty. | |
| 41674 | + ** in this case as an optimization. Likewise, if pWal->readLock==0, | |
| 41675 | + ** then the WAL is ignored by the reader so return early, as if the | |
| 41676 | + ** WAL were empty. | |
| 41613 | 41677 | */ |
| 41614 | 41678 | if( iLast==0 || pWal->readLock==0 ){ |
| 41615 | 41679 | *pInWal = 0; |
| 41616 | 41680 | return SQLITE_OK; |
| 41617 | 41681 | } |
| @@ -41618,11 +41682,11 @@ | ||
| 41618 | 41682 | |
| 41619 | 41683 | /* Search the hash table or tables for an entry matching page number |
| 41620 | 41684 | ** pgno. Each iteration of the following for() loop searches one |
| 41621 | 41685 | ** hash table (each hash table indexes up to HASHTABLE_NPAGE frames). |
| 41622 | 41686 | ** |
| 41623 | - ** This code may run concurrently to the code in walIndexAppend() | |
| 41687 | + ** This code might run concurrently to the code in walIndexAppend() | |
| 41624 | 41688 | ** that adds entries to the wal-index (and possibly to this hash |
| 41625 | 41689 | ** table). This means the value just read from the hash |
| 41626 | 41690 | ** slot (aHash[iKey]) may have been added before or after the |
| 41627 | 41691 | ** current read transaction was opened. Values added after the |
| 41628 | 41692 | ** read transaction was opened may have been written incorrectly - |
| @@ -41941,24 +42005,32 @@ | ||
| 41941 | 42005 | ** header to the start of the WAL file. See comments at the top of |
| 41942 | 42006 | ** this source file for a description of the WAL header format. |
| 41943 | 42007 | */ |
| 41944 | 42008 | iFrame = pWal->hdr.mxFrame; |
| 41945 | 42009 | if( iFrame==0 ){ |
| 41946 | - u8 aWalHdr[WAL_HDRSIZE]; /* Buffer to assembly wal-header in */ | |
| 42010 | + u8 aWalHdr[WAL_HDRSIZE]; /* Buffer to assemble wal-header in */ | |
| 42011 | + u32 aCksum[2]; /* Checksum for wal-header */ | |
| 42012 | + | |
| 41947 | 42013 | sqlite3Put4byte(&aWalHdr[0], (WAL_MAGIC | SQLITE_BIGENDIAN)); |
| 41948 | - sqlite3Put4byte(&aWalHdr[4], 3007000); | |
| 42014 | + sqlite3Put4byte(&aWalHdr[4], WAL_MAX_VERSION); | |
| 41949 | 42015 | sqlite3Put4byte(&aWalHdr[8], szPage); |
| 41950 | - pWal->szPage = szPage; | |
| 41951 | - pWal->hdr.bigEndCksum = SQLITE_BIGENDIAN; | |
| 41952 | 42016 | sqlite3Put4byte(&aWalHdr[12], pWal->nCkpt); |
| 41953 | 42017 | memcpy(&aWalHdr[16], pWal->hdr.aSalt, 8); |
| 42018 | + walChecksumBytes(1, aWalHdr, WAL_HDRSIZE-2*4, 0, aCksum); | |
| 42019 | + sqlite3Put4byte(&aWalHdr[24], aCksum[0]); | |
| 42020 | + sqlite3Put4byte(&aWalHdr[28], aCksum[1]); | |
| 42021 | + | |
| 42022 | + pWal->szPage = szPage; | |
| 42023 | + pWal->hdr.bigEndCksum = SQLITE_BIGENDIAN; | |
| 42024 | + pWal->hdr.aFrameCksum[0] = aCksum[0]; | |
| 42025 | + pWal->hdr.aFrameCksum[1] = aCksum[1]; | |
| 42026 | + | |
| 41954 | 42027 | rc = sqlite3OsWrite(pWal->pWalFd, aWalHdr, sizeof(aWalHdr), 0); |
| 41955 | 42028 | WALTRACE(("WAL%p: wal-header write %s\n", pWal, rc ? "failed" : "ok")); |
| 41956 | 42029 | if( rc!=SQLITE_OK ){ |
| 41957 | 42030 | return rc; |
| 41958 | 42031 | } |
| 41959 | - walChecksumBytes(1, aWalHdr, sizeof(aWalHdr), 0, pWal->hdr.aFrameCksum); | |
| 41960 | 42032 | } |
| 41961 | 42033 | assert( pWal->szPage==szPage ); |
| 41962 | 42034 | |
| 41963 | 42035 | /* Write the log file. */ |
| 41964 | 42036 | for(p=pList; p; p=p->pDirty){ |
| @@ -103943,21 +104015,26 @@ | ||
| 103943 | 104015 | ** a low-level error is first detected. |
| 103944 | 104016 | */ |
| 103945 | 104017 | SQLITE_PRIVATE int sqlite3CorruptError(int lineno){ |
| 103946 | 104018 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 103947 | 104019 | sqlite3_log(SQLITE_CORRUPT, |
| 103948 | - "database corruption found by source line %d", lineno); | |
| 104020 | + "database corruption at line %d of [%.10s]", | |
| 104021 | + lineno, 20+sqlite3_sourceid()); | |
| 103949 | 104022 | return SQLITE_CORRUPT; |
| 103950 | 104023 | } |
| 103951 | 104024 | SQLITE_PRIVATE int sqlite3MisuseError(int lineno){ |
| 103952 | 104025 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 103953 | - sqlite3_log(SQLITE_MISUSE, "misuse detected by source line %d", lineno); | |
| 104026 | + sqlite3_log(SQLITE_MISUSE, | |
| 104027 | + "misuse at line %d of [%.10s]", | |
| 104028 | + lineno, 20+sqlite3_sourceid()); | |
| 103954 | 104029 | return SQLITE_MISUSE; |
| 103955 | 104030 | } |
| 103956 | 104031 | SQLITE_PRIVATE int sqlite3CantopenError(int lineno){ |
| 103957 | 104032 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 103958 | - sqlite3_log(SQLITE_CANTOPEN, "cannot open file at source line %d", lineno); | |
| 104033 | + sqlite3_log(SQLITE_CANTOPEN, | |
| 104034 | + "cannot open file at line %d of [%.10s]", | |
| 104035 | + lineno, 20+sqlite3_sourceid()); | |
| 103959 | 104036 | return SQLITE_CANTOPEN; |
| 103960 | 104037 | } |
| 103961 | 104038 | |
| 103962 | 104039 | |
| 103963 | 104040 | #ifndef SQLITE_OMIT_DEPRECATED |
| 103964 | 104041 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -636,11 +636,11 @@ | |
| 636 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 637 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 638 | */ |
| 639 | #define SQLITE_VERSION "3.7.0" |
| 640 | #define SQLITE_VERSION_NUMBER 3007000 |
| 641 | #define SQLITE_SOURCE_ID "2010-06-23 15:18:12 51ef43b9f7db8fabf73d9c8a76dae6c275e50d58" |
| 642 | |
| 643 | /* |
| 644 | ** CAPI3REF: Run-Time Library Version Numbers |
| 645 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 646 | ** |
| @@ -25586,11 +25586,11 @@ | |
| 25586 | }; |
| 25587 | |
| 25588 | /* |
| 25589 | ** Constants used for locking |
| 25590 | */ |
| 25591 | #define UNIX_SHM_BASE ((18+SQLITE_SHM_NLOCK)*4) /* first lock byte */ |
| 25592 | #define UNIX_SHM_DMS (UNIX_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */ |
| 25593 | |
| 25594 | /* |
| 25595 | ** Apply posix advisory locks for all bytes from ofst through ofst+n-1. |
| 25596 | ** |
| @@ -30017,11 +30017,11 @@ | |
| 30017 | }; |
| 30018 | |
| 30019 | /* |
| 30020 | ** Constants used for locking |
| 30021 | */ |
| 30022 | #define WIN_SHM_BASE ((18+SQLITE_SHM_NLOCK)*4) /* first lock byte */ |
| 30023 | #define WIN_SHM_DMS (WIN_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */ |
| 30024 | |
| 30025 | /* |
| 30026 | ** Apply advisory locks for all n bytes beginning at ofst. |
| 30027 | */ |
| @@ -34840,11 +34840,11 @@ | |
| 34840 | ** structure, the second the error-code about to be returned by a pager |
| 34841 | ** API function. The value returned is a copy of the second argument |
| 34842 | ** to this function. |
| 34843 | ** |
| 34844 | ** If the second argument is SQLITE_IOERR, SQLITE_CORRUPT, or SQLITE_FULL |
| 34845 | ** the error becomes persistent. Until the persisten error is cleared, |
| 34846 | ** subsequent API calls on this Pager will immediately return the same |
| 34847 | ** error code. |
| 34848 | ** |
| 34849 | ** A persistent error indicates that the contents of the pager-cache |
| 34850 | ** cannot be trusted. This state can be cleared by completely discarding |
| @@ -37092,13 +37092,11 @@ | |
| 37092 | ** reusing pPg. |
| 37093 | ** |
| 37094 | ** Similarly, if the pager has already entered the error state, do not |
| 37095 | ** try to write the contents of pPg to disk. |
| 37096 | */ |
| 37097 | if( NEVER(pPager->errCode) |
| 37098 | || (pPager->doNotSync && pPg->flags&PGHDR_NEED_SYNC) |
| 37099 | ){ |
| 37100 | return SQLITE_OK; |
| 37101 | } |
| 37102 | |
| 37103 | /* Sync the journal file if required. */ |
| 37104 | if( pPg->flags&PGHDR_NEED_SYNC ){ |
| @@ -38649,11 +38647,11 @@ | |
| 38649 | |
| 38650 | /* The dbOrigSize is never set if journal_mode=OFF */ |
| 38651 | assert( pPager->journalMode!=PAGER_JOURNALMODE_OFF || pPager->dbOrigSize==0 ); |
| 38652 | |
| 38653 | /* If a prior error occurred, report that error again. */ |
| 38654 | if( NEVER(pPager->errCode) ) return pPager->errCode; |
| 38655 | |
| 38656 | PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n", |
| 38657 | pPager->zFilename, zMaster, pPager->dbSize)); |
| 38658 | |
| 38659 | if( MEMDB && pPager->dbModified ){ |
| @@ -38879,11 +38877,11 @@ | |
| 38879 | ** performed. If successful, task (2). Regardless of the outcome |
| 38880 | ** of either, the error state error code is returned to the caller |
| 38881 | ** (i.e. either SQLITE_IOERR or SQLITE_CORRUPT). |
| 38882 | ** |
| 38883 | ** * If the pager is in PAGER_RESERVED state, then attempt (1). Whether |
| 38884 | ** or not (1) is succussful, also attempt (2). If successful, return |
| 38885 | ** SQLITE_OK. Otherwise, enter the error state and return the first |
| 38886 | ** error code encountered. |
| 38887 | ** |
| 38888 | ** In this case there is no chance that the database was written to. |
| 38889 | ** So is safe to finalize the journal file even if the playback |
| @@ -39708,23 +39706,25 @@ | |
| 39708 | ** frames can overwrite the old ones. A WAL always grows from beginning |
| 39709 | ** toward the end. Checksums and counters attached to each frame are |
| 39710 | ** used to determine which frames within the WAL are valid and which |
| 39711 | ** are leftovers from prior checkpoints. |
| 39712 | ** |
| 39713 | ** The WAL header is 24 bytes in size and consists of the following six |
| 39714 | ** big-endian 32-bit unsigned integer values: |
| 39715 | ** |
| 39716 | ** 0: Magic number. 0x377f0682 or 0x377f0683 |
| 39717 | ** 4: File format version. Currently 3007000 |
| 39718 | ** 8: Database page size. Example: 1024 |
| 39719 | ** 12: Checkpoint sequence number |
| 39720 | ** 16: Salt-1, random integer incremented with each checkpoint |
| 39721 | ** 20: Salt-2, a different random integer changing with each ckpt |
| 39722 | ** |
| 39723 | ** Immediately following the wal-header are zero or more frames. Each |
| 39724 | ** frame consists of a 24-byte frame-header followed by a <page-size> bytes |
| 39725 | ** of page data. The frame-header is broken into 6 big-endian 32-bit unsigned |
| 39726 | ** integer values, as follows: |
| 39727 | ** |
| 39728 | ** 0: Page number. |
| 39729 | ** 4: For commit records, the size of the database image in pages |
| 39730 | ** after the commit. For all other records, zero. |
| @@ -39755,10 +39755,15 @@ | |
| 39755 | ** |
| 39756 | ** for i from 0 to n-1 step 2: |
| 39757 | ** s0 += x[i] + s1; |
| 39758 | ** s1 += x[i+1] + s0; |
| 39759 | ** endfor |
| 39760 | ** |
| 39761 | ** On a checkpoint, the WAL is first VFS.xSync-ed, then valid content of the |
| 39762 | ** WAL is transferred into the database, then the database is VFS.xSync-ed. |
| 39763 | ** The VFS.xSync operations serve as write barriers - all writes launched |
| 39764 | ** before the xSync must complete before any write that launches after the |
| @@ -39922,10 +39927,25 @@ | |
| 39922 | # define WALTRACE(X) if(sqlite3WalTrace) sqlite3DebugPrintf X |
| 39923 | #else |
| 39924 | # define WALTRACE(X) |
| 39925 | #endif |
| 39926 | |
| 39927 | |
| 39928 | /* |
| 39929 | ** Indices of various locking bytes. WAL_NREADER is the number |
| 39930 | ** of available reader locks and should be at least 3. |
| 39931 | */ |
| @@ -39948,10 +39968,12 @@ | |
| 39948 | ** |
| 39949 | ** The actual header in the wal-index consists of two copies of this |
| 39950 | ** object. |
| 39951 | */ |
| 39952 | struct WalIndexHdr { |
| 39953 | u32 iChange; /* Counter incremented each transaction */ |
| 39954 | u8 isInit; /* 1 when initialized */ |
| 39955 | u8 bigEndCksum; /* True if checksums in WAL are big-endian */ |
| 39956 | u16 szPage; /* Database page size in bytes */ |
| 39957 | u32 mxFrame; /* Index of last valid frame in the WAL */ |
| @@ -40027,12 +40049,13 @@ | |
| 40027 | #define WALINDEX_HDR_SIZE (WALINDEX_LOCK_OFFSET+WALINDEX_LOCK_RESERVED) |
| 40028 | |
| 40029 | /* Size of header before each frame in wal */ |
| 40030 | #define WAL_FRAME_HDRSIZE 24 |
| 40031 | |
| 40032 | /* Size of write ahead log header */ |
| 40033 | #define WAL_HDRSIZE 24 |
| 40034 | |
| 40035 | /* WAL magic value. Either this value, or the same value with the least |
| 40036 | ** significant bit also set (WAL_MAGIC | 0x00000001) is stored in 32-bit |
| 40037 | ** big-endian format in the first 4 bytes of a WAL file. |
| 40038 | ** |
| @@ -40256,10 +40279,11 @@ | |
| 40256 | volatile WalIndexHdr *aHdr = walIndexHdr(pWal); |
| 40257 | const int nCksum = offsetof(WalIndexHdr, aCksum); |
| 40258 | |
| 40259 | assert( pWal->writeLock ); |
| 40260 | pWal->hdr.isInit = 1; |
| 40261 | walChecksumBytes(1, (u8*)&pWal->hdr, nCksum, 0, pWal->hdr.aCksum); |
| 40262 | memcpy((void *)&aHdr[1], (void *)&pWal->hdr, sizeof(WalIndexHdr)); |
| 40263 | sqlite3OsShmBarrier(pWal->pDbFd); |
| 40264 | memcpy((void *)&aHdr[0], (void *)&pWal->hdr, sizeof(WalIndexHdr)); |
| 40265 | } |
| @@ -40705,10 +40729,11 @@ | |
| 40705 | u8 *aData; /* Pointer to data part of aFrame buffer */ |
| 40706 | int iFrame; /* Index of last frame read */ |
| 40707 | i64 iOffset; /* Next offset to read from log file */ |
| 40708 | int szPage; /* Page size according to the log */ |
| 40709 | u32 magic; /* Magic value read from WAL header */ |
| 40710 | |
| 40711 | /* Read in the WAL header. */ |
| 40712 | rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0); |
| 40713 | if( rc!=SQLITE_OK ){ |
| 40714 | goto recovery_error; |
| @@ -40730,13 +40755,28 @@ | |
| 40730 | } |
| 40731 | pWal->hdr.bigEndCksum = (magic&0x00000001); |
| 40732 | pWal->szPage = szPage; |
| 40733 | pWal->nCkpt = sqlite3Get4byte(&aBuf[12]); |
| 40734 | memcpy(&pWal->hdr.aSalt, &aBuf[16], 8); |
| 40735 | walChecksumBytes(pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN, |
| 40736 | aBuf, WAL_HDRSIZE, 0, pWal->hdr.aFrameCksum |
| 40737 | ); |
| 40738 | |
| 40739 | /* Malloc a buffer to read frames into. */ |
| 40740 | szFrame = szPage + WAL_FRAME_HDRSIZE; |
| 40741 | aFrame = (u8 *)sqlite3_malloc(szFrame); |
| 40742 | if( !aFrame ){ |
| @@ -41297,30 +41337,24 @@ | |
| 41297 | return 0; |
| 41298 | } |
| 41299 | |
| 41300 | /* |
| 41301 | ** Read the wal-index header from the wal-index and into pWal->hdr. |
| 41302 | ** If the wal-header appears to be corrupt, try to recover the log |
| 41303 | ** before returning. |
| 41304 | ** |
| 41305 | ** Set *pChanged to 1 if the wal-index header value in pWal->hdr is |
| 41306 | ** changed by this opertion. If pWal->hdr is unchanged, set *pChanged |
| 41307 | ** to 0. |
| 41308 | ** |
| 41309 | ** This routine also maps the wal-index content into memory and assigns |
| 41310 | ** ownership of that mapping to the current thread. In some implementations, |
| 41311 | ** only one thread at a time can hold a mapping of the wal-index. Hence, |
| 41312 | ** the caller should strive to invoke walIndexUnmap() as soon as possible |
| 41313 | ** after this routine returns. |
| 41314 | ** |
| 41315 | ** If the wal-index header is successfully read, return SQLITE_OK. |
| 41316 | ** Otherwise an SQLite error code. |
| 41317 | */ |
| 41318 | static int walIndexReadHdr(Wal *pWal, int *pChanged){ |
| 41319 | int rc; /* Return code */ |
| 41320 | int badHdr; /* True if a header read failed */ |
| 41321 | volatile u32 *page0; |
| 41322 | |
| 41323 | /* Ensure that page 0 of the wal-index (the page that contains the |
| 41324 | ** wal-index header) is mapped. Return early if an error occurs here. |
| 41325 | */ |
| 41326 | assert( pChanged ); |
| @@ -41331,11 +41365,11 @@ | |
| 41331 | assert( page0 || pWal->writeLock==0 ); |
| 41332 | |
| 41333 | /* If the first page of the wal-index has been mapped, try to read the |
| 41334 | ** wal-index header immediately, without holding any lock. This usually |
| 41335 | ** works, but may fail if the wal-index header is corrupt or currently |
| 41336 | ** being modified by another user. |
| 41337 | */ |
| 41338 | badHdr = (page0 ? walIndexTryHdr(pWal, pChanged) : 1); |
| 41339 | |
| 41340 | /* If the first attempt failed, it might have been due to a race |
| 41341 | ** with a writer. So get a WRITE lock and try again. |
| @@ -41355,10 +41389,18 @@ | |
| 41355 | } |
| 41356 | } |
| 41357 | pWal->writeLock = 0; |
| 41358 | walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1); |
| 41359 | } |
| 41360 | |
| 41361 | return rc; |
| 41362 | } |
| 41363 | |
| 41364 | /* |
| @@ -41370,13 +41412,33 @@ | |
| 41370 | /* |
| 41371 | ** Attempt to start a read transaction. This might fail due to a race or |
| 41372 | ** other transient condition. When that happens, it returns WAL_RETRY to |
| 41373 | ** indicate to the caller that it is safe to retry immediately. |
| 41374 | ** |
| 41375 | ** On success return SQLITE_OK. On a permantent failure (such an |
| 41376 | ** I/O error or an SQLITE_BUSY because another process is running |
| 41377 | ** recovery) return a positive error code. |
| 41378 | ** |
| 41379 | ** On success, this routine obtains a read lock on |
| 41380 | ** WAL_READ_LOCK(pWal->readLock). The pWal->readLock integer is |
| 41381 | ** in the range 0 <= pWal->readLock < WAL_NREADER. If pWal->readLock==(-1) |
| 41382 | ** that means the Wal does not hold any read lock. The reader must not |
| @@ -41383,10 +41445,12 @@ | |
| 41383 | ** access any database page that is modified by a WAL frame up to and |
| 41384 | ** including frame number aReadMark[pWal->readLock]. The reader will |
| 41385 | ** use WAL frames up to and including pWal->hdr.mxFrame if pWal->readLock>0 |
| 41386 | ** Or if pWal->readLock==0, then the reader will ignore the WAL |
| 41387 | ** completely and get all content directly from the database file. |
| 41388 | ** When the read transaction is completed, the caller must release the |
| 41389 | ** lock on WAL_READ_LOCK(pWal->readLock) and set pWal->readLock to -1. |
| 41390 | ** |
| 41391 | ** This routine uses the nBackfill and aReadMark[] fields of the header |
| 41392 | ** to select a particular WAL_READ_LOCK() that strives to let the |
| @@ -41427,13 +41491,13 @@ | |
| 41427 | rc = WAL_RETRY; |
| 41428 | }else if( rc==SQLITE_BUSY ){ |
| 41429 | rc = SQLITE_BUSY_RECOVERY; |
| 41430 | } |
| 41431 | } |
| 41432 | } |
| 41433 | if( rc!=SQLITE_OK ){ |
| 41434 | return rc; |
| 41435 | } |
| 41436 | |
| 41437 | pInfo = walCkptInfo(pWal); |
| 41438 | if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame ){ |
| 41439 | /* The WAL has been completely backfilled (or it is empty). |
| @@ -41605,13 +41669,13 @@ | |
| 41605 | /* This routine is only be called from within a read transaction. */ |
| 41606 | assert( pWal->readLock>=0 || pWal->lockError ); |
| 41607 | |
| 41608 | /* If the "last page" field of the wal-index header snapshot is 0, then |
| 41609 | ** no data will be read from the wal under any circumstances. Return early |
| 41610 | ** in this case to avoid the walIndexMap/Unmap overhead. Likewise, if |
| 41611 | ** pWal->readLock==0, then the WAL is ignored by the reader so |
| 41612 | ** return early, as if the WAL were empty. |
| 41613 | */ |
| 41614 | if( iLast==0 || pWal->readLock==0 ){ |
| 41615 | *pInWal = 0; |
| 41616 | return SQLITE_OK; |
| 41617 | } |
| @@ -41618,11 +41682,11 @@ | |
| 41618 | |
| 41619 | /* Search the hash table or tables for an entry matching page number |
| 41620 | ** pgno. Each iteration of the following for() loop searches one |
| 41621 | ** hash table (each hash table indexes up to HASHTABLE_NPAGE frames). |
| 41622 | ** |
| 41623 | ** This code may run concurrently to the code in walIndexAppend() |
| 41624 | ** that adds entries to the wal-index (and possibly to this hash |
| 41625 | ** table). This means the value just read from the hash |
| 41626 | ** slot (aHash[iKey]) may have been added before or after the |
| 41627 | ** current read transaction was opened. Values added after the |
| 41628 | ** read transaction was opened may have been written incorrectly - |
| @@ -41941,24 +42005,32 @@ | |
| 41941 | ** header to the start of the WAL file. See comments at the top of |
| 41942 | ** this source file for a description of the WAL header format. |
| 41943 | */ |
| 41944 | iFrame = pWal->hdr.mxFrame; |
| 41945 | if( iFrame==0 ){ |
| 41946 | u8 aWalHdr[WAL_HDRSIZE]; /* Buffer to assembly wal-header in */ |
| 41947 | sqlite3Put4byte(&aWalHdr[0], (WAL_MAGIC | SQLITE_BIGENDIAN)); |
| 41948 | sqlite3Put4byte(&aWalHdr[4], 3007000); |
| 41949 | sqlite3Put4byte(&aWalHdr[8], szPage); |
| 41950 | pWal->szPage = szPage; |
| 41951 | pWal->hdr.bigEndCksum = SQLITE_BIGENDIAN; |
| 41952 | sqlite3Put4byte(&aWalHdr[12], pWal->nCkpt); |
| 41953 | memcpy(&aWalHdr[16], pWal->hdr.aSalt, 8); |
| 41954 | rc = sqlite3OsWrite(pWal->pWalFd, aWalHdr, sizeof(aWalHdr), 0); |
| 41955 | WALTRACE(("WAL%p: wal-header write %s\n", pWal, rc ? "failed" : "ok")); |
| 41956 | if( rc!=SQLITE_OK ){ |
| 41957 | return rc; |
| 41958 | } |
| 41959 | walChecksumBytes(1, aWalHdr, sizeof(aWalHdr), 0, pWal->hdr.aFrameCksum); |
| 41960 | } |
| 41961 | assert( pWal->szPage==szPage ); |
| 41962 | |
| 41963 | /* Write the log file. */ |
| 41964 | for(p=pList; p; p=p->pDirty){ |
| @@ -103943,21 +104015,26 @@ | |
| 103943 | ** a low-level error is first detected. |
| 103944 | */ |
| 103945 | SQLITE_PRIVATE int sqlite3CorruptError(int lineno){ |
| 103946 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 103947 | sqlite3_log(SQLITE_CORRUPT, |
| 103948 | "database corruption found by source line %d", lineno); |
| 103949 | return SQLITE_CORRUPT; |
| 103950 | } |
| 103951 | SQLITE_PRIVATE int sqlite3MisuseError(int lineno){ |
| 103952 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 103953 | sqlite3_log(SQLITE_MISUSE, "misuse detected by source line %d", lineno); |
| 103954 | return SQLITE_MISUSE; |
| 103955 | } |
| 103956 | SQLITE_PRIVATE int sqlite3CantopenError(int lineno){ |
| 103957 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 103958 | sqlite3_log(SQLITE_CANTOPEN, "cannot open file at source line %d", lineno); |
| 103959 | return SQLITE_CANTOPEN; |
| 103960 | } |
| 103961 | |
| 103962 | |
| 103963 | #ifndef SQLITE_OMIT_DEPRECATED |
| 103964 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -636,11 +636,11 @@ | |
| 636 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 637 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 638 | */ |
| 639 | #define SQLITE_VERSION "3.7.0" |
| 640 | #define SQLITE_VERSION_NUMBER 3007000 |
| 641 | #define SQLITE_SOURCE_ID "2010-06-24 10:50:18 7aac9ad6dd14b1c56eb8e4750ac769c6197c30bd" |
| 642 | |
| 643 | /* |
| 644 | ** CAPI3REF: Run-Time Library Version Numbers |
| 645 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 646 | ** |
| @@ -25586,11 +25586,11 @@ | |
| 25586 | }; |
| 25587 | |
| 25588 | /* |
| 25589 | ** Constants used for locking |
| 25590 | */ |
| 25591 | #define UNIX_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */ |
| 25592 | #define UNIX_SHM_DMS (UNIX_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */ |
| 25593 | |
| 25594 | /* |
| 25595 | ** Apply posix advisory locks for all bytes from ofst through ofst+n-1. |
| 25596 | ** |
| @@ -30017,11 +30017,11 @@ | |
| 30017 | }; |
| 30018 | |
| 30019 | /* |
| 30020 | ** Constants used for locking |
| 30021 | */ |
| 30022 | #define WIN_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */ |
| 30023 | #define WIN_SHM_DMS (WIN_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */ |
| 30024 | |
| 30025 | /* |
| 30026 | ** Apply advisory locks for all n bytes beginning at ofst. |
| 30027 | */ |
| @@ -34840,11 +34840,11 @@ | |
| 34840 | ** structure, the second the error-code about to be returned by a pager |
| 34841 | ** API function. The value returned is a copy of the second argument |
| 34842 | ** to this function. |
| 34843 | ** |
| 34844 | ** If the second argument is SQLITE_IOERR, SQLITE_CORRUPT, or SQLITE_FULL |
| 34845 | ** the error becomes persistent. Until the persistent error is cleared, |
| 34846 | ** subsequent API calls on this Pager will immediately return the same |
| 34847 | ** error code. |
| 34848 | ** |
| 34849 | ** A persistent error indicates that the contents of the pager-cache |
| 34850 | ** cannot be trusted. This state can be cleared by completely discarding |
| @@ -37092,13 +37092,11 @@ | |
| 37092 | ** reusing pPg. |
| 37093 | ** |
| 37094 | ** Similarly, if the pager has already entered the error state, do not |
| 37095 | ** try to write the contents of pPg to disk. |
| 37096 | */ |
| 37097 | if( pPager->errCode || (pPager->doNotSync && pPg->flags&PGHDR_NEED_SYNC) ){ |
| 37098 | return SQLITE_OK; |
| 37099 | } |
| 37100 | |
| 37101 | /* Sync the journal file if required. */ |
| 37102 | if( pPg->flags&PGHDR_NEED_SYNC ){ |
| @@ -38649,11 +38647,11 @@ | |
| 38647 | |
| 38648 | /* The dbOrigSize is never set if journal_mode=OFF */ |
| 38649 | assert( pPager->journalMode!=PAGER_JOURNALMODE_OFF || pPager->dbOrigSize==0 ); |
| 38650 | |
| 38651 | /* If a prior error occurred, report that error again. */ |
| 38652 | if( pPager->errCode ) return pPager->errCode; |
| 38653 | |
| 38654 | PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n", |
| 38655 | pPager->zFilename, zMaster, pPager->dbSize)); |
| 38656 | |
| 38657 | if( MEMDB && pPager->dbModified ){ |
| @@ -38879,11 +38877,11 @@ | |
| 38877 | ** performed. If successful, task (2). Regardless of the outcome |
| 38878 | ** of either, the error state error code is returned to the caller |
| 38879 | ** (i.e. either SQLITE_IOERR or SQLITE_CORRUPT). |
| 38880 | ** |
| 38881 | ** * If the pager is in PAGER_RESERVED state, then attempt (1). Whether |
| 38882 | ** or not (1) is successful, also attempt (2). If successful, return |
| 38883 | ** SQLITE_OK. Otherwise, enter the error state and return the first |
| 38884 | ** error code encountered. |
| 38885 | ** |
| 38886 | ** In this case there is no chance that the database was written to. |
| 38887 | ** So is safe to finalize the journal file even if the playback |
| @@ -39708,23 +39706,25 @@ | |
| 39706 | ** frames can overwrite the old ones. A WAL always grows from beginning |
| 39707 | ** toward the end. Checksums and counters attached to each frame are |
| 39708 | ** used to determine which frames within the WAL are valid and which |
| 39709 | ** are leftovers from prior checkpoints. |
| 39710 | ** |
| 39711 | ** The WAL header is 32 bytes in size and consists of the following eight |
| 39712 | ** big-endian 32-bit unsigned integer values: |
| 39713 | ** |
| 39714 | ** 0: Magic number. 0x377f0682 or 0x377f0683 |
| 39715 | ** 4: File format version. Currently 3007000 |
| 39716 | ** 8: Database page size. Example: 1024 |
| 39717 | ** 12: Checkpoint sequence number |
| 39718 | ** 16: Salt-1, random integer incremented with each checkpoint |
| 39719 | ** 20: Salt-2, a different random integer changing with each ckpt |
| 39720 | ** 24: Checksum-1 (first part of checksum for first 24 bytes of header). |
| 39721 | ** 28: Checksum-2 (second part of checksum for first 24 bytes of header). |
| 39722 | ** |
| 39723 | ** Immediately following the wal-header are zero or more frames. Each |
| 39724 | ** frame consists of a 24-byte frame-header followed by a <page-size> bytes |
| 39725 | ** of page data. The frame-header is six big-endian 32-bit unsigned |
| 39726 | ** integer values, as follows: |
| 39727 | ** |
| 39728 | ** 0: Page number. |
| 39729 | ** 4: For commit records, the size of the database image in pages |
| 39730 | ** after the commit. For all other records, zero. |
| @@ -39755,10 +39755,15 @@ | |
| 39755 | ** |
| 39756 | ** for i from 0 to n-1 step 2: |
| 39757 | ** s0 += x[i] + s1; |
| 39758 | ** s1 += x[i+1] + s0; |
| 39759 | ** endfor |
| 39760 | ** |
| 39761 | ** Note that s0 and s1 are both weighted checksums using fibonacci weights |
| 39762 | ** in reverse order (the largest fibonacci weight occurs on the first element |
| 39763 | ** of the sequence being summed.) The s1 value spans all 32-bit |
| 39764 | ** terms of the sequence whereas s0 omits the final term. |
| 39765 | ** |
| 39766 | ** On a checkpoint, the WAL is first VFS.xSync-ed, then valid content of the |
| 39767 | ** WAL is transferred into the database, then the database is VFS.xSync-ed. |
| 39768 | ** The VFS.xSync operations serve as write barriers - all writes launched |
| 39769 | ** before the xSync must complete before any write that launches after the |
| @@ -39922,10 +39927,25 @@ | |
| 39927 | # define WALTRACE(X) if(sqlite3WalTrace) sqlite3DebugPrintf X |
| 39928 | #else |
| 39929 | # define WALTRACE(X) |
| 39930 | #endif |
| 39931 | |
| 39932 | /* |
| 39933 | ** The maximum (and only) versions of the wal and wal-index formats |
| 39934 | ** that may be interpreted by this version of SQLite. |
| 39935 | ** |
| 39936 | ** If a client begins recovering a WAL file and finds that (a) the checksum |
| 39937 | ** values in the wal-header are correct and (b) the version field is not |
| 39938 | ** WAL_MAX_VERSION, recovery fails and SQLite returns SQLITE_CANTOPEN. |
| 39939 | ** |
| 39940 | ** Similarly, if a client successfully reads a wal-index header (i.e. the |
| 39941 | ** checksum test is successful) and finds that the version field is not |
| 39942 | ** WALINDEX_MAX_VERSION, then no read-transaction is opened and SQLite |
| 39943 | ** returns SQLITE_CANTOPEN. |
| 39944 | */ |
| 39945 | #define WAL_MAX_VERSION 3007000 |
| 39946 | #define WALINDEX_MAX_VERSION 3007000 |
| 39947 | |
| 39948 | /* |
| 39949 | ** Indices of various locking bytes. WAL_NREADER is the number |
| 39950 | ** of available reader locks and should be at least 3. |
| 39951 | */ |
| @@ -39948,10 +39968,12 @@ | |
| 39968 | ** |
| 39969 | ** The actual header in the wal-index consists of two copies of this |
| 39970 | ** object. |
| 39971 | */ |
| 39972 | struct WalIndexHdr { |
| 39973 | u32 iVersion; /* Wal-index version */ |
| 39974 | u32 unused; /* Unused (padding) field */ |
| 39975 | u32 iChange; /* Counter incremented each transaction */ |
| 39976 | u8 isInit; /* 1 when initialized */ |
| 39977 | u8 bigEndCksum; /* True if checksums in WAL are big-endian */ |
| 39978 | u16 szPage; /* Database page size in bytes */ |
| 39979 | u32 mxFrame; /* Index of last valid frame in the WAL */ |
| @@ -40027,12 +40049,13 @@ | |
| 40049 | #define WALINDEX_HDR_SIZE (WALINDEX_LOCK_OFFSET+WALINDEX_LOCK_RESERVED) |
| 40050 | |
| 40051 | /* Size of header before each frame in wal */ |
| 40052 | #define WAL_FRAME_HDRSIZE 24 |
| 40053 | |
| 40054 | /* Size of write ahead log header, including checksum. */ |
| 40055 | /* #define WAL_HDRSIZE 24 */ |
| 40056 | #define WAL_HDRSIZE 32 |
| 40057 | |
| 40058 | /* WAL magic value. Either this value, or the same value with the least |
| 40059 | ** significant bit also set (WAL_MAGIC | 0x00000001) is stored in 32-bit |
| 40060 | ** big-endian format in the first 4 bytes of a WAL file. |
| 40061 | ** |
| @@ -40256,10 +40279,11 @@ | |
| 40279 | volatile WalIndexHdr *aHdr = walIndexHdr(pWal); |
| 40280 | const int nCksum = offsetof(WalIndexHdr, aCksum); |
| 40281 | |
| 40282 | assert( pWal->writeLock ); |
| 40283 | pWal->hdr.isInit = 1; |
| 40284 | pWal->hdr.iVersion = WALINDEX_MAX_VERSION; |
| 40285 | walChecksumBytes(1, (u8*)&pWal->hdr, nCksum, 0, pWal->hdr.aCksum); |
| 40286 | memcpy((void *)&aHdr[1], (void *)&pWal->hdr, sizeof(WalIndexHdr)); |
| 40287 | sqlite3OsShmBarrier(pWal->pDbFd); |
| 40288 | memcpy((void *)&aHdr[0], (void *)&pWal->hdr, sizeof(WalIndexHdr)); |
| 40289 | } |
| @@ -40705,10 +40729,11 @@ | |
| 40729 | u8 *aData; /* Pointer to data part of aFrame buffer */ |
| 40730 | int iFrame; /* Index of last frame read */ |
| 40731 | i64 iOffset; /* Next offset to read from log file */ |
| 40732 | int szPage; /* Page size according to the log */ |
| 40733 | u32 magic; /* Magic value read from WAL header */ |
| 40734 | u32 version; /* Magic value read from WAL header */ |
| 40735 | |
| 40736 | /* Read in the WAL header. */ |
| 40737 | rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0); |
| 40738 | if( rc!=SQLITE_OK ){ |
| 40739 | goto recovery_error; |
| @@ -40730,13 +40755,28 @@ | |
| 40755 | } |
| 40756 | pWal->hdr.bigEndCksum = (magic&0x00000001); |
| 40757 | pWal->szPage = szPage; |
| 40758 | pWal->nCkpt = sqlite3Get4byte(&aBuf[12]); |
| 40759 | memcpy(&pWal->hdr.aSalt, &aBuf[16], 8); |
| 40760 | |
| 40761 | /* Verify that the WAL header checksum is correct */ |
| 40762 | walChecksumBytes(pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN, |
| 40763 | aBuf, WAL_HDRSIZE-2*4, 0, pWal->hdr.aFrameCksum |
| 40764 | ); |
| 40765 | if( pWal->hdr.aFrameCksum[0]!=sqlite3Get4byte(&aBuf[24]) |
| 40766 | || pWal->hdr.aFrameCksum[1]!=sqlite3Get4byte(&aBuf[28]) |
| 40767 | ){ |
| 40768 | goto finished; |
| 40769 | } |
| 40770 | |
| 40771 | /* Verify that the version number on the WAL format is one that |
| 40772 | ** are able to understand */ |
| 40773 | version = sqlite3Get4byte(&aBuf[4]); |
| 40774 | if( version!=WAL_MAX_VERSION ){ |
| 40775 | rc = SQLITE_CANTOPEN_BKPT; |
| 40776 | goto finished; |
| 40777 | } |
| 40778 | |
| 40779 | /* Malloc a buffer to read frames into. */ |
| 40780 | szFrame = szPage + WAL_FRAME_HDRSIZE; |
| 40781 | aFrame = (u8 *)sqlite3_malloc(szFrame); |
| 40782 | if( !aFrame ){ |
| @@ -41297,30 +41337,24 @@ | |
| 41337 | return 0; |
| 41338 | } |
| 41339 | |
| 41340 | /* |
| 41341 | ** Read the wal-index header from the wal-index and into pWal->hdr. |
| 41342 | ** If the wal-header appears to be corrupt, try to reconstruct the |
| 41343 | ** wal-index from the WAL before returning. |
| 41344 | ** |
| 41345 | ** Set *pChanged to 1 if the wal-index header value in pWal->hdr is |
| 41346 | ** changed by this opertion. If pWal->hdr is unchanged, set *pChanged |
| 41347 | ** to 0. |
| 41348 | ** |
| 41349 | ** If the wal-index header is successfully read, return SQLITE_OK. |
| 41350 | ** Otherwise an SQLite error code. |
| 41351 | */ |
| 41352 | static int walIndexReadHdr(Wal *pWal, int *pChanged){ |
| 41353 | int rc; /* Return code */ |
| 41354 | int badHdr; /* True if a header read failed */ |
| 41355 | volatile u32 *page0; /* Chunk of wal-index containing header */ |
| 41356 | |
| 41357 | /* Ensure that page 0 of the wal-index (the page that contains the |
| 41358 | ** wal-index header) is mapped. Return early if an error occurs here. |
| 41359 | */ |
| 41360 | assert( pChanged ); |
| @@ -41331,11 +41365,11 @@ | |
| 41365 | assert( page0 || pWal->writeLock==0 ); |
| 41366 | |
| 41367 | /* If the first page of the wal-index has been mapped, try to read the |
| 41368 | ** wal-index header immediately, without holding any lock. This usually |
| 41369 | ** works, but may fail if the wal-index header is corrupt or currently |
| 41370 | ** being modified by another thread or process. |
| 41371 | */ |
| 41372 | badHdr = (page0 ? walIndexTryHdr(pWal, pChanged) : 1); |
| 41373 | |
| 41374 | /* If the first attempt failed, it might have been due to a race |
| 41375 | ** with a writer. So get a WRITE lock and try again. |
| @@ -41355,10 +41389,18 @@ | |
| 41389 | } |
| 41390 | } |
| 41391 | pWal->writeLock = 0; |
| 41392 | walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1); |
| 41393 | } |
| 41394 | |
| 41395 | /* If the header is read successfully, check the version number to make |
| 41396 | ** sure the wal-index was not constructed with some future format that |
| 41397 | ** this version of SQLite cannot understand. |
| 41398 | */ |
| 41399 | if( badHdr==0 && pWal->hdr.iVersion!=WALINDEX_MAX_VERSION ){ |
| 41400 | rc = SQLITE_CANTOPEN_BKPT; |
| 41401 | } |
| 41402 | |
| 41403 | return rc; |
| 41404 | } |
| 41405 | |
| 41406 | /* |
| @@ -41370,13 +41412,33 @@ | |
| 41412 | /* |
| 41413 | ** Attempt to start a read transaction. This might fail due to a race or |
| 41414 | ** other transient condition. When that happens, it returns WAL_RETRY to |
| 41415 | ** indicate to the caller that it is safe to retry immediately. |
| 41416 | ** |
| 41417 | ** On success return SQLITE_OK. On a permanent failure (such an |
| 41418 | ** I/O error or an SQLITE_BUSY because another process is running |
| 41419 | ** recovery) return a positive error code. |
| 41420 | ** |
| 41421 | ** The useWal parameter is true to force the use of the WAL and disable |
| 41422 | ** the case where the WAL is bypassed because it has been completely |
| 41423 | ** checkpointed. If useWal==0 then this routine calls walIndexReadHdr() |
| 41424 | ** to make a copy of the wal-index header into pWal->hdr. If the |
| 41425 | ** wal-index header has changed, *pChanged is set to 1 (as an indication |
| 41426 | ** to the caller that the local paget cache is obsolete and needs to be |
| 41427 | ** flushed.) When useWal==1, the wal-index header is assumed to already |
| 41428 | ** be loaded and the pChanged parameter is unused. |
| 41429 | ** |
| 41430 | ** The caller must set the cnt parameter to the number of prior calls to |
| 41431 | ** this routine during the current read attempt that returned WAL_RETRY. |
| 41432 | ** This routine will start taking more aggressive measures to clear the |
| 41433 | ** race conditions after multiple WAL_RETRY returns, and after an excessive |
| 41434 | ** number of errors will ultimately return SQLITE_PROTOCOL. The |
| 41435 | ** SQLITE_PROTOCOL return indicates that some other process has gone rogue |
| 41436 | ** and is not honoring the locking protocol. There is a vanishingly small |
| 41437 | ** chance that SQLITE_PROTOCOL could be returned because of a run of really |
| 41438 | ** bad luck when there is lots of contention for the wal-index, but that |
| 41439 | ** possibility is so small that it can be safely neglected, we believe. |
| 41440 | ** |
| 41441 | ** On success, this routine obtains a read lock on |
| 41442 | ** WAL_READ_LOCK(pWal->readLock). The pWal->readLock integer is |
| 41443 | ** in the range 0 <= pWal->readLock < WAL_NREADER. If pWal->readLock==(-1) |
| 41444 | ** that means the Wal does not hold any read lock. The reader must not |
| @@ -41383,10 +41445,12 @@ | |
| 41445 | ** access any database page that is modified by a WAL frame up to and |
| 41446 | ** including frame number aReadMark[pWal->readLock]. The reader will |
| 41447 | ** use WAL frames up to and including pWal->hdr.mxFrame if pWal->readLock>0 |
| 41448 | ** Or if pWal->readLock==0, then the reader will ignore the WAL |
| 41449 | ** completely and get all content directly from the database file. |
| 41450 | ** If the useWal parameter is 1 then the WAL will never be ignored and |
| 41451 | ** this routine will always set pWal->readLock>0 on success. |
| 41452 | ** When the read transaction is completed, the caller must release the |
| 41453 | ** lock on WAL_READ_LOCK(pWal->readLock) and set pWal->readLock to -1. |
| 41454 | ** |
| 41455 | ** This routine uses the nBackfill and aReadMark[] fields of the header |
| 41456 | ** to select a particular WAL_READ_LOCK() that strives to let the |
| @@ -41427,13 +41491,13 @@ | |
| 41491 | rc = WAL_RETRY; |
| 41492 | }else if( rc==SQLITE_BUSY ){ |
| 41493 | rc = SQLITE_BUSY_RECOVERY; |
| 41494 | } |
| 41495 | } |
| 41496 | if( rc!=SQLITE_OK ){ |
| 41497 | return rc; |
| 41498 | } |
| 41499 | } |
| 41500 | |
| 41501 | pInfo = walCkptInfo(pWal); |
| 41502 | if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame ){ |
| 41503 | /* The WAL has been completely backfilled (or it is empty). |
| @@ -41605,13 +41669,13 @@ | |
| 41669 | /* This routine is only be called from within a read transaction. */ |
| 41670 | assert( pWal->readLock>=0 || pWal->lockError ); |
| 41671 | |
| 41672 | /* If the "last page" field of the wal-index header snapshot is 0, then |
| 41673 | ** no data will be read from the wal under any circumstances. Return early |
| 41674 | ** in this case as an optimization. Likewise, if pWal->readLock==0, |
| 41675 | ** then the WAL is ignored by the reader so return early, as if the |
| 41676 | ** WAL were empty. |
| 41677 | */ |
| 41678 | if( iLast==0 || pWal->readLock==0 ){ |
| 41679 | *pInWal = 0; |
| 41680 | return SQLITE_OK; |
| 41681 | } |
| @@ -41618,11 +41682,11 @@ | |
| 41682 | |
| 41683 | /* Search the hash table or tables for an entry matching page number |
| 41684 | ** pgno. Each iteration of the following for() loop searches one |
| 41685 | ** hash table (each hash table indexes up to HASHTABLE_NPAGE frames). |
| 41686 | ** |
| 41687 | ** This code might run concurrently to the code in walIndexAppend() |
| 41688 | ** that adds entries to the wal-index (and possibly to this hash |
| 41689 | ** table). This means the value just read from the hash |
| 41690 | ** slot (aHash[iKey]) may have been added before or after the |
| 41691 | ** current read transaction was opened. Values added after the |
| 41692 | ** read transaction was opened may have been written incorrectly - |
| @@ -41941,24 +42005,32 @@ | |
| 42005 | ** header to the start of the WAL file. See comments at the top of |
| 42006 | ** this source file for a description of the WAL header format. |
| 42007 | */ |
| 42008 | iFrame = pWal->hdr.mxFrame; |
| 42009 | if( iFrame==0 ){ |
| 42010 | u8 aWalHdr[WAL_HDRSIZE]; /* Buffer to assemble wal-header in */ |
| 42011 | u32 aCksum[2]; /* Checksum for wal-header */ |
| 42012 | |
| 42013 | sqlite3Put4byte(&aWalHdr[0], (WAL_MAGIC | SQLITE_BIGENDIAN)); |
| 42014 | sqlite3Put4byte(&aWalHdr[4], WAL_MAX_VERSION); |
| 42015 | sqlite3Put4byte(&aWalHdr[8], szPage); |
| 42016 | sqlite3Put4byte(&aWalHdr[12], pWal->nCkpt); |
| 42017 | memcpy(&aWalHdr[16], pWal->hdr.aSalt, 8); |
| 42018 | walChecksumBytes(1, aWalHdr, WAL_HDRSIZE-2*4, 0, aCksum); |
| 42019 | sqlite3Put4byte(&aWalHdr[24], aCksum[0]); |
| 42020 | sqlite3Put4byte(&aWalHdr[28], aCksum[1]); |
| 42021 | |
| 42022 | pWal->szPage = szPage; |
| 42023 | pWal->hdr.bigEndCksum = SQLITE_BIGENDIAN; |
| 42024 | pWal->hdr.aFrameCksum[0] = aCksum[0]; |
| 42025 | pWal->hdr.aFrameCksum[1] = aCksum[1]; |
| 42026 | |
| 42027 | rc = sqlite3OsWrite(pWal->pWalFd, aWalHdr, sizeof(aWalHdr), 0); |
| 42028 | WALTRACE(("WAL%p: wal-header write %s\n", pWal, rc ? "failed" : "ok")); |
| 42029 | if( rc!=SQLITE_OK ){ |
| 42030 | return rc; |
| 42031 | } |
| 42032 | } |
| 42033 | assert( pWal->szPage==szPage ); |
| 42034 | |
| 42035 | /* Write the log file. */ |
| 42036 | for(p=pList; p; p=p->pDirty){ |
| @@ -103943,21 +104015,26 @@ | |
| 104015 | ** a low-level error is first detected. |
| 104016 | */ |
| 104017 | SQLITE_PRIVATE int sqlite3CorruptError(int lineno){ |
| 104018 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 104019 | sqlite3_log(SQLITE_CORRUPT, |
| 104020 | "database corruption at line %d of [%.10s]", |
| 104021 | lineno, 20+sqlite3_sourceid()); |
| 104022 | return SQLITE_CORRUPT; |
| 104023 | } |
| 104024 | SQLITE_PRIVATE int sqlite3MisuseError(int lineno){ |
| 104025 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 104026 | sqlite3_log(SQLITE_MISUSE, |
| 104027 | "misuse at line %d of [%.10s]", |
| 104028 | lineno, 20+sqlite3_sourceid()); |
| 104029 | return SQLITE_MISUSE; |
| 104030 | } |
| 104031 | SQLITE_PRIVATE int sqlite3CantopenError(int lineno){ |
| 104032 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 104033 | sqlite3_log(SQLITE_CANTOPEN, |
| 104034 | "cannot open file at line %d of [%.10s]", |
| 104035 | lineno, 20+sqlite3_sourceid()); |
| 104036 | return SQLITE_CANTOPEN; |
| 104037 | } |
| 104038 | |
| 104039 | |
| 104040 | #ifndef SQLITE_OMIT_DEPRECATED |
| 104041 |
+1
-1
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -107,11 +107,11 @@ | ||
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | 110 | #define SQLITE_VERSION "3.7.0" |
| 111 | 111 | #define SQLITE_VERSION_NUMBER 3007000 |
| 112 | -#define SQLITE_SOURCE_ID "2010-06-23 15:18:12 51ef43b9f7db8fabf73d9c8a76dae6c275e50d58" | |
| 112 | +#define SQLITE_SOURCE_ID "2010-06-24 10:50:18 7aac9ad6dd14b1c56eb8e4750ac769c6197c30bd" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| 118 | 118 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.7.0" |
| 111 | #define SQLITE_VERSION_NUMBER 3007000 |
| 112 | #define SQLITE_SOURCE_ID "2010-06-23 15:18:12 51ef43b9f7db8fabf73d9c8a76dae6c275e50d58" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| 118 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.7.0" |
| 111 | #define SQLITE_VERSION_NUMBER 3007000 |
| 112 | #define SQLITE_SOURCE_ID "2010-06-24 10:50:18 7aac9ad6dd14b1c56eb8e4750ac769c6197c30bd" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| 118 |