/ Check-in [40030c07]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Update header comments in wal.c to correctly describe the WAL file format. Update the locking region offsets in os_unix.c and os_win.c and add assert() statement to verify that the locking region offsets are correct.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 40030c0739f821ea8ee188c28c579507f10448bc
User & Date: drh 2010-05-25 13:40:04
Context
2010-05-25
13:49
Modify walcrash2.test so that it works with DEFAULT_AUTOVACUUM=1. check-in: 77438882 user: dan tags: trunk
13:40
Update header comments in wal.c to correctly describe the WAL file format. Update the locking region offsets in os_unix.c and os_win.c and add assert() statement to verify that the locking region offsets are correct. check-in: 40030c07 user: drh tags: trunk
10:50
If a writer exits unexpectedly in the middle of a transaction, have the following writer remove any wal-index hash-table entries left by the interrupted transaction. check-in: ed77556a user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

  3182   3182   ** Size increment by which shared memory grows
  3183   3183   */
  3184   3184   #define SQLITE_UNIX_SHM_INCR  4096
  3185   3185   
  3186   3186   /*
  3187   3187   ** Constants used for locking
  3188   3188   */
  3189         -#define UNIX_SHM_BASE      32        /* Byte offset of the first lock byte */
         3189  +#define UNIX_SHM_BASE      80        /* Byte offset of the first lock byte */
  3190   3190   #define UNIX_SHM_DMS       0x01      /* Mask for Dead-Man-Switch lock */
  3191   3191   #define UNIX_SHM_A         0x10      /* Mask for region locks... */
  3192   3192   #define UNIX_SHM_B         0x20
  3193   3193   #define UNIX_SHM_C         0x40
  3194   3194   #define UNIX_SHM_D         0x80
  3195   3195   
  3196   3196   #ifdef SQLITE_DEBUG

Changes to src/os_win.c.

  1267   1267   ** Size increment by which shared memory grows
  1268   1268   */
  1269   1269   #define SQLITE_WIN_SHM_INCR  4096
  1270   1270   
  1271   1271   /*
  1272   1272   ** Constants used for locking
  1273   1273   */
  1274         -#define WIN_SHM_BASE      32        /* Byte offset of the first lock byte */
         1274  +#define WIN_SHM_BASE      80        /* Byte offset of the first lock byte */
  1275   1275   #define WIN_SHM_DMS       0x01      /* Mask for Dead-Man-Switch lock */
  1276   1276   #define WIN_SHM_A         0x10      /* Mask for region locks... */
  1277   1277   #define WIN_SHM_B         0x20
  1278   1278   #define WIN_SHM_C         0x40
  1279   1279   #define WIN_SHM_D         0x80
  1280   1280   
  1281   1281   #ifdef SQLITE_DEBUG

Changes to src/wal.c.

    30     30   ** toward the end.  Checksums and counters attached to each frame are
    31     31   ** used to determine which frames within the WAL are valid and which
    32     32   ** are leftovers from prior checkpoints.
    33     33   **
    34     34   ** The WAL header is 24 bytes in size and consists of the following six
    35     35   ** big-endian 32-bit unsigned integer values:
    36     36   **
    37         -**     0: Magic number.  0x377f0682 (big endian)
           37  +**     0: Magic number.  0x377f0682 or 0x377f0683
    38     38   **     4: File format version.  Currently 3007000
    39     39   **     8: Database page size.  Example: 1024
    40     40   **    12: Checkpoint sequence number
    41     41   **    16: Salt-1, random integer incremented with each checkpoint
    42     42   **    20: Salt-2, a different random integer changing with each ckpt
    43     43   **
    44     44   ** Immediately following the wal-header are zero or more frames. Each
................................................................................
    57     57   ** A frame is considered valid if and only if the following conditions are
    58     58   ** true:
    59     59   **
    60     60   **    (1) The salt-1 and salt-2 values in the frame-header match
    61     61   **        salt values in the wal-header
    62     62   **
    63     63   **    (2) The checksum values in the final 8 bytes of the frame-header
    64         -**        exactly match the checksum computed consecutively on
    65         -**        (a) the first 16 bytes of the frame-header, and
    66         -**        (b) the frame data.
           64  +**        exactly match the checksum computed consecutively on the
           65  +**        WAL header and the first 8 bytes and the content of all frames
           66  +**        up to and including the current frame.
           67  +**
           68  +** The checksum is computed using 32-bit big-endian integers if the
           69  +** magic number in the first 4 bytes of the WAL is 0x377f0683 and it
           70  +** is computed using little-endian if the magic number is 0x377f0682.
    67     71   **
    68     72   ** On a checkpoint, the WAL is first VFS.xSync-ed, then valid content of the
    69     73   ** WAL is transferred into the database, then the database is VFS.xSync-ed.
    70     74   ** The VFS.xSync operations server as write barriers - all writes launched
    71     75   ** before the xSync must complete before any write that launches after the
    72     76   ** xSync begins.
    73     77   **
................................................................................
   942    946     Wal *pRet;                      /* Object to allocate and return */
   943    947     int flags;                      /* Flags passed to OsOpen() */
   944    948     char *zWal;                     /* Name of write-ahead log file */
   945    949     int nWal;                       /* Length of zWal in bytes */
   946    950   
   947    951     assert( zDbName && zDbName[0] );
   948    952     assert( pDbFd );
          953  +
          954  +  /* In the amalgamation, the os_unix.c and os_win.c source files come before
          955  +  ** this source file.  Verify that the #defines of the locking byte offsets
          956  +  ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
          957  +  */
          958  +#ifdef WIN_SHM_BASE
          959  +  assert( WIN_SHM_BASE==WALINDEX_LOCK_OFFSET );
          960  +#endif
          961  +#ifdef UNIX_SHM_BASE
          962  +  assert( UNIX_SHM_BASE==WALINDEX_LOCK_OFFSET );
          963  +#endif
          964  +
   949    965   
   950    966     /* Allocate an instance of struct Wal to return. */
   951    967     *ppWal = 0;
   952    968     nWal = sqlite3Strlen30(zDbName) + 5;
   953    969     pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile + nWal);
   954    970     if( !pRet ){
   955    971       return SQLITE_NOMEM;