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 flag. (#8594)

Signed-off-by: Harish Bhakuni <hbhakuni@amazon.com>
(cherry picked from commit c677f35)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Jul 11, 2023
1 parent b40d956 commit db62ee5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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 @@ -156,7 +157,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 Down Expand Up @@ -189,7 +190,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 @@ -629,6 +630,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 Expand Up @@ -679,7 +685,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
if (storageType != null) {
storageType.toXContent(builder);
}
if (sourceRemoteStoreRepository != null) {
if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE) && sourceRemoteStoreRepository != null) {
builder.field("source_remote_store_repository", sourceRemoteStoreRepository);
}
builder.endObject();
Expand All @@ -696,7 +702,7 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RestoreSnapshotRequest that = (RestoreSnapshotRequest) o;
return waitForCompletion == that.waitForCompletion
boolean equals = waitForCompletion == that.waitForCompletion
&& includeGlobalState == that.includeGlobalState
&& partial == that.partial
&& includeAliases == that.includeAliases
Expand All @@ -709,27 +715,48 @@ public boolean equals(Object o) {
&& Objects.equals(indexSettings, that.indexSettings)
&& Arrays.equals(ignoreIndexSettings, that.ignoreIndexSettings)
&& Objects.equals(snapshotUuid, that.snapshotUuid)
&& Objects.equals(storageType, that.storageType)
&& Objects.equals(sourceRemoteStoreRepository, that.sourceRemoteStoreRepository);
&& Objects.equals(storageType, that.storageType);
if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE)) {
equals = Objects.equals(sourceRemoteStoreRepository, that.sourceRemoteStoreRepository);
}
return equals;
}

@Override
public int hashCode() {
int result = Objects.hash(
snapshot,
repository,
indicesOptions,
renamePattern,
renameReplacement,
waitForCompletion,
includeGlobalState,
partial,
includeAliases,
indexSettings,
snapshotUuid,
storageType,
sourceRemoteStoreRepository
);
int result;
if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE)) {
result = Objects.hash(
snapshot,
repository,
indicesOptions,
renamePattern,
renameReplacement,
waitForCompletion,
includeGlobalState,
partial,
includeAliases,
indexSettings,
snapshotUuid,
storageType,
sourceRemoteStoreRepository
);
} else {
result = Objects.hash(
snapshot,
repository,
indicesOptions,
renamePattern,
renameReplacement,
waitForCompletion,
includeGlobalState,
partial,
includeAliases,
indexSettings,
snapshotUuid,
storageType
);
}
result = 31 * result + Arrays.hashCode(indices);
result = 31 * result + Arrays.hashCode(ignoreIndexSettings);
return result;
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 @@ -464,6 +464,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

0 comments on commit db62ee5

Please sign in to comment.