Skip to content

Commit

Permalink
Run tests with random value for metadata segment infos separation
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 9, 2024
1 parent a4cc193 commit 9cef8ae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.shard.IndexShard;
import org.opensearch.indices.IndicesService;
import org.opensearch.indices.RemoteStoreSettings;
import org.opensearch.indices.replication.common.ReplicationType;
import org.opensearch.repositories.RepositoriesService;
import org.opensearch.repositories.blobstore.BlobStoreRepository;
Expand Down Expand Up @@ -135,14 +136,17 @@ protected Settings nodeSettings(int nodeOrdinal) {
segmentRepoPath = randomRepoPath().toAbsolutePath();
translogRepoPath = randomRepoPath().toAbsolutePath();
}
Settings.Builder settingsBuilder = Settings.builder();
if (clusterSettingsSuppliedByTest) {
return Settings.builder().put(super.nodeSettings(nodeOrdinal)).build();
settingsBuilder.put(super.nodeSettings(nodeOrdinal));
} else {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(remoteStoreClusterSettings(REPOSITORY_NAME, segmentRepoPath, REPOSITORY_2_NAME, translogRepoPath))
.build();
settingsBuilder.put(super.nodeSettings(nodeOrdinal))
.put(remoteStoreClusterSettings(REPOSITORY_NAME, segmentRepoPath, REPOSITORY_2_NAME, translogRepoPath));
}
if (randomBoolean()) {
settingsBuilder.put(RemoteStoreSettings.CLUSTER_REMOTE_SEGMENT_SEPARATE_METADATA_SEGMENTINFOS_SETTING.getKey(), true);
}
return settingsBuilder.build();
}

protected void setFailRate(String repoName, int value) throws ExecutionException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5051,7 +5051,7 @@ public void syncSegmentsFromRemoteSegmentStore(boolean overrideLocal, final Runn
final SegmentInfos infosSnapshot;
if (remoteSegmentMetadata.getSegmentInfosBytes().length == 0) {
List<String> segmentInfosSnapshotFilenames = Arrays.stream(store.directory().listAll())
.filter(file -> file.startsWith("segment_infos_snapshot"))
.filter(file -> file.startsWith(RemoteSegmentStoreDirectory.SEGMENT_INFOS_SNAPSHOT_PREFIX))
.collect(Collectors.toList());
assert segmentInfosSnapshotFilenames.size() == 1;
infosSnapshot = SegmentInfos.readCommit(store.directory(), segmentInfosSnapshotFilenames.get(0));
Expand All @@ -5065,7 +5065,8 @@ public void syncSegmentsFromRemoteSegmentStore(boolean overrideLocal, final Runn
// delete any other commits, we want to start the engine only from a new commit made with the downloaded infos bytes.
// Extra segments will be wiped on engine open.
for (String file : List.of(store.directory().listAll())) {
if (file.startsWith(IndexFileNames.SEGMENTS) || file.startsWith("segment_infos_snapshot")) {
if (file.startsWith(IndexFileNames.SEGMENTS)
|| file.startsWith(RemoteSegmentStoreDirectory.SEGMENT_INFOS_SNAPSHOT_PREFIX)) {
store.deleteQuiet(file);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public final class RemoteSegmentStoreDirectory extends FilterDirectory implement
*/
public static final String SEGMENT_NAME_UUID_SEPARATOR = "__";

public static final String SEGMENT_INFOS_SNAPSHOT_PREFIX = "segment_infos_snapshot";

/**
* remoteDataDirectory is used to store segment files at path: cluster_UUID/index_UUID/shardId/segments/data
*/
Expand Down Expand Up @@ -633,7 +635,7 @@ public void uploadMetadata(
} else {
String segmentInfoSnapshotFilename = getMetadataFilename(
MetadataFilenameUtils.SEPARATOR,
"segment_infos_snapshot",
SEGMENT_INFOS_SNAPSHOT_PREFIX,
replicationCheckpoint.getPrimaryTerm(),
segmentInfosSnapshot.getGeneration(),
translogGeneration,
Expand All @@ -656,7 +658,7 @@ public void uploadMetadata(
segmentInfoSnapshotFilename,
segmentInfoSnapshotFilename,
segmentInfosSnapshotChecksum,
storeDirectory.fileLength(segmentInfosSnapshotChecksum)
storeDirectory.fileLength(segmentInfoSnapshotFilename)
);
segmentInfosSnapshotMetadata.setWrittenByMajor(segmentInfosSnapshot.getCommitLuceneVersion().major);
uploadedSegments.put(segmentInfoSnapshotFilename, segmentInfosSnapshotMetadata.toString());
Expand Down

0 comments on commit 9cef8ae

Please sign in to comment.