journal 主要用途是,当事务要修改page时,先把未修改的page存入journal中,如果事务rollback时,就从journal中得到修改前的数据,覆盖已改的,达到事务的一致性。
journal是一个不同于数据库文件的另一个文件,它在事务开始时创建,当事务结束时就删除了
The format for the journal header is as follows:
- 8 bytes: Magic identifying journal format.
- 4 bytes: Number of records in journal,or -1 no-sync mode is on.
- 4 bytes: Random number used for page hash.
- 4 bytes: Initial database page count.
- 4 bytes: Sector size used by the process that wrote this journal.
- 4 bytes: Database page size.
** The journal file format is as follows: **** (1) 8 byte prefix. A copy of aJournalMagic[].** (2) 4 byte big-endian integer which is the number of valid page records** in the journal. If this value is 0xffffffff,then compute the** number of page records from the journal size.** (3) 4 byte big-endian integer which is the initial value for the ** sanity checksum.** (4) 4 byte integer which is the number of pages to truncate the** database to during a rollback.** (5) 4 byte big-endian integer which is the sector size. The header** is this many bytes in size.** (6) 4 byte big-endian integer which is the page size.** (7) zero padding out to the next sector size.** (8) Zero or more pages instances,each as follows:** + 4 byte page number.** + pPager->pageSize bytes of data.** + 4 byte checksum**** When we speak of the journal header,we mean the first 7 items above.** Each entry in the journal is an instance of the 8th item.
原文链接:https://www.f2er.com/sqlite/202913.html