public class RaftLog extends Object
RaftLog
keeps and maintains Raft log entries and snapshot. Entries
appended in leader's RaftLog are replicated to all followers in the same
order and all nodes in a Raft group eventually keep the exact same
copy of the RaftLog.
Raft maintains the following properties, which together constitute the LogMatching Property:
LogEntry
,
SnapshotEntry
Constructor and Description |
---|
RaftLog(int capacity) |
Modifier and Type | Method and Description |
---|---|
void |
appendEntries(LogEntry... newEntries)
Appends new entries to the Raft log.
|
int |
availableCapacity()
Returns the number of empty indices in the Raft log
|
boolean |
checkAvailableCapacity(int requestedCapacity)
Returns true if the Raft log contains empty indices for the requested amount
|
boolean |
containsLogEntry(long entryIndex)
Returns true if the log contains an entry at
entryIndex ,
false otherwise. |
LogEntry[] |
getEntriesBetween(long fromEntryIndex,
long toEntryIndex)
Returns log entries between
fromEntryIndex and toEntryIndex , both inclusive. |
LogEntry |
getLogEntry(long entryIndex)
Returns the log entry stored at
entryIndex . |
LogEntry |
lastLogOrSnapshotEntry()
Returns the last entry in the Raft log,
either from the last log entry or from the last snapshot
if no logs are available.
|
long |
lastLogOrSnapshotIndex()
Returns the last entry index in the Raft log,
either from the last log entry or from the last snapshot
if no logs are available.
|
int |
lastLogOrSnapshotTerm()
Returns the last term in the Raft log,
either from the last log entry or from the last snapshot
if no logs are available.
|
int |
setSnapshot(SnapshotEntry snapshot)
Installs the snapshot entry and truncates log entries those are included
in snapshot (entries whose indexes are smaller than
the snapshot's index).
|
int |
setSnapshot(SnapshotEntry snapshot,
long truncateUpToIndex) |
SnapshotEntry |
snapshot()
Returns snapshot entry.
|
long |
snapshotIndex()
Returns snapshot entry index.
|
List<LogEntry> |
truncateEntriesFrom(long entryIndex)
Truncates log entries with indexes
>= entryIndex . |
public long lastLogOrSnapshotIndex()
public int lastLogOrSnapshotTerm()
public LogEntry lastLogOrSnapshotEntry()
public boolean containsLogEntry(long entryIndex)
entryIndex
,
false otherwise.
Important: Log entry indices start from 1, not 0.
public LogEntry getLogEntry(long entryIndex)
entryIndex
. Entry is retrieved
only from the current log, not from the snapshot entry.
If no entry available at this index, then null
is returned.
Important: Log entry indices start from 1, not 0.
public List<LogEntry> truncateEntriesFrom(long entryIndex)
>= entryIndex
.IllegalArgumentException
- If no entries are available to
truncate, if entryIndex
is
greater than last log index or smaller
than snapshot index.public int availableCapacity()
public boolean checkAvailableCapacity(int requestedCapacity)
public void appendEntries(LogEntry... newEntries)
IllegalArgumentException
- If an entry is appended with a lower
term than the last term in the log or
if an entry is appended with an index
not equal to
index == lastIndex + 1
.public LogEntry[] getEntriesBetween(long fromEntryIndex, long toEntryIndex)
fromEntryIndex
and toEntryIndex
, both inclusive.IllegalArgumentException
- If fromEntryIndex
is greater
than toEntryIndex
, or
if fromEntryIndex
is equal to /
smaller than snapshotIndex
,
or if fromEntryIndex
is greater
than last log index,
or if toEntryIndex
is greater
than last log index.public int setSnapshot(SnapshotEntry snapshot)
IllegalArgumentException
- if the snapshot's index is smaller than
or equal to current snapshot indexpublic int setSnapshot(SnapshotEntry snapshot, long truncateUpToIndex)
public long snapshotIndex()
public SnapshotEntry snapshot()
Copyright © 2021 Hazelcast, Inc.. All Rights Reserved.