Skip to content

Commit

Permalink
Add prefix path for remote state and routing table
Browse files Browse the repository at this point in the history
Signed-off-by: Sooraj Sinha <soosinha@amazon.com>
  • Loading branch information
soosinha committed Sep 3, 2024
1 parent 0ad528d commit fad4e7d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ public void apply(Settings value, Settings current, Settings previous) {
GLOBAL_METADATA_UPLOAD_TIMEOUT_SETTING,
METADATA_MANIFEST_UPLOAD_TIMEOUT_SETTING,
RemoteClusterStateService.REMOTE_STATE_READ_TIMEOUT_SETTING,
RemoteClusterStateService.CLUSTER_REMOTE_STORE_STATE_PATH_PREFIX_CHAR,
RemoteIndexMetadataManager.REMOTE_INDEX_METADATA_PATH_TYPE_SETTING,
RemoteIndexMetadataManager.REMOTE_INDEX_METADATA_PATH_HASH_ALGO_SETTING,
RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING,
Expand All @@ -743,6 +744,7 @@ public void apply(Settings value, Settings current, Settings previous) {
IndicesService.CLUSTER_INDEX_RESTRICT_REPLICATION_TYPE_SETTING,
RemoteRoutingTableBlobStore.REMOTE_ROUTING_TABLE_PATH_TYPE_SETTING,
RemoteRoutingTableBlobStore.REMOTE_ROUTING_TABLE_PATH_HASH_ALGO_SETTING,
RemoteRoutingTableBlobStore.CLUSTER_REMOTE_STORE_ROUTING_TABLE_PATH_PREFIX_CHAR,

// Admission Control Settings
AdmissionControlSettings.ADMISSION_CONTROL_TRANSPORT_LAYER_MODE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ public class RemoteClusterStateService implements Closeable {
Setting.Property.NodeScope
);

/**
* Controls the fixed prefix for the cluster state path on remote store.
*/
public static final Setting<String> CLUSTER_REMOTE_STORE_STATE_PATH_PREFIX_CHAR = Setting.simpleString(
"cluster.remote_store.state.path.prefix",
"",
Property.NodeScope,
Property.Final
);

private TimeValue remoteStateReadTimeout;
private final String nodeId;
private final Supplier<RepositoriesService> repositoriesService;
Expand All @@ -165,6 +175,7 @@ public class RemoteClusterStateService implements Closeable {
+ "indices, coordination metadata updated : [{}], settings metadata updated : [{}], templates metadata "
+ "updated : [{}], custom metadata updated : [{}], indices routing updated : [{}]";
private final boolean isPublicationEnabled;
private final String remotePathPrefix;

// ToXContent Params with gateway mode.
// We are using gateway context mode to persist all custom metadata.
Expand Down Expand Up @@ -203,6 +214,7 @@ public RemoteClusterStateService(
this.isPublicationEnabled = FeatureFlags.isEnabled(REMOTE_PUBLICATION_EXPERIMENTAL)
&& RemoteStoreNodeAttribute.isRemoteStoreClusterStateEnabled(settings)
&& RemoteStoreNodeAttribute.isRemoteRoutingTableEnabled(settings);
this.remotePathPrefix = CLUSTER_REMOTE_STORE_STATE_PATH_PREFIX_CHAR.get(settings);
this.remoteRoutingTableService = RemoteRoutingTableServiceFactory.getService(
repositoriesService,
settings,
Expand Down Expand Up @@ -679,7 +691,8 @@ UploadedMetadataResults writeMetadataInParallel(
blobStoreRepository.getCompressor(),
blobStoreRepository.getNamedXContentRegistry(),
remoteIndexMetadataManager.getPathTypeSetting(),
remoteIndexMetadataManager.getPathHashAlgoSetting()
remoteIndexMetadataManager.getPathHashAlgoSetting(),
remotePathPrefix
),
listener
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ public class RemoteIndexMetadata extends AbstractClusterMetadataWriteableBlobEnt
private IndexMetadata indexMetadata;
private RemoteStoreEnums.PathType pathType;
private RemoteStoreEnums.PathHashAlgorithm pathHashAlgo;
private String fixedPrefix;

public RemoteIndexMetadata(
final IndexMetadata indexMetadata,
final String clusterUUID,
final Compressor compressor,
final NamedXContentRegistry namedXContentRegistry,
final RemoteStoreEnums.PathType pathType,
final RemoteStoreEnums.PathHashAlgorithm pathHashAlgo
final RemoteStoreEnums.PathHashAlgorithm pathHashAlgo,
final String fixedPrefix
) {
this(indexMetadata, clusterUUID, compressor, namedXContentRegistry);
this.pathType = pathType;
Expand Down Expand Up @@ -111,7 +113,11 @@ public BlobPath getPrefixedPath(BlobPath blobPath) {
}
assert pathHashAlgo != null;
return pathType.path(
RemoteStorePathStrategy.PathInput.builder().basePath(blobPath).indexUUID(indexMetadata.getIndexUUID()).build(),
RemoteStorePathStrategy.PathInput.builder()
.fixedPrefix(fixedPrefix)
.basePath(blobPath)
.indexUUID(indexMetadata.getIndexUUID())
.build(),
pathHashAlgo
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.opensearch.common.remote.RemoteWriteableEntityBlobStore;
import org.opensearch.common.settings.ClusterSettings;
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Setting.Property;
import org.opensearch.gateway.remote.RemoteClusterStateUtils;
import org.opensearch.gateway.remote.routingtable.RemoteIndexRoutingTable;
import org.opensearch.index.remote.RemoteStoreEnums;
Expand Down Expand Up @@ -58,8 +59,19 @@ public class RemoteRoutingTableBlobStore<IndexRoutingTable, U extends AbstractCl
Setting.Property.Dynamic
);

/**
* Controls the fixed prefix for the routing table path on remote store.
*/
public static final Setting<String> CLUSTER_REMOTE_STORE_ROUTING_TABLE_PATH_PREFIX_CHAR = Setting.simpleString(
"cluster.remote_store.routing_table.path.prefix",
"",
Property.NodeScope,
Property.Final
);

private RemoteStoreEnums.PathType pathType;
private RemoteStoreEnums.PathHashAlgorithm pathHashAlgo;
private String pathPrefix;

public RemoteRoutingTableBlobStore(
BlobStoreTransferService blobStoreTransferService,
Expand All @@ -79,6 +91,7 @@ public RemoteRoutingTableBlobStore(
);
this.pathType = clusterSettings.get(REMOTE_ROUTING_TABLE_PATH_TYPE_SETTING);
this.pathHashAlgo = clusterSettings.get(REMOTE_ROUTING_TABLE_PATH_HASH_ALGO_SETTING);
this.pathPrefix = clusterSettings.get(CLUSTER_REMOTE_STORE_ROUTING_TABLE_PATH_PREFIX_CHAR);
clusterSettings.addSettingsUpdateConsumer(REMOTE_ROUTING_TABLE_PATH_TYPE_SETTING, this::setPathTypeSetting);
clusterSettings.addSettingsUpdateConsumer(REMOTE_ROUTING_TABLE_PATH_HASH_ALGO_SETTING, this::setPathHashAlgoSetting);
}
Expand All @@ -90,6 +103,7 @@ public BlobPath getBlobPathForUpload(final RemoteWriteableBlobEntity<IndexRoutin

BlobPath path = pathType.path(
RemoteStorePathStrategy.PathInput.builder()
.fixedPrefix(pathPrefix)
.basePath(indexRoutingPath)
.indexUUID(String.join("", obj.getBlobPathParameters().getPathTokens()))
.build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ public BlobPath generatePath(PathInput pathInput) {
public static class PathInput {
private final BlobPath basePath;
private final String indexUUID;
private final String fixedPrefix;

public PathInput(Builder<?> builder) {
this.basePath = Objects.requireNonNull(builder.basePath);
this.indexUUID = Objects.requireNonNull(builder.indexUUID);
this.fixedPrefix = Objects.isNull(builder.fixedPrefix) ? "" : builder.fixedPrefix;
}

BlobPath basePath() {
Expand All @@ -97,6 +99,10 @@ String indexUUID() {
return indexUUID;
}

String fixedPrefix() {
return fixedPrefix;
}

BlobPath fixedSubPath() {
return BlobPath.cleanPath().add(indexUUID);
}
Expand Down Expand Up @@ -126,6 +132,7 @@ public void assertIsValid() {
public static class Builder<T extends Builder<T>> {
private BlobPath basePath;
private String indexUUID;
private String fixedPrefix;

public T basePath(BlobPath basePath) {
this.basePath = basePath;
Expand All @@ -137,6 +144,11 @@ public T indexUUID(String indexUUID) {
return self();
}

public T fixedPrefix(String fixedPrefix) {
this.fixedPrefix = fixedPrefix;
return self();
}

protected T self() {
return (T) this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ public void testPrefixedPath() {
compressor,
namedXContentRegistry,
PathType.HASHED_PREFIX,
PathHashAlgorithm.FNV_1A_COMPOSITE_1
PathHashAlgorithm.FNV_1A_COMPOSITE_1,
"*"
);
String testPath = "test-path";
String expectedPath = "410100110100101/test-path/index-uuid/";
Expand Down

0 comments on commit fad4e7d

Please sign in to comment.