Skip to content

Commit c677f35

Browse files
[Snapshot Interop] Keep API parameters behind remote store experimental flag. (#8594)
Signed-off-by: Harish Bhakuni <hbhakuni@amazon.com>
1 parent 11f4699 commit c677f35

File tree

3 files changed

+61
-21
lines changed

3 files changed

+61
-21
lines changed

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.opensearch.common.io.stream.StreamOutput;
4242
import org.opensearch.common.logging.DeprecationLogger;
4343
import org.opensearch.common.settings.Settings;
44+
import org.opensearch.common.util.FeatureFlags;
4445
import org.opensearch.core.common.Strings;
4546
import org.opensearch.core.xcontent.ToXContentObject;
4647
import org.opensearch.core.xcontent.XContentBuilder;
@@ -150,7 +151,7 @@ public RestoreSnapshotRequest(StreamInput in) throws IOException {
150151
if (in.getVersion().onOrAfter(Version.V_2_7_0)) {
151152
storageType = in.readEnum(StorageType.class);
152153
}
153-
if (in.getVersion().onOrAfter(Version.V_2_9_0)) {
154+
if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE) && in.getVersion().onOrAfter(Version.V_2_9_0)) {
154155
sourceRemoteStoreRepository = in.readOptionalString();
155156
}
156157
}
@@ -174,7 +175,7 @@ public void writeTo(StreamOutput out) throws IOException {
174175
if (out.getVersion().onOrAfter(Version.V_2_7_0)) {
175176
out.writeEnum(storageType);
176177
}
177-
if (out.getVersion().onOrAfter(Version.V_2_9_0)) {
178+
if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE) && out.getVersion().onOrAfter(Version.V_2_9_0)) {
178179
out.writeOptionalString(sourceRemoteStoreRepository);
179180
}
180181
}
@@ -614,6 +615,11 @@ public RestoreSnapshotRequest source(Map<String, Object> source) {
614615
}
615616

616617
} else if (name.equals("source_remote_store_repository")) {
618+
if (!FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE)) {
619+
throw new IllegalArgumentException(
620+
"Unsupported parameter " + name + ". Please enable remote store feature flag for this experimental feature"
621+
);
622+
}
617623
if (entry.getValue() instanceof String) {
618624
setSourceRemoteStoreRepository((String) entry.getValue());
619625
} else {
@@ -664,7 +670,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
664670
if (storageType != null) {
665671
storageType.toXContent(builder);
666672
}
667-
if (sourceRemoteStoreRepository != null) {
673+
if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE) && sourceRemoteStoreRepository != null) {
668674
builder.field("source_remote_store_repository", sourceRemoteStoreRepository);
669675
}
670676
builder.endObject();
@@ -681,7 +687,7 @@ public boolean equals(Object o) {
681687
if (this == o) return true;
682688
if (o == null || getClass() != o.getClass()) return false;
683689
RestoreSnapshotRequest that = (RestoreSnapshotRequest) o;
684-
return waitForCompletion == that.waitForCompletion
690+
boolean equals = waitForCompletion == that.waitForCompletion
685691
&& includeGlobalState == that.includeGlobalState
686692
&& partial == that.partial
687693
&& includeAliases == that.includeAliases
@@ -694,27 +700,48 @@ public boolean equals(Object o) {
694700
&& Objects.equals(indexSettings, that.indexSettings)
695701
&& Arrays.equals(ignoreIndexSettings, that.ignoreIndexSettings)
696702
&& Objects.equals(snapshotUuid, that.snapshotUuid)
697-
&& Objects.equals(storageType, that.storageType)
698-
&& Objects.equals(sourceRemoteStoreRepository, that.sourceRemoteStoreRepository);
703+
&& Objects.equals(storageType, that.storageType);
704+
if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE)) {
705+
equals = Objects.equals(sourceRemoteStoreRepository, that.sourceRemoteStoreRepository);
706+
}
707+
return equals;
699708
}
700709

701710
@Override
702711
public int hashCode() {
703-
int result = Objects.hash(
704-
snapshot,
705-
repository,
706-
indicesOptions,
707-
renamePattern,
708-
renameReplacement,
709-
waitForCompletion,
710-
includeGlobalState,
711-
partial,
712-
includeAliases,
713-
indexSettings,
714-
snapshotUuid,
715-
storageType,
716-
sourceRemoteStoreRepository
717-
);
712+
int result;
713+
if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE)) {
714+
result = Objects.hash(
715+
snapshot,
716+
repository,
717+
indicesOptions,
718+
renamePattern,
719+
renameReplacement,
720+
waitForCompletion,
721+
includeGlobalState,
722+
partial,
723+
includeAliases,
724+
indexSettings,
725+
snapshotUuid,
726+
storageType,
727+
sourceRemoteStoreRepository
728+
);
729+
} else {
730+
result = Objects.hash(
731+
snapshot,
732+
repository,
733+
indicesOptions,
734+
renamePattern,
735+
renameReplacement,
736+
waitForCompletion,
737+
includeGlobalState,
738+
partial,
739+
includeAliases,
740+
indexSettings,
741+
snapshotUuid,
742+
storageType
743+
);
744+
}
718745
result = 31 * result + Arrays.hashCode(indices);
719746
result = 31 * result + Arrays.hashCode(ignoreIndexSettings);
720747
return result;

server/src/main/java/org/opensearch/repositories/RepositoriesService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import org.opensearch.common.settings.Setting;
6464
import org.opensearch.common.settings.Settings;
6565
import org.opensearch.common.unit.TimeValue;
66+
import org.opensearch.common.util.FeatureFlags;
6667
import org.opensearch.common.util.concurrent.ConcurrentCollections;
6768
import org.opensearch.common.util.io.IOUtils;
6869
import org.opensearch.repositories.blobstore.MeteredBlobStoreRepository;
@@ -627,6 +628,12 @@ public static void validateRepositoryMetadataSettings(
627628
+ minVersionInCluster
628629
);
629630
}
631+
if (REMOTE_STORE_INDEX_SHALLOW_COPY.get(repositoryMetadataSettings) && !FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE)) {
632+
throw new RepositoryException(
633+
repositoryName,
634+
"setting " + REMOTE_STORE_INDEX_SHALLOW_COPY.getKey() + " cannot be enabled, as remote store feature is not enabled."
635+
);
636+
}
630637
}
631638

632639
private static void ensureRepositoryNotInUse(ClusterState clusterState, String repository) {

server/src/main/java/org/opensearch/snapshots/RestoreService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,12 @@ public ClusterState execute(ClusterState currentState) {
453453
final boolean isRemoteStoreShallowCopy = Boolean.TRUE.equals(
454454
snapshotInfo.isRemoteStoreIndexShallowCopyEnabled()
455455
) && metadata.index(index).getSettings().getAsBoolean(SETTING_REMOTE_STORE_ENABLED, false);
456+
if (isSearchableSnapshot && isRemoteStoreShallowCopy) {
457+
throw new SnapshotRestoreException(
458+
snapshot,
459+
"Shallow copy snapshot cannot be restored as searchable snapshot."
460+
);
461+
}
456462
if (isRemoteStoreShallowCopy && !currentState.getNodes().getMinNodeVersion().onOrAfter(Version.V_2_9_0)) {
457463
throw new SnapshotRestoreException(
458464
snapshot,

0 commit comments

Comments
 (0)