diff --git a/server/src/main/java/org/opensearch/index/translog/RemoteBlobStoreInternalTranslogFactory.java b/server/src/main/java/org/opensearch/index/translog/RemoteBlobStoreInternalTranslogFactory.java index ce109640682e5..5dc2ad076d21c 100644 --- a/server/src/main/java/org/opensearch/index/translog/RemoteBlobStoreInternalTranslogFactory.java +++ b/server/src/main/java/org/opensearch/index/translog/RemoteBlobStoreInternalTranslogFactory.java @@ -70,7 +70,7 @@ public Translog newTranslog( assert repository instanceof BlobStoreRepository : "repository should be instance of BlobStoreRepository"; BlobStoreRepository blobStoreRepository = ((BlobStoreRepository) repository); if (RemoteStoreSettings.isPinnedTimestampsEnabled()) { - return new RemoteFsTranslogWithPinnedTimestamps( + return new RemoteFsTimestampAwareTranslog( config, translogUUID, deletionPolicy, @@ -81,8 +81,7 @@ public Translog newTranslog( threadPool, startedPrimarySupplier, remoteTranslogTransferTracker, - remoteStoreSettings, - 0 + remoteStoreSettings ); } else { return new RemoteFsTranslog( diff --git a/server/src/main/java/org/opensearch/index/translog/RemoteFsTranslogWithPinnedTimestamps.java b/server/src/main/java/org/opensearch/index/translog/RemoteFsTimestampAwareTranslog.java similarity index 96% rename from server/src/main/java/org/opensearch/index/translog/RemoteFsTranslogWithPinnedTimestamps.java rename to server/src/main/java/org/opensearch/index/translog/RemoteFsTimestampAwareTranslog.java index 8441186e1d29e..0b134b3bddbec 100644 --- a/server/src/main/java/org/opensearch/index/translog/RemoteFsTranslogWithPinnedTimestamps.java +++ b/server/src/main/java/org/opensearch/index/translog/RemoteFsTimestampAwareTranslog.java @@ -45,18 +45,19 @@ * A Translog implementation which syncs local FS with a remote store * The current impl uploads translog , ckp and metadata to remote store * for every sync, post syncing to disk. Post that, a new generation is - * created. + * created. This implementation is also aware of pinned timestamp and makes + * sure data against pinned timestamp is retained. * * @opensearch.internal */ -public class RemoteFsTranslogWithPinnedTimestamps extends RemoteFsTranslog { +public class RemoteFsTimestampAwareTranslog extends RemoteFsTranslog { private final Logger logger; private final Map metadataFilePinnedTimestampMap; // For metadata files, with no min generation in the name, we cache generation data to avoid multiple reads. private final Map> oldFormatMetadataFileGenerationMap; - public RemoteFsTranslogWithPinnedTimestamps( + public RemoteFsTimestampAwareTranslog( TranslogConfig config, String translogUUID, TranslogDeletionPolicy deletionPolicy, @@ -67,8 +68,7 @@ public RemoteFsTranslogWithPinnedTimestamps( ThreadPool threadPool, BooleanSupplier startedPrimarySupplier, RemoteTranslogTransferTracker remoteTranslogTransferTracker, - RemoteStoreSettings remoteStoreSettings, - long timestamp + RemoteStoreSettings remoteStoreSettings ) throws IOException { super( config, @@ -81,8 +81,7 @@ public RemoteFsTranslogWithPinnedTimestamps( threadPool, startedPrimarySupplier, remoteTranslogTransferTracker, - remoteStoreSettings, - timestamp + remoteStoreSettings ); logger = Loggers.getLogger(getClass(), shardId); this.metadataFilePinnedTimestampMap = new HashMap<>(); @@ -179,19 +178,19 @@ public void onResponse(List blobMetadata) { return; } - logger.debug("metadataFilesToBeDeleted = {}", metadataFilesToBeDeleted); + logger.debug(() -> "metadataFilesToBeDeleted = " + metadataFilesToBeDeleted); // For all the files that we are keeping, fetch min and max generations List metadataFilesNotToBeDeleted = new ArrayList<>(metadataFiles); metadataFilesNotToBeDeleted.removeAll(metadataFilesToBeDeleted); - logger.debug("metadataFilesNotToBeDeleted = {}", metadataFilesNotToBeDeleted); + logger.debug(() -> "metadataFilesNotToBeDeleted = " + metadataFilesNotToBeDeleted); Set generationsToBeDeleted = getGenerationsToBeDeleted( metadataFilesNotToBeDeleted, metadataFilesToBeDeleted, indexDeleted ); - logger.debug("generationsToBeDeleted = {}", generationsToBeDeleted); + logger.debug(() -> "generationsToBeDeleted = " + generationsToBeDeleted); if (generationsToBeDeleted.isEmpty() == false) { // Delete stale generations translogTransferManager.deleteGenerationAsync( diff --git a/server/src/test/java/org/opensearch/index/translog/RemoteFsTranslogWithPinnedTimestampTests.java b/server/src/test/java/org/opensearch/index/translog/RemoteFsTimestampAwareTranslogTests.java similarity index 96% rename from server/src/test/java/org/opensearch/index/translog/RemoteFsTranslogWithPinnedTimestampTests.java rename to server/src/test/java/org/opensearch/index/translog/RemoteFsTimestampAwareTranslogTests.java index 427ad43fb1855..ce0968664991e 100644 --- a/server/src/test/java/org/opensearch/index/translog/RemoteFsTranslogWithPinnedTimestampTests.java +++ b/server/src/test/java/org/opensearch/index/translog/RemoteFsTimestampAwareTranslogTests.java @@ -68,7 +68,7 @@ import static org.mockito.Mockito.when; @LuceneTestCase.SuppressFileSystems("ExtrasFS") -public class RemoteFsTranslogWithPinnedTimestampTests extends RemoteFsTranslogTests { +public class RemoteFsTimestampAwareTranslogTests extends RemoteFsTranslogTests { Runnable updatePinnedTimstampTask; BlobContainer blobContainer; @@ -132,7 +132,7 @@ protected RemoteFsTranslog createTranslogInstance( String translogUUID, TranslogDeletionPolicy deletionPolicy ) throws IOException { - return new RemoteFsTranslogWithPinnedTimestamps( + return new RemoteFsTimestampAwareTranslog( translogConfig, translogUUID, deletionPolicy, @@ -143,8 +143,7 @@ protected RemoteFsTranslog createTranslogInstance( threadPool, primaryMode::get, new RemoteTranslogTransferTracker(shardId, 10), - DefaultRemoteStoreSettings.INSTANCE, - 0 + DefaultRemoteStoreSettings.INSTANCE ); } @@ -242,7 +241,7 @@ public void testIndexDeletionWithNoPinnedTimestampNoRecentMdFiles() throws Excep assertBusy(() -> assertTrue(translog.isRemoteGenerationDeletionPermitsAvailable())); updatePinnedTimstampTask.run(); - ((RemoteFsTranslogWithPinnedTimestamps) translog).trimUnreferencedReaders(true, false); + ((RemoteFsTimestampAwareTranslog) translog).trimUnreferencedReaders(true, false); assertBusy(() -> assertTrue(translog.isRemoteGenerationDeletionPermitsAvailable())); @@ -265,7 +264,7 @@ public void testIndexDeletionWithNoPinnedTimestampButRecentFiles() throws Except addToTranslogAndListAndUpload(translog, ops, new Translog.Index("4", 4, primaryTerm.get(), new byte[] { 1 })); updatePinnedTimstampTask.run(); - ((RemoteFsTranslogWithPinnedTimestamps) translog).trimUnreferencedReaders(true, false); + ((RemoteFsTimestampAwareTranslog) translog).trimUnreferencedReaders(true, false); assertBusy(() -> assertTrue(translog.isRemoteGenerationDeletionPermitsAvailable())); assertBusy(() -> { @@ -611,7 +610,7 @@ public void testGetGenerationsToBeDeletedEmptyMetadataFilesNotToBeDeleted() thro // 27 to 42 "metadata__9223372036438563903__9223372036854775765__9223370311919910403__31__9223372036854775780__1" ); - Set generations = ((RemoteFsTranslogWithPinnedTimestamps) translog).getGenerationsToBeDeleted( + Set generations = ((RemoteFsTimestampAwareTranslog) translog).getGenerationsToBeDeleted( metadataFilesNotToBeDeleted, metadataFilesToBeDeleted, true @@ -646,7 +645,7 @@ public void testGetGenerationsToBeDeleted() throws IOException { // 27 to 42 "metadata__9223372036438563903__9223372036854775765__9223370311919910403__31__9223372036854775780__1" ); - Set generations = ((RemoteFsTranslogWithPinnedTimestamps) translog).getGenerationsToBeDeleted( + Set generations = ((RemoteFsTimestampAwareTranslog) translog).getGenerationsToBeDeleted( metadataFilesNotToBeDeleted, metadataFilesToBeDeleted, true @@ -673,7 +672,7 @@ public void testGetMetadataFilesToBeDeletedNoExclusion() { "metadata__9223372036438563903__9223372036854775701__9223370311919910403__31__9223372036854775701__1" ); - assertEquals(metadataFiles, ((RemoteFsTranslogWithPinnedTimestamps) translog).getMetadataFilesToBeDeleted(metadataFiles)); + assertEquals(metadataFiles, ((RemoteFsTimestampAwareTranslog) translog).getMetadataFilesToBeDeleted(metadataFiles)); } public void testGetMetadataFilesToBeDeletedExclusionBasedOnAgeOnly() { @@ -689,7 +688,7 @@ public void testGetMetadataFilesToBeDeletedExclusionBasedOnAgeOnly() { "metadata__9223372036438563903__9223372036854775701__" + md3Timestamp + "__31__9223372036854775701__1" ); - List metadataFilesToBeDeleted = ((RemoteFsTranslogWithPinnedTimestamps) translog).getMetadataFilesToBeDeleted( + List metadataFilesToBeDeleted = ((RemoteFsTimestampAwareTranslog) translog).getMetadataFilesToBeDeleted( metadataFiles ); assertEquals(1, metadataFilesToBeDeleted.size()); @@ -713,7 +712,7 @@ public void testGetMetadataFilesToBeDeletedExclusionBasedOnPinningOnly() throws "metadata__9223372036438563903__9223372036854775701__" + md3Timestamp + "__31__9223372036854775701__1" ); - List metadataFilesToBeDeleted = ((RemoteFsTranslogWithPinnedTimestamps) translog).getMetadataFilesToBeDeleted( + List metadataFilesToBeDeleted = ((RemoteFsTimestampAwareTranslog) translog).getMetadataFilesToBeDeleted( metadataFiles ); assertEquals(2, metadataFilesToBeDeleted.size()); @@ -738,7 +737,7 @@ public void testGetMetadataFilesToBeDeletedExclusionBasedOnAgeAndPinning() throw "metadata__9223372036438563903__9223372036854775701__" + md3Timestamp + "__31__9223372036854775701__1" ); - List metadataFilesToBeDeleted = ((RemoteFsTranslogWithPinnedTimestamps) translog).getMetadataFilesToBeDeleted( + List metadataFilesToBeDeleted = ((RemoteFsTimestampAwareTranslog) translog).getMetadataFilesToBeDeleted( metadataFiles ); assertEquals(1, metadataFilesToBeDeleted.size()); @@ -765,7 +764,7 @@ public void testIsGenerationPinned() { pinnedGenerations.add(new Tuple<>(142L, 180L)); pinnedGenerations.add(new Tuple<>(4L, 9L)); - RemoteFsTranslogWithPinnedTimestamps translog = (RemoteFsTranslogWithPinnedTimestamps) this.translog; + RemoteFsTimestampAwareTranslog translog = (RemoteFsTimestampAwareTranslog) this.translog; assertFalse(translog.isGenerationPinned(3, pinnedGenerations)); assertFalse(translog.isGenerationPinned(10, pinnedGenerations)); @@ -784,7 +783,7 @@ public void testIsGenerationPinned() { public void testGetMinMaxTranslogGenerationFromMetadataFile() throws IOException { TranslogTransferManager translogTransferManager = mock(TranslogTransferManager.class); - RemoteFsTranslogWithPinnedTimestamps translog = (RemoteFsTranslogWithPinnedTimestamps) this.translog; + RemoteFsTimestampAwareTranslog translog = (RemoteFsTimestampAwareTranslog) this.translog; // Fetch generations directly from the filename assertEquals(