|
49 | 49 | import static org.exist.util.ThreadUtils.newInstanceThread;
|
50 | 50 |
|
51 | 51 | /**
|
52 |
| - * Manages the journalling log. The database uses one central journal for |
| 52 | + * Manages the journal log. The database uses one central journal for |
53 | 53 | * all data files. If the journal exceeds the predefined maximum size, a new file is created.
|
54 | 54 | * Every journal file has a unique number, which keeps growing during the lifetime of the db.
|
55 | 55 | * The name of the file corresponds to the file number. The file with the highest
|
56 | 56 | * number will be used for recovery.
|
57 |
| - * <p> |
| 57 | + * |
58 | 58 | * A buffer is used to temporarily buffer journal entries. To guarantee consistency, the buffer will be flushed
|
59 |
| - * and the journal is synched after every commit or whenever a db page is written to disk. |
60 |
| - * <p> |
61 |
| - * Each entry has the structure: |
| 59 | + * and the journal is synced after every commit or whenever a db page is written to disk. |
| 60 | + * |
| 61 | + * Each journal file has the following format: |
| 62 | + * |
| 63 | + * <pre>{@code |
| 64 | + * [magicNumber, version, entry*] |
| 65 | + * }</pre> |
| 66 | + * |
| 67 | + * {@code magicNumber} 4 bytes with the value {@link #JOURNAL_MAGIC_NUMBER}. |
| 68 | + * {@code version} 2 bytes (java.lang.short) with the value {@link #JOURNAL_VERSION}. |
| 69 | + * {@code entry} one or more variable length journal {@code entry} records. |
| 70 | + * |
| 71 | + * Each {@code entry} record has the format: |
| 72 | + * |
| 73 | + * <pre>{@code |
| 74 | + * [entryHeader, data, backLink] |
| 75 | + * }</pre> |
| 76 | + * |
| 77 | + * {@code entryHeader} 11 bytes describes the entry (see below). |
| 78 | + * {@code data} {@code entryHeader->length} bytes of data for the entry. |
| 79 | + * {@code backLink} 2 bytes (java.lang.short) offset to the start of the entry record, calculated by {@code entryHeader.length + dataLength}. |
| 80 | + * The offset for the start of the entry record can be calculated as {@code endOfRecordOffset - 2 - backLink}. |
| 81 | + * This is used when scanning the log file backwards for recovery. |
| 82 | + * |
| 83 | + * The {@code entryHeader} has the format: |
62 | 84 | *
|
63 |
| - * <pre>[byte: entryType, long: transactionId, short length, byte[] data, short backLink]</pre> |
| 85 | + * <pre>{@code |
| 86 | + * [entryType, transactionId, dataLength] |
| 87 | + * }</pre> |
64 | 88 | *
|
65 |
| - * <ul> |
66 |
| - * <li>entryType is a unique id that identifies the log record. Entry types are registered via the |
67 |
| - * {@link org.exist.storage.journal.LogEntryTypes} class.</li> |
68 |
| - * <li>transactionId: the id of the transaction that created the record.</li> |
69 |
| - * <li>length: the length of the log entry data.</li> |
70 |
| - * <li>data: the payload data provided by the {@link org.exist.storage.journal.Loggable} object.</li> |
71 |
| - * <li>backLink: offset to the start of the record. Used when scanning the log file backwards.</li> |
72 |
| - * </ul> |
| 89 | + * {@code entryType} 1 byte indicates the type of the entry. |
| 90 | + * {@code transactionId} 8 bytes (java.lang.long) the id of the transaction that created the record. |
| 91 | + * {@code dataLength} 2 bytes (java.lang.short) the length of the log entry {@code data}. |
73 | 92 | *
|
74 | 93 | * @author wolf
|
| 94 | + * @author aretter |
75 | 95 | */
|
76 | 96 | @ConfigurationClass("journal")
|
77 | 97 | //TODO: conf.xml refactoring <recovery> => <recovery><journal/></recovery>
|
|
0 commit comments