/ 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 Unified Diffs Ignore Whitespace Patch

Changes to src/wal.c.

781
782
783
784
785
786
787



















788
789








790
791
792
793
794
795
796
  Wal *pWal,                      /* Wal to close */
  sqlite3_file *pFd,              /* Database file */
  int sync_flags,                 /* Flags to pass to OsSync() (or 0) */
  u8 *zBuf                        /* Buffer of at least page-size bytes */
){
  int rc = SQLITE_OK;
  if( pWal ){



















    pWal->pVfs->xShmClose(pWal->pWIndex);
    sqlite3OsClose(pWal->pFd);








    sqlite3_free(pWal);
  }
  return rc;
}

/*
** Try to read the wal-index header. Attempt to verify the header







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


>
>
>
>
>
>
>
>







781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
  Wal *pWal,                      /* Wal to close */
  sqlite3_file *pFd,              /* Database file */
  int sync_flags,                 /* Flags to pass to OsSync() (or 0) */
  u8 *zBuf                        /* Buffer of at least page-size bytes */
){
  int rc = SQLITE_OK;
  if( pWal ){
    int isDelete = 0;             /* True to unlink wal and wal-index files */

    /* If an EXCLUSIVE lock can be obtained on the database file (using the
    ** ordinary, rollback-mode locking methods, this guarantees that the
    ** connection associated with this log file is the only connection to
    ** the database. In this case checkpoint the database and unlink both
    ** the wal and wal-index files.
    **
    ** The EXCLUSIVE lock is not released before returning.
    */
    rc = sqlite3OsLock(pFd, SQLITE_LOCK_EXCLUSIVE);
    if( rc==SQLITE_OK ){
      rc = walCheckpoint(pWal, pFd, sync_flags, zBuf);
      if( rc==SQLITE_OK ){
        isDelete = 1;
      }
      walIndexUnmap(pWal);
    }

    pWal->pVfs->xShmClose(pWal->pWIndex);
    sqlite3OsClose(pWal->pFd);
    if( isDelete ){
      int nWal;
      char *zWal = &((char *)pWal->pFd)[pWal->pVfs->szOsFile];
      sqlite3OsDelete(pWal->pVfs, zWal, 0);
      nWal = sqlite3Strlen30(zWal);
      memcpy(&zWal[nWal], "-index", 7);
      pWal->pVfs->xShmDelete(pWal->pVfs, zWal);
    }
    sqlite3_free(pWal);
  }
  return rc;
}

/*
** Try to read the wal-index header. Attempt to verify the header