Lines Matching refs: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.
823 /* If the useJournal flag is clear, the journal-mode must be "OFF".
824 ** And if the journal-mode is "OFF", the journal file must not be open.
829 /* Check that MEMDB implies noSync. And an in-memory journal. Since
832 ** a journal file. (although the in-memory journal implementation may
833 ** return SQLITE_IOERR_NOMEM while the journal file is being written). It
882 ** journal file nor the WAL file are open. This happens during
984 ** Return true if it is necessary to write page *pPg into the sub-journal.
985 ** A page needs to be written into the sub-journal if there exists one
1006 ** Return true if the page is already in the journal file.
1108 ** then the value returned is the size of the journal file when it
1179 ** When this is called the journal file for pager pPager must be open.
1180 ** This function attempts to read a master journal file name from the
1183 ** used to store a master journal file name at the end of a journal file.
1187 ** enough space to write the master journal name). If the master journal
1188 ** name in the journal is longer than nMaster bytes (including a
1189 ** nul-terminator), then this is handled as if no master journal name
1190 ** were present in the journal.
1192 ** If a master journal file name is present at the end of the journal
1195 ** journal file name.
1197 ** If it is determined that no master journal file name is present
1200 ** If an error occurs while reading from the journal file, an SQLite
1205 u32 len; /* Length in bytes of master journal name */
1206 i64 szJ; /* Total size in bytes of journal file pJrnl */
1207 u32 cksum; /* MJ checksum value read from journal */
1224 /* See if the checksum matches the master journal name */
1230 ** containing the master journal filename is corrupted. This means
1232 ** master-journal filename.
1269 ** The journal file must be open when this function is called.
1271 ** This function is a no-op if the journal file has not been written to
1275 ** set to 0, then truncate the journal file to zero bytes in size. Otherwise,
1276 ** zero the 28-byte header at the start of the journal file. In either case,
1277 ** if the pager is not in no-sync mode, sync the journal file immediately
1282 ** journal file in bytes is larger than this value, then truncate the
1283 ** journal file to Pager.journalSizeLimit bytes. The journal file does
1308 ** the persistent journal and the journal file currently consumes more
1324 ** The journal file must be open when this routine is called. A journal
1325 ** header (JOURNAL_HDR_SZ bytes) is written into the journal file at the
1328 ** The format for the journal header is as follows:
1329 ** - 8 bytes: Magic identifying journal format.
1330 ** - 4 bytes: Number of records in journal, or -1 no-sync mode is on.
1333 ** - 4 bytes: Sector size used by the process that wrote this journal.
1352 ** since the most recent journal header was written, update the
1365 ** journal header. Normally, zero is written to this value at this time.
1366 ** After the records are added to the journal (and the journal synced,
1371 ** reading the journal this value tells SQLite to assume that the
1372 ** rest of the journal file contains valid page records. This assumption
1373 ** is dangerous, as if a failure occurred whilst writing to the journal
1381 ** that garbage data is never appended to the journal file.
1413 ** journal header consumes to the journal file here. Then increment the
1427 ** to populate the entire journal header sector.
1440 ** The journal file must be open when this is called. A journal header file
1441 ** (JOURNAL_HDR_SZ bytes) is read from the current location in the journal
1442 ** file. The current location in the journal file is given by
1444 ** a description of the journal header format.
1449 ** is set to the value read from the journal header. SQLITE_OK is returned
1452 ** If the journal header file appears to be corrupted, SQLITE_DONE is
1454 ** cannot be read from the journal file an error code is returned.
1459 i64 journalSize, /* Size of the open journal file in bytes */
1465 i64 iHdrOff; /* Offset of journal header being read */
1470 ** journal file is too small for there to be a header stored at this
1479 /* Read in the first 8 bytes of the journal header. If they do not match
1480 ** the magic string found at the start of each journal header, return
1494 /* Read the first three 32-bit fields of the journal header: The nRec
1506 u32 iPageSize; /* Page-size field of journal header */
1507 u32 iSectorSize; /* Sector-size field of journal header */
1509 /* Read the page-size and sector-size journal header fields. */
1517 ** journal header to zero. In this case, assume that the Pager.pageSize
1533 /* If the either the page-size or sector-size in the journal-header is
1534 ** invalid, then the process that wrote the journal-header must have
1536 ** the journal file here.
1541 /* Update the page-size to match the value read from the journal.
1549 ** the process that created this journal. If this journal was
1563 ** Write the supplied master journal name into the journal file for pager
1564 ** pPager at the current location. The master journal name must be the last
1565 ** thing written to a journal file. If the pager is in full-sync mode, the
1566 ** journal file descriptor is advanced to the next sector boundary before
1570 ** + N bytes: Master journal filename in utf-8.
1571 ** + 4 bytes: N (length of master journal name in bytes, no nul-terminator).
1572 ** + 4 bytes: Master journal name checksum.
1575 ** The master journal page checksum is the sum of the bytes in the master
1576 ** journal name, where each byte is interpreted as a signed 8-bit integer.
1584 i64 iHdrOff; /* Offset of header in journal file */
1585 i64 jrnlSize; /* Size of journal file on disk */
1607 ** the master journal name. This is in case the previous page written to
1608 ** the journal has already been synced.
1615 /* Write the master journal data to the end of the journal file. If
1628 /* If the pager is in peristent-journal mode, then the physical
1629 ** journal-file may extend past the end of the master-journal name
1631 ** dangerous because the code to rollback a hot-journal file
1632 ** will not be able to find the master-journal name to determine
1633 ** whether or not the journal is hot.
1635 ** Easiest thing to do in this scenario is to truncate the journal
1671 ** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal
1715 ** not exhibit the UNDELETABLE_WHEN_OPEN property, the journal file is
1721 ** or not, any journal file left in the file-system will be treated
1722 ** as a hot-journal and rolled back the next time a read-transaction
1745 ** close the journal file when dropping the database lock. Otherwise
1813 ** the persistent error occurred, then the rollback journal may need
1815 ** it were a hot-journal).
1835 ** after rollback of a hot-journal, or if an error occurs while opening
1836 ** the journal file or writing the very first journal-header of a
1845 ** If the journal file is open, then it is "finalized". Once a journal
1847 ** transaction. Nor will it be considered to be a hot-journal by this
1848 ** or any other database connection. Exactly how a journal is finalized
1850 ** the current journal-mode (Pager.journalMode value), as follows:
1854 ** in-memory journal.
1860 ** The first 28 bytes of the journal file are zeroed. This invalidates
1861 ** the first journal header in the file, and hence the entire journal
1862 ** file. An invalid journal file cannot be rolled back.
1865 ** The journal file is closed and deleted using sqlite3OsDelete().
1868 ** the journal file is never used. Instead, if the journalMode is
1872 ** After the journal is finalized, the pager moves to PAGER_READER state.
1877 ** any of the IO operations to finalize the journal file or unlock the
1879 ** operation to finalize the journal file fails, then the code still
1882 ** to the first error encountered (the journal finalization one) is
1886 int rc = SQLITE_OK; /* Error code from journal finalization operation */
1894 ** 1. After a successful hot-journal rollback, it is called with
1913 /* Finalize the journal file. */
1931 ** a hot-journal was just rolled back. In this case the journal
1933 ** the database file, it will do so using an in-memory journal.
1991 ** means that there is a hot-journal left in the file-system, the next
2026 ** incompatible journal file format.
2028 ** If journal corruption occurs due to a power failure, the most likely
2030 ** It is much less likely that the two ends of the journal record will be
2060 ** Read a single page from either the journal file (if isMainJrnl==1) or
2061 ** from the sub-journal (if isMainJrnl==0) and playback that page.
2063 ** value is increased to the start of the next page in the journal.
2065 ** The main rollback journal uses checksums - the statement journal does
2068 ** If the page number of the page record read from the (sub-)journal file
2078 ** If the page record is successfully read from the (sub-)journal file
2080 ** while reading the record from the (sub-)journal file or while writing
2082 ** is successfully read from the (sub-)journal file but appears to be
2087 ** * If the record is being rolled back from the main journal file
2100 int isMainJrnl, /* 1 -> main journal. 0 -> sub-journal. */
2105 Pgno pgno; /* The page number of a page in journal */
2108 sqlite3_file *jfd; /* The file descriptor for the journal file */
2109 int isSynced; /* True if journal page is synced */
2122 ** a hot-journal rollback. If it is a hot-journal rollback, the pager
2123 ** is in state OPEN and holds an EXCLUSIVE lock. Hot-journal rollback
2124 ** only reads from the main journal, not the sub-journal.
2131 /* Read the page number and page data from the journal or sub-journal
2142 ** thought. If a power failure occurs while the journal is being written,
2143 ** it could cause invalid data to be written into the journal. We need to
2189 ** a hot-journal rollback, it is guaranteed that the page-cache is empty
2192 ** Ticket #1171: The statement journal might contain page content that is
2198 ** journal. Otherwise, a power loss might leave modified data in the
2199 ** database file without an entry in the rollback journal that can
2203 ** in the main journal either because the page is not in cache or else
2219 (isMainJrnl?"main-journal":"sub-journal")
2255 ** the data just read from the sub-journal. Mark the page as dirty
2256 ** and if the pager requires a journal-sync, then mark the page as
2257 ** requiring a journal-sync before it is written.
2282 ** journal file, then its content must be as they were when the
2289 ** unsynced portion of the main journal file, then it is not safe
2292 ** already in the journal file (recorded in Pager.pInJournal) and
2296 ** be written out into the database file before its journal file
2319 ** Parameter zMaster is the name of a master journal file. A single journal
2320 ** file that referred to the master journal file has just been rolled back.
2321 ** This routine checks if it is possible to delete the master journal file,
2327 ** When a master journal file is created, it is populated with the names
2329 ** encoded text. The end of each child journal file is marked with a
2330 ** nul-terminator byte (0x00). i.e. the entire contents of a master journal
2333 ** "/home/bill/a.db-journal\x00/home/bill/b.db-journal\x00"
2335 ** A master journal file may only be deleted once all of its child
2338 ** This function reads the contents of the master-journal file into
2339 ** memory and loops through each of the child journal names. For
2340 ** each child journal, it checks if:
2342 ** * if the child journal exists, and if so
2343 ** * if the child journal contains a reference to master journal
2346 ** If a child journal can be found that matches both of the criteria
2348 ** no such child journal can be found, file zMaster is deleted from
2357 ** the entire contents of the master journal file. This could be
2364 sqlite3_file *pMaster; /* Malloc'd master-journal file descriptor */
2365 sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
2366 char *zMasterJournal = 0; /* Contents of master journal file */
2367 i64 nMasterJournal; /* Size of master journal file */
2368 char *zJournal; /* Pointer to one journal within MJ file */
2369 char *zMasterPtr; /* Space to hold MJ filename from a journal file */
2373 ** If successful, open the master journal file for reading.
2385 /* Load the entire master journal file into space obtained from
2388 ** journal files extracted from regular rollback-journals.
2411 /* One of the journals pointed to by the master journal exists.
2412 ** Open it and check if it points at the master journal. If
2413 ** so, return without deleting the master journal file.
2430 /* We have a match. Do not delete the master journal file. */
2454 ** or rolling back a transaction (including rolling back a hot-journal).
2508 ** to determine the size and alignment of journal header and
2509 ** master journal pointers within created journal files.
2538 ** Playback the journal and thus restore the database file to
2541 ** The journal file format is as follows:
2545 ** in the journal. If this value is 0xffffffff, then compute the
2546 ** number of page records from the journal size.
2560 ** When we speak of the journal header, we mean the first 7 items above.
2561 ** Each entry in the journal is an instance of the 8th item.
2564 ** valid page entries in the journal. In most cases, you can compute the
2565 ** value of nRec from the size of the journal file. But if a power
2566 ** failure occurred while the journal was being written, it could be the
2567 ** case that the size of the journal file had already been increased but
2574 ** no-sync option for the journal. A power failure could lead to corruption
2578 ** If the file opened as the journal file is not a well-formed
2579 ** journal file then all pages up to the first corrupted page are rolled
2580 ** back (or no pages if the journal header is corrupted). The journal file
2584 ** If an I/O or malloc() error occurs, the journal-file is not deleted
2587 ** The isHot parameter indicates that we are trying to rollback a journal
2588 ** that might be a hot journal. Or, it could be that the journal is
2590 ** If the journal really is hot, reset the pager cache prior rolling
2591 ** back any content. If the journal is merely persistent, no reset is
2596 i64 szJ; /* Size of the journal file in bytes */
2597 u32 nRec; /* Number of Records in the journal */
2602 char *zMaster = 0; /* Name of master journal file if any */
2605 /* Figure out how many records are in the journal. Abort early if
2606 ** the journal is empty.
2614 /* Read the master journal name from the journal, if it is present.
2615 ** If a master journal file name is specified, but the file is not
2616 ** present on disk, then the journal is not hot and does not need to be
2642 /* Read the next journal header from the journal file. If there are
2643 ** not enough bytes left in the journal file for a complete header, or
2655 /* If nRec is 0xffffffff, then this journal was created by a process
2656 ** working in no-sync mode. This means that the rest of the journal
2657 ** file consists of pages, there are no more journal headers. Compute
2666 ** process and if this is the final header in the journal, then it means
2667 ** that this part of the journal was being filled but has not yet been
2672 ** When rolling back a hot journal, nRec==0 always means that the next
2673 ** chunk of the journal contains zero pages to be rolled back. But
2675 ** the journal, it means that the journal might contain additional
2677 ** should be computed based on the journal file size.
2684 /* If this is the first header read from the journal, truncate the
2695 /* Copy original pages out of the journal and back into the
2710 /* If the journal has been truncated, simply stop reading and
2711 ** processing the journal. This might happen if the journal was
2768 /* If there was a master journal and this routine will return success,
2769 ** see if it is possible to delete the master journal.
2776 ** back a journal created by a process with a different sector size
2908 ** updated as data is copied out of the rollback journal and into the
3148 ** the entire master journal file. The case pSavepoint==NULL occurs when
3156 ** * Pages are played back from the main journal starting at byte
3158 ** PagerSavepoint.iHdrOffset, or to the end of the main journal
3162 ** back starting from the journal header immediately following
3163 ** PagerSavepoint.iHdrOffset to the end of the main journal file.
3165 ** * Pages are then played back from the sub-journal file, starting
3167 ** the journal file.
3172 ** rolled back the first time it is encountered in either journal.
3175 ** journal file. There is no need for a bitvec in this case.
3183 i64 szJ; /* Effective size of the main journal */
3184 i64 iHdrOff; /* End of first segment of main-journal records */
3210 ** journal. The actual file might be larger than this in
3217 /* Begin by rolling back records from the main journal starting at
3218 ** PagerSavepoint.iOffset and continuing to the next journal header.
3219 ** There might be records in the main journal that have a page number
3235 /* Continue rolling back records out of the main journal starting at
3236 ** the first journal header seen and continuing until the effective end
3237 ** of the main journal file. Continue to skip out-of-range pages and
3264 /* Finally, rollback pages from the sub-journal. Page that were
3265 ** previously rolled back out of the main journal (and are hence in pDone)
3300 ** the rollback journal. There are three levels:
3305 ** NORMAL The journal is synced once before writes begin on the
3308 ** that an inopertune power failure could leave the journal
3312 ** FULL The journal is synced twice before writes begin on the
3314 ** of the journal header - being written in between the two
3317 ** assurance that the journal will not be corrupted to the
3320 ** The above is for a rollback-journal mode. For WAL mode, OFF continues
3416 ** (which occurs during hot-journal rollback). Summary:
3660 ** be necessary to write the current content out to the sub-journal
3669 ** the database file or the portion of the rollback journal and
3670 ** sub-journal rolled back the content could not be restored and the
3701 ** This function is called before attempting a hot-journal rollback. It
3702 ** syncs the journal file to disk, then sets pPager->journalHdr to the
3703 ** size of the journal file so that the pager_playback() routine knows
3704 ** that the entire journal file has been synced.
3706 ** Syncing a hot-journal to disk before attempting to roll it back ensures
3708 ** attempts rollback following system recovery sees the same journal
3736 ** a hot journal may be left in the filesystem but no error is returned
3754 /* If it is open, sync the journal file before calling UnlockAndRollback.
3755 ** If this is not done, then an unsynced portion of the open journal
3759 ** If an error occurs while trying to sync the journal, shift the pager
3761 ** database and close the journal file without attempting to roll it
3762 ** back or finalize it. The next database user will have to do hot-journal
3807 ** Sync the journal. In other words, make sure all the pages that have
3808 ** been written to the journal have actually reached the surface of the
3809 ** disk and can be restored in the event of a hot-journal rollback.
3812 ** Otherwise, the actions required depend on the journal-mode and the
3815 ** * If the journal file is an in-memory journal file, no action need
3819 ** then the nRec field of the most recently written journal header
3820 ** is updated to contain the number of journal records that have
3822 ** mode, then the journal file is synced before this field is updated.
3825 ** journal file is synced.
3829 ** if( NOT <in-memory journal> ){
3831 ** if( <full-sync mode> ) xSync(<journal file>);
3834 ** if( NOT SEQUENTIAL ) xSync(<journal file>);
3861 ** that wrote to this database was operating in persistent-journal
3862 ** mode, then the journal file may at this point actually be larger
3863 ** than Pager.journalOff bytes. If the next thing in the journal
3864 ** file happens to be a journal-header (written as part of the
3867 ** anything else to the journal file (or commits/rolls back its
3869 ** hot-journal rollback following recovery. It may roll back all
3873 ** To work around this, if the journal file does appear to contain
3880 ** the potential journal header.
3899 /* Write the nRec value into the journal file header. If in
3900 ** full-synchronous mode, sync the journal first. This ensures that
3907 ** is populated with 0xFFFFFFFF when the journal header is written
3911 PAGERTRACE(("SYNC journal of %d\n", PAGERID(pPager)));
3923 PAGERTRACE(("SYNC journal of %d\n", PAGERID(pPager)));
3942 /* Unless the pager is in noSync mode, the journal file was just
4065 ** Ensure that the sub-journal file is open. If it is already open, this
4085 ** Append a record of the current state of page pPg to the sub-journal.
4093 ** error code if the attempt to write to the sub-journal fails, or
4102 /* Open the sub-journal, if it has not already been opened */
4112 /* If the sub-journal was opened successfully (or was already open),
4113 ** write the journal record into the file. */
4146 ** journal file.
4162 ** journal (and adding a new header) is not allowed. This occurs
4163 ** during calls to sqlite3PagerWrite() while trying to journal multiple
4193 /* Sync the journal file if required. */
4201 ** the database image, it may need to be written to the sub-journal.
4208 ** <journal page X>
4223 ** sub-journal file now (if it is not already there), so that it will
4295 int journalFileSize; /* Bytes to allocate for each journal fd */
4298 int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */
4303 /* Figure out how much space is required for each journal file-handle
4304 ** (there are two of them, the main journal and the sub-journal). This
4305 ** is the maximum space required for an in-memory journal file handle
4306 ** and a regular journal file-handle. Note that a "regular journal-handle"
4307 ** may be a wrapper capable of caching the first portion of the journal
4309 ** source file journal.c).
4341 /* This branch is taken when the journal path required by
4344 ** as it will not be possible to open the journal file or even
4345 ** check for a hot-journal before reading.
4356 ** three file descriptors, the database file name and the journal
4362 ** Sub-journal file handle (journalFileSize bytes)
4363 ** Main journal file handle (journalFileSize bytes)
4371 journalFileSize * 2 + /* The two journal files */
4397 memcpy(&pPager->zJournal[nPathname], "-journal", 8);
4456 ** disk and uses an in-memory rollback journal.
4544 ** PAGER_SHARED state. It tests if there is a hot journal present in
4545 ** the file-system for the given pager. A hot journal is one that
4546 ** needs to be played back. According to this function, a hot-journal
4549 ** * The journal file exists in the file system, and
4552 ** * The first byte of the journal file exists and is not 0x00.
4554 ** If the current size of the database file is 0 but a journal file
4555 ** exists, that is probably an old journal left over from a prior
4556 ** database with the same name. In this case the journal file is
4560 ** This routine does not check if there is a master journal filename
4561 ** at the end of the file. If there is, and that master journal file
4562 ** does not exist, then the journal file is not really hot. In this
4564 ** routine will discover that the journal file is not really hot and
4567 ** If a hot-journal file is found to exist, *pExists is set to 1 and
4568 ** SQLITE_OK returned. If no hot-journal file is present, *pExists is
4570 ** to determine whether or not a hot-journal file exists, the IO error
4576 int exists = 1; /* True if a journal file is present */
4595 ** the RESERVED lock and have a journal open at the sqlite3OsAccess()
4596 ** call above, but then delete the journal and drop the lock before
4598 ** is the case, this routine might think there is a hot journal when
4607 ** then delete the journal file. See the header comment above for
4608 ** the reasoning here. Delete the obsolete journal file under
4622 /* The journal file exists and no other connection has a reserved
4624 ** at least one non-zero bytes at the start of the journal file.
4625 ** If there is, then we consider this journal to be hot. If not,
4643 /* If we cannot open the rollback journal file in order to see if
4646 ** ticket #3883. Either way, assume that the journal is hot.
4648 ** automatic journal playback and recovery mechanism will deal
4674 ** the SHARED lock, the file-system is checked for a hot-journal,
4675 ** which is played back if present. Following any hot-journal
4683 ** the contents of the page cache and rolling back any open journal
4687 ** occurs while locking the database, checking for a hot-journal file or
4688 ** rolling back a journal file, the IO error code is returned.
4704 int bHotJournal = 1; /* True if there exists a hot journal-file */
4717 /* If a journal file exists, and there is no RESERVED lock on the
4732 ** hot-journal back.
4748 ** journal for read/write access. Write access is required because
4751 ** is usually required to finalize the journal in journal_mode=persist
4754 ** If the journal does not exist, it usually means that some
4758 ** function was called and the journal file does not exist.
4762 int bExists; /* True if journal file exists */
4778 /* Playback and delete the journal. Drop the database write
4780 ** playing back the hot-journal so that we don't end up with
4781 ** an inconsistent cache. Sync the hot journal before playing
4782 ** it back since the process that crashed and left the hot journal
4784 ** the journal before playing it back.
4799 ** or roll back a hot-journal while holding an EXCLUSIVE lock. The
4898 ** the rollback journal, the unlock is not performed and there is
4936 ** from the savepoint journal.
4941 ** journal file) and the PagerSavepoint.pInSavepoint bitvecs of any open
4953 ** has to go to disk, and could also playback an old journal if necessary.
4955 ** or journal files.
5020 ** It merely means that we might do some extra work to journal a
5115 ** Open the journal file for pager pPager and write a journal header
5116 ** to the start of it. If there are active savepoints, open the sub-journal
5117 ** as well. This function is only used when the journal file is being
5119 ** when opening a hot journal file to roll it back.
5121 ** If the journal file is already open (as it may be in exclusive mode),
5122 ** then this function just writes a journal header to the start of the
5125 ** Whether or not the journal file is opened by this function, the
5130 ** an IO error code if opening or writing the journal file fails.
5151 /* Open the journal file if it is not already open. */
5156 const int flags = /* VFS flags to open journal file */
5170 /* Set the TimeMachine exclusion metadata for the journal if it has
5179 CFURLRef journal = create_cfurl_from_cstring(pPager->zJournal);
5181 CSBackupSetItemExcluded(journal, TRUE, FALSE);
5182 CFRelease(journal);
5192 /* Write the first journal header to the journal file and open
5193 ** the sub-journal if necessary.
5225 ** If the subjInMemory argument is non-zero, then any sub-journal opened
5227 ** has no effect if the sub-journal is already opened (as it may be when
5229 ** sub-journal. If the subjInMemory argument is zero, then any required
5230 ** sub-journal is implemented in-memory if pPager is an in-memory database,
5279 ** transactions may copy data from the sub-journal into the database
5301 ** main journal or sub-journal as required. If the page is written into
5312 ** been started. The journal file may or may not be open at this point.
5331 /* The journal file needs to be opened. Higher level routines have already
5333 ** rollback journal might not yet be open. Open it now if this is the case.
5348 ** to the journal then we can return right away.
5355 /* The transaction journal now exists and we have a RESERVED or an
5357 ** the transaction journal if it is not there already.
5366 /* We should never write to the journal file the page that
5419 /* If the statement journal is open and the page is not in it,
5420 ** then write the current page to the statement journal. Note that
5421 ** the statement journal format differs from the standard journal format
5446 ** must have been written to the journal file before returning.
5465 int nPage = 0; /* Number of pages starting at pg1 to journal */
5470 ** a journal header to be written between the pages journaled by
5520 ** journal file must contain sync()ed copies of all of them
5714 ** of a master journal file that should be written into the individual
5715 ** journal file. zMaster may be NULL, which is interpreted as no master
5716 ** journal (a single database transaction).
5721 ** * the journal is synced (unless the atomic-write optimization is used),
5727 ** (delete, truncate or zero the first part of) the journal file (or
5728 ** delete the master journal file if specified).
5736 ** journal file in this case.
5740 const char *zMaster, /* If not NULL, the master journal name */
5797 ** * Exactly one page has been modified and store in the journal file.
5803 ** to make sure the journal file has actually been created, then call
5809 ** in 'direct' mode. In this case the journal file will never be
5842 ** being discarded by the truncation must be written to the journal
5861 PgHdr *pPage; /* Page to journal */
5873 /* Write the master journal name into the journal file. If a master
5874 ** journal file name has already been written to the journal file,
5875 ** or if zMaster is NULL (no master journal), then this call is a no-op.
5880 /* Sync the journal file and write all dirty pages to the database.
5882 ** create the journal file or perform any real IO.
5886 ** journal requires a sync here. However, in locking_mode=exclusive
5930 ** synced to disk. The journal file still exists in the file-system
5932 ** be used as a hot-journal and the current transaction rolled back.
5934 ** This function finalizes the journal file, either by deleting,
5936 ** for hot-journal rollback. Once this is done the transaction is
5960 ** The start of the journal file currently contains a single journal
5961 ** header with the nRec field set to 0. If such a journal is used as
5962 ** a hot-journal during hot-journal rollback, 0 changes will be made
5963 ** to the database file. So there is no need to zero the journal
5992 ** 1) It rolls back the journal file, restoring all database file and
5996 ** 2) It finalizes the journal file, so that it is not used for hot
5999 ** Finalization of the journal file (task 2) is only performed if the
6118 ** occurs while opening the sub-journal file, then an IO error code is
6221 ** the sub-journal to zero bytes in size. */
6224 /* Only truncate if it is an in-memory sub-journal. */
6233 ** If this is a temp-file, it is possible that the journal file has
6271 ** Return the full pathname of the journal file.
6315 ** in the rollback journal, it is not put there by by this routine.
6346 /* In order to be able to rollback, an in-memory database must journal
6356 ** sub-journal now. This is required to handle the following scenario:
6359 ** <journal page X, then modify it in memory>
6364 ** If page X were not written to the sub-journal here, it would not
6383 /* If the journal needs to be sync()ed before page pPg->pgno can
6387 ** the journal needs to be sync()ed before database page pPg->pgno
6430 /* If needSyncPgno is non-zero, then the journal file needs to be
6441 ** it is synced into the journal file. This way, it may end up in
6442 ** the journal file twice, but that is not a problem.
6502 ** Set the journal-mode for this pager. Parameter eMode must be one of:
6519 ** The returned indicate the current (possibly updated) journal-mode.
6557 /* Change the journal mode. */
6561 /* When transistioning from TRUNCATE or PERSIST to any other journal
6563 ** delete the journal file.
6575 /* In this case we would like to delete the journal file. If it is
6576 ** not possible, then that is not a problem. Deleting the journal file
6579 ** Before deleting the journal file, obtain a RESERVED lock on the
6580 ** database file. This ensures that the journal file is not deleted
6610 /* Return the new journal mode */
6615 ** Return the current journal mode.
6634 ** Get/set the size-limit used for persistent journal files.
6771 /* Close any rollback journal previously open */