From 949fc68daec1e7543d91f87fb9840adcac6386b0 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Sat, 8 Sep 2018 23:21:04 -0400 Subject: [PATCH] CCR: Use single global checkpoint to normalize range We may use different global checkpoints to validate/normalize the range of a change request if the global checkpoint is advanced between these calls. If this is the case, then we generate an invalid request range. --- .../org/elasticsearch/xpack/ccr/action/ShardChangesAction.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 b505ee015bab6..d102c6b5b7af8 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 @@ -297,12 +297,13 @@ static Translog.Operation[] getOperations(IndexShard indexShard, long globalChec if (indexShard.state() != IndexShardState.STARTED) { throw new IndexShardNotStartedException(indexShard.shardId(), indexShard.state()); } - if (fromSeqNo > indexShard.getGlobalCheckpoint()) { + if (fromSeqNo > globalCheckpoint) { return EMPTY_OPERATIONS_ARRAY; } int seenBytes = 0; // - 1 is needed, because toSeqNo is inclusive long toSeqNo = Math.min(globalCheckpoint, (fromSeqNo + maxOperationCount) - 1); + assert fromSeqNo <= toSeqNo : "invalid range from_seqno[" + fromSeqNo + "] > to_seqno[" + toSeqNo + "]"; final List operations = new ArrayList<>(); try (Translog.Snapshot snapshot = indexShard.newChangesSnapshot("ccr", fromSeqNo, toSeqNo, true)) { Translog.Operation op;