@@ -50,7 +50,6 @@ public class ConsensusState<T extends ConsensusState.CommittedState> extends Abs
50
50
private Optional <AcceptedState <T >> acceptedState ;
51
51
// transient state
52
52
private boolean electionWon ;
53
- private boolean electionValueForced ;
54
53
private NodeCollection joinVotes ;
55
54
private boolean publishPermitted ;
56
55
private NodeCollection publishVotes ;
@@ -69,7 +68,6 @@ public ConsensusState(Settings settings, long currentTerm, T committedState, Opt
69
68
70
69
// transient state
71
70
this .electionWon = false ;
72
- this .electionValueForced = false ;
73
71
this .joinVotes = new NodeCollection ();
74
72
this .publishPermitted = false ;
75
73
this .publishVotes = new NodeCollection ();
@@ -125,7 +123,6 @@ public Vote handleStartVote(long newTerm) {
125
123
currentTerm = newTerm ;
126
124
joinVotes = new NodeCollection ();
127
125
electionWon = false ;
128
- electionValueForced = false ;
129
126
publishPermitted = true ;
130
127
publishVotes = new NodeCollection ();
131
128
@@ -152,35 +149,26 @@ public Optional<PublishRequest<T>> handleVote(DiscoveryNode sourceNode, Vote vot
152
149
throw new IllegalArgumentException ("incoming slot " + vote .getFirstUncommittedSlot () + " higher than current slot " +
153
150
firstUncommittedSlot ());
154
151
}
155
- if (vote .getFirstUncommittedSlot () == firstUncommittedSlot () && vote .getLastAcceptedTerm () != NO_TERM ) {
156
- final long lastAcceptedTermInSlot = lastAcceptedTerm ();
157
- if (vote .getLastAcceptedTerm () > lastAcceptedTermInSlot ) {
158
- logger .debug ("handleVote: ignored vote as voter has better last accepted term (expected: <=[{}], actual: [{}])" ,
159
- lastAcceptedTermInSlot , vote .getLastAcceptedTerm ());
160
- throw new IllegalArgumentException ("incoming last accepted term " + vote .getLastAcceptedTerm () + " higher than " +
161
- "current last accepted term " + lastAcceptedTermInSlot );
162
- }
163
- if (vote .getLastAcceptedTerm () < lastAcceptedTermInSlot && electionValueForced == false ) {
164
- logger .debug ("handleVote: ignored vote as voter has worse last accepted term and election value not forced " +
165
- "(expected: <=[{}], actual: [{}])" , lastAcceptedTermInSlot , vote .getLastAcceptedTerm ());
166
- throw new IllegalArgumentException ("incoming last accepted term " + vote .getLastAcceptedTerm () + " lower than " +
167
- "current last accepted term " + lastAcceptedTermInSlot + " and election value not forced" );
168
- }
169
- electionValueForced = true ;
152
+ final long lastAcceptedTerm = lastAcceptedTerm ();
153
+ if (vote .getFirstUncommittedSlot () == firstUncommittedSlot () && vote .getLastAcceptedTerm () > lastAcceptedTerm ) {
154
+ logger .debug ("handleVote: ignored vote as voter has better last accepted term (expected: <=[{}], actual: [{}])" ,
155
+ lastAcceptedTerm , vote .getLastAcceptedTerm ());
156
+ throw new IllegalArgumentException ("incoming last accepted term " + vote .getLastAcceptedTerm () + " higher than " +
157
+ "current last accepted term " + lastAcceptedTerm );
170
158
}
171
159
172
160
logger .debug ("handleVote: adding vote {} from [{}] for election at slot {}" , vote , sourceNode .getId (), firstUncommittedSlot ());
173
161
joinVotes .add (sourceNode );
174
162
175
163
electionWon = isQuorumInCurrentConfiguration (joinVotes );
176
164
177
- logger .debug ("handleVote: electionWon={} publishPermitted={} electionValueForce ={}" ,
178
- electionWon , publishPermitted , electionValueForced );
179
- if (electionWon && publishPermitted && electionValueForced ) {
165
+ logger .debug ("handleVote: electionWon={} publishPermitted={} lastAcceptedTerm ={}" ,
166
+ electionWon , publishPermitted , lastAcceptedTerm );
167
+ if (electionWon && publishPermitted && lastAcceptedTerm != NO_TERM ) {
180
168
logger .debug ("handleVote: sending PublishRequest" );
181
169
182
170
publishPermitted = false ;
183
- assert acceptedState .isPresent (); // must be true because electionValueForced == true
171
+ assert acceptedState .isPresent (); // must be true because lastAcceptedTerm != NO_TERM
184
172
return Optional .of (new PublishRequest <>(firstUncommittedSlot (), currentTerm , acceptedState .get ().getDiff ()));
185
173
}
186
174
@@ -287,7 +275,6 @@ public void handleCommit(ApplyCommit applyCommit) {
287
275
committedState = newCommittedState ;
288
276
acceptedState = Optional .empty ();
289
277
publishPermitted = true ;
290
- electionValueForced = false ;
291
278
publishVotes = new NodeCollection ();
292
279
}
293
280
@@ -318,7 +305,6 @@ public void applyCatchup(T newCommittedState) {
318
305
persistence .persistCommittedState (newCommittedState );
319
306
committedState = newCommittedState ;
320
307
acceptedState = Optional .empty ();
321
- electionValueForced = false ;
322
308
joinVotes = new NodeCollection ();
323
309
electionWon = false ;
324
310
publishVotes = new NodeCollection ();
@@ -341,10 +327,7 @@ public PublishRequest<T> handleClientValue(Diff<T> diff) {
341
327
logger .debug ("handleClientValue: ignored request as publishing is not permitted" );
342
328
throw new IllegalArgumentException ("publishing not permitted" );
343
329
}
344
- if (electionValueForced ) {
345
- logger .debug ("handleClientValue: ignored request as election value is forced" );
346
- throw new IllegalArgumentException ("election value forced" );
347
- }
330
+ assert lastAcceptedTerm () == NO_TERM ; // see https://github.com/elastic/elasticsearch-formal-models/issues/24
348
331
349
332
logger .trace ("handleClientValue: processing request for slot [{}] and term [{}]" , firstUncommittedSlot (), currentTerm );
350
333
publishPermitted = false ;
0 commit comments