Skip to content

Commit 81e162d

Browse files
committed
Improve rollback logic (comments etc)
1 parent 4f4cfe8 commit 81e162d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

test/framework/src/main/java/org/elasticsearch/cluster/coordination/AbstractCoordinatorTestCase.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -729,11 +729,14 @@ class MockPersistedState implements CoordinationState.PersistedState {
729729

730730
final long persistedCurrentTerm;
731731

732-
if ((oldState.getLastAcceptedState().nodes().getLocalNode().isMasterNode() && newLocalNode.isMasterNode()) == false
732+
if ( // node is master-ineligible either before or after the restart ...
733+
(oldState.getLastAcceptedState().nodes().getLocalNode().isMasterNode() && newLocalNode.isMasterNode()) == false
734+
// ... and it's accepted some non-initial state so we can roll back ...
733735
&& (oldState.getLastAcceptedState().term() > 0L || oldState.getLastAcceptedState().version() > 0L)
736+
// ... and we're feeling lucky ...
734737
&& randomBoolean()) {
735738

736-
// master-ineligible nodes do not reliably persist the cluster state, so emulate a rollback
739+
// ... then we might not have reliably persisted the cluster state, so emulate a rollback
737740

738741
persistedCurrentTerm = randomLongBetween(0L, oldState.getCurrentTerm());
739742
final long lastAcceptedTerm = oldState.getLastAcceptedState().term();
@@ -750,7 +753,8 @@ && randomBoolean()) {
750753
newLastAcceptedVersion = randomLongBetween(0L,
751754
newLastAcceptedTerm == lastAcceptedTerm ? lastAcceptedVersion - 1 : Long.MAX_VALUE);
752755
}
753-
final VotingConfiguration newVotingConfiguration = new VotingConfiguration(singleton(randomAlphaOfLength(10)));
756+
final VotingConfiguration newVotingConfiguration
757+
= new VotingConfiguration(randomBoolean() ? emptySet() : singleton(randomAlphaOfLength(10)));
754758
final long newValue = randomLong();
755759

756760
logger.trace("rolling back persisted cluster state on master-ineligible node [{}]: " +

0 commit comments

Comments
 (0)