From 6e527d9939e635ff0d2734f4a5d4ffdad96a1a7f Mon Sep 17 00:00:00 2001 From: Ashish Singh Date: Mon, 30 Oct 2023 14:22:29 +0530 Subject: [PATCH] [Remote Translog] Fix translog inconsistent generation assertion failure in ITs Signed-off-by: Ashish Singh --- .../java/org/opensearch/index/translog/RemoteFsTranslog.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 65d16e213cad1..9ff93e7c86fc5 100644 --- a/server/src/main/java/org/opensearch/index/translog/RemoteFsTranslog.java +++ b/server/src/main/java/org/opensearch/index/translog/RemoteFsTranslog.java @@ -268,6 +268,7 @@ public void rollGeneration() throws IOException { private boolean prepareAndUpload(Long primaryTerm, Long generation) throws IOException { long maxSeqNo = -1; + boolean translogOpen = closed.get() == false; try (Releasable ignored = writeLock.acquire()) { if (generation == null || generation == current.getGeneration()) { try { @@ -277,7 +278,7 @@ private boolean prepareAndUpload(Long primaryTerm, Long generation) throws IOExc final TranslogReader reader = current.closeIntoReader(); readers.add(reader); copyCheckpointTo(location.resolve(getCommitCheckpointFileName(current.getGeneration()))); - if (closed.get() == false) { + if (translogOpen) { logger.trace("Creating new writer for gen: [{}]", current.getGeneration() + 1); current = createWriter(current.getGeneration() + 1); } @@ -304,7 +305,7 @@ private boolean prepareAndUpload(Long primaryTerm, Long generation) throws IOExc // Writing remote in sync fashion doesn't hurt as global ckp update // is not updated in remote translog except in primary to primary recovery. if (generation == null) { - if (closed.get() == false) { + if (translogOpen) { return upload(primaryTerm, current.getGeneration() - 1, maxSeqNo); } else { return upload(primaryTerm, current.getGeneration(), maxSeqNo);