From ac864f0c0f833fec20c182071fb555d2bceb4693 Mon Sep 17 00:00:00 2001 From: Ashish Singh Date: Thu, 19 Sep 2024 12:56:41 +0530 Subject: [PATCH] Add code to fix the red index on close Signed-off-by: Ashish Singh --- .../opensearch/index/translog/TranslogWriter.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/opensearch/index/translog/TranslogWriter.java b/server/src/main/java/org/opensearch/index/translog/TranslogWriter.java index b0c7d51c3e43b..94435f650b5bb 100644 --- a/server/src/main/java/org/opensearch/index/translog/TranslogWriter.java +++ b/server/src/main/java/org/opensearch/index/translog/TranslogWriter.java @@ -405,13 +405,25 @@ public int totalOperations() { @Override synchronized Checkpoint getCheckpoint() { + // On a remote store enabled cluster, the global checkpoint is always the max seq no of the shard. + // case 1- Whenever a sync translog happens, we create an empty translog writer (TR) with value as -1 + // (SequenceNumbers.NO_OPS_PERFORMED). If we try to sync the translog on account of ensureSynced / flush / roll generation, then + // checkpoint contains value as -1. + // Case 2 - In other cases where at-least operation has been added to TR, then the maxSeqNo is set + // correctly in the checkpoint. Since the in-memory global checkpoint is read from translog checkpoint, we set the same correctly as + // max of seqNo and globalCheckpoint supplied by the supplier. + // In case 1, the max value would be supplied global checkpoint. In case 2, it would be the maxSeqNo. + assert maxSeqNo == SequenceNumbers.NO_OPS_PERFORMED || maxSeqNo >= globalCheckpointSupplier.getAsLong(); + long globalCheckpoint = remoteTranslogEnabled + ? Math.max(maxSeqNo, globalCheckpointSupplier.getAsLong()) + : globalCheckpointSupplier.getAsLong(); return new Checkpoint( totalOffset, operationCounter, generation, minSeqNo, maxSeqNo, - globalCheckpointSupplier.getAsLong(), + globalCheckpoint, minTranslogGenerationSupplier.getAsLong(), SequenceNumbers.UNASSIGNED_SEQ_NO );