Skip to content

Commit

Permalink
Add support to integ tests to pass separate metadata repo
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Kale <[email protected]>
  • Loading branch information
Sachin Kale committed Apr 3, 2024
1 parent cfe4449 commit 506d6b4
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.UUIDs;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.common.unit.ByteSizeUnit;
import org.opensearch.core.index.Index;
import org.opensearch.index.IndexModule;
import org.opensearch.index.IndexService;
Expand Down Expand Up @@ -57,16 +56,14 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_SEGMENT_DATA_REPOSITORY_NAME_ATTRIBUTE_KEY;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_TRANSLOG_DATA_REPOSITORY_NAME_ATTRIBUTE_KEY;
import static org.opensearch.repositories.fs.ReloadableFsRepository.REPOSITORIES_FAILRATE_SETTING;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;

public class RemoteStoreBaseIntegTestCase extends OpenSearchIntegTestCase {
protected static final String REPOSITORY_NAME = "test-remote-store-repo";
protected static final String SEGMENT_METADATA_REPOSITORY_NAME = "test-remote-segment-metadata-repo";
protected static final String REPOSITORY_2_NAME = "test-remote-store-repo-2";
protected static final int SHARD_COUNT = 1;
protected static int REPLICA_COUNT = 1;
Expand All @@ -76,6 +73,7 @@ public class RemoteStoreBaseIntegTestCase extends OpenSearchIntegTestCase {
protected static final String MAX_SEQ_NO_REFRESHED_OR_FLUSHED = "max-seq-no-refreshed-or-flushed";

protected Path segmentRepoPath;
protected Path segmentMetadataRepoPath;
protected Path translogRepoPath;
protected boolean clusterSettingsSuppliedByTest = false;
private final List<String> documentKeys = List.of(
Expand Down Expand Up @@ -137,15 +135,29 @@ protected Map<String, Long> indexData(int numberOfIterations, boolean invokeFlus
protected Settings nodeSettings(int nodeOrdinal) {
if (segmentRepoPath == null || translogRepoPath == null) {
segmentRepoPath = randomRepoPath().toAbsolutePath();
segmentMetadataRepoPath = randomRepoPath().toAbsolutePath();
translogRepoPath = randomRepoPath().toAbsolutePath();
}
if (clusterSettingsSuppliedByTest) {
return Settings.builder().put(super.nodeSettings(nodeOrdinal)).build();
} else {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(remoteStoreClusterSettings(REPOSITORY_NAME, segmentRepoPath, REPOSITORY_2_NAME, translogRepoPath))
.build();
Settings.Builder settingsBuilder = Settings.builder().put(super.nodeSettings(nodeOrdinal));
if (randomBoolean()) {
settingsBuilder.put(remoteStoreClusterSettings(REPOSITORY_NAME, segmentRepoPath, REPOSITORY_2_NAME, translogRepoPath));
} else {
// Use a separate segment metadata repository
settingsBuilder.put(
remoteStoreClusterSettings(
REPOSITORY_NAME,
segmentRepoPath,
SEGMENT_METADATA_REPOSITORY_NAME,
segmentMetadataRepoPath,
REPOSITORY_2_NAME,
translogRepoPath
)
);
}
return settingsBuilder.build();
}
}

Expand Down Expand Up @@ -191,121 +203,6 @@ protected BulkResponse indexBulk(String indexName, int numDocs) {
return client().bulk(bulkRequest).actionGet();
}

public static Settings remoteStoreClusterSettings(String name, Path path) {
return remoteStoreClusterSettings(name, path, name, path);
}

public static Settings remoteStoreClusterSettings(
String segmentRepoName,
Path segmentRepoPath,
String segmentRepoType,
String translogRepoName,
Path translogRepoPath,
String translogRepoType
) {
Settings.Builder settingsBuilder = Settings.builder();
settingsBuilder.put(
buildRemoteStoreNodeAttributes(
segmentRepoName,
segmentRepoPath,
segmentRepoType,
translogRepoName,
translogRepoPath,
translogRepoType,
false
)
);
return settingsBuilder.build();
}

public static Settings remoteStoreClusterSettings(
String segmentRepoName,
Path segmentRepoPath,
String translogRepoName,
Path translogRepoPath
) {
Settings.Builder settingsBuilder = Settings.builder();
settingsBuilder.put(buildRemoteStoreNodeAttributes(segmentRepoName, segmentRepoPath, translogRepoName, translogRepoPath, false));
return settingsBuilder.build();
}

public static Settings buildRemoteStoreNodeAttributes(
String segmentRepoName,
Path segmentRepoPath,
String translogRepoName,
Path translogRepoPath,
boolean withRateLimiterAttributes
) {
return buildRemoteStoreNodeAttributes(
segmentRepoName,
segmentRepoPath,
ReloadableFsRepository.TYPE,
translogRepoName,
translogRepoPath,
ReloadableFsRepository.TYPE,
withRateLimiterAttributes
);
}

public static Settings buildRemoteStoreNodeAttributes(
String segmentRepoName,
Path segmentRepoPath,
String segmentRepoType,
String translogRepoName,
Path translogRepoPath,
String translogRepoType,
boolean withRateLimiterAttributes
) {
String segmentRepoTypeAttributeKey = String.format(
Locale.getDefault(),
"node.attr." + REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT,
segmentRepoName
);
String segmentRepoSettingsAttributeKeyPrefix = String.format(
Locale.getDefault(),
"node.attr." + REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX,
segmentRepoName
);
String translogRepoTypeAttributeKey = String.format(
Locale.getDefault(),
"node.attr." + REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT,
translogRepoName
);
String translogRepoSettingsAttributeKeyPrefix = String.format(
Locale.getDefault(),
"node.attr." + REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX,
translogRepoName
);
String stateRepoTypeAttributeKey = String.format(
Locale.getDefault(),
"node.attr." + REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT,
segmentRepoName
);
String stateRepoSettingsAttributeKeyPrefix = String.format(
Locale.getDefault(),
"node.attr." + REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX,
segmentRepoName
);

Settings.Builder settings = Settings.builder()
.put("node.attr." + REMOTE_STORE_SEGMENT_DATA_REPOSITORY_NAME_ATTRIBUTE_KEY, segmentRepoName)
.put(segmentRepoTypeAttributeKey, segmentRepoType)
.put(segmentRepoSettingsAttributeKeyPrefix + "location", segmentRepoPath)
.put("node.attr." + REMOTE_STORE_TRANSLOG_DATA_REPOSITORY_NAME_ATTRIBUTE_KEY, translogRepoName)
.put(translogRepoTypeAttributeKey, translogRepoType)
.put(translogRepoSettingsAttributeKeyPrefix + "location", translogRepoPath)
.put("node.attr." + REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY, segmentRepoName)
.put(stateRepoTypeAttributeKey, segmentRepoType)
.put(stateRepoSettingsAttributeKeyPrefix + "location", segmentRepoPath);

if (withRateLimiterAttributes) {
settings.put(segmentRepoSettingsAttributeKeyPrefix + "compress", randomBoolean())
.put(segmentRepoSettingsAttributeKeyPrefix + "chunk_size", 200, ByteSizeUnit.BYTES);
}

return settings.build();
}

Settings defaultIndexSettings() {
return Settings.builder()
.put(super.indexSettings())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_SEGMENT_DATA_REPOSITORY_NAME_ATTRIBUTE_KEY;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_SEGMENT_METADATA_REPOSITORY_NAME_ATTRIBUTE_KEY;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_TRANSLOG_DATA_REPOSITORY_NAME_ATTRIBUTE_KEY;
import static org.opensearch.test.XContentTestUtils.convertToMap;
import static org.opensearch.test.XContentTestUtils.differenceBetweenMapsIgnoringArrayOrder;
Expand Down Expand Up @@ -2500,6 +2501,9 @@ public static Settings remoteStoreClusterSettings(
segmentRepoName,
segmentRepoPath,
segmentRepoType,
null,
null,
null,
translogRepoName,
translogRepoPath,
translogRepoType,
Expand All @@ -2520,6 +2524,28 @@ public static Settings remoteStoreClusterSettings(
return settingsBuilder.build();
}

public static Settings remoteStoreClusterSettings(
String segmentRepoName,
Path segmentRepoPath,
String segmentMetadataRepoName,
Path segmentMetadataRepoPath,
String translogRepoName,
Path translogRepoPath
) {
return buildRemoteStoreNodeAttributes(
segmentRepoName,
segmentRepoPath,
ReloadableFsRepository.TYPE,
segmentMetadataRepoName,
segmentMetadataRepoPath,
ReloadableFsRepository.TYPE,
translogRepoName,
translogRepoPath,
ReloadableFsRepository.TYPE,
false
);
}

public static Settings buildRemoteStoreNodeAttributes(
String segmentRepoName,
Path segmentRepoPath,
Expand All @@ -2531,31 +2557,37 @@ public static Settings buildRemoteStoreNodeAttributes(
segmentRepoName,
segmentRepoPath,
ReloadableFsRepository.TYPE,
null,
null,
null,
translogRepoName,
translogRepoPath,
ReloadableFsRepository.TYPE,
withRateLimiterAttributes
);
}

public static Settings buildRemoteStoreNodeAttributes(
String segmentRepoName,
Path segmentRepoPath,
String segmentRepoType,
private static Settings buildRemoteStoreNodeAttributes(
String segmentDataRepoName,
Path segmentDataRepoPath,
String segmentDataRepoType,
String segmentMetadataRepoName,
Path segmentMetadataRepoPath,
String segmentMetadataRepoType,
String translogRepoName,
Path translogRepoPath,
String translogRepoType,
boolean withRateLimiterAttributes
) {
String segmentRepoTypeAttributeKey = String.format(
String segmentDataRepoTypeAttributeKey = String.format(
Locale.getDefault(),
"node.attr." + REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT,
segmentRepoName
segmentDataRepoName
);
String segmentRepoSettingsAttributeKeyPrefix = String.format(
String segmentDataRepoSettingsAttributeKeyPrefix = String.format(
Locale.getDefault(),
"node.attr." + REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX,
segmentRepoName
segmentDataRepoName
);
String translogRepoTypeAttributeKey = String.format(
Locale.getDefault(),
Expand All @@ -2570,28 +2602,45 @@ public static Settings buildRemoteStoreNodeAttributes(
String stateRepoTypeAttributeKey = String.format(
Locale.getDefault(),
"node.attr." + REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT,
segmentRepoName
segmentDataRepoName
);
String stateRepoSettingsAttributeKeyPrefix = String.format(
Locale.getDefault(),
"node.attr." + REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX,
segmentRepoName
segmentDataRepoName
);

Settings.Builder settings = Settings.builder()
.put("node.attr." + REMOTE_STORE_SEGMENT_DATA_REPOSITORY_NAME_ATTRIBUTE_KEY, segmentRepoName)
.put(segmentRepoTypeAttributeKey, segmentRepoType)
.put(segmentRepoSettingsAttributeKeyPrefix + "location", segmentRepoPath)
.put("node.attr." + REMOTE_STORE_SEGMENT_DATA_REPOSITORY_NAME_ATTRIBUTE_KEY, segmentDataRepoName)
.put(segmentDataRepoTypeAttributeKey, segmentDataRepoType)
.put(segmentDataRepoSettingsAttributeKeyPrefix + "location", segmentDataRepoPath)
.put("node.attr." + REMOTE_STORE_TRANSLOG_DATA_REPOSITORY_NAME_ATTRIBUTE_KEY, translogRepoName)
.put(translogRepoTypeAttributeKey, translogRepoType)
.put(translogRepoSettingsAttributeKeyPrefix + "location", translogRepoPath)
.put("node.attr." + REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY, segmentRepoName)
.put(stateRepoTypeAttributeKey, segmentRepoType)
.put(stateRepoSettingsAttributeKeyPrefix + "location", segmentRepoPath);
.put("node.attr." + REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY, segmentDataRepoName)
.put(stateRepoTypeAttributeKey, segmentDataRepoType)
.put(stateRepoSettingsAttributeKeyPrefix + "location", segmentDataRepoPath);

String segmentMetadataRepoTypeAttributeKey = String.format(
Locale.getDefault(),
"node.attr." + REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT,
segmentMetadataRepoName
);
String segmentMetadataRepoSettingsAttributeKeyPrefix = String.format(
Locale.getDefault(),
"node.attr." + REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX,
segmentMetadataRepoName
);
if (segmentMetadataRepoName != null && segmentMetadataRepoPath != null && segmentMetadataRepoType != null) {
Settings.builder()
.put("node.attr." + REMOTE_STORE_SEGMENT_METADATA_REPOSITORY_NAME_ATTRIBUTE_KEY, segmentMetadataRepoName)
.put(segmentMetadataRepoTypeAttributeKey, segmentMetadataRepoType)
.put(segmentMetadataRepoSettingsAttributeKeyPrefix + "location", segmentMetadataRepoPath);
}

if (withRateLimiterAttributes) {
settings.put(segmentRepoSettingsAttributeKeyPrefix + "compress", randomBoolean())
.put(segmentRepoSettingsAttributeKeyPrefix + "chunk_size", 200, ByteSizeUnit.BYTES);
settings.put(segmentDataRepoSettingsAttributeKeyPrefix + "compress", randomBoolean())
.put(segmentDataRepoSettingsAttributeKeyPrefix + "chunk_size", 200, ByteSizeUnit.BYTES);
}
return settings.build();
}
Expand Down

0 comments on commit 506d6b4

Please sign in to comment.