-
Notifications
You must be signed in to change notification settings - Fork 438
RATIS-2167. Add default value in TermIndex #1161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@szetszwo , can you help review this PR? |
| return Optional.ofNullable(proto).map(p -> valueOf(p.getTerm(), p.getIndex())).orElse(null); | ||
| } | ||
|
|
||
| static final TermIndex DEFAULT_TERMINDEX = valueOf(0, -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jianghuazhu , thanks a lot for working on this!
Let's call it INITIAL_VALUE, move it to the top and add some javadoc.
BTW, could you also add javadoc for EMPTY_ARRAY?
+++ b/ratis-server-api/src/main/java/org/apache/ratis/server/protocol/TermIndex.java
@@ -19,12 +19,25 @@ package org.apache.ratis.server.protocol;
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. */
szetszwo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 the change looks good.
|
Thanks @szetszwo for the comment and review. |
|
@jianghuazhu , agree that the failures were not related to this. |
|
Thanks @szetszwo . |
What changes were proposed in this pull request?
In the Ratis project and other projects, the default value of TermIndex is used. Here we create a default value for TermIndex.
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/RATIS-2167
How was this patch tested?
Make sure UT passes.