public abstract class RaftLog extends Object implements Closeable
| Modifier and Type | Class and Description |
|---|---|
class |
RaftLog.EntryWithData
Holds proto entry along with future which contains read state machine data
|
static class |
RaftLog.Metadata |
static class |
RaftLogSequentialOps.Runner |
| Modifier and Type | Field and Description |
|---|---|
static long |
INVALID_LOG_INDEX |
static long |
LEAST_VALID_LOG_INDEX
The least valid log index, i.e.
|
static org.slf4j.Logger |
LOG |
static String |
LOG_SYNC |
| Modifier | Constructor and Description |
|---|---|
protected |
RaftLog(RaftGroupMemberId memberId,
long commitIndex,
RaftProperties properties) |
| Modifier and Type | Method and Description |
|---|---|
long |
append(long term,
RaftConfiguration configuration)
Append asynchronously a log entry for the given term and configuration
Used by the leader.
|
long |
append(long term,
TransactionContext transaction)
Append asynchronously a log entry for the given term and transaction.
|
List<CompletableFuture<Long>> |
append(org.apache.ratis.proto.RaftProtos.LogEntryProto... entries)
Append asynchronously all the given log entries.
|
CompletableFuture<Long> |
appendEntry(org.apache.ratis.proto.RaftProtos.LogEntryProto entry)
Append asynchronously an entry.
|
protected abstract CompletableFuture<Long> |
appendEntryImpl(org.apache.ratis.proto.RaftProtos.LogEntryProto entry) |
protected abstract List<CompletableFuture<Long>> |
appendImpl(org.apache.ratis.proto.RaftProtos.LogEntryProto... entries) |
long |
appendMetadata(long term,
long newCommitIndex)
Append asynchronously a log entry for the given term and commit index
unless the given commit index is an index of a metadata entry
Used by the leader.
|
void |
checkLogState() |
void |
close() |
boolean |
contains(TermIndex ti)
Does the log contains the given term and index? Used to check the
consistency between the local log of a follower and the log entries sent
by the leader.
|
abstract org.apache.ratis.proto.RaftProtos.LogEntryProto |
get(long index)
Get the log entry of the given index.
|
abstract TermIndex[] |
getEntries(long startIndex,
long endIndex) |
abstract RaftLog.EntryWithData |
getEntryWithData(long index)
Get the log entry of the given index along with the state machine data.
|
abstract long |
getFlushIndex() |
long |
getLastCommittedIndex() |
abstract TermIndex |
getLastEntryTermIndex() |
String |
getName() |
long |
getNextIndex() |
RaftLogMetrics |
getRaftLogMetrics() |
long |
getSnapshotIndex() |
abstract long |
getStartIndex() |
abstract TermIndex |
getTermIndex(long index)
Get the TermIndex information of the given index.
|
boolean |
hasReadLock() |
boolean |
hasWriteLock() |
abstract boolean |
isConfigEntry(TermIndex ti) |
boolean |
isOpened() |
abstract RaftLog.Metadata |
loadMetadata() |
void |
open(long lastIndexInSnapshot,
Consumer<org.apache.ratis.proto.RaftProtos.LogEntryProto> consumer) |
protected void |
openImpl(long lastIndexInSnapshot,
Consumer<org.apache.ratis.proto.RaftProtos.LogEntryProto> consumer) |
CompletableFuture<Long> |
purge(long suggestedIndex)
Purge asynchronously the log transactions.
|
protected abstract CompletableFuture<Long> |
purgeImpl(long index) |
AutoCloseableLock |
readLock() |
abstract void |
syncWithSnapshot(long lastSnapshotIndex) |
String |
toLogEntryString(org.apache.ratis.proto.RaftProtos.LogEntryProto logEntry) |
String |
toString() |
CompletableFuture<Long> |
truncate(long index)
Truncate asynchronously the log entries till the given index (inclusively).
|
protected abstract CompletableFuture<Long> |
truncateImpl(long index) |
boolean |
updateLastCommitted(long majorityIndex,
long currentTerm)
Update the last committed index.
|
void |
updateSnapshotIndex(long newSnapshotIndex)
Update the last committed index and snapshotIndex with the last index in
the snapshot.
|
protected void |
validateLogEntry(org.apache.ratis.proto.RaftProtos.LogEntryProto entry)
Validate the term and index of entry w.r.t RaftLog
|
AutoCloseableLock |
writeLock() |
abstract void |
writeMetadata(long term,
RaftPeerId votedFor)
Write and flush the metadata (votedFor and term) into the meta file.
|
public static final org.slf4j.Logger LOG
public static final String LOG_SYNC
public static final long LEAST_VALID_LOG_INDEX
public static final long INVALID_LOG_INDEX
protected RaftLog(RaftGroupMemberId memberId, long commitIndex, RaftProperties properties)
public RaftLogMetrics getRaftLogMetrics()
public long getLastCommittedIndex()
public long getSnapshotIndex()
public void checkLogState()
public boolean isOpened()
public boolean updateLastCommitted(long majorityIndex,
long currentTerm)
majorityIndex - the index that has achieved majority.currentTerm - the current term.public void updateSnapshotIndex(long newSnapshotIndex)
newSnapshotIndex - the last index in the snapshotpublic boolean contains(TermIndex ti)
public long getNextIndex()
public final long append(long term,
TransactionContext transaction)
throws StateMachineException
StateMachineExceptionpublic final long appendMetadata(long term,
long newCommitIndex)
RaftServerConstants.INVALID_LOG_INDEX.public final long append(long term,
RaftConfiguration configuration)
public final void open(long lastIndexInSnapshot,
Consumer<org.apache.ratis.proto.RaftProtos.LogEntryProto> consumer)
throws IOException
IOExceptionprotected void openImpl(long lastIndexInSnapshot,
Consumer<org.apache.ratis.proto.RaftProtos.LogEntryProto> consumer)
throws IOException
IOExceptionpublic abstract long getStartIndex()
public abstract org.apache.ratis.proto.RaftProtos.LogEntryProto get(long index) throws RaftLogIOException
index - The given index.RaftLogIOExceptionpublic abstract RaftLog.EntryWithData getEntryWithData(long index) throws RaftLogIOException
index - The given index.RaftLogIOExceptionpublic abstract TermIndex getTermIndex(long index)
index - The given index.public abstract TermIndex[] getEntries(long startIndex, long endIndex)
startIndex - the starting log index (inclusive)endIndex - the ending log index (exclusive)public abstract TermIndex getLastEntryTermIndex()
protected void validateLogEntry(org.apache.ratis.proto.RaftProtos.LogEntryProto entry)
public final CompletableFuture<Long> truncate(long index)
protected abstract CompletableFuture<Long> truncateImpl(long index)
public final CompletableFuture<Long> purge(long suggestedIndex)
suggestedIndex - the suggested index (inclusive) to be purged.protected abstract CompletableFuture<Long> purgeImpl(long index)
public final CompletableFuture<Long> appendEntry(org.apache.ratis.proto.RaftProtos.LogEntryProto entry)
protected abstract CompletableFuture<Long> appendEntryImpl(org.apache.ratis.proto.RaftProtos.LogEntryProto entry)
public final List<CompletableFuture<Long>> append(org.apache.ratis.proto.RaftProtos.LogEntryProto... entries)
protected abstract List<CompletableFuture<Long>> appendImpl(org.apache.ratis.proto.RaftProtos.LogEntryProto... entries)
public abstract long getFlushIndex()
public abstract void writeMetadata(long term,
RaftPeerId votedFor)
throws IOException
IOExceptionpublic abstract RaftLog.Metadata loadMetadata() throws IOException
IOExceptionpublic abstract void syncWithSnapshot(long lastSnapshotIndex)
public abstract boolean isConfigEntry(TermIndex ti)
public AutoCloseableLock readLock()
public AutoCloseableLock writeLock()
public boolean hasWriteLock()
public boolean hasReadLock()
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic String getName()
public String toLogEntryString(org.apache.ratis.proto.RaftProtos.LogEntryProto logEntry)
Copyright © 2017–2020 The Apache Software Foundation. All rights reserved.