Skip to content

Commit

Permalink
[Snapshot Interop] Keep API parameters behind remote store experiment…
Browse files Browse the repository at this point in the history
…al feature flag.

Signed-off-by: Harish Bhakuni <hbhakuni@amazon.com>
  • Loading branch information
Harish Bhakuni committed Jul 11, 2023
1 parent e334145 commit 4b10185
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.common.logging.DeprecationLogger;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.FeatureFlags;
import org.opensearch.core.common.Strings;
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.core.xcontent.XContentBuilder;
Expand Down Expand Up @@ -150,7 +151,7 @@ public RestoreSnapshotRequest(StreamInput in) throws IOException {
if (in.getVersion().onOrAfter(Version.V_2_7_0)) {
storageType = in.readEnum(StorageType.class);
}
if (in.getVersion().onOrAfter(Version.V_2_9_0)) {
if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE) && in.getVersion().onOrAfter(Version.V_2_9_0)) {
sourceRemoteStoreRepository = in.readOptionalString();
}
}
Expand All @@ -174,7 +175,7 @@ public void writeTo(StreamOutput out) throws IOException {
if (out.getVersion().onOrAfter(Version.V_2_7_0)) {
out.writeEnum(storageType);
}
if (out.getVersion().onOrAfter(Version.V_2_9_0)) {
if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE) && out.getVersion().onOrAfter(Version.V_2_9_0)) {
out.writeOptionalString(sourceRemoteStoreRepository);
}
}
Expand Down Expand Up @@ -614,6 +615,11 @@ public RestoreSnapshotRequest source(Map<String, Object> source) {
}

} else if (name.equals("source_remote_store_repository")) {
if (!FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE)) {
throw new IllegalArgumentException(
"Unsupported parameter " + name + ". Please enable remote store feature flag for this experimental feature"
);
}
if (entry.getValue() instanceof String) {
setSourceRemoteStoreRepository((String) entry.getValue());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.FeatureFlags;
import org.opensearch.common.util.concurrent.ConcurrentCollections;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.repositories.blobstore.MeteredBlobStoreRepository;
Expand Down Expand Up @@ -627,6 +628,12 @@ public static void validateRepositoryMetadataSettings(
+ minVersionInCluster
);
}
if (REMOTE_STORE_INDEX_SHALLOW_COPY.get(repositoryMetadataSettings) && !FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE)) {
throw new RepositoryException(
repositoryName,
"setting " + REMOTE_STORE_INDEX_SHALLOW_COPY.getKey() + " cannot be enabled, as remote store feature is not enabled."
);
}
}

private static void ensureRepositoryNotInUse(ClusterState clusterState, String repository) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ public ClusterState execute(ClusterState currentState) {
final boolean isRemoteStoreShallowCopy = Boolean.TRUE.equals(
snapshotInfo.isRemoteStoreIndexShallowCopyEnabled()
) && metadata.index(index).getSettings().getAsBoolean(SETTING_REMOTE_STORE_ENABLED, false);
if (isSearchableSnapshot && isRemoteStoreShallowCopy) {
throw new SnapshotRestoreException(
snapshot,
"Shallow copy snapshot cannot be restored as searchable snapshot."
);
}
if (isRemoteStoreShallowCopy && !currentState.getNodes().getMinNodeVersion().onOrAfter(Version.V_2_9_0)) {
throw new SnapshotRestoreException(
snapshot,
Expand Down
16 changes: 9 additions & 7 deletions server/src/main/java/org/opensearch/snapshots/SnapshotInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest;
import org.opensearch.cluster.SnapshotsInProgress;
import org.opensearch.common.Nullable;
import org.opensearch.common.util.FeatureFlags;
import org.opensearch.core.ParseField;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -420,7 +421,7 @@ public SnapshotInfo(final StreamInput in) throws IOException {
includeGlobalState = in.readOptionalBoolean();
userMetadata = in.readMap();
dataStreams = in.readStringList();
if (in.getVersion().onOrAfter(Version.V_2_9_0)) {
if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE) && in.getVersion().onOrAfter(Version.V_2_9_0)) {
remoteStoreIndexShallowCopy = in.readOptionalBoolean();
}
}
Expand Down Expand Up @@ -636,7 +637,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
builder.field(VERSION_ID, version.id);
builder.field(VERSION, version.toString());
}
if (remoteStoreIndexShallowCopy != null) {
if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE) && remoteStoreIndexShallowCopy != null) {
builder.field(REMOTE_STORE_INDEX_SHALLOW_COPY, remoteStoreIndexShallowCopy);
}
builder.startArray(INDICES);
Expand Down Expand Up @@ -694,7 +695,7 @@ private XContentBuilder toXContentInternal(final XContentBuilder builder, final
builder.field(UUID, snapshotId.getUUID());
assert version != null : "version must always be known when writing a snapshot metadata blob";
builder.field(VERSION_ID, version.id);
if (remoteStoreIndexShallowCopy != null) {
if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE) && remoteStoreIndexShallowCopy != null) {
builder.field(REMOTE_STORE_INDEX_SHALLOW_COPY, remoteStoreIndexShallowCopy);
}
builder.startArray(INDICES);
Expand Down Expand Up @@ -784,9 +785,10 @@ public static SnapshotInfo fromXContentInternal(final XContentParser parser) thr
version = Version.fromId(parser.intValue());
} else if (INCLUDE_GLOBAL_STATE.equals(currentFieldName)) {
includeGlobalState = parser.booleanValue();
} else if (REMOTE_STORE_INDEX_SHALLOW_COPY.equals(currentFieldName)) {
remoteStoreIndexShallowCopy = parser.booleanValue();
}
} else if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE)
&& REMOTE_STORE_INDEX_SHALLOW_COPY.equals(currentFieldName)) {
remoteStoreIndexShallowCopy = parser.booleanValue();
}
} else if (token == XContentParser.Token.START_ARRAY) {
if (DATA_STREAMS.equals(currentFieldName)) {
dataStreams = new ArrayList<>();
Expand Down Expand Up @@ -867,7 +869,7 @@ public void writeTo(final StreamOutput out) throws IOException {
out.writeOptionalBoolean(includeGlobalState);
out.writeMap(userMetadata);
out.writeStringCollection(dataStreams);
if (out.getVersion().onOrAfter(Version.V_2_9_0)) {
if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE) && out.getVersion().onOrAfter(Version.V_2_9_0)) {
out.writeOptionalBoolean(remoteStoreIndexShallowCopy);
}
}
Expand Down

0 comments on commit 4b10185

Please sign in to comment.