Skip to content

Commit 902d20c

Browse files
dnhatnjasontedor
authored andcommitted
CCR: Use single global checkpoint to normalize range (#33545)
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.
1 parent d4b212c commit 902d20c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,13 @@ static Translog.Operation[] getOperations(IndexShard indexShard, long globalChec
297297
if (indexShard.state() != IndexShardState.STARTED) {
298298
throw new IndexShardNotStartedException(indexShard.shardId(), indexShard.state());
299299
}
300-
if (fromSeqNo > indexShard.getGlobalCheckpoint()) {
300+
if (fromSeqNo > globalCheckpoint) {
301301
return EMPTY_OPERATIONS_ARRAY;
302302
}
303303
int seenBytes = 0;
304304
// - 1 is needed, because toSeqNo is inclusive
305305
long toSeqNo = Math.min(globalCheckpoint, (fromSeqNo + maxOperationCount) - 1);
306+
assert fromSeqNo <= toSeqNo : "invalid range from_seqno[" + fromSeqNo + "] > to_seqno[" + toSeqNo + "]";
306307
final List<Translog.Operation> operations = new ArrayList<>();
307308
try (Translog.Snapshot snapshot = indexShard.newChangesSnapshot("ccr", fromSeqNo, toSeqNo, true)) {
308309
Translog.Operation op;

0 commit comments

Comments
 (0)