-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[Remote Migration] Changes for Primary Relocation during migration #12494
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
sachinpkale
merged 14 commits into
opensearch-project:main
from
gbbafna:mixed-relocation
Mar 21, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
891edf3
WIP changes for remote primary to remote primary relocation
gbbafna b0607f9
refactor
gbbafna 29c1614
fixing flakiness
gbbafna bd23d77
Moving isSegRepEnabled to IndexSetting itself
gbbafna bec0de5
Fixing UTs , some restructuring
gbbafna 9730194
Fixing relocation issue of ckp not found when opening engine
gbbafna cb716cf
Address PR comments
gbbafna 24e53a5
java doc check fix
gbbafna 63574fa
removing redundant logs
gbbafna 8204388
Using isRemoteDataAttributePresent for determining if node is remote
gbbafna d075375
spotless fix
gbbafna 72cefe9
Address PR comments
gbbafna 8b20f1a
PR Test comments
gbbafna 5601758
Changing wait period for sync to 30 sec from 1 min
gbbafna 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
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
223 changes: 223 additions & 0 deletions
223
...rc/internalClusterTest/java/org/opensearch/remotemigration/RemotePrimaryRelocationIT.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,223 @@ | ||
| /* | ||
| * 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.remotemigration; | ||
|
|
||
| import com.carrotsearch.randomizedtesting.generators.RandomNumbers; | ||
|
|
||
| import org.opensearch.action.DocWriteResponse; | ||
| import org.opensearch.action.admin.cluster.health.ClusterHealthResponse; | ||
| import org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest; | ||
| import org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse; | ||
| import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; | ||
| import org.opensearch.action.delete.DeleteResponse; | ||
| import org.opensearch.action.index.IndexResponse; | ||
| import org.opensearch.client.Client; | ||
| import org.opensearch.cluster.routing.allocation.command.MoveAllocationCommand; | ||
| import org.opensearch.common.Priority; | ||
| import org.opensearch.common.settings.Settings; | ||
| import org.opensearch.common.unit.TimeValue; | ||
| import org.opensearch.index.query.QueryBuilders; | ||
| import org.opensearch.plugins.Plugin; | ||
| import org.opensearch.test.OpenSearchIntegTestCase; | ||
| import org.opensearch.test.hamcrest.OpenSearchAssertions; | ||
| import org.opensearch.test.transport.MockTransportService; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| import static java.util.Arrays.asList; | ||
| import static org.opensearch.node.remotestore.RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING; | ||
| import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; | ||
|
|
||
| @OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
| public class RemotePrimaryRelocationIT extends MigrationBaseTestCase { | ||
| protected int maximumNumberOfShards() { | ||
| return 1; | ||
| } | ||
|
|
||
| // ToDo : Fix me when we support migration of replicas | ||
| protected int maximumNumberOfReplicas() { | ||
| return 0; | ||
| } | ||
|
|
||
| protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
| return asList(MockTransportService.TestPlugin.class); | ||
| } | ||
|
|
||
| public void testMixedModeRelocation() throws Exception { | ||
gbbafna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| String docRepNode = internalCluster().startNode(); | ||
| Client client = internalCluster().client(docRepNode); | ||
| ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest(); | ||
| updateSettingsRequest.persistentSettings(Settings.builder().put(REMOTE_STORE_COMPATIBILITY_MODE_SETTING.getKey(), "mixed")); | ||
| assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet()); | ||
|
|
||
| // create shard with 0 replica and 1 shard | ||
| client().admin().indices().prepareCreate("test").setSettings(indexSettings()).setMapping("field", "type=text").get(); | ||
| ensureGreen("test"); | ||
|
|
||
| AtomicInteger numAutoGenDocs = new AtomicInteger(); | ||
| final AtomicBoolean finished = new AtomicBoolean(false); | ||
| Thread indexingThread = getIndexingThread(finished, numAutoGenDocs); | ||
|
|
||
| refresh("test"); | ||
|
|
||
| // add remote node in mixed mode cluster | ||
| addRemote = true; | ||
| String remoteNode = internalCluster().startNode(); | ||
| internalCluster().validateClusterFormed(); | ||
|
|
||
| String remoteNode2 = internalCluster().startNode(); | ||
| internalCluster().validateClusterFormed(); | ||
|
|
||
| // assert repo gets registered | ||
| GetRepositoriesRequest gr = new GetRepositoriesRequest(new String[] { REPOSITORY_NAME }); | ||
| GetRepositoriesResponse getRepositoriesResponse = client.admin().cluster().getRepositories(gr).actionGet(); | ||
| assertEquals(1, getRepositoriesResponse.repositories().size()); | ||
|
|
||
| // Index some more docs | ||
| int currentDoc = numAutoGenDocs.get(); | ||
| int finalCurrentDoc1 = currentDoc; | ||
| waitUntil(() -> numAutoGenDocs.get() > finalCurrentDoc1 + 5); | ||
|
|
||
| logger.info("--> relocating from {} to {} ", docRepNode, remoteNode); | ||
| client().admin().cluster().prepareReroute().add(new MoveAllocationCommand("test", 0, docRepNode, remoteNode)).execute().actionGet(); | ||
| ClusterHealthResponse clusterHealthResponse = client().admin() | ||
| .cluster() | ||
| .prepareHealth() | ||
| .setTimeout(TimeValue.timeValueSeconds(60)) | ||
| .setWaitForEvents(Priority.LANGUID) | ||
| .setWaitForNoRelocatingShards(true) | ||
| .execute() | ||
| .actionGet(); | ||
gbbafna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| assertEquals(0, clusterHealthResponse.getRelocatingShards()); | ||
| assertEquals(remoteNode, primaryNodeName("test")); | ||
| logger.info("--> relocation from docrep to remote complete"); | ||
|
|
||
| // Index some more docs | ||
| currentDoc = numAutoGenDocs.get(); | ||
| int finalCurrentDoc = currentDoc; | ||
| waitUntil(() -> numAutoGenDocs.get() > finalCurrentDoc + 5); | ||
|
|
||
| client().admin() | ||
| .cluster() | ||
| .prepareReroute() | ||
| .add(new MoveAllocationCommand("test", 0, remoteNode, remoteNode2)) | ||
gbbafna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .execute() | ||
| .actionGet(); | ||
| clusterHealthResponse = client().admin() | ||
| .cluster() | ||
| .prepareHealth() | ||
| .setTimeout(TimeValue.timeValueSeconds(60)) | ||
| .setWaitForEvents(Priority.LANGUID) | ||
| .setWaitForNoRelocatingShards(true) | ||
| .execute() | ||
| .actionGet(); | ||
|
|
||
| assertEquals(0, clusterHealthResponse.getRelocatingShards()); | ||
| assertEquals(remoteNode2, primaryNodeName("test")); | ||
|
|
||
| logger.info("--> relocation from remote to remote complete"); | ||
|
|
||
| finished.set(true); | ||
| indexingThread.join(); | ||
| refresh("test"); | ||
| OpenSearchAssertions.assertHitCount(client().prepareSearch("test").setTrackTotalHits(true).get(), numAutoGenDocs.get()); | ||
| OpenSearchAssertions.assertHitCount( | ||
| client().prepareSearch("test") | ||
| .setTrackTotalHits(true)// extra paranoia ;) | ||
| .setQuery(QueryBuilders.termQuery("auto", true)) | ||
| .get(), | ||
| numAutoGenDocs.get() | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| public void testMixedModeRelocation_RemoteSeedingFail() throws Exception { | ||
| String docRepNode = internalCluster().startNode(); | ||
| Client client = internalCluster().client(docRepNode); | ||
| ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest(); | ||
| updateSettingsRequest.persistentSettings(Settings.builder().put(REMOTE_STORE_COMPATIBILITY_MODE_SETTING.getKey(), "mixed")); | ||
| assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet()); | ||
|
|
||
| // create shard with 0 replica and 1 shard | ||
| client().admin().indices().prepareCreate("test").setSettings(indexSettings()).setMapping("field", "type=text").get(); | ||
| ensureGreen("test"); | ||
|
|
||
| AtomicInteger numAutoGenDocs = new AtomicInteger(); | ||
| final AtomicBoolean finished = new AtomicBoolean(false); | ||
| Thread indexingThread = getIndexingThread(finished, numAutoGenDocs); | ||
|
|
||
| refresh("test"); | ||
|
|
||
| // add remote node in mixed mode cluster | ||
| addRemote = true; | ||
| String remoteNode = internalCluster().startNode(); | ||
| internalCluster().validateClusterFormed(); | ||
|
|
||
| // assert repo gets registered | ||
| GetRepositoriesRequest gr = new GetRepositoriesRequest(new String[] { REPOSITORY_NAME }); | ||
| GetRepositoriesResponse getRepositoriesResponse = client.admin().cluster().getRepositories(gr).actionGet(); | ||
| assertEquals(1, getRepositoriesResponse.repositories().size()); | ||
|
|
||
| setFailRate(REPOSITORY_NAME, 100); | ||
|
|
||
| logger.info("--> relocating from {} to {} ", docRepNode, remoteNode); | ||
| client().admin().cluster().prepareReroute().add(new MoveAllocationCommand("test", 0, docRepNode, remoteNode)).execute().actionGet(); | ||
| ClusterHealthResponse clusterHealthResponse = client().admin() | ||
| .cluster() | ||
| .prepareHealth() | ||
| .setTimeout(TimeValue.timeValueSeconds(5)) | ||
| .setWaitForEvents(Priority.LANGUID) | ||
| .setWaitForNoRelocatingShards(true) | ||
gbbafna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .execute() | ||
| .actionGet(); | ||
|
|
||
| assertTrue(clusterHealthResponse.getRelocatingShards() == 1); | ||
| setFailRate(REPOSITORY_NAME, 0); | ||
| Thread.sleep(RandomNumbers.randomIntBetween(random(), 0, 2000)); | ||
| clusterHealthResponse = client().admin() | ||
| .cluster() | ||
| .prepareHealth() | ||
| .setTimeout(TimeValue.timeValueSeconds(45)) | ||
| .setWaitForEvents(Priority.LANGUID) | ||
| .setWaitForNoRelocatingShards(true) | ||
| .execute() | ||
| .actionGet(); | ||
| assertTrue(clusterHealthResponse.getRelocatingShards() == 0); | ||
| logger.info("--> remote to remote relocation complete"); | ||
| finished.set(true); | ||
| indexingThread.join(); | ||
| refresh("test"); | ||
| OpenSearchAssertions.assertHitCount(client().prepareSearch("test").setTrackTotalHits(true).get(), numAutoGenDocs.get()); | ||
| OpenSearchAssertions.assertHitCount( | ||
| client().prepareSearch("test") | ||
| .setTrackTotalHits(true)// extra paranoia ;) | ||
| .setQuery(QueryBuilders.termQuery("auto", true)) | ||
| .get(), | ||
| numAutoGenDocs.get() | ||
| ); | ||
| } | ||
|
|
||
| private static Thread getIndexingThread(AtomicBoolean finished, AtomicInteger numAutoGenDocs) { | ||
| Thread indexingThread = new Thread(() -> { | ||
| while (finished.get() == false && numAutoGenDocs.get() < 10_000) { | ||
| IndexResponse indexResponse = client().prepareIndex("test").setId("id").setSource("field", "value").get(); | ||
| assertEquals(DocWriteResponse.Result.CREATED, indexResponse.getResult()); | ||
| DeleteResponse deleteResponse = client().prepareDelete("test", "id").get(); | ||
| assertEquals(DocWriteResponse.Result.DELETED, deleteResponse.getResult()); | ||
| client().prepareIndex("test").setSource("auto", true).get(); | ||
| numAutoGenDocs.incrementAndGet(); | ||
| } | ||
| }); | ||
| indexingThread.start(); | ||
| return indexingThread; | ||
| } | ||
| } | ||
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
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.