Skip to content

Commit

Permalink
RATIS-2167. Add default value in TermIndex (#1161)
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghuazhu authored Oct 4, 2024
1 parent e3d6736 commit a0c4255
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,25 @@

import org.apache.ratis.proto.RaftProtos.LogEntryProto;
import org.apache.ratis.proto.RaftProtos.TermIndexProto;
import org.apache.ratis.server.raftlog.RaftLog;

import java.util.Comparator;
import java.util.Optional;

/** The term and the log index defined in the Raft consensus algorithm. */
public interface TermIndex extends Comparable<TermIndex> {
/**
* The initial value.
* When a new Raft group starts,
* all the servers has term 0 and index -1 (= {@link RaftLog#INVALID_LOG_INDEX}).
* Note that term is incremented during leader election
* and index is incremented when writing to the {@link RaftLog}.
* The least term and index possibly written to the {@link RaftLog}
* are respectively 1 and 0 (= {@link RaftLog#LEAST_VALID_LOG_INDEX}).
*/
TermIndex INITIAL_VALUE = valueOf(0, RaftLog.INVALID_LOG_INDEX);

/** An empty {@link TermIndex} array. */
TermIndex[] EMPTY_ARRAY = {};

/** @return the term. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class BaseStateMachine implements StateMachine, StateMachine.DataApi,
private final SortedMap<Long, CompletableFuture<Void>> transactionFutures = new TreeMap<>();

public BaseStateMachine() {
setLastAppliedTermIndex(TermIndex.valueOf(0, -1));
setLastAppliedTermIndex(TermIndex.INITIAL_VALUE);
}

public RaftPeerId getId() {
Expand Down

0 comments on commit a0c4255

Please sign in to comment.