Skip to content

Commit

Permalink
Fix spotless and test compile error
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Kale <kalsac@amazon.com>
  • Loading branch information
Sachin Kale committed Apr 8, 2024
1 parent bfedb4f commit 7052aca
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,24 +407,6 @@ void uploadMetadata(Collection<String> localSegmentsPostRefresh, SegmentInfos se
}
}

String uploadSegmentInfosSnapshot(String latestSegmentsNFilename, SegmentInfos segmentInfosSnapshot) throws IOException {
final long maxSeqNoFromSegmentInfos = indexShard.getEngine().getMaxSeqNoFromSegmentInfos(segmentInfosSnapshot);

Map<String, String> userData = segmentInfosSnapshot.getUserData();
userData.put(LOCAL_CHECKPOINT_KEY, String.valueOf(maxSeqNoFromSegmentInfos));
userData.put(SequenceNumbers.MAX_SEQ_NO, Long.toString(maxSeqNoFromSegmentInfos));
segmentInfosSnapshot.setUserData(userData, false);

long commitGeneration = SegmentInfos.generationFromSegmentsFileName(latestSegmentsNFilename);
String segmentInfoSnapshotFilename = SEGMENT_INFO_SNAPSHOT_FILENAME_PREFIX + "__" + commitGeneration;
try (IndexOutput indexOutput = storeDirectory.createOutput(segmentInfoSnapshotFilename, IOContext.DEFAULT)) {
segmentInfosSnapshot.write(indexOutput);
}
storeDirectory.sync(Collections.singleton(segmentInfoSnapshotFilename));
remoteDirectory.copyFrom(storeDirectory, segmentInfoSnapshotFilename, segmentInfoSnapshotFilename, IOContext.DEFAULT, true);
return segmentInfoSnapshotFilename;
}

private void uploadNewSegments(
Collection<String> localSegmentsPostRefresh,
Map<String, Long> localSegmentsSizeMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,37 @@

public class RemoteStoreUtilsTests extends OpenSearchTestCase {

private final String metadataFilename = RemoteSegmentStoreDirectory.getMetadataFilename(12, 23, 34, 1, 1, "node-1");

private final String metadataFilenameDup = RemoteSegmentStoreDirectory.getMetadataFilename(12, 23, 34, 2, 1, "node-2");
private final String metadataFilename2 = RemoteSegmentStoreDirectory.getMetadataFilename(12, 13, 34, 1, 1, "node-1");
private final String metadataFilename = RemoteSegmentStoreDirectory.getMetadataFilename(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR,
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
12,
23,
34,
1,
1,
"node-1"
);

private final String metadataFilenameDup = RemoteSegmentStoreDirectory.getMetadataFilename(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR,
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
12,
23,
34,
2,
1,
"node-2"
);
private final String metadataFilename2 = RemoteSegmentStoreDirectory.getMetadataFilename(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR,
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
12,
13,
34,
1,
1,
"node-1"
);

private final String oldMetadataFilename = getOldSegmentMetadataFilename(12, 23, 34, 1, 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,57 @@ public class RemoteSegmentStoreDirectoryTests extends IndexShardTestCase {
private SegmentInfos segmentInfos;
private ThreadPool threadPool;

private final String metadataFilename = RemoteSegmentStoreDirectory.getMetadataFilename(12, 23, 34, 1, 1, "node-1");

private final String metadataFilenameDup = RemoteSegmentStoreDirectory.getMetadataFilename(12, 23, 34, 2, 1, "node-2");
private final String metadataFilename2 = RemoteSegmentStoreDirectory.getMetadataFilename(12, 13, 34, 1, 1, "node-1");
private final String metadataFilename3 = RemoteSegmentStoreDirectory.getMetadataFilename(10, 38, 34, 1, 1, "node-1");
private final String metadataFilename4 = RemoteSegmentStoreDirectory.getMetadataFilename(10, 36, 34, 1, 1, "node-1");
private final String metadataFilename = RemoteSegmentStoreDirectory.getMetadataFilename(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR,
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
12,
23,
34,
1,
1,
"node-1"
);

private final String metadataFilenameDup = RemoteSegmentStoreDirectory.getMetadataFilename(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR,
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
12,
23,
34,
2,
1,
"node-2"
);
private final String metadataFilename2 = RemoteSegmentStoreDirectory.getMetadataFilename(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR,
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
12,
13,
34,
1,
1,
"node-1"
);
private final String metadataFilename3 = RemoteSegmentStoreDirectory.getMetadataFilename(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR,
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
10,
38,
34,
1,
1,
"node-1"
);
private final String metadataFilename4 = RemoteSegmentStoreDirectory.getMetadataFilename(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR,
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
10,
36,
34,
1,
1,
"node-1"
);

@Before
public void setup() throws IOException {
Expand Down Expand Up @@ -473,7 +518,18 @@ public void testIsAcquiredException() throws IOException {
private List<String> getDummyMetadataFiles(int count) {
List<String> sortedMetadataFiles = new ArrayList<>();
for (int counter = 0; counter < count; counter++) {
sortedMetadataFiles.add(RemoteSegmentStoreDirectory.getMetadataFilename(counter, 23, 34, 1, 1, "node-1"));
sortedMetadataFiles.add(
RemoteSegmentStoreDirectory.getMetadataFilename(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR,
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
counter,
23,
34,
1,
1,
"node-1"
)
);
}
return sortedMetadataFiles;
}
Expand Down Expand Up @@ -752,7 +808,8 @@ public void testUploadMetadataEmpty() throws IOException {
storeDirectory,
34L,
indexShard.getLatestReplicationCheckpoint(),
""
"",
false
)
);
}
Expand Down Expand Up @@ -799,7 +856,8 @@ public void testUploadMetadataNonEmpty() throws IOException {
storeDirectory,
generation,
indexShard.getLatestReplicationCheckpoint(),
""
"",
false
);

verify(remoteMetadataDirectory).copyFrom(
Expand Down Expand Up @@ -847,7 +905,8 @@ public void testUploadMetadataMissingSegment() throws IOException {
storeDirectory,
12L,
indexShard.getLatestReplicationCheckpoint(),
""
"",
false
)
);
verify(indexOutput).close();
Expand Down Expand Up @@ -1238,12 +1297,66 @@ private void indexDocs(int startDocId, int numberOfDocs) throws IOException {
}

public void testMetadataFileNameOrder() {
String file1 = RemoteSegmentStoreDirectory.getMetadataFilename(15, 21, 23, 1, 1, "");
String file2 = RemoteSegmentStoreDirectory.getMetadataFilename(15, 38, 38, 1, 1, "");
String file3 = RemoteSegmentStoreDirectory.getMetadataFilename(18, 12, 26, 1, 1, "");
String file4 = RemoteSegmentStoreDirectory.getMetadataFilename(15, 38, 32, 10, 1, "");
String file5 = RemoteSegmentStoreDirectory.getMetadataFilename(15, 38, 32, 1, 1, "");
String file6 = RemoteSegmentStoreDirectory.getMetadataFilename(15, 38, 32, 5, 1, "");
String file1 = RemoteSegmentStoreDirectory.getMetadataFilename(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR,
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
15,
21,
23,
1,
1,
""
);
String file2 = RemoteSegmentStoreDirectory.getMetadataFilename(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR,
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
15,
38,
38,
1,
1,
""
);
String file3 = RemoteSegmentStoreDirectory.getMetadataFilename(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR,
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
18,
12,
26,
1,
1,
""
);
String file4 = RemoteSegmentStoreDirectory.getMetadataFilename(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR,
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
15,
38,
32,
10,
1,
""
);
String file5 = RemoteSegmentStoreDirectory.getMetadataFilename(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR,
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
15,
38,
32,
1,
1,
""
);
String file6 = RemoteSegmentStoreDirectory.getMetadataFilename(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR,
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
15,
38,
32,
5,
1,
""
);

List<String> actualList = new ArrayList<>(List.of(file1, file2, file3, file4, file5, file6));
actualList.sort(String::compareTo);
Expand Down

0 comments on commit 7052aca

Please sign in to comment.