chungen0126 commented on code in PR #1130:
URL: https://github.com/apache/ratis/pull/1130#discussion_r1704855115
##########
ratis-server/src/main/java/org/apache/ratis/server/raftlog/RaftLogBase.java:
##########
@@ -230,6 +230,9 @@ private long appendMetadataImpl(long term, long
newCommitIndex) {
final long nextIndex;
try(AutoCloseableLock writeLock = writeLock()) {
nextIndex = getNextIndex();
+ if (nextIndex - 1 != newCommitIndex) {
+ return INVALID_LOG_INDEX;
+ }
Review Comment:
> Let's add more information to your example. Suppose`entriesToCommit` are
>
> * STATEMACHINELOGENTRY(1, 1)
> * STATEMACHINELOGENTRY(1, 2)
> * METADATAENTRY(term: 1, index: 3, commitIndex: 1)
>
> and
>
> * `nextIndex` is 4.
In your case, `entriesToCommit` will become:
- STATEMACHINELOGENTRY(1, 1)
- STATEMACHINELOGENTRY(1, 2)
- METADATAENTRY(term: 1, index: 3, commitIndex: 2)
> Then, `newCommitIndex` is 2 and `nextIndex - 1 != newCommitIndex` is
false. It won't append the metadata entry in this case. Why checking the
if-condition here?
The metadata entry (term: 1, index: 3, commitIndex: 1) will not be appended
because the condition `nextIndex - 1 != newCommitIndex` is false. Specifically,
nextIndex - 1 (2) is not equal to newCommitIndex (1).
Ideally, when there are consecutive commits, it will only log one metadata
with last commit index. However, if the `commitIndex` was always slower than
the nextIndex, it won't append the metadata entry until `commitIndex` catches
up.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]