From b0ea4d8db509075eb44c00b095c1999084a420c0 Mon Sep 17 00:00:00 2001 From: Sachin Kale Date: Thu, 14 Sep 2023 10:48:07 +0530 Subject: [PATCH] Add comment explaining the change Signed-off-by: Sachin Kale --- .../org/opensearch/index/shard/IndexShard.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/shard/IndexShard.java b/server/src/main/java/org/opensearch/index/shard/IndexShard.java index 3325f6ad9afe2..cce233a0f30f9 100644 --- a/server/src/main/java/org/opensearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/opensearch/index/shard/IndexShard.java @@ -2356,10 +2356,11 @@ private void innerOpenEngineAndTranslog(LongSupplier globalCheckpointSupplier, b synchronized (engineMutex) { assert currentEngineReference.get() == null : "engine is running"; verifyNotClosed(); - if (indexSettings.isRemoteStoreEnabled() && syncFromRemote) { - syncSegmentsFromRemoteSegmentStore(false); - } - if (indexSettings.isRemoteTranslogStoreEnabled()) { + if (indexSettings.isRemoteStoreEnabled()) + // Download missing segments from remote segment store. + if (syncFromRemote) { + syncSegmentsFromRemoteSegmentStore(false); + } if (shardRouting.primary()) { if (syncFromRemote) { syncRemoteTranslogAndUpdateGlobalCheckpoint(); @@ -2371,6 +2372,11 @@ private void innerOpenEngineAndTranslog(LongSupplier globalCheckpointSupplier, b deleteTranslogFilesFromRemoteTranslog(); } } else if (syncFromRemote) { + // For replicas, when we download segments from remote segment store, we need to make sure that local + // translog is having the same UUID that is referred by the segments. If they are different, engine open + // fails with TranslogCorruptedException. It is safe to create empty translog for remote store enabled + // indices as replica would only need to read translog in failover scenario and we always fetch data + // from remote translog at the time of failover. final SegmentInfos lastCommittedSegmentInfos = store().readLastCommittedSegmentsInfo(); final String translogUUID = lastCommittedSegmentInfos.userData.get(TRANSLOG_UUID_KEY); final long checkpoint = Long.parseLong(lastCommittedSegmentInfos.userData.get(SequenceNumbers.LOCAL_CHECKPOINT_KEY));