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
journalIndex
to replay on recovery, and - the
journalIndex
of 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 TypeMethodDescriptionlong
appendEntry
(LogEntry entry) Append an entry at the currentjournalIndex
.long
Returns thejournalIndex
of the last entry which is to be applied.void
close()
void
discardHead
(long firstRetainedIndex) Discard all entries starting from the beginning of journal up to, but excluding,firstRetainedIndex
.void
discardTail
(long firstRemovedIndex) Discard all entries starting fromfirstRemovedIndex
.memberId()
long
Returns a newEntryJournal.Reader
.void
setApplyTo
(long newApplyTo) Update thejournalIndex
to 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:EntryJournal
Returns thejournalIndex
of the last entry which is to be applied.- Specified by:
applyToJournalIndex
in interfaceEntryJournal
- Returns:
- the
journalIndex
of the last entry which is to be applied
-
setApplyTo
Description copied from interface:EntryJournal
Update thejournalIndex
to report fromEntryJournal.applyToJournalIndex()
.- Specified by:
setApplyTo
in interfaceEntryJournal
- Parameters:
newApplyTo
- the newjournalIndex
to return- Throws:
IOException
- if an I/O error occurs
-
openReader
Description copied from interface:EntryJournal
Returns a newEntryJournal.Reader
.- Specified by:
openReader
in interfaceEntryJournal
- Returns:
- a new
EntryJournal.Reader
-
nextToWrite
public long nextToWrite() -
appendEntry
Description copied from interface:EntryJournal
Append an entry at the currentjournalIndex
.- Specified by:
appendEntry
in 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:EntryJournal
Discard 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 reportingfirstRetainedIndex
as the initialEntryJournal.Reader.nextJournalIndex()
.- Specified by:
discardHead
in interfaceEntryJournal
- Parameters:
firstRetainedIndex
- the index of the first entry to retain- Throws:
IOException
- if an I/O error occurs
-
discardTail
Description copied from interface:EntryJournal
Discard all entries starting fromfirstRemovedIndex
. The journal will be positioned such that the nextEntryJournal.appendEntry(LogEntry)
will returnfirstRemovedIndex
.- Specified by:
discardTail
in 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceEntryJournal
-
toString
-