From 790e2fe890441274ac83fb96164cdf02a25f030a Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Thu, 31 May 2018 20:00:33 -0400 Subject: [PATCH] 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 --- .../xpack/ccr/action/ShardChangesAction.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardChangesAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardChangesAction.java index e59c51d29217c..4a25b446e25be 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardChangesAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardChangesAction.java @@ -236,13 +236,11 @@ protected Response shardOperation(Request request, ShardId shardId) throws IOExc IndexService indexService = indicesService.indexServiceSafe(request.getShard().getIndex()); IndexShard indexShard = indexService.getShard(request.getShard().id()); final long indexMetaDataVersion = clusterService.state().metaData().index(shardId.getIndex()).getVersion(); - // The following shard generates the request based on the global checkpoint which may not be synced to all leading copies. - // However, this guarantees that the requesting range always be below the local-checkpoint of any leading copies. - final long localCheckpoint = indexShard.getLocalCheckpoint(); - if (localCheckpoint < request.minSeqNo || localCheckpoint < request.maxSeqNo) { - throw new IllegalStateException("invalid request from_seqno=[" + request.minSeqNo + "], " + - "to_seqno=[" + request.maxSeqNo + "], local_checkpoint=[" + localCheckpoint + "], shardId=[" + shardId + "]"); - } + // The following shard generates this request based on the global checkpoint on the primary copy on the leader. + // Although this value might not have been synced to all replica copies on the leader, the requesting range + // is guaranteed to be at most the local-checkpoint of any shard copies on the leader. + assert request.maxSeqNo <= indexShard.getLocalCheckpoint() : "invalid request from_seqno=[" + request.minSeqNo + "]," + + " to_seqno=[" + request.maxSeqNo + "], local_checkpoint=[" + indexShard.getLocalCheckpoint() + "]"; final Translog.Operation[] operations = getOperationsBetween(indexShard, request.minSeqNo, request.maxSeqNo, request.maxTranslogsBytes); return new Response(indexMetaDataVersion, operations);