-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Enable Safe Bidirectional CCR via Alias policy on Restore #19368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9d1056c
Restore: enable safe bidirectional CCR via alias policy on restore
atris ac856a1
Add updated version
atris e041a3c
Update per comments
atris 685bda1
Update gating version and add CHANGELOG entry
atris e5b6100
Merge branch 'main' into new_bds
atris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
.../opensearch/action/admin/cluster/snapshots/restore/AliasWriteIndexPolicyRequestTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.action.admin.cluster.snapshots.restore; | ||
|
|
||
| import org.opensearch.common.io.stream.BytesStreamOutput; | ||
| import org.opensearch.core.common.io.stream.StreamInput; | ||
| import org.opensearch.core.xcontent.ToXContent; | ||
| import org.opensearch.core.xcontent.XContentBuilder; | ||
| import org.opensearch.core.xcontent.XContentParser; | ||
| import org.opensearch.test.OpenSearchTestCase; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
|
|
||
| public class AliasWriteIndexPolicyRequestTests extends OpenSearchTestCase { | ||
|
|
||
| public void testEqualsAndHashCode() { | ||
| RestoreSnapshotRequest request1 = new RestoreSnapshotRequest("repo", "snapshot").indices("index1", "index2") | ||
| .aliasWriteIndexPolicy(RestoreSnapshotRequest.AliasWriteIndexPolicy.STRIP_WRITE_INDEX) | ||
| .aliasSuffix("_backup"); | ||
|
|
||
| RestoreSnapshotRequest request2 = new RestoreSnapshotRequest("repo", "snapshot").indices("index1", "index2") | ||
| .aliasWriteIndexPolicy(RestoreSnapshotRequest.AliasWriteIndexPolicy.STRIP_WRITE_INDEX) | ||
| .aliasSuffix("_backup"); | ||
|
|
||
| assertEquals(request1, request2); | ||
| assertEquals(request1.hashCode(), request2.hashCode()); | ||
|
|
||
| // Test with different policy | ||
| RestoreSnapshotRequest request3 = new RestoreSnapshotRequest("repo", "snapshot").indices("index1", "index2") | ||
| .aliasWriteIndexPolicy(RestoreSnapshotRequest.AliasWriteIndexPolicy.CUSTOM_SUFFIX) | ||
| .aliasSuffix("_backup"); | ||
|
|
||
| assertNotEquals(request1, request3); | ||
|
|
||
| // Test with different suffix | ||
| RestoreSnapshotRequest request4 = new RestoreSnapshotRequest("repo", "snapshot").indices("index1", "index2") | ||
| .aliasWriteIndexPolicy(RestoreSnapshotRequest.AliasWriteIndexPolicy.STRIP_WRITE_INDEX) | ||
| .aliasSuffix("_different"); | ||
|
|
||
| assertNotEquals(request1, request4); | ||
| } | ||
|
|
||
| public void testSerialization() throws IOException { | ||
| RestoreSnapshotRequest request = new RestoreSnapshotRequest("test-repo", "test-snapshot").indices("index1", "index2") | ||
| .renamePattern("(.+)") | ||
| .renameReplacement("restored-$1") | ||
| .aliasWriteIndexPolicy(RestoreSnapshotRequest.AliasWriteIndexPolicy.CUSTOM_SUFFIX) | ||
| .aliasSuffix("_restored") | ||
| .includeAliases(true) | ||
| .partial(true) | ||
| .waitForCompletion(false); | ||
|
|
||
| BytesStreamOutput out = new BytesStreamOutput(); | ||
| request.writeTo(out); | ||
|
|
||
| StreamInput in = out.bytes().streamInput(); | ||
| RestoreSnapshotRequest deserialized = new RestoreSnapshotRequest(in); | ||
|
|
||
| assertEquals(request.repository(), deserialized.repository()); | ||
| assertEquals(request.snapshot(), deserialized.snapshot()); | ||
| assertArrayEquals(request.indices(), deserialized.indices()); | ||
| assertEquals(request.aliasWriteIndexPolicy(), deserialized.aliasWriteIndexPolicy()); | ||
| assertEquals(request.aliasSuffix(), deserialized.aliasSuffix()); | ||
| assertEquals(request.includeAliases(), deserialized.includeAliases()); | ||
| } | ||
|
|
||
| public void testXContentRoundTrip() throws IOException { | ||
| RestoreSnapshotRequest request = new RestoreSnapshotRequest("test-repo", "test-snapshot").indices("index1", "index2") | ||
| .aliasWriteIndexPolicy(RestoreSnapshotRequest.AliasWriteIndexPolicy.STRIP_WRITE_INDEX) | ||
| .aliasSuffix("_test") | ||
| .includeAliases(true) | ||
| .includeGlobalState(false) | ||
| .partial(true); | ||
|
|
||
| // Convert to XContent | ||
| XContentBuilder builder = jsonBuilder(); | ||
| request.toXContent(builder, ToXContent.EMPTY_PARAMS); | ||
|
|
||
| // Parse from XContent | ||
| XContentParser parser = createParser(builder); | ||
| Map<String, Object> source = parser.map(); | ||
| RestoreSnapshotRequest parsed = new RestoreSnapshotRequest().source(source); | ||
|
|
||
| // Verify key fields | ||
| assertArrayEquals(request.indices(), parsed.indices()); | ||
| assertEquals(request.aliasWriteIndexPolicy(), parsed.aliasWriteIndexPolicy()); | ||
| assertEquals(request.aliasSuffix(), parsed.aliasSuffix()); | ||
| assertEquals(request.includeAliases(), parsed.includeAliases()); | ||
| assertEquals(request.includeGlobalState(), parsed.includeGlobalState()); | ||
| assertEquals(request.partial(), parsed.partial()); | ||
| } | ||
|
|
||
| public void testPolicyFromString() { | ||
| assertEquals( | ||
| RestoreSnapshotRequest.AliasWriteIndexPolicy.PRESERVE, | ||
| RestoreSnapshotRequest.AliasWriteIndexPolicy.fromString("preserve") | ||
| ); | ||
| assertEquals( | ||
| RestoreSnapshotRequest.AliasWriteIndexPolicy.STRIP_WRITE_INDEX, | ||
| RestoreSnapshotRequest.AliasWriteIndexPolicy.fromString("strip_write_index") | ||
| ); | ||
| assertEquals( | ||
| RestoreSnapshotRequest.AliasWriteIndexPolicy.CUSTOM_SUFFIX, | ||
| RestoreSnapshotRequest.AliasWriteIndexPolicy.fromString("CUSTOM_SUFFIX") | ||
| ); | ||
|
|
||
| expectThrows(IllegalArgumentException.class, () -> RestoreSnapshotRequest.AliasWriteIndexPolicy.fromString("invalid")); | ||
| } | ||
|
|
||
| public void testDefaultValues() { | ||
| RestoreSnapshotRequest request = new RestoreSnapshotRequest(); | ||
| assertThat(request.aliasWriteIndexPolicy(), equalTo(RestoreSnapshotRequest.AliasWriteIndexPolicy.PRESERVE)); | ||
| assertNull(request.aliasSuffix()); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.