@@ -105,13 +105,13 @@ public long lastAcceptedTerm() {
105
105
*
106
106
* @param newTerm The new term
107
107
* @return A Vote that must be sent to at most one other node.
108
- * @throws IllegalArgumentException if the arguments were incompatible with the current state of this object.
108
+ * @throws ConsensusMessageRejectedException if the arguments were incompatible with the current state of this object.
109
109
*/
110
110
public Vote handleStartVote (long newTerm ) {
111
111
if (newTerm <= getCurrentTerm ()) {
112
112
logger .debug ("handleStartVote: ignored as term provided [{}] lower or equal than current term [{}]" ,
113
113
newTerm , getCurrentTerm ());
114
- throw new IllegalArgumentException ("incoming term " + newTerm + " lower than current term " + getCurrentTerm ());
114
+ throw new ConsensusMessageRejectedException ("incoming term " + newTerm + " lower than current term " + getCurrentTerm ());
115
115
}
116
116
117
117
logger .debug ("handleStartVote: updating term from [{}] to [{}]" , getCurrentTerm (), newTerm );
@@ -132,25 +132,26 @@ public Vote handleStartVote(long newTerm) {
132
132
* @param sourceNode The sender of the Vote received.
133
133
* @param vote The Vote received.
134
134
* @return An optional PublishRequest which, if present, can be broadcast to all peers.
135
- * @throws IllegalArgumentException if the arguments were incompatible with the current state of this object.
135
+ * @throws ConsensusMessageRejectedException if the arguments were incompatible with the current state of this object.
136
136
*/
137
137
public Optional <PublishRequest <T >> handleVote (DiscoveryNode sourceNode , Vote vote ) {
138
138
if (vote .getTerm () != getCurrentTerm ()) {
139
139
logger .debug ("handleVote: ignored vote due to term mismatch (expected: [{}], actual: [{}])" ,
140
140
getCurrentTerm (), vote .getTerm ());
141
- throw new IllegalArgumentException ("incoming term " + vote .getTerm () + " does not match current term " + getCurrentTerm ());
141
+ throw new ConsensusMessageRejectedException (
142
+ "incoming term " + vote .getTerm () + " does not match current term " + getCurrentTerm ());
142
143
}
143
144
if (vote .getFirstUncommittedSlot () > firstUncommittedSlot ()) {
144
145
logger .debug ("handleVote: ignored vote due to slot mismatch (expected: <=[{}], actual: [{}])" ,
145
146
firstUncommittedSlot (), vote .getFirstUncommittedSlot ());
146
- throw new IllegalArgumentException ( "incoming slot " + vote . getFirstUncommittedSlot () + " higher than current slot " +
147
- firstUncommittedSlot ());
147
+ throw new ConsensusMessageRejectedException (
148
+ "incoming slot " + vote . getFirstUncommittedSlot () + " higher than current slot " + firstUncommittedSlot ());
148
149
}
149
150
final long lastAcceptedTerm = lastAcceptedTerm ();
150
151
if (vote .getFirstUncommittedSlot () == firstUncommittedSlot () && vote .getLastAcceptedTerm () > lastAcceptedTerm ) {
151
152
logger .debug ("handleVote: ignored vote as voter has better last accepted term (expected: <=[{}], actual: [{}])" ,
152
153
lastAcceptedTerm , vote .getLastAcceptedTerm ());
153
- throw new IllegalArgumentException ("incoming last accepted term " + vote .getLastAcceptedTerm () + " higher than " +
154
+ throw new ConsensusMessageRejectedException ("incoming last accepted term " + vote .getLastAcceptedTerm () + " higher than " +
154
155
"current last accepted term " + lastAcceptedTerm );
155
156
}
156
157
@@ -177,19 +178,19 @@ public Optional<PublishRequest<T>> handleVote(DiscoveryNode sourceNode, Vote vot
177
178
*
178
179
* @param publishRequest The PublishRequest received.
179
180
* @return A PublishResponse which can be sent back to the sender of the PublishRequest.
180
- * @throws IllegalArgumentException if the arguments were incompatible with the current state of this object.
181
+ * @throws ConsensusMessageRejectedException if the arguments were incompatible with the current state of this object.
181
182
*/
182
183
public PublishResponse handlePublishRequest (PublishRequest <T > publishRequest ) {
183
184
if (publishRequest .getTerm () != getCurrentTerm ()) {
184
185
logger .debug ("handlePublishRequest: ignored publish request due to term mismatch (expected: [{}], actual: [{}])" ,
185
186
getCurrentTerm (), publishRequest .getTerm ());
186
- throw new IllegalArgumentException ("incoming term " + publishRequest .getTerm () + " does not match current term " +
187
+ throw new ConsensusMessageRejectedException ("incoming term " + publishRequest .getTerm () + " does not match current term " +
187
188
getCurrentTerm ());
188
189
}
189
190
if (publishRequest .getSlot () != firstUncommittedSlot ()) {
190
191
logger .debug ("handlePublishRequest: ignored publish request due to slot mismatch (expected: [{}], actual: [{}])" ,
191
192
firstUncommittedSlot (), publishRequest .getSlot ());
192
- throw new IllegalArgumentException ("incoming slot " + publishRequest .getSlot () + " does not match current slot " +
193
+ throw new ConsensusMessageRejectedException ("incoming slot " + publishRequest .getSlot () + " does not match current slot " +
193
194
firstUncommittedSlot ());
194
195
}
195
196
@@ -209,13 +210,13 @@ public PublishResponse handlePublishRequest(PublishRequest<T> publishRequest) {
209
210
* @param publishResponse The PublishResponse received.
210
211
* @return An optional ApplyCommit which, if present, may be broadcast to all peers, indicating that this publication
211
212
* has been accepted at a quorum of peers and is therefore committed.
212
- * @throws IllegalArgumentException if the arguments were incompatible with the current state of this object.
213
+ * @throws ConsensusMessageRejectedException if the arguments were incompatible with the current state of this object.
213
214
*/
214
215
public Optional <ApplyCommit > handlePublishResponse (DiscoveryNode sourceNode , PublishResponse publishResponse ) {
215
216
if (publishResponse .getTerm () != getCurrentTerm ()) {
216
217
logger .debug ("handlePublishResponse: ignored publish response due to term mismatch (expected: [{}], actual: [{}])" ,
217
218
getCurrentTerm (), publishResponse .getTerm ());
218
- throw new IllegalArgumentException ("incoming term " + publishResponse .getTerm ()
219
+ throw new ConsensusMessageRejectedException ("incoming term " + publishResponse .getTerm ()
219
220
+ " does not match current term " + getCurrentTerm ());
220
221
}
221
222
if (publishResponse .getSlot () != firstUncommittedSlot ()) {
@@ -225,7 +226,7 @@ public Optional<ApplyCommit> handlePublishResponse(DiscoveryNode sourceNode, Pub
225
226
logger .debug ("handlePublishResponse: ignored publish response due to slot mismatch (expected: [{}], actual: [{}])" ,
226
227
firstUncommittedSlot (), publishResponse .getSlot ());
227
228
}
228
- throw new IllegalArgumentException ("incoming slot " + publishResponse .getSlot () + " does not match current slot " +
229
+ throw new ConsensusMessageRejectedException ("incoming slot " + publishResponse .getSlot () + " does not match current slot " +
229
230
firstUncommittedSlot ());
230
231
}
231
232
@@ -245,20 +246,20 @@ public Optional<ApplyCommit> handlePublishResponse(DiscoveryNode sourceNode, Pub
245
246
* May be called on receipt of an ApplyCommit. Updates the committed state accordingly.
246
247
*
247
248
* @param applyCommit The ApplyCommit received.
248
- * @throws IllegalArgumentException if the arguments were incompatible with the current state of this object.
249
+ * @throws ConsensusMessageRejectedException if the arguments were incompatible with the current state of this object.
249
250
*/
250
251
public void handleCommit (ApplyCommit applyCommit ) {
251
252
if (applyCommit .getTerm () != lastAcceptedTerm ()) {
252
253
logger .debug ("handleCommit: ignored commit request due to term mismatch " +
253
254
"(expected: [term {} slot {}], actual: [term {} slot {}])" ,
254
255
lastAcceptedTerm (), firstUncommittedSlot (), applyCommit .getTerm (), applyCommit .getSlot ());
255
- throw new IllegalArgumentException ("incoming term " + applyCommit .getTerm () + " does not match last accepted term " +
256
+ throw new ConsensusMessageRejectedException ("incoming term " + applyCommit .getTerm () + " does not match last accepted term " +
256
257
lastAcceptedTerm ());
257
258
}
258
259
if (applyCommit .getSlot () != firstUncommittedSlot ()) {
259
260
logger .debug ("handleCommit: ignored commit request due to slot mismatch (term {}, expected: [{}], actual: [{}])" ,
260
261
lastAcceptedTerm (), firstUncommittedSlot (), applyCommit .getSlot ());
261
- throw new IllegalArgumentException ("incoming slot " + applyCommit .getSlot () + " does not match current slot " +
262
+ throw new ConsensusMessageRejectedException ("incoming slot " + applyCommit .getSlot () + " does not match current slot " +
262
263
firstUncommittedSlot ());
263
264
}
264
265
@@ -295,13 +296,13 @@ public T generateCatchup() {
295
296
/**
296
297
* May be called on receipt of a catch-up message containing the current committed state from a peer.
297
298
*
298
- * @throws IllegalArgumentException if the arguments were incompatible with the current state of this object.
299
+ * @throws ConsensusMessageRejectedException if the arguments were incompatible with the current state of this object.
299
300
*/
300
301
public void applyCatchup (T newCommittedState ) {
301
302
if (newCommittedState .getSlot () <= getCommittedState ().getSlot ()) {
302
303
logger .debug ("applyCatchup: ignored catch up request due to slot mismatch (expected: >[{}], actual: [{}])" ,
303
304
getCommittedState ().getSlot (), newCommittedState .getSlot ());
304
- throw new IllegalArgumentException ("incoming slot " + newCommittedState .getSlot () + " no higher than current slot " +
305
+ throw new ConsensusMessageRejectedException ("incoming slot " + newCommittedState .getSlot () + " no higher than current slot " +
305
306
getCommittedState ().getSlot ());
306
307
}
307
308
@@ -320,16 +321,16 @@ public void applyCatchup(T newCommittedState) {
320
321
*
321
322
* @param diff The RSM transition on which to achieve consensus.
322
323
* @return A PublishRequest that may be broadcast to all peers.
323
- * @throws IllegalArgumentException if the arguments were incompatible with the current state of this object.
324
+ * @throws ConsensusMessageRejectedException if the arguments were incompatible with the current state of this object.
324
325
*/
325
326
public PublishRequest <T > handleClientValue (Diff <T > diff ) {
326
327
if (electionWon == false ) {
327
328
logger .debug ("handleClientValue: ignored request as election not won" );
328
- throw new IllegalArgumentException ("election not won" );
329
+ throw new ConsensusMessageRejectedException ("election not won" );
329
330
}
330
331
if (publishPermitted == false ) {
331
332
logger .debug ("handleClientValue: ignored request as publishing is not permitted" );
332
- throw new IllegalArgumentException ("publishing not permitted" );
333
+ throw new ConsensusMessageRejectedException ("publishing not permitted" );
333
334
}
334
335
assert lastAcceptedTerm () == NO_TERM ; // see https://github.com/elastic/elasticsearch-formal-models/issues/24
335
336
0 commit comments