/ Check-in [c05e7dca]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:When closing a WAL connection, attempt an exclusive lock on the database file. If the lock is obtained, checkpoint the database and delete the wal and wal-index files.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wal
Files: files | file ages | folders
SHA1: c05e7dca172719f33e245c08d0c0e8ab47e5a537
User & Date: dan 2010-04-30 15:49:28
References
2010-04-30
16:24
Reapply commits [837d82a929] and [c05e7dca17] that were accidentally overwritten. check-in: 598de527 user: dan tags: wal
Context
2010-04-30
15:54
Fix a couple uninitialized variables in the xShmLock method of the unix VFS. Improved debugging logic for xShmLock. check-in: 69567c5f user: drh tags: wal
15:49
When closing a WAL connection, attempt an exclusive lock on the database file. If the lock is obtained, checkpoint the database and delete the wal and wal-index files. check-in: c05e7dca user: dan tags: wal
15:24
If a reader attempts to upgrade to a writer, but is not reading the most recent database snapshot, return SQLITE_BUSY. check-in: 837d82a9 user: dan tags: wal
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/wal.c.

   781    781     Wal *pWal,                      /* Wal to close */
   782    782     sqlite3_file *pFd,              /* Database file */
   783    783     int sync_flags,                 /* Flags to pass to OsSync() (or 0) */
   784    784     u8 *zBuf                        /* Buffer of at least page-size bytes */
   785    785   ){
   786    786     int rc = SQLITE_OK;
   787    787     if( pWal ){
          788  +    int isDelete = 0;             /* True to unlink wal and wal-index files */
          789  +
          790  +    /* If an EXCLUSIVE lock can be obtained on the database file (using the
          791  +    ** ordinary, rollback-mode locking methods, this guarantees that the
          792  +    ** connection associated with this log file is the only connection to
          793  +    ** the database. In this case checkpoint the database and unlink both
          794  +    ** the wal and wal-index files.
          795  +    **
          796  +    ** The EXCLUSIVE lock is not released before returning.
          797  +    */
          798  +    rc = sqlite3OsLock(pFd, SQLITE_LOCK_EXCLUSIVE);
          799  +    if( rc==SQLITE_OK ){
          800  +      rc = walCheckpoint(pWal, pFd, sync_flags, zBuf);
          801  +      if( rc==SQLITE_OK ){
          802  +        isDelete = 1;
          803  +      }
          804  +      walIndexUnmap(pWal);
          805  +    }
          806  +
   788    807       pWal->pVfs->xShmClose(pWal->pWIndex);
   789    808       sqlite3OsClose(pWal->pFd);
          809  +    if( isDelete ){
          810  +      int nWal;
          811  +      char *zWal = &((char *)pWal->pFd)[pWal->pVfs->szOsFile];
          812  +      sqlite3OsDelete(pWal->pVfs, zWal, 0);
          813  +      nWal = sqlite3Strlen30(zWal);
          814  +      memcpy(&zWal[nWal], "-index", 7);
          815  +      pWal->pVfs->xShmDelete(pWal->pVfs, zWal);
          816  +    }
   790    817       sqlite3_free(pWal);
   791    818     }
   792    819     return rc;
   793    820   }
   794    821   
   795    822   /*
   796    823   ** Try to read the wal-index header. Attempt to verify the header