mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-10 01:02:56 +03:00
Merge recent trunk enhancements into the wal2 branch.
FossilOrigin-Name: f615d7baa889030b230e0d4f018dc9f8a6fe95cd3a671d7e2b941ae3240fa6ca
This commit is contained in:
102
src/wal.c
102
src/wal.c
@@ -161,7 +161,10 @@
|
||||
** HASHTABLE_NPAGE_ONE frames. The values of HASHTABLE_NPAGE_ONE and
|
||||
** HASHTABLE_NPAGE are selected so that together the wal-index header and
|
||||
** first index block are the same size as all other index blocks in the
|
||||
** wal-index.
|
||||
** wal-index. The values are:
|
||||
**
|
||||
** HASHTABLE_NPAGE 4096
|
||||
** HASHTABLE_NPAGE_ONE 4062
|
||||
**
|
||||
** Each index block contains two sections, a page-mapping that contains the
|
||||
** database page number associated with each wal frame, and a hash-table
|
||||
@@ -656,6 +659,70 @@ struct WalCkptInfo {
|
||||
};
|
||||
#define READMARK_NOT_USED 0xffffffff
|
||||
|
||||
/*
|
||||
** This is a schematic view of the complete 136-byte header of the
|
||||
** wal-index file (also known as the -shm file):
|
||||
**
|
||||
** +-----------------------------+
|
||||
** 0: | iVersion | \
|
||||
** +-----------------------------+ |
|
||||
** 4: | (unused padding) | |
|
||||
** +-----------------------------+ |
|
||||
** 8: | iChange | |
|
||||
** +-------+-------+-------------+ |
|
||||
** 12: | bInit | bBig | szPage | |
|
||||
** +-------+-------+-------------+ |
|
||||
** 16: | mxFrame | | First copy of the
|
||||
** +-----------------------------+ | WalIndexHdr object
|
||||
** 20: | nPage | |
|
||||
** +-----------------------------+ |
|
||||
** 24: | aFrameCksum | |
|
||||
** | | |
|
||||
** +-----------------------------+ |
|
||||
** 32: | aSalt | |
|
||||
** | | |
|
||||
** +-----------------------------+ |
|
||||
** 40: | aCksum | |
|
||||
** | | /
|
||||
** +-----------------------------+
|
||||
** 48: | iVersion | \
|
||||
** +-----------------------------+ |
|
||||
** 52: | (unused padding) | |
|
||||
** +-----------------------------+ |
|
||||
** 56: | iChange | |
|
||||
** +-------+-------+-------------+ |
|
||||
** 60: | bInit | bBig | szPage | |
|
||||
** +-------+-------+-------------+ | Second copy of the
|
||||
** 64: | mxFrame | | WalIndexHdr
|
||||
** +-----------------------------+ |
|
||||
** 68: | nPage | |
|
||||
** +-----------------------------+ |
|
||||
** 72: | aFrameCksum | |
|
||||
** | | |
|
||||
** +-----------------------------+ |
|
||||
** 80: | aSalt | |
|
||||
** | | |
|
||||
** +-----------------------------+ |
|
||||
** 88: | aCksum | |
|
||||
** | | /
|
||||
** +-----------------------------+
|
||||
** 96: | nBackfill |
|
||||
** +-----------------------------+
|
||||
** 100: | 5 read marks |
|
||||
** | |
|
||||
** | |
|
||||
** | |
|
||||
** | |
|
||||
** +-------+-------+------+------+
|
||||
** 120: | Write | Ckpt | Rcvr | Rd0 | \
|
||||
** +-------+-------+------+------+ ) 8 lock bytes
|
||||
** | Read1 | Read2 | Rd3 | Rd4 | /
|
||||
** +-------+-------+------+------+
|
||||
** 128: | nBackfillAttempted |
|
||||
** +-----------------------------+
|
||||
** 132: | (unused padding) |
|
||||
** +-----------------------------+
|
||||
*/
|
||||
|
||||
/* A block of WALINDEX_LOCK_RESERVED bytes beginning at
|
||||
** WALINDEX_LOCK_OFFSET is reserved for locks. Since some systems
|
||||
@@ -1891,14 +1958,43 @@ int sqlite3WalOpen(
|
||||
assert( zWalName && zWalName[0] );
|
||||
assert( pDbFd );
|
||||
|
||||
/* Verify the values of various constants. Any changes to the values
|
||||
** of these constants would result in an incompatible on-disk format
|
||||
** for the -shm file. Any change that causes one of these asserts to
|
||||
** fail is a backward compatibility problem, even if the change otherwise
|
||||
** works.
|
||||
**
|
||||
** This table also serves as a helpful cross-reference when trying to
|
||||
** interpret hex dumps of the -shm file.
|
||||
*/
|
||||
assert( 48 == sizeof(WalIndexHdr) );
|
||||
assert( 40 == sizeof(WalCkptInfo) );
|
||||
assert( 120 == WALINDEX_LOCK_OFFSET );
|
||||
assert( 136 == WALINDEX_HDR_SIZE );
|
||||
assert( 4096 == HASHTABLE_NPAGE );
|
||||
assert( 4062 == HASHTABLE_NPAGE_ONE );
|
||||
assert( 8192 == HASHTABLE_NSLOT );
|
||||
assert( 383 == HASHTABLE_HASH_1 );
|
||||
assert( 32768 == WALINDEX_PGSZ );
|
||||
assert( 8 == SQLITE_SHM_NLOCK );
|
||||
assert( 5 == WAL_NREADER );
|
||||
assert( 24 == WAL_FRAME_HDRSIZE );
|
||||
assert( 32 == WAL_HDRSIZE );
|
||||
assert( 120 == WALINDEX_LOCK_OFFSET + WAL_WRITE_LOCK );
|
||||
assert( 121 == WALINDEX_LOCK_OFFSET + WAL_CKPT_LOCK );
|
||||
assert( 122 == WALINDEX_LOCK_OFFSET + WAL_RECOVER_LOCK );
|
||||
assert( 123 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(0) );
|
||||
assert( 124 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(1) );
|
||||
assert( 125 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(2) );
|
||||
assert( 126 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(3) );
|
||||
assert( 127 == WALINDEX_LOCK_OFFSET + WAL_READ_LOCK(4) );
|
||||
|
||||
/* In the amalgamation, the os_unix.c and os_win.c source files come before
|
||||
** this source file. Verify that the #defines of the locking byte offsets
|
||||
** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
|
||||
** For that matter, if the lock offset ever changes from its initial design
|
||||
** value of 120, we need to know that so there is an assert() to check it.
|
||||
*/
|
||||
assert( 120==WALINDEX_LOCK_OFFSET );
|
||||
assert( 136==WALINDEX_HDR_SIZE );
|
||||
#ifdef WIN_SHM_BASE
|
||||
assert( WIN_SHM_BASE==WALINDEX_LOCK_OFFSET );
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user