Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add _list/shards API as paginated alternate to _cat/shards ([#14641](https://github.com/opensearch-project/OpenSearch/pull/14641))
- Latency and Memory allocation improvements to Multi Term Aggregation queries ([#14993](https://github.com/opensearch-project/OpenSearch/pull/14993))
- Flat object field use IndexOrDocValuesQuery to optimize query ([#14383](https://github.com/opensearch-project/OpenSearch/issues/14383))
- Add support for renaming aliases during snapshot restore ([#16292](https://github.com/opensearch-project/OpenSearch/pull/16292))
- Add method to return dynamic SecureTransportParameters from SecureTransportSettingsProvider interface ([#16387](https://github.com/opensearch-project/OpenSearch/pull/16387))
- URI path filtering support in cluster stats API ([#15938](https://github.com/opensearch-project/OpenSearch/pull/15938))
- [Star Tree - Search] Add support for metric aggregations with/without term query ([15289](https://github.com/opensearch-project/OpenSearch/pull/15289))

### Dependencies
- Bump `com.azure:azure-identity` from 1.13.0 to 1.13.2 ([#15578](https://github.com/opensearch-project/OpenSearch/pull/15578))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ private static StorageType fromString(String string) {
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen();
private String renamePattern;
private String renameReplacement;
private String renameAliasPattern;
private String renameAliasReplacement;
private boolean waitForCompletion;
private boolean includeGlobalState = false;
private boolean partial = false;
Expand Down Expand Up @@ -164,6 +166,13 @@ public RestoreSnapshotRequest(StreamInput in) throws IOException {
if (in.getVersion().onOrAfter(Version.V_2_17_0)) {
sourceRemoteTranslogRepository = in.readOptionalString();
}
// TODO: change to V_2_18_0 once this is backported into that version
if (in.getVersion().onOrAfter(Version.CURRENT)) {
renameAliasPattern = in.readOptionalString();
}
if (in.getVersion().onOrAfter(Version.CURRENT)) {
renameAliasReplacement = in.readOptionalString();
}
}

@Override
Expand Down Expand Up @@ -191,6 +200,13 @@ public void writeTo(StreamOutput out) throws IOException {
if (out.getVersion().onOrAfter(Version.V_2_17_0)) {
out.writeOptionalString(sourceRemoteTranslogRepository);
}
// TODO: change to V_2_18_0 once this is backported into that version
if (out.getVersion().onOrAfter(Version.CURRENT)) {
out.writeOptionalString(renameAliasPattern);
}
if (out.getVersion().onOrAfter(Version.CURRENT)) {
out.writeOptionalString(renameAliasReplacement);
}
}

@Override
Expand Down Expand Up @@ -361,6 +377,51 @@ public String renameReplacement() {
return renameReplacement;
}

/**
* Sets rename pattern that should be applied to restored indices' alias.
* <p>
* Alias that match the rename pattern will be renamed according to {@link #renameAliasReplacement(String)}. The
* rename pattern is applied according to the {@link java.util.regex.Matcher#appendReplacement(StringBuffer, String)}
* If two or more aliases are renamed into the same name, they will be merged.
*
* @param renameAliasPattern rename pattern
* @return this request
*/
public RestoreSnapshotRequest renameAliasPattern(String renameAliasPattern) {
this.renameAliasPattern = renameAliasPattern;
return this;
}

/**
* Returns rename alias pattern
*
* @return rename alias pattern
*/
public String renameAliasPattern() {
return renameAliasPattern;
}

/**
* Sets rename alias replacement
* <p>
* See {@link #renameAliasPattern(String)} for more information.
*
* @param renameAliasReplacement rename replacement
*/
public RestoreSnapshotRequest renameAliasReplacement(String renameAliasReplacement) {
this.renameAliasReplacement = renameAliasReplacement;
return this;
}

/**
* Returns rename alias replacement
*
* @return rename alias replacement
*/
public String renameAliasReplacement() {
return renameAliasReplacement;
}

/**
* If this parameter is set to true the operation will wait for completion of restore process before returning.
*
Expand Down Expand Up @@ -625,6 +686,18 @@ public RestoreSnapshotRequest source(Map<String, Object> source) {
} else {
throw new IllegalArgumentException("malformed rename_replacement");
}
} else if (name.equals("rename_alias_pattern")) {
if (entry.getValue() instanceof String) {
renameAliasPattern((String) entry.getValue());
} else {
throw new IllegalArgumentException("malformed rename_alias_pattern");
}
} else if (name.equals("rename_alias_replacement")) {
if (entry.getValue() instanceof String) {
renameAliasReplacement((String) entry.getValue());
} else {
throw new IllegalArgumentException("malformed rename_alias_replacement");
}
} else if (name.equals("index_settings")) {
if (!(entry.getValue() instanceof Map)) {
throw new IllegalArgumentException("malformed index_settings section");
Expand Down Expand Up @@ -685,6 +758,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
if (renameReplacement != null) {
builder.field("rename_replacement", renameReplacement);
}
if (renameAliasPattern != null) {
builder.field("rename_alias_pattern", renameAliasPattern);
}
if (renameAliasReplacement != null) {
builder.field("rename_alias_replacement", renameAliasReplacement);
}
builder.field("include_global_state", includeGlobalState);
builder.field("partial", partial);
builder.field("include_aliases", includeAliases);
Expand Down Expand Up @@ -733,6 +812,8 @@ public boolean equals(Object o) {
&& Objects.equals(indicesOptions, that.indicesOptions)
&& Objects.equals(renamePattern, that.renamePattern)
&& Objects.equals(renameReplacement, that.renameReplacement)
&& Objects.equals(renameAliasPattern, that.renameAliasPattern)
&& Objects.equals(renameAliasReplacement, that.renameAliasReplacement)
&& Objects.equals(indexSettings, that.indexSettings)
&& Arrays.equals(ignoreIndexSettings, that.ignoreIndexSettings)
&& Objects.equals(snapshotUuid, that.snapshotUuid)
Expand All @@ -751,6 +832,8 @@ public int hashCode() {
indicesOptions,
renamePattern,
renameReplacement,
renameAliasPattern,
renameAliasReplacement,
waitForCompletion,
includeGlobalState,
partial,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,34 @@ public RestoreSnapshotRequestBuilder setRenameReplacement(String renameReplaceme
return this;
}

/**
* Sets rename pattern that should be applied to restored indices' aliases.
* <p>
* Aliases that match the rename pattern will be renamed according to {@link #setRenameAliasReplacement(String)}. The
* rename pattern is applied according to the {@link java.util.regex.Matcher#appendReplacement(StringBuffer, String)}
* The request will fail if two or more alias will be renamed into the same name.
*
* @param renameAliasPattern rename alias pattern
* @return this builder
*/
public RestoreSnapshotRequestBuilder setRenameAliasPattern(String renameAliasPattern) {
request.renameAliasPattern(renameAliasPattern);
return this;
}

/**
* Sets rename replacement
* <p>
* See {@link #setRenameAliasPattern(String)} for more information.
*
* @param renameAliasReplacement rename alias replacement
* @return this builder
*/
public RestoreSnapshotRequestBuilder setRenameAliasReplacement(String renameAliasReplacement) {
request.renameAliasReplacement(renameAliasReplacement);
return this;
}

/**
* If this parameter is set to true the operation will wait for completion of restore process before returning.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static java.util.Collections.unmodifiableSet;
Expand Down Expand Up @@ -486,9 +487,7 @@ public ClusterState execute(ClusterState currentState) {
// Remove all aliases - they shouldn't be restored
indexMdBuilder.removeAllAliases();
} else {
for (final String alias : snapshotIndexMetadata.getAliases().keySet()) {
aliases.add(alias);
}
applyAliasesWithRename(snapshotIndexMetadata, indexMdBuilder, aliases);
}
IndexMetadata updatedIndexMetadata = indexMdBuilder.build();
if (partial) {
Expand Down Expand Up @@ -533,9 +532,7 @@ public ClusterState execute(ClusterState currentState) {
indexMdBuilder.putAlias(alias);
}
} else {
for (final String alias : snapshotIndexMetadata.getAliases().keySet()) {
aliases.add(alias);
}
applyAliasesWithRename(snapshotIndexMetadata, indexMdBuilder, aliases);
}
final Settings.Builder indexSettingsBuilder = Settings.builder()
.put(snapshotIndexMetadata.getSettings())
Expand Down Expand Up @@ -665,6 +662,27 @@ private void checkAliasNameConflicts(Map<String, String> renamedIndices, Set<Str
}
}

private void applyAliasesWithRename(
IndexMetadata snapshotIndexMetadata,
IndexMetadata.Builder indexMdBuilder,
Set<String> aliases
) {
if (request.renameAliasPattern() == null || request.renameAliasReplacement() == null) {
aliases.addAll(snapshotIndexMetadata.getAliases().keySet());
} else {
Pattern renameAliasPattern = Pattern.compile(request.renameAliasPattern());
for (final Map.Entry<String, AliasMetadata> alias : snapshotIndexMetadata.getAliases().entrySet()) {
String currentAliasName = alias.getKey();
indexMdBuilder.removeAlias(currentAliasName);
String newAliasName = renameAliasPattern.matcher(currentAliasName)
.replaceAll(request.renameAliasReplacement());
AliasMetadata newAlias = AliasMetadata.newAliasMetadata(alias.getValue(), newAliasName);
indexMdBuilder.putAlias(newAlias);
aliases.add(newAliasName);
}
}
}

private String[] getIgnoreSettingsInternal() {
// for non-remote store enabled domain, we will remove all the remote store
// related index settings present in the snapshot.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ private RestoreSnapshotRequest randomState(RestoreSnapshotRequest instance) {
if (randomBoolean()) {
instance.renameReplacement(randomUnicodeOfLengthBetween(1, 100));
}
if (randomBoolean()) {
instance.renameAliasPattern(randomUnicodeOfLengthBetween(1, 100));
}
if (randomBoolean()) {
instance.renameAliasReplacement(randomUnicodeOfLengthBetween(1, 100));
}
instance.partial(randomBoolean());
instance.includeAliases(randomBoolean());

Expand Down
Loading