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
This commit is contained in:
Nhat Nguyen 2018-05-31 20:00:33 -04:00
parent ba78aa8c02
commit 2a9a2002e6
1 changed files with 5 additions and 7 deletions

View File

@ -236,13 +236,11 @@ public class ShardChangesAction extends Action<ShardChangesAction.Request, Shard
IndexService indexService = indicesService.indexServiceSafe(request.getShard().getIndex()); IndexService indexService = indicesService.indexServiceSafe(request.getShard().getIndex());
IndexShard indexShard = indexService.getShard(request.getShard().id()); IndexShard indexShard = indexService.getShard(request.getShard().id());
final long indexMetaDataVersion = clusterService.state().metaData().index(shardId.getIndex()).getVersion(); 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. // The following shard generates this request based on the global checkpoint on the primary copy on the leader.
// However, this guarantees that the requesting range always be below the local-checkpoint of any leading copies. // Although this value might not have been synced to all replica copies on the leader, the requesting range
final long localCheckpoint = indexShard.getLocalCheckpoint(); // is guaranteed to be at most the local-checkpoint of any shard copies on the leader.
if (localCheckpoint < request.minSeqNo || localCheckpoint < request.maxSeqNo) { assert request.maxSeqNo <= indexShard.getLocalCheckpoint() : "invalid request from_seqno=[" + request.minSeqNo + "]," +
throw new IllegalStateException("invalid request from_seqno=[" + request.minSeqNo + "], " + " to_seqno=[" + request.maxSeqNo + "], local_checkpoint=[" + indexShard.getLocalCheckpoint() + "]";
"to_seqno=[" + request.maxSeqNo + "], local_checkpoint=[" + localCheckpoint + "], shardId=[" + shardId + "]");
}
final Translog.Operation[] operations = final Translog.Operation[] operations =
getOperationsBetween(indexShard, request.minSeqNo, request.maxSeqNo, request.maxTranslogsBytes); getOperationsBetween(indexShard, request.minSeqNo, request.maxSeqNo, request.maxTranslogsBytes);
return new Response(indexMetaDataVersion, operations); return new Response(indexMetaDataVersion, operations);