diff --git a/server/src/main/java/org/opensearch/index/remote/RemoteStoreUtils.java b/server/src/main/java/org/opensearch/index/remote/RemoteStoreUtils.java index efbe4534bf0ef..32a1ca0e5d5ab 100644 --- a/server/src/main/java/org/opensearch/index/remote/RemoteStoreUtils.java +++ b/server/src/main/java/org/opensearch/index/remote/RemoteStoreUtils.java @@ -476,7 +476,8 @@ private static Set getPinnedTimestampLockedFiles( Set newPinnedTimestamps = new TreeSet<>(Collections.reverseOrder()); for (Long pinnedTimestamp : pinnedTimestampSet) { String cachedFile = metadataFilePinnedTimestampMap.get(pinnedTimestamp); - if (cachedFile != null && metadataFiles.contains(cachedFile)) { + if (cachedFile != null) { + assert metadataFiles.contains(cachedFile) : "Metadata files should contain [" + cachedFile + "]"; implicitLockedFiles.add(cachedFile); } else { newPinnedTimestamps.add(pinnedTimestamp); diff --git a/server/src/test/java/org/opensearch/index/remote/RemoteStoreUtilsTests.java b/server/src/test/java/org/opensearch/index/remote/RemoteStoreUtilsTests.java index 2a7a38587198e..d134a2bad7b74 100644 --- a/server/src/test/java/org/opensearch/index/remote/RemoteStoreUtilsTests.java +++ b/server/src/test/java/org/opensearch/index/remote/RemoteStoreUtilsTests.java @@ -1162,6 +1162,15 @@ public void testGetPinnedTimestampLockedFilesWithCache() { assertEquals(0, implicitLockedFiles.size()); assertEquals(3, metadataFilePinnedTimestampCache.size()); + assertThrows( + AssertionError.class, + () -> testGetPinnedTimestampLockedFilesWithPinnedTimestamps( + List.of(2000L, 2200L, 3001L, 4200L, 4600L, 5010L), + Set.of(3000L, 4000L, 5000L, 6000L), + metadataFilePinnedTimestampCache + ) + ); + metadataAndLocks = testGetPinnedTimestampLockedFilesWithPinnedTimestamps( List.of(2000L, 2200L, 2500L, 3001L, 4200L, 4600L, 5010L), Set.of(),