/ Check-in [ad78ccac]
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:Changes to the comments describing the Pager.setMaster variable in pager.c. Add an assert() statement to verify that two master journal pointers are not written to a single journal file.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ad78ccacb00e2f8a5ca93e2c9006266d9477fe48
User & Date: dan 2010-07-30 11:31:13
Context
2010-07-30
16:44
Remove a test from sqlite3PagerCommitPhaseOne which is now always true after the multi-file transaction fix. check-in: 6758f6a8 user: drh tags: trunk
14:39
Merge trunk changes into experimental again. check-in: 87e0f4e1 user: dan tags: experimental
11:31
Changes to the comments describing the Pager.setMaster variable in pager.c. Add an assert() statement to verify that two master journal pointers are not written to a single journal file. check-in: ad78ccac user: dan tags: trunk
11:20
Cherry-pick the multi-file transaction fix for ticket [f3e5abed55] out of the experimental branch. check-in: 40f7f0a5 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

   278    278   **   It is cleared at the end of each transaction.
   279    279   **
   280    280   **   It is used when committing or otherwise ending a transaction. If
   281    281   **   the dbModified flag is clear then less work has to be done.
   282    282   **
   283    283   ** journalStarted
   284    284   **
   285         -**   This flag is set whenever the the main journal is opened and
   286         -**   initialized
          285  +**   This flag is set during a write-transaction after the first 
          286  +**   journal-header is written and synced to disk.
   287    287   **
   288         -**   The point of this flag is that it must be set after the 
   289         -**   first journal header in a journal file has been synced to disk.
   290    288   **   After this has happened, new pages appended to the database 
   291    289   **   do not need the PGHDR_NEED_SYNC flag set, as they do not need
   292    290   **   to wait for a journal sync before they can be written out to
   293    291   **   the database file (see function pager_write()).
   294    292   **   
   295    293   ** setMaster
   296    294   **
   297         -**   This variable is used to ensure that the master journal file name
   298         -**   (if any) is only written into the journal file once.
          295  +**   When PagerCommitPhaseOne() is called to commit a transaction, it may
          296  +**   (or may not) specify a master-journal name to be written into the 
          297  +**   journal file before it is synced to disk.
   299    298   **
   300         -**   When committing a transaction, the master journal file name (if any)
   301         -**   may be written into the journal file while the pager is still in
   302         -**   PAGER_RESERVED state (see CommitPhaseOne() for the action). It
   303         -**   then attempts to upgrade to an exclusive lock. If this attempt
   304         -**   fails, then SQLITE_BUSY may be returned to the user and the user
   305         -**   may attempt to commit the transaction again later (calling
   306         -**   CommitPhaseOne() again). This flag is used to ensure that the 
   307         -**   master journal name is only written to the journal file the first
   308         -**   time CommitPhaseOne() is called.
          299  +**   Whether or not a journal file contains a master-journal pointer affects 
          300  +**   the way in which the journal file is finalized after the transaction is 
          301  +**   committed or rolled back when running in "journal_mode=PERSIST" mode.
          302  +**   If a journal file does not contain a master-journal pointer, it is
          303  +**   finalized by overwriting the first journal header with zeroes. If,
          304  +**   on the other hand, it does contain a master-journal pointer, the
          305  +**   journal file is finalized by truncating it to zero bytes, just as if
          306  +**   the connection were running in "journal_mode=truncate" mode.
          307  +**
          308  +**   Journal files that contain master journal pointers cannot be finalized
          309  +**   simply by overwriting the first journal-header with zeroes, as the
          310  +**   master journal pointer could interfere with hot-journal rollback of any
          311  +**   subsequently interrupted transaction that reuses the journal file.
          312  +**
          313  +**   The flag is cleared as soon as the journal file is finalized (either
          314  +**   by PagerCommitPhaseTwo or PagerRollback). If an IO error prevents the
          315  +**   journal file from being successfully finalized, the setMaster flag
          316  +**   is cleared anyway.
   309    317   **
   310    318   ** doNotSpill, doNotSyncSpill
   311    319   **
   312    320   **   When enabled, cache spills are prohibited.  The doNotSpill variable
   313    321   **   inhibits all cache spill and doNotSyncSpill inhibits those spills that
   314    322   **   would require a journal sync.  The doNotSyncSpill is set and cleared 
   315    323   **   by sqlite3PagerWrite() in order to prevent a journal sync from happening 
................................................................................
  1069   1077   static int writeMasterJournal(Pager *pPager, const char *zMaster){
  1070   1078     int rc;                          /* Return code */
  1071   1079     int nMaster;                     /* Length of string zMaster */
  1072   1080     i64 iHdrOff;                     /* Offset of header in journal file */
  1073   1081     i64 jrnlSize;                    /* Size of journal file on disk */
  1074   1082     u32 cksum = 0;                   /* Checksum of string zMaster */
  1075   1083   
  1076         -  if( !zMaster || pPager->setMaster
         1084  +  assert( pPager->setMaster==0 );
         1085  +
         1086  +  if( !zMaster 
  1077   1087      || pPager->journalMode==PAGER_JOURNALMODE_MEMORY 
  1078   1088      || pPager->journalMode==PAGER_JOURNALMODE_OFF 
  1079   1089     ){
  1080   1090       return SQLITE_OK;
  1081   1091     }
  1082   1092     pPager->setMaster = 1;
  1083   1093     assert( isOpen(pPager->jfd) );