Skip to content

Commit 5d30441

Browse files
author
Sachin Kale
committed
Address PR comments
Signed-off-by: Sachin Kale <kalsac@amazon.com>
1 parent 9e53228 commit 5d30441

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

server/src/main/java/org/opensearch/index/store/RemoteSegmentStoreDirectory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ private String getLocalSegmentFilename(String remoteFilename) {
372372

373373
// Visible for testing
374374
public Map<String, UploadedSegmentMetadata> getSegmentsUploadedToRemoteStore() {
375-
return this.segmentsUploadedToRemoteStore;
375+
return Collections.unmodifiableMap(this.segmentsUploadedToRemoteStore);
376376
}
377377

378378
/**

server/src/test/java/org/opensearch/index/store/RemoteSegmentStoreDirectoryTests.java

+27-8
Original file line numberDiff line numberDiff line change
@@ -318,20 +318,39 @@ public void testCopyFromException() throws IOException {
318318
}
319319

320320
public void testContainsFile() throws IOException {
321-
populateMetadata();
321+
List<String> metadataFiles = List.of("metadata__1__5__abc");
322+
when(remoteMetadataDirectory.listFilesByPrefix(RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX)).thenReturn(
323+
metadataFiles
324+
);
325+
326+
Map<String, String> metadata = new HashMap<>();
327+
metadata.put("_0.cfe", "_0.cfe::_0.cfe__" + UUIDs.base64UUID() + "::1234");
328+
metadata.put("_0.cfs", "_0.cfs::_0.cfs__" + UUIDs.base64UUID() + "::2345");
329+
330+
Map<String, Map<String, String>> metadataFilenameContentMapping = Map.of("metadata__1__5__abc", metadata);
331+
332+
IndexInput indexInput1 = mock(IndexInput.class);
333+
when(indexInput1.readMapOfStrings()).thenReturn(metadataFilenameContentMapping.get("metadata__1__5__abc"));
334+
when(remoteMetadataDirectory.openInput("metadata__1__5__abc", IOContext.DEFAULT)).thenReturn(indexInput1);
335+
322336
remoteSegmentStoreDirectory.init();
323337

324-
// This is not the correct way to add files but the other way is to open up access to fields in UploadedSegmentMetadata
325338
Map<String, RemoteSegmentStoreDirectory.UploadedSegmentMetadata> uploadedSegmentMetadataMap = remoteSegmentStoreDirectory
326339
.getSegmentsUploadedToRemoteStore();
327-
uploadedSegmentMetadataMap.put(
328-
"_100.si",
329-
new RemoteSegmentStoreDirectory.UploadedSegmentMetadata("_100.si", "_100.si__uuid1", "1234")
340+
341+
assertThrows(
342+
UnsupportedOperationException.class,
343+
() -> uploadedSegmentMetadataMap.put(
344+
"_100.si",
345+
new RemoteSegmentStoreDirectory.UploadedSegmentMetadata("_100.si", "_100.si__uuid1", "1234")
346+
)
330347
);
331348

332-
assertTrue(remoteSegmentStoreDirectory.containsFile("_100.si", "1234"));
333-
assertFalse(remoteSegmentStoreDirectory.containsFile("_100.si", "2345"));
334-
assertFalse(remoteSegmentStoreDirectory.containsFile("_200.si", "1234"));
349+
assertTrue(remoteSegmentStoreDirectory.containsFile("_0.cfe", "1234"));
350+
assertTrue(remoteSegmentStoreDirectory.containsFile("_0.cfs", "2345"));
351+
assertFalse(remoteSegmentStoreDirectory.containsFile("_0.cfe", "1234000"));
352+
assertFalse(remoteSegmentStoreDirectory.containsFile("_0.cfs", "2345000"));
353+
assertFalse(remoteSegmentStoreDirectory.containsFile("_0.si", "23"));
335354
}
336355

337356
public void testUploadMetadataEmpty() throws IOException {

0 commit comments

Comments
 (0)