Lines Matching defs:journal

15 ** atomic commit and rollback through the use of a journal file that
29 ** journal. These invariants do not apply for journal_mode=WAL,
41 ** the transaction has been written into the rollback journal and
58 ** (2) The content of a page written into the rollback journal exactly matches
59 ** both the content in the database when the rollback journal was written
70 ** (5) All writes to the database file are synced prior to the rollback journal
73 ** (6) If a master journal file is used, then all writes to the database file
74 ** are synced prior to the master journal being deleted.
83 ** of the unsynced changes to a rollback journal are removed and the
84 ** journal is rolled back, the resulting database file will be logical
204 ** there is no hot-journal in the file-system.
215 ** moving to this state, but the journal file is not written to or opened
232 ** * The journal file may or may not be open.
233 ** * Nothing (not even the first header) has been written to the journal.
238 ** first modified by the upper layer. In rollback mode the journal file
244 ** * The journal file is open and the first header has been written
257 ** * The journal file is open and the first header has been written
269 ** by finalizing the journal file. Once in WRITER_FINISHED state, it is
275 ** * All writing and syncing of journal and database data has finished.
276 ** If no error occured, all that remains is to finalize the journal to
304 ** is reloaded from disk (and, if necessary, hot-journal rollback peformed)
314 ** 2. An error occurs while attempting to finalize a journal file
317 ** 3. An error occurs while attempting to write to the journal or
380 ** from ERROR to OPEN state. At this point there may be a hot-journal file
385 ** of hot-journal detection.
391 ** a hot-journal may be mistaken for a journal being created by an active
399 ** omits the check for a hot-journal if Pager.eLock is set to UNKNOWN_LOCK
400 ** lock. Instead, it assumes a hot-journal exists and obtains an EXCLUSIVE
438 ** set to 0. If a journal-header is written into the main journal while
440 ** immediately following the last journal record written into the main
441 ** journal before the journal-header. This is required during savepoint
446 i64 iOffset; /* Starting offset in main journal */
450 Pgno iSubRec; /* Index of first record in sub-journal */
500 ** (or may not) specify a master-journal name to be written into the
501 ** journal file before it is synced to disk.
503 ** Whether or not a journal file contains a master-journal pointer affects
504 ** the way in which the journal file is finalized after the transaction is
506 ** If a journal file does not contain a master-journal pointer, it is
507 ** finalized by overwriting the first journal header with zeroes. If
508 ** it does contain a master-journal pointer the journal file is finalized
512 ** Journal files that contain master journal pointers cannot be finalized
513 ** simply by overwriting the first journal-header with zeroes, as the
514 ** master journal pointer could interfere with hot-journal rollback of any
515 ** subsequently interrupted transaction that reuses the journal file.
517 ** The flag is cleared as soon as the journal file is finalized (either
519 ** journal file from being successfully finalized, the setMaster flag
531 ** to allocate a new page to prevent the journal file from being written
535 ** is permitted, but syncing the journal file is not. This flag is set
537 ** the database page-size in order to prevent a journal sync from happening
542 ** This is a boolean variable. If true, then any required sub-journal
543 ** is opened as an in-memory journal file. If false, then in-memory
614 u8 useJournal; /* Use a rollback journal on this file */
616 u8 noSync; /* Do not sync the journal if true */
617 u8 fullSync; /* Do extra syncs of the journal for robustness */
647 u32 nSubRec; /* Number of records written to sub-journal */
650 sqlite3_file *jfd; /* File descriptor for main journal */
651 sqlite3_file *sjfd; /* File descriptor for sub-journal */
652 i64 journalOff; /* Current write offset in the journal file */
653 i64 journalHdr; /* Byte offset to previous journal header */
668 i64 journalSizeLimit; /* Size limit for persistent journal files */
670 char *zJournal; /* Name of the journal file */
700 int sqlite3_pager_writej_count = 0; /* Number of pages written to journal */
712 ** Since version 2.8.0, the journal format contains additional sanity
713 ** checking information. If the power fails while the journal is being
714 ** written, semi-random garbage data might appear in the journal
716 ** to roll the journal back, the database could be corrupted. The additional
718 ** journal and ignore it.
720 ** The sanity checking information for the new journal format consists
724 ** journal file right after the header. The random initializer is important,
725 ** because garbage data that appears at the end of a journal is likely
727 ** garbage data came from an obsolete journal file, the checksums might
729 ** is different for every journal, we minimize that risk.
736 ** The size of the of each page record in the journal is given by
742 ** The journal header size for this pager. This is usually the same
780 ** rollback journal. Otherwise false.
833 /* If the useJournal flag is clear, the journal-mode must be "OFF".
834 ** And if the journal-mode is "OFF", the journal file must not be open.
839 /* Check that MEMDB implies noSync. And an in-memory journal. Since
842 ** a journal file. (although the in-memory journal implementation may
843 ** return SQLITE_IOERR_NOMEM while the journal file is being written). It
892 ** journal file nor the WAL file are open. This happens during
994 ** Return true if it is necessary to write page *pPg into the sub-journal.
995 ** A page needs to be written into the sub-journal if there exists one
1016 ** Return true if the page is already in the journal file.
1118 ** then the value returned is the size of the journal file when it
1189 ** When this is called the journal file for pager pPager must be open.
1190 ** This function attempts to read a master journal file name from the
1193 ** used to store a master journal file name at the end of a journal file.
1197 ** enough space to write the master journal name). If the master journal
1198 ** name in the journal is longer than nMaster bytes (including a
1199 ** nul-terminator), then this is handled as if no master journal name
1200 ** were present in the journal.
1202 ** If a master journal file name is present at the end of the journal
1205 ** journal file name.
1207 ** If it is determined that no master journal file name is present
1210 ** If an error occurs while reading from the journal file, an SQLite
1215 u32 len; /* Length in bytes of master journal name */
1216 i64 szJ; /* Total size in bytes of journal file pJrnl */
1217 u32 cksum; /* MJ checksum value read from journal */
1234 /* See if the checksum matches the master journal name */
1240 ** containing the master journal filename is corrupted. This means
1242 ** master-journal filename.
1279 ** The journal file must be open when this function is called.
1281 ** This function is a no-op if the journal file has not been written to
1285 ** set to 0, then truncate the journal file to zero bytes in size. Otherwise,
1286 ** zero the 28-byte header at the start of the journal file. In either case,
1287 ** if the pager is not in no-sync mode, sync the journal file immediately
1292 ** journal file in bytes is larger than this value, then truncate the
1293 ** journal file to Pager.journalSizeLimit bytes. The journal file does
1318 ** the persistent journal and the journal file currently consumes more
1334 ** The journal file must be open when this routine is called. A journal
1335 ** header (JOURNAL_HDR_SZ bytes) is written into the journal file at the
1338 ** The format for the journal header is as follows:
1339 ** - 8 bytes: Magic identifying journal format.
1340 ** - 4 bytes: Number of records in journal, or -1 no-sync mode is on.
1343 ** - 4 bytes: Sector size used by the process that wrote this journal.
1362 ** since the most recent journal header was written, update the
1375 ** journal header. Normally, zero is written to this value at this time.
1376 ** After the records are added to the journal (and the journal synced,
1381 ** reading the journal this value tells SQLite to assume that the
1382 ** rest of the journal file contains valid page records. This assumption
1383 ** is dangerous, as if a failure occurred whilst writing to the journal
1391 ** that garbage data is never appended to the journal file.
1423 ** journal header consumes to the journal file here. Then increment the
1437 ** to populate the entire journal header sector.
1450 ** The journal file must be open when this is called. A journal header file
1451 ** (JOURNAL_HDR_SZ bytes) is read from the current location in the journal
1452 ** file. The current location in the journal file is given by
1454 ** a description of the journal header format.
1459 ** is set to the value read from the journal header. SQLITE_OK is returned
1462 ** If the journal header file appears to be corrupted, SQLITE_DONE is
1464 ** cannot be read from the journal file an error code is returned.
1469 i64 journalSize, /* Size of the open journal file in bytes */
1475 i64 iHdrOff; /* Offset of journal header being read */
1480 ** journal file is too small for there to be a header stored at this
1489 /* Read in the first 8 bytes of the journal header. If they do not match
1490 ** the magic string found at the start of each journal header, return
1504 /* Read the first three 32-bit fields of the journal header: The nRec
1516 u32 iPageSize; /* Page-size field of journal header */
1517 u32 iSectorSize; /* Sector-size field of journal header */
1519 /* Read the page-size and sector-size journal header fields. */
1527 ** journal header to zero. In this case, assume that the Pager.pageSize
1543 /* If the either the page-size or sector-size in the journal-header is
1544 ** invalid, then the process that wrote the journal-header must have
1546 ** the journal file here.
1551 /* Update the page-size to match the value read from the journal.
1559 ** the process that created this journal. If this journal was
1573 ** Write the supplied master journal name into the journal file for pager
1574 ** pPager at the current location. The master journal name must be the last
1575 ** thing written to a journal file. If the pager is in full-sync mode, the
1576 ** journal file descriptor is advanced to the next sector boundary before
1580 ** + N bytes: Master journal filename in utf-8.
1581 ** + 4 bytes: N (length of master journal name in bytes, no nul-terminator).
1582 ** + 4 bytes: Master journal name checksum.
1585 ** The master journal page checksum is the sum of the bytes in the master
1586 ** journal name, where each byte is interpreted as a signed 8-bit integer.
1594 i64 iHdrOff; /* Offset of header in journal file */
1595 i64 jrnlSize; /* Size of journal file on disk */
1617 ** the master journal name. This is in case the previous page written to
1618 ** the journal has already been synced.
1625 /* Write the master journal data to the end of the journal file. If
1638 /* If the pager is in peristent-journal mode, then the physical
1639 ** journal-file may extend past the end of the master-journal name
1641 ** dangerous because the code to rollback a hot-journal file
1642 ** will not be able to find the master-journal name to determine
1643 ** whether or not the journal is hot.
1645 ** Easiest thing to do in this scenario is to truncate the journal
1681 ** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal
1725 ** not exhibit the UNDELETABLE_WHEN_OPEN property, the journal file is
1731 ** or not, any journal file left in the file-system will be treated
1732 ** as a hot-journal and rolled back the next time a read-transaction
1755 ** close the journal file when dropping the database lock. Otherwise
1823 ** the persistent error occurred, then the rollback journal may need
1825 ** it were a hot-journal).
1845 ** after rollback of a hot-journal, or if an error occurs while opening
1846 ** the journal file or writing the very first journal-header of a
1855 ** If the journal file is open, then it is "finalized". Once a journal
1857 ** transaction. Nor will it be considered to be a hot-journal by this
1858 ** or any other database connection. Exactly how a journal is finalized
1860 ** the current journal-mode (Pager.journalMode value), as follows:
1864 ** in-memory journal.
1870 ** The first 28 bytes of the journal file are zeroed. This invalidates
1871 ** the first journal header in the file, and hence the entire journal
1872 ** file. An invalid journal file cannot be rolled back.
1875 ** The journal file is closed and deleted using sqlite3OsDelete().
1878 ** the journal file is never used. Instead, if the journalMode is
1882 ** After the journal is finalized, the pager moves to PAGER_READER state.
1887 ** any of the IO operations to finalize the journal file or unlock the
1889 ** operation to finalize the journal file fails, then the code still
1892 ** to the first error encountered (the journal finalization one) is
1896 int rc = SQLITE_OK; /* Error code from journal finalization operation */
1904 ** 1. After a successful hot-journal rollback, it is called with
1923 /* Finalize the journal file. */
1941 ** a hot-journal was just rolled back. In this case the journal
1943 ** the database file, it will do so using an in-memory journal.
2001 ** means that there is a hot-journal left in the file-system, the next
2036 ** incompatible journal file format.
2038 ** If journal corruption occurs due to a power failure, the most likely
2040 ** It is much less likely that the two ends of the journal record will be
2070 ** Read a single page from either the journal file (if isMainJrnl==1) or
2071 ** from the sub-journal (if isMainJrnl==0) and playback that page.
2073 ** value is increased to the start of the next page in the journal.
2075 ** The main rollback journal uses checksums - the statement journal does
2078 ** If the page number of the page record read from the (sub-)journal file
2088 ** If the page record is successfully read from the (sub-)journal file
2090 ** while reading the record from the (sub-)journal file or while writing
2092 ** is successfully read from the (sub-)journal file but appears to be
2097 ** * If the record is being rolled back from the main journal file
2110 int isMainJrnl, /* 1 -> main journal. 0 -> sub-journal. */
2115 Pgno pgno; /* The page number of a page in journal */
2118 sqlite3_file *jfd; /* The file descriptor for the journal file */
2119 int isSynced; /* True if journal page is synced */
2132 ** a hot-journal rollback. If it is a hot-journal rollback, the pager
2133 ** is in state OPEN and holds an EXCLUSIVE lock. Hot-journal rollback
2134 ** only reads from the main journal, not the sub-journal.
2141 /* Read the page number and page data from the journal or sub-journal
2152 ** thought. If a power failure occurs while the journal is being written,
2153 ** it could cause invalid data to be written into the journal. We need to
2199 ** a hot-journal rollback, it is guaranteed that the page-cache is empty
2202 ** Ticket #1171: The statement journal might contain page content that is
2208 ** journal. Otherwise, a power loss might leave modified data in the
2209 ** database file without an entry in the rollback journal that can
2213 ** in the main journal either because the page is not in cache or else
2229 (isMainJrnl?"main-journal":"sub-journal")
2265 ** the data just read from the sub-journal. Mark the page as dirty
2266 ** and if the pager requires a journal-sync, then mark the page as
2267 ** requiring a journal-sync before it is written.
2292 ** journal file, then its content must be as they were when the
2299 ** unsynced portion of the main journal file, then it is not safe
2302 ** already in the journal file (recorded in Pager.pInJournal) and
2306 ** be written out into the database file before its journal file
2329 ** Parameter zMaster is the name of a master journal file. A single journal
2330 ** file that referred to the master journal file has just been rolled back.
2331 ** This routine checks if it is possible to delete the master journal file,
2337 ** When a master journal file is created, it is populated with the names
2339 ** encoded text. The end of each child journal file is marked with a
2340 ** nul-terminator byte (0x00). i.e. the entire contents of a master journal
2343 ** "/home/bill/a.db-journal\x00/home/bill/b.db-journal\x00"
2345 ** A master journal file may only be deleted once all of its child
2348 ** This function reads the contents of the master-journal file into
2349 ** memory and loops through each of the child journal names. For
2350 ** each child journal, it checks if:
2352 ** * if the child journal exists, and if so
2353 ** * if the child journal contains a reference to master journal
2356 ** If a child journal can be found that matches both of the criteria
2358 ** no such child journal can be found, file zMaster is deleted from
2367 ** the entire contents of the master journal file. This could be
2374 sqlite3_file *pMaster; /* Malloc'd master-journal file descriptor */
2375 sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
2376 char *zMasterJournal = 0; /* Contents of master journal file */
2377 i64 nMasterJournal; /* Size of master journal file */
2378 char *zJournal; /* Pointer to one journal within MJ file */
2379 char *zMasterPtr; /* Space to hold MJ filename from a journal file */
2383 ** If successful, open the master journal file for reading.
2395 /* Load the entire master journal file into space obtained from
2398 ** journal files extracted from regular rollback-journals.
2421 /* One of the journals pointed to by the master journal exists.
2422 ** Open it and check if it points at the master journal. If
2423 ** so, return without deleting the master journal file.
2440 /* We have a match. Do not delete the master journal file. */
2464 ** or rolling back a transaction (including rolling back a hot-journal).
2518 ** to determine the size and alignment of journal header and
2519 ** master journal pointers within created journal files.
2548 ** Playback the journal and thus restore the database file to
2551 ** The journal file format is as follows:
2555 ** in the journal. If this value is 0xffffffff, then compute the
2556 ** number of page records from the journal size.
2570 ** When we speak of the journal header, we mean the first 7 items above.
2571 ** Each entry in the journal is an instance of the 8th item.
2574 ** valid page entries in the journal. In most cases, you can compute the
2575 ** value of nRec from the size of the journal file. But if a power
2576 ** failure occurred while the journal was being written, it could be the
2577 ** case that the size of the journal file had already been increased but
2584 ** no-sync option for the journal. A power failure could lead to corruption
2588 ** If the file opened as the journal file is not a well-formed
2589 ** journal file then all pages up to the first corrupted page are rolled
2590 ** back (or no pages if the journal header is corrupted). The journal file
2594 ** If an I/O or malloc() error occurs, the journal-file is not deleted
2597 ** The isHot parameter indicates that we are trying to rollback a journal
2598 ** that might be a hot journal. Or, it could be that the journal is
2600 ** If the journal really is hot, reset the pager cache prior rolling
2601 ** back any content. If the journal is merely persistent, no reset is
2606 i64 szJ; /* Size of the journal file in bytes */
2607 u32 nRec; /* Number of Records in the journal */
2612 char *zMaster = 0; /* Name of master journal file if any */
2615 /* Figure out how many records are in the journal. Abort early if
2616 ** the journal is empty.
2624 /* Read the master journal name from the journal, if it is present.
2625 ** If a master journal file name is specified, but the file is not
2626 ** present on disk, then the journal is not hot and does not need to be
2652 /* Read the next journal header from the journal file. If there are
2653 ** not enough bytes left in the journal file for a complete header, or
2665 /* If nRec is 0xffffffff, then this journal was created by a process
2666 ** working in no-sync mode. This means that the rest of the journal
2667 ** file consists of pages, there are no more journal headers. Compute
2676 ** process and if this is the final header in the journal, then it means
2677 ** that this part of the journal was being filled but has not yet been
2682 ** When rolling back a hot journal, nRec==0 always means that the next
2683 ** chunk of the journal contains zero pages to be rolled back. But
2685 ** the journal, it means that the journal might contain additional
2687 ** should be computed based on the journal file size.
2694 /* If this is the first header read from the journal, truncate the
2705 /* Copy original pages out of the journal and back into the
2720 /* If the journal has been truncated, simply stop reading and
2721 ** processing the journal. This might happen if the journal was
2778 /* If there was a master journal and this routine will return success,
2779 ** see if it is possible to delete the master journal.
2786 ** back a journal created by a process with a different sector size
2918 ** updated as data is copied out of the rollback journal and into the
3158 ** the entire master journal file. The case pSavepoint==NULL occurs when
3166 ** * Pages are played back from the main journal starting at byte
3168 ** PagerSavepoint.iHdrOffset, or to the end of the main journal
3172 ** back starting from the journal header immediately following
3173 ** PagerSavepoint.iHdrOffset to the end of the main journal file.
3175 ** * Pages are then played back from the sub-journal file, starting
3177 ** the journal file.
3182 ** rolled back the first time it is encountered in either journal.
3185 ** journal file. There is no need for a bitvec in this case.
3193 i64 szJ; /* Effective size of the main journal */
3194 i64 iHdrOff; /* End of first segment of main-journal records */
3220 ** journal. The actual file might be larger than this in
3227 /* Begin by rolling back records from the main journal starting at
3228 ** PagerSavepoint.iOffset and continuing to the next journal header.
3229 ** There might be records in the main journal that have a page number
3245 /* Continue rolling back records out of the main journal starting at
3246 ** the first journal header seen and continuing until the effective end
3247 ** of the main journal file. Continue to skip out-of-range pages and
3274 /* Finally, rollback pages from the sub-journal. Page that were
3275 ** previously rolled back out of the main journal (and are hence in pDone)
3310 ** the rollback journal. There are three levels:
3315 ** NORMAL The journal is synced once before writes begin on the
3318 ** that an inopertune power failure could leave the journal
3322 ** FULL The journal is synced twice before writes begin on the
3324 ** of the journal header - being written in between the two
3327 ** assurance that the journal will not be corrupted to the
3330 ** The above is for a rollback-journal mode. For WAL mode, OFF continues
3426 ** (which occurs during hot-journal rollback). Summary:
3670 ** be necessary to write the current content out to the sub-journal
3679 ** the database file or the portion of the rollback journal and
3680 ** sub-journal rolled back the content could not be restored and the
3711 ** This function is called before attempting a hot-journal rollback. It
3712 ** syncs the journal file to disk, then sets pPager->journalHdr to the
3713 ** size of the journal file so that the pager_playback() routine knows
3714 ** that the entire journal file has been synced.
3716 ** Syncing a hot-journal to disk before attempting to roll it back ensures
3718 ** attempts rollback following system recovery sees the same journal
3746 ** a hot journal may be left in the filesystem but no error is returned
3764 /* If it is open, sync the journal file before calling UnlockAndRollback.
3765 ** If this is not done, then an unsynced portion of the open journal
3769 ** If an error occurs while trying to sync the journal, shift the pager
3771 ** database and close the journal file without attempting to roll it
3772 ** back or finalize it. The next database user will have to do hot-journal
3817 ** Sync the journal. In other words, make sure all the pages that have
3818 ** been written to the journal have actually reached the surface of the
3819 ** disk and can be restored in the event of a hot-journal rollback.
3822 ** Otherwise, the actions required depend on the journal-mode and the
3825 ** * If the journal file is an in-memory journal file, no action need
3829 ** then the nRec field of the most recently written journal header
3830 ** is updated to contain the number of journal records that have
3832 ** mode, then the journal file is synced before this field is updated.
3835 ** journal file is synced.
3839 ** if( NOT <in-memory journal> ){
3841 ** if( <full-sync mode> ) xSync(<journal file>);
3844 ** if( NOT SEQUENTIAL ) xSync(<journal file>);
3871 ** that wrote to this database was operating in persistent-journal
3872 ** mode, then the journal file may at this point actually be larger
3873 ** than Pager.journalOff bytes. If the next thing in the journal
3874 ** file happens to be a journal-header (written as part of the
3877 ** anything else to the journal file (or commits/rolls back its
3879 ** hot-journal rollback following recovery. It may roll back all
3883 ** To work around this, if the journal file does appear to contain
3890 ** the potential journal header.
3909 /* Write the nRec value into the journal file header. If in
3910 ** full-synchronous mode, sync the journal first. This ensures that
3917 ** is populated with 0xFFFFFFFF when the journal header is written
3921 PAGERTRACE(("SYNC journal of %d\n", PAGERID(pPager)));
3933 PAGERTRACE(("SYNC journal of %d\n", PAGERID(pPager)));
3952 /* Unless the pager is in noSync mode, the journal file was just
4075 ** Ensure that the sub-journal file is open. If it is already open, this
4095 ** Append a record of the current state of page pPg to the sub-journal.
4103 ** error code if the attempt to write to the sub-journal fails, or
4112 /* Open the sub-journal, if it has not already been opened */
4122 /* If the sub-journal was opened successfully (or was already open),
4123 ** write the journal record into the file. */
4156 ** journal file.
4172 ** journal (and adding a new header) is not allowed. This occurs
4173 ** during calls to sqlite3PagerWrite() while trying to journal multiple
4203 /* Sync the journal file if required. */
4211 ** the database image, it may need to be written to the sub-journal.
4218 ** <journal page X>
4233 ** sub-journal file now (if it is not already there), so that it will
4305 int journalFileSize; /* Bytes to allocate for each journal fd */
4308 int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */
4313 /* Figure out how much space is required for each journal file-handle
4314 ** (there are two of them, the main journal and the sub-journal). This
4315 ** is the maximum space required for an in-memory journal file handle
4316 ** and a regular journal file-handle. Note that a "regular journal-handle"
4317 ** may be a wrapper capable of caching the first portion of the journal
4319 ** source file journal.c).
4351 /* This branch is taken when the journal path required by
4354 ** as it will not be possible to open the journal file or even
4355 ** check for a hot-journal before reading.
4366 ** three file descriptors, the database file name and the journal
4372 ** Sub-journal file handle (journalFileSize bytes)
4373 ** Main journal file handle (journalFileSize bytes)
4381 journalFileSize * 2 + /* The two journal files */
4407 memcpy(&pPager->zJournal[nPathname], "-journal", 8);
4466 ** disk and uses an in-memory rollback journal.
4554 ** PAGER_SHARED state. It tests if there is a hot journal present in
4555 ** the file-system for the given pager. A hot journal is one that
4556 ** needs to be played back. According to this function, a hot-journal
4559 ** * The journal file exists in the file system, and
4562 ** * The first byte of the journal file exists and is not 0x00.
4564 ** If the current size of the database file is 0 but a journal file
4565 ** exists, that is probably an old journal left over from a prior
4566 ** database with the same name. In this case the journal file is
4570 ** This routine does not check if there is a master journal filename
4571 ** at the end of the file. If there is, and that master journal file
4572 ** does not exist, then the journal file is not really hot. In this
4574 ** routine will discover that the journal file is not really hot and
4577 ** If a hot-journal file is found to exist, *pExists is set to 1 and
4578 ** SQLITE_OK returned. If no hot-journal file is present, *pExists is
4580 ** to determine whether or not a hot-journal file exists, the IO error
4586 int exists = 1; /* True if a journal file is present */
4605 ** the RESERVED lock and have a journal open at the sqlite3OsAccess()
4606 ** call above, but then delete the journal and drop the lock before
4608 ** is the case, this routine might think there is a hot journal when
4617 ** then delete the journal file. See the header comment above for
4618 ** the reasoning here. Delete the obsolete journal file under
4632 /* The journal file exists and no other connection has a reserved
4634 ** at least one non-zero bytes at the start of the journal file.
4635 ** If there is, then we consider this journal to be hot. If not,
4653 /* If we cannot open the rollback journal file in order to see if
4656 ** ticket #3883. Either way, assume that the journal is hot.
4658 ** automatic journal playback and recovery mechanism will deal
4684 ** the SHARED lock, the file-system is checked for a hot-journal,
4685 ** which is played back if present. Following any hot-journal
4693 ** the contents of the page cache and rolling back any open journal
4697 ** occurs while locking the database, checking for a hot-journal file or
4698 ** rolling back a journal file, the IO error code is returned.
4714 int bHotJournal = 1; /* True if there exists a hot journal-file */
4727 /* If a journal file exists, and there is no RESERVED lock on the
4742 ** hot-journal back.
4758 ** journal for read/write access. Write access is required because
4761 ** is usually required to finalize the journal in journal_mode=persist
4764 ** If the journal does not exist, it usually means that some
4768 ** function was called and the journal file does not exist.
4772 int bExists; /* True if journal file exists */
4788 /* Playback and delete the journal. Drop the database write
4790 ** playing back the hot-journal so that we don't end up with
4791 ** an inconsistent cache. Sync the hot journal before playing
4792 ** it back since the process that crashed and left the hot journal
4794 ** the journal before playing it back.
4809 ** or roll back a hot-journal while holding an EXCLUSIVE lock. The
4908 ** the rollback journal, the unlock is not performed and there is
4946 ** from the savepoint journal.
4951 ** journal file) and the PagerSavepoint.pInSavepoint bitvecs of any open
4963 ** has to go to disk, and could also playback an old journal if necessary.
4965 ** or journal files.
5049 ** It merely means that we might do some extra work to journal a
5152 ** Open the journal file for pager pPager and write a journal header
5153 ** to the start of it. If there are active savepoints, open the sub-journal
5154 ** as well. This function is only used when the journal file is being
5156 ** when opening a hot journal file to roll it back.
5158 ** If the journal file is already open (as it may be in exclusive mode),
5159 ** then this function just writes a journal header to the start of the
5162 ** Whether or not the journal file is opened by this function, the
5167 ** an IO error code if opening or writing the journal file fails.
5188 /* Open the journal file if it is not already open. */
5193 const int flags = /* VFS flags to open journal file */
5207 /* Set the TimeMachine exclusion metadata for the journal if it has
5216 CFURLRef journal = create_cfurl_from_cstring(pPager->zJournal);
5218 CSBackupSetItemExcluded(journal, TRUE, FALSE);
5219 CFRelease(journal);
5229 /* Write the first journal header to the journal file and open
5230 ** the sub-journal if necessary.
5262 ** If the subjInMemory argument is non-zero, then any sub-journal opened
5264 ** has no effect if the sub-journal is already opened (as it may be when
5266 ** sub-journal. If the subjInMemory argument is zero, then any required
5267 ** sub-journal is implemented in-memory if pPager is an in-memory database,
5316 ** transactions may copy data from the sub-journal into the database
5338 ** main journal or sub-journal as required. If the page is written into
5349 ** been started. The journal file may or may not be open at this point.
5368 /* The journal file needs to be opened. Higher level routines have already
5370 ** rollback journal might not yet be open. Open it now if this is the case.
5385 ** to the journal then we can return right away.
5392 /* The transaction journal now exists and we have a RESERVED or an
5394 ** the transaction journal if it is not there already.
5403 /* We should never write to the journal file the page that
5456 /* If the statement journal is open and the page is not in it,
5457 ** then write the current page to the statement journal. Note that
5458 ** the statement journal format differs from the standard journal format
5483 ** must have been written to the journal file before returning.
5502 int nPage = 0; /* Number of pages starting at pg1 to journal */
5507 ** a journal header to be written between the pages journaled by
5557 ** journal file must contain sync()ed copies of all of them
5751 ** of a master journal file that should be written into the individual
5752 ** journal file. zMaster may be NULL, which is interpreted as no master
5753 ** journal (a single database transaction).
5758 ** * the journal is synced (unless the atomic-write optimization is used),
5764 ** (delete, truncate or zero the first part of) the journal file (or
5765 ** delete the master journal file if specified).
5773 ** journal file in this case.
5777 const char *zMaster, /* If not NULL, the master journal name */
5834 ** * Exactly one page has been modified and store in the journal file.
5840 ** to make sure the journal file has actually been created, then call
5846 ** in 'direct' mode. In this case the journal file will never be
5879 ** being discarded by the truncation must be written to the journal
5898 PgHdr *pPage; /* Page to journal */
5910 /* Write the master journal name into the journal file. If a master
5911 ** journal file name has already been written to the journal file,
5912 ** or if zMaster is NULL (no master journal), then this call is a no-op.
5917 /* Sync the journal file and write all dirty pages to the database.
5919 ** create the journal file or perform any real IO.
5923 ** journal requires a sync here. However, in locking_mode=exclusive
5967 ** synced to disk. The journal file still exists in the file-system
5969 ** be used as a hot-journal and the current transaction rolled back.
5971 ** This function finalizes the journal file, either by deleting,
5973 ** for hot-journal rollback. Once this is done the transaction is
5997 ** The start of the journal file currently contains a single journal
5998 ** header with the nRec field set to 0. If such a journal is used as
5999 ** a hot-journal during hot-journal rollback, 0 changes will be made
6000 ** to the database file. So there is no need to zero the journal
6029 ** 1) It rolls back the journal file, restoring all database file and
6033 ** 2) It finalizes the journal file, so that it is not used for hot
6036 ** Finalization of the journal file (task 2) is only performed if the
6155 ** occurs while opening the sub-journal file, then an IO error code is
6258 ** the sub-journal to zero bytes in size. */
6261 /* Only truncate if it is an in-memory sub-journal. */
6270 ** If this is a temp-file, it is possible that the journal file has
6308 ** Return the full pathname of the journal file.
6352 ** in the rollback journal, it is not put there by by this routine.
6383 /* In order to be able to rollback, an in-memory database must journal
6393 ** sub-journal now. This is required to handle the following scenario:
6396 ** <journal page X, then modify it in memory>
6401 ** If page X were not written to the sub-journal here, it would not
6420 /* If the journal needs to be sync()ed before page pPg->pgno can
6424 ** the journal needs to be sync()ed before database page pPg->pgno
6467 /* If needSyncPgno is non-zero, then the journal file needs to be
6478 ** it is synced into the journal file. This way, it may end up in
6479 ** the journal file twice, but that is not a problem.
6668 ** Set the journal-mode for this pager. Parameter eMode must be one of:
6685 ** The returned indicate the current (possibly updated) journal-mode.
6723 /* Change the journal mode. */
6727 /* When transistioning from TRUNCATE or PERSIST to any other journal
6729 ** delete the journal file.
6741 /* In this case we would like to delete the journal file. If it is
6742 ** not possible, then that is not a problem. Deleting the journal file
6745 ** Before deleting the journal file, obtain a RESERVED lock on the
6746 ** database file. This ensures that the journal file is not deleted
6776 /* Return the new journal mode */
6781 ** Return the current journal mode.
6800 ** Get/set the size-limit used for persistent journal files.
6937 /* Close any rollback journal previously open */