Skip to content

Commit 2a9a200

Browse files
committed
CCR: Tighten requesting range check on leader
This commit clarifies the origin of the global checkpoint that the following shard uses and replaces illegal_state_exc E by an assertion. Relates #30980
1 parent ba78aa8 commit 2a9a200

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardChangesAction.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,11 @@ protected Response shardOperation(Request request, ShardId shardId) throws IOExc
236236
IndexService indexService = indicesService.indexServiceSafe(request.getShard().getIndex());
237237
IndexShard indexShard = indexService.getShard(request.getShard().id());
238238
final long indexMetaDataVersion = clusterService.state().metaData().index(shardId.getIndex()).getVersion();
239-
// The following shard generates the request based on the global checkpoint which may not be synced to all leading copies.
240-
// However, this guarantees that the requesting range always be below the local-checkpoint of any leading copies.
241-
final long localCheckpoint = indexShard.getLocalCheckpoint();
242-
if (localCheckpoint < request.minSeqNo || localCheckpoint < request.maxSeqNo) {
243-
throw new IllegalStateException("invalid request from_seqno=[" + request.minSeqNo + "], " +
244-
"to_seqno=[" + request.maxSeqNo + "], local_checkpoint=[" + localCheckpoint + "], shardId=[" + shardId + "]");
245-
}
239+
// The following shard generates this request based on the global checkpoint on the primary copy on the leader.
240+
// Although this value might not have been synced to all replica copies on the leader, the requesting range
241+
// is guaranteed to be at most the local-checkpoint of any shard copies on the leader.
242+
assert request.maxSeqNo <= indexShard.getLocalCheckpoint() : "invalid request from_seqno=[" + request.minSeqNo + "]," +
243+
" to_seqno=[" + request.maxSeqNo + "], local_checkpoint=[" + indexShard.getLocalCheckpoint() + "]";
246244
final Translog.Operation[] operations =
247245
getOperationsBetween(indexShard, request.minSeqNo, request.maxSeqNo, request.maxTranslogsBytes);
248246
return new Response(indexMetaDataVersion, operations);

0 commit comments

Comments
 (0)