Interface EntryJournal
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
EntryJournalV1
Interface for RAFT log entry persistence implementations. This is rather opinionated take with
RaftJournal
acting as the backing implementation.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classA handle to aLogEntrystored in the journal.static interfaceA reader-side interface to log entries being stored in this journal. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intA friendly constant to centralize the places where we assume counting from 1. -
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.Returns a newEntryJournal.Reader.voidsetApplyTo(long newApplyTo) Update thejournalIndexto report fromapplyToJournalIndex().
-
Field Details
-
FIRST_JOURNAL_INDEX
static final int FIRST_JOURNAL_INDEXA friendly constant to centralize the places where we assume counting from 1.- See Also:
-
-
Method Details
-
applyToJournalIndex
long applyToJournalIndex()Returns thejournalIndexof the last entry which is to be applied.- Returns:
- the
journalIndexof the last entry which is to be applied
-
openReader
EntryJournal.Reader openReader()Returns a newEntryJournal.Reader.- Returns:
- a new
EntryJournal.Reader
-
appendEntry
Append an entry at the currentjournalIndex.- Parameters:
entry- the journal entry to append- Returns:
- the serialized size of
LogEntry.command() - Throws:
IOException- if an I/O error occurs
-
discardHead
Discard all entries starting from the beginning of journal up to, but excluding,firstRetainedIndex. The journal will be updated such that the nextopenReader()invocation will result in the reader reportingfirstRetainedIndexas the initialEntryJournal.Reader.nextJournalIndex().- Parameters:
firstRetainedIndex- the index of the first entry to retain- Throws:
IOException- if an I/O error occurs
-
discardTail
Discard all entries starting fromfirstRemovedIndex. The journal will be positioned such that the nextappendEntry(LogEntry)will returnfirstRemovedIndex.- Parameters:
firstRemovedIndex- the index of the first entry to remove- Throws:
IOException- if an I/O error occurs
-
setApplyTo
Update thejournalIndexto report fromapplyToJournalIndex().- Parameters:
newApplyTo- the newjournalIndexto return- Throws:
IOException- if an I/O error occurs
-
close
void close()- Specified by:
closein interfaceAutoCloseable
-