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 class
A handle to aLogEntry
stored in the journal.static interface
A reader-side interface to log entries being stored in this journal. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
A friendly constant to centralize the places where we assume counting from 1. -
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
.Returns a newEntryJournal.Reader
.void
setApplyTo
(long newApplyTo) Update thejournalIndex
to 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 thejournalIndex
of the last entry which is to be applied.- Returns:
- the
journalIndex
of 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 reportingfirstRetainedIndex
as 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 thejournalIndex
to report fromapplyToJournalIndex()
.- Parameters:
newApplyTo
- the newjournalIndex
to return- Throws:
IOException
- if an I/O error occurs
-
close
void close()- Specified by:
close
in interfaceAutoCloseable
-