From 9e34d1ec7a4a0f24e5bd04ac4f6f9add93218adf Mon Sep 17 00:00:00 2001 From: Ashish Singh Date: Fri, 20 Oct 2023 15:58:45 +0530 Subject: [PATCH] Incorporate PR review comments --- .../opensearch/index/translog/InternalTranslogManager.java | 7 +++---- .../org/opensearch/index/translog/RemoteFsTranslog.java | 3 ++- .../main/java/org/opensearch/index/translog/Translog.java | 4 ++++ .../indices/recovery/RemoteRecoveryTargetHandler.java | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/translog/InternalTranslogManager.java b/server/src/main/java/org/opensearch/index/translog/InternalTranslogManager.java index 0e4239bf785b6..4d0fc13d433c6 100644 --- a/server/src/main/java/org/opensearch/index/translog/InternalTranslogManager.java +++ b/server/src/main/java/org/opensearch/index/translog/InternalTranslogManager.java @@ -430,10 +430,9 @@ public String getTranslogUUID() { * @return if the translog should be flushed */ public boolean shouldPeriodicallyFlush(long localCheckpointOfLastCommit, long flushThreshold) { - long minRefSeqNo = translog instanceof RemoteFsTranslog - ? ((RemoteFsTranslog) translog).getMinSeqNoToKeep() - : localCheckpointOfLastCommit + 1; - final long minReferencedTranslogGeneration = translog.getMinGenerationForSeqNo(minRefSeqNo).translogFileGeneration; + // This is the minimum seqNo that is referred in translog and considered for calculating translog size + long minTranslogRefSeqNo = translog.getMinUnreferencedSeqNoInSegments(localCheckpointOfLastCommit + 1); + final long minReferencedTranslogGeneration = translog.getMinGenerationForSeqNo(minTranslogRefSeqNo).translogFileGeneration; if (translog.sizeInBytesByMinGen(minReferencedTranslogGeneration) < flushThreshold) { return false; } diff --git a/server/src/main/java/org/opensearch/index/translog/RemoteFsTranslog.java b/server/src/main/java/org/opensearch/index/translog/RemoteFsTranslog.java index 790eed93bd1ec..2dd9b1a545d4a 100644 --- a/server/src/main/java/org/opensearch/index/translog/RemoteFsTranslog.java +++ b/server/src/main/java/org/opensearch/index/translog/RemoteFsTranslog.java @@ -545,7 +545,8 @@ public void onUploadFailed(TransferSnapshot transferSnapshot, Exception ex) thro } } - long getMinSeqNoToKeep() { + @Override + public long getMinUnreferencedSeqNoInSegments(long minUnrefCheckpointInLastCommit) { return minSeqNoToKeep; } } diff --git a/server/src/main/java/org/opensearch/index/translog/Translog.java b/server/src/main/java/org/opensearch/index/translog/Translog.java index cf7f18840a03e..b44aa6e059224 100644 --- a/server/src/main/java/org/opensearch/index/translog/Translog.java +++ b/server/src/main/java/org/opensearch/index/translog/Translog.java @@ -2034,4 +2034,8 @@ public static String createEmptyTranslog( writer.close(); return uuid; } + + public long getMinUnreferencedSeqNoInSegments(long minUnrefCheckpointInLastCommit) { + return minUnrefCheckpointInLastCommit; + } } diff --git a/server/src/main/java/org/opensearch/indices/recovery/RemoteRecoveryTargetHandler.java b/server/src/main/java/org/opensearch/indices/recovery/RemoteRecoveryTargetHandler.java index d6d03cf8ecd3b..37227596fdfe7 100644 --- a/server/src/main/java/org/opensearch/indices/recovery/RemoteRecoveryTargetHandler.java +++ b/server/src/main/java/org/opensearch/indices/recovery/RemoteRecoveryTargetHandler.java @@ -134,7 +134,7 @@ public void prepareForTranslogOperations(int totalTranslogOps, ActionListener responseListener = ActionListener.map(listener, r -> null); if (remoteStoreEnabled) { // If remote store is enabled, during the prepare_translog phase, translog is also downloaded on the - // target host along with incremental segments download. This + // target host along with incremental segments download. retryableTransportClient.executeRetryableAction(action, request, translogOpsRequestOptions, responseListener, reader); } else { retryableTransportClient.executeRetryableAction(action, request, responseListener, reader);