public class RaftLog
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
RaftLog.Snapshot
This is used in truncating the logs when they grow too long.
|
| Modifier and Type | Field and Description |
|---|---|
java.util.Set<java.lang.String> |
committedQuorumMembers
LOG COMPACTION + MEMBERSHIP CHANGES: This is used for log compaction, so we can track membership at the time of a
snapshot of the state.
|
static int |
COMPACTION_LIMIT
The number of log entries to keep in the log before compacting into a snapshot.
|
java.util.Optional<RaftLog.Snapshot> |
snapshot
LOG COMPACTION: This is used to backstop the log when we compact committed entries.
|
RaftStateMachine |
stateMachine
CORE: This is the state machine reference that the logs refer to.
|
| Constructor and Description |
|---|
RaftLog(RaftStateMachine stateMachine,
java.util.Collection<java.lang.String> initialConfiguration,
java.util.concurrent.ExecutorService pool)
Create a log from a state machine and initial configuration.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
appendEntries(long prevLogIndex,
long prevLogTerm,
java.util.List<EloquentRaftProto.LogEntry> entries)
This gets called from handleAppendEntriesRPC() in EloquentRaftMember.
|
RaftLog |
copy()
Create a medium-deep copy of this log.
|
java.util.concurrent.CompletableFuture<java.lang.Boolean> |
createCommitFuture(long index,
long term) |
java.util.concurrent.CompletableFuture<java.lang.Boolean> |
createCommitFuture(RaftLogEntryLocation location) |
boolean |
equals(java.lang.Object o) |
RaftLog.Snapshot |
forceSnapshot()
This forces a log compaction step, where all the committed log entries are compacted away, and we backstop with a
single snapshot of the state machine.
|
java.util.List<EloquentRaftProto.LogEntry> |
getAllUncompressedEntries() |
long |
getCommitIndex()
This gets called when preparing an AppendEntriesRPC, in order to send other members the
This returns the commit index that we've applied up to.
|
java.util.Optional<java.util.List<EloquentRaftProto.LogEntry>> |
getEntriesSinceInclusive(long startIndex)
This gets called when preparing to call an AppendEntriesRPC, in order to send other members of the cluster the
current view of the log.
|
long |
getLastEntryIndex()
This gets called when preparing to call an RequestVoteRPC, in order to prevent other members from voting for an
out-of-date log.
|
long |
getLastEntryTerm()
This gets called when preparing to call an RequestVoteRPC, in order to prevent other members from voting for an
out-of-date log.
|
java.util.Optional<java.lang.Long> |
getPreviousEntryTerm(long index)
This gets called when preparing to call an AppendEntriesRPC, in order to send other members of the cluster the
current view of the log.
|
java.util.Set<java.lang.String> |
getQuorumMembers()
This returns the most up-to-date view of the cluster membership that we have.
|
boolean |
getSafeToChangeMembership()
This should only be called by leaders while appending to their log!
Raft only allows one membership change to be uncommitted at a time.
|
int |
hashCode() |
boolean |
installSnapshot(RaftLog.Snapshot snapshot,
long now)
This gets called from handleInstallSnapshotRPC() in EloquentRaftMember.
|
java.util.Optional<RaftLogEntryLocation> |
lastConfigurationEntryLocation()
Get the location of the most recent log entry.
|
static int |
level()
Get the current log level.
|
void |
setCommitIndex(long leaderCommit,
long now)
If leaderCommit > commitIndex, set commitIndex = min(leaderCommit, index of last new entry)
|
static void |
setLevel(int level)
Explicitly set the log level.
|
static void |
setLevel(java.lang.String level)
Explicitly set the log level.
|
void |
unsafeSetLog(java.util.List<EloquentRaftProto.LogEntry> log)
WARNING: UNSAFE!!!
This function violates the correctness principles of Raft, and should never be called in production code.
|
public static final int COMPACTION_LIMIT
public final RaftStateMachine stateMachine
public java.util.Optional<RaftLog.Snapshot> snapshot
public final java.util.Set<java.lang.String> committedQuorumMembers
public RaftLog(RaftStateMachine stateMachine, java.util.Collection<java.lang.String> initialConfiguration, java.util.concurrent.ExecutorService pool)
public static void setLevel(int level)
public static void setLevel(java.lang.String level)
public static int level()
public RaftLog copy()
public long getCommitIndex()
public long getLastEntryIndex()
public long getLastEntryTerm()
public java.util.Set<java.lang.String> getQuorumMembers()
public java.util.List<EloquentRaftProto.LogEntry> getAllUncompressedEntries()
public java.util.Optional<java.util.List<EloquentRaftProto.LogEntry>> getEntriesSinceInclusive(long startIndex)
startIndex - the index (inclusive) to get the logs frompublic java.util.Optional<java.lang.Long> getPreviousEntryTerm(long index)
index - the index to find the term of (if possible)public boolean getSafeToChangeMembership()
public java.util.Optional<RaftLogEntryLocation> lastConfigurationEntryLocation()
public java.util.concurrent.CompletableFuture<java.lang.Boolean> createCommitFuture(long index,
long term)
createCommitFuture(long, long, boolean)public java.util.concurrent.CompletableFuture<java.lang.Boolean> createCommitFuture(RaftLogEntryLocation location)
createCommitFuture(long, long)public void setCommitIndex(long leaderCommit,
long now)
leaderCommit - the commit from the leaderpublic boolean appendEntries(long prevLogIndex,
long prevLogTerm,
java.util.List<EloquentRaftProto.LogEntry> entries)
prevLogIndex - the log index for the entry immediately preceding the entries to be appendedprevLogTerm - the log term for the entry immediately preceding the entries to be appendedentries - the entries to be appendedpublic boolean installSnapshot(RaftLog.Snapshot snapshot, long now)
snapshot - the snapshot to installnow - the current time, in case we want to mock itpublic RaftLog.Snapshot forceSnapshot()
public void unsafeSetLog(java.util.List<EloquentRaftProto.LogEntry> log)
log - The new log to set. The old log is cleared in favor of these entriespublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object