From 42eb605ff9f6ebc44727104d1f736327fc253a13 Mon Sep 17 00:00:00 2001 From: bansvaru Date: Thu, 8 Jun 2023 10:07:56 +0530 Subject: [PATCH] Minor code refactoring Signed-off-by: bansvaru --- .../transfer/TranslogTransferManager.java | 3 +- .../index/translog/RemoteFSTranslogTests.java | 30 ++++--------------- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/translog/transfer/TranslogTransferManager.java b/server/src/main/java/org/opensearch/index/translog/transfer/TranslogTransferManager.java index fc4192a4efe0e..62be6fe2d406e 100644 --- a/server/src/main/java/org/opensearch/index/translog/transfer/TranslogTransferManager.java +++ b/server/src/main/java/org/opensearch/index/translog/transfer/TranslogTransferManager.java @@ -59,6 +59,7 @@ public class TranslogTransferManager { private static final Logger logger = LogManager.getLogger(TranslogTransferManager.class); private final static String METADATA_DIR = "metadata"; + private final static String DATA_DIR = "data"; public TranslogTransferManager( ShardId shardId, @@ -68,7 +69,7 @@ public TranslogTransferManager( ) { this.shardId = shardId; this.transferService = transferService; - this.remoteBaseTransferPath = remoteBaseTransferPath.add("data"); + this.remoteBaseTransferPath = remoteBaseTransferPath.add(DATA_DIR); this.remoteMetadataTransferPath = remoteBaseTransferPath.add(METADATA_DIR); this.fileTransferTracker = fileTransferTracker; } diff --git a/server/src/test/java/org/opensearch/index/translog/RemoteFSTranslogTests.java b/server/src/test/java/org/opensearch/index/translog/RemoteFSTranslogTests.java index 94b2f58ecd066..07abbd54d6844 100644 --- a/server/src/test/java/org/opensearch/index/translog/RemoteFSTranslogTests.java +++ b/server/src/test/java/org/opensearch/index/translog/RemoteFSTranslogTests.java @@ -112,6 +112,7 @@ public class RemoteFSTranslogTests extends OpenSearchTestCase { private final AtomicReference persistedSeqNoConsumer = new AtomicReference<>(); private ThreadPool threadPool; private final static String METADATA_DIR = "metadata"; + private final static String DATA_DIR = "data"; BlobStoreRepository repository; BlobStoreTransferService blobStoreTransferService; @@ -484,20 +485,15 @@ public void testSimpleOperationsUpload() throws Exception { translog.rollGeneration(); assertEquals(6, translog.allUploaded().size()); - Set mdFiles = blobStoreTransferService.listAll(getTranslogDirectory().add("metadata")); + Set mdFiles = blobStoreTransferService.listAll(getTranslogDirectory().add(METADATA_DIR)); assertEquals(2, mdFiles.size()); logger.info("All md files {}", mdFiles); - Set tlogFiles = blobStoreTransferService.listAll(getTranslogDirectory().add("data").add(String.valueOf(primaryTerm.get()))); + Set tlogFiles = blobStoreTransferService.listAll(getTranslogDirectory().add(DATA_DIR).add(String.valueOf(primaryTerm.get()))); logger.info("All data files {}", tlogFiles); // assert content of ckp and tlog files - BlobPath path = repository.basePath() - .add(shardId.getIndex().getUUID()) - .add(String.valueOf(shardId.id())) - .add(TRANSLOG) - .add("data") - .add(String.valueOf(primaryTerm.get())); + BlobPath path = getTranslogDirectory().add(DATA_DIR).add(String.valueOf(primaryTerm.get())); for (TranslogReader reader : translog.readers) { final long readerGeneration = reader.getGeneration(); logger.error("Asserting content of {}", readerGeneration); @@ -532,14 +528,7 @@ public void testSimpleOperationsUpload() throws Exception { assertEquals(4, translog.allUploaded().size()); assertEquals( 4, - blobStoreTransferService.listAll( - repository.basePath() - .add(shardId.getIndex().getUUID()) - .add(String.valueOf(shardId.id())) - .add(TRANSLOG) - .add("data") - .add(String.valueOf(primaryTerm.get())) - ).size() + blobStoreTransferService.listAll(getTranslogDirectory().add(DATA_DIR).add(String.valueOf(primaryTerm.get()))).size() ); }); @@ -552,14 +541,7 @@ public void testSimpleOperationsUpload() throws Exception { assertEquals(4, translog.allUploaded().size()); assertEquals( 4, - blobStoreTransferService.listAll( - repository.basePath() - .add(shardId.getIndex().getUUID()) - .add(String.valueOf(shardId.id())) - .add(TRANSLOG) - .add("data") - .add(String.valueOf(primaryTerm.get())) - ).size() + blobStoreTransferService.listAll(getTranslogDirectory().add(DATA_DIR).add(String.valueOf(primaryTerm.get()))).size() ); });