From 502e3f24b13896cc328f1d174cd2dac10d9f51f2 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 a305a774f5854..68d97cbae4abf 100644 --- a/server/src/main/java/org/opensearch/index/translog/RemoteFsTranslog.java +++ b/server/src/main/java/org/opensearch/index/translog/RemoteFsTranslog.java @@ -266,13 +266,14 @@ public void rollGeneration() throws IOException { } private boolean prepareAndUpload(Long primaryTerm, Long generation) throws IOException { + boolean translogOpen = closed.get() == false; try (Releasable ignored = writeLock.acquire()) { if (generation == null || generation == current.getGeneration()) { try { 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); } @@ -299,7 +300,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); } else { return upload(primaryTerm, current.getGeneration());