Skip to content

Commit be1bf55

Browse files
committed
[doc] Improve the Javadoc describing the format of the Journal file
1 parent 24d435f commit be1bf55

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

src/org/exist/storage/journal/Journal.java

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,49 @@
4949
import static org.exist.util.ThreadUtils.newInstanceThread;
5050

5151
/**
52-
* Manages the journalling log. The database uses one central journal for
52+
* Manages the journal log. The database uses one central journal for
5353
* all data files. If the journal exceeds the predefined maximum size, a new file is created.
5454
* Every journal file has a unique number, which keeps growing during the lifetime of the db.
5555
* The name of the file corresponds to the file number. The file with the highest
5656
* number will be used for recovery.
57-
* <p>
57+
*
5858
* 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:
6284
*
63-
* <pre>[byte: entryType, long: transactionId, short length, byte[] data, short backLink]</pre>
85+
* <pre>{@code
86+
* [entryType, transactionId, dataLength]
87+
* }</pre>
6488
*
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}.
7392
*
7493
* @author wolf
94+
* @author aretter
7595
*/
7696
@ConfigurationClass("journal")
7797
//TODO: conf.xml refactoring <recovery> => <recovery><journal/></recovery>

0 commit comments

Comments
 (0)