Skip to content

Commit 5e327e2

Browse files
authored
Fail in beforeCommit on all other terms (#94833)
Today `beforeCommit()` would succeed in production if the current term decreases. This shouldn't happen for sure, but if it does it would be safer to fail. This commit adjusts the condition so that we only proceed with the commit if the term is exactly correct.
1 parent 7cd484a commit 5e327e2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

server/src/test/java/org/elasticsearch/cluster/coordination/AtomicRegisterCoordinatorTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,10 @@ public boolean isInvalidReconfiguration(
514514
public void beforeCommit(long term, long version, ActionListener<Void> listener) {
515515
// TODO: add a test to ensure that this gets called
516516
final var currentTerm = register.readCurrentTerm();
517-
if (currentTerm > term) {
517+
if (currentTerm == term) {
518+
listener.onResponse(null);
519+
} else {
520+
assert term < currentTerm : term + " vs " + currentTerm;
518521
listener.onFailure(
519522
new CoordinationStateRejectedException(
520523
Strings.format(
@@ -525,9 +528,6 @@ public void beforeCommit(long term, long version, ActionListener<Void> listener)
525528
)
526529
)
527530
);
528-
} else {
529-
assert currentTerm == term : currentTerm + " vs " + term;
530-
listener.onResponse(null);
531531
}
532532
}
533533
}

0 commit comments

Comments
 (0)