Class EntryJournalV1
- All Implemented Interfaces:
AutoCloseable,EntryJournal
commitIndex.
The second part is not something RAFT mandates, but rather is an artifact of our current implementation originating from the initial design: stable storage was organized around Pekko persistence with all its semantics. This meant that we had no direct access to specific entry for the purposes of applying its state nor sending it to peers and all entries were replayed during actor recovery, i.e. before we start participating in RAFT protocol and those are kept on-heap.
In order to deal with all that we maintain a RaftJournal of metadata, tracking two indices:
- the first
journalIndexto replay on recovery, and - the
journalIndexof the entry having the same index as the last observed RAFTcommitIndex
The other part we maintain is a RaftJournal of individual entries, but there is a twist there as well:
since each journal requires a fixed maximum entry size, we specify that as 256KiB and provide our own dance
to store larger entries in separate files.
Note: this introduces the concept of journalIndex, which currently defined to start with at 1.
Value 0 is explicitly reserved for unsigned long overflow. Negative values yield undefined results.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.opendaylight.controller.cluster.raft.spi.EntryJournal
EntryJournal.JournalEntry, EntryJournal.Reader -
Field Summary
Fields inherited from interface org.opendaylight.controller.cluster.raft.spi.EntryJournal
FIRST_JOURNAL_INDEX -
Constructor Summary
ConstructorsConstructorDescriptionEntryJournalV1(String memberId, Path directory, CompressionType compression, boolean mapped) -
Method Summary
Modifier and TypeMethodDescriptionlongappendEntry(LogEntry entry) Append an entry at the currentjournalIndex.longReturns thejournalIndexof the last entry which is to be applied.voidclose()voiddiscardHead(long firstRetainedIndex) Discard all entries starting from the beginning of journal up to, but excluding,firstRetainedIndex.voiddiscardTail(long firstRemovedIndex) Discard all entries starting fromfirstRemovedIndex.memberId()longReturns a newEntryJournal.Reader.voidsetApplyTo(long newApplyTo) Update thejournalIndexto report fromEntryJournal.applyToJournalIndex().toString()
-
Constructor Details
-
EntryJournalV1
public EntryJournalV1(String memberId, Path directory, CompressionType compression, boolean mapped) throws IOException - Throws:
IOException
-
-
Method Details
-
memberId
-
applyToJournalIndex
public long applyToJournalIndex()Description copied from interface:EntryJournalReturns thejournalIndexof the last entry which is to be applied.- Specified by:
applyToJournalIndexin interfaceEntryJournal- Returns:
- the
journalIndexof the last entry which is to be applied
-
setApplyTo
Description copied from interface:EntryJournalUpdate thejournalIndexto report fromEntryJournal.applyToJournalIndex().- Specified by:
setApplyToin interfaceEntryJournal- Parameters:
newApplyTo- the newjournalIndexto return- Throws:
IOException- if an I/O error occurs
-
openReader
Description copied from interface:EntryJournalReturns a newEntryJournal.Reader.- Specified by:
openReaderin interfaceEntryJournal- Returns:
- a new
EntryJournal.Reader
-
nextToWrite
public long nextToWrite() -
appendEntry
Description copied from interface:EntryJournalAppend an entry at the currentjournalIndex.- Specified by:
appendEntryin interfaceEntryJournal- Parameters:
entry- the journal entry to append- Returns:
- the serialized size of
LogEntry.command() - Throws:
IOException- if an I/O error occurs
-
discardHead
Description copied from interface:EntryJournalDiscard all entries starting from the beginning of journal up to, but excluding,firstRetainedIndex. The journal will be updated such that the nextEntryJournal.openReader()invocation will result in the reader reportingfirstRetainedIndexas the initialEntryJournal.Reader.nextJournalIndex().- Specified by:
discardHeadin interfaceEntryJournal- Parameters:
firstRetainedIndex- the index of the first entry to retain- Throws:
IOException- if an I/O error occurs
-
discardTail
Description copied from interface:EntryJournalDiscard all entries starting fromfirstRemovedIndex. The journal will be positioned such that the nextEntryJournal.appendEntry(LogEntry)will returnfirstRemovedIndex.- Specified by:
discardTailin interfaceEntryJournal- Parameters:
firstRemovedIndex- the index of the first entry to remove- Throws:
IOException- if an I/O error occurs
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceEntryJournal
-
toString
-