Skip to content

Commit 896b127

Browse files
[Remote Store] Adding ITs to ensure RemoteIndexPath file gets created after migration for each index. (opensearch-project#13367)
Signed-off-by: Shubh Sahu <shubhvs@amazon.com>
1 parent 771f4ec commit 896b127

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

server/src/internalClusterTest/java/org/opensearch/remotemigration/MigrationBaseTestCase.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.concurrent.atomic.AtomicLong;
3636

3737
import static org.opensearch.cluster.routing.allocation.decider.EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING;
38+
import static org.opensearch.gateway.remote.RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING;
3839
import static org.opensearch.node.remotestore.RemoteStoreNodeService.MIGRATION_DIRECTION_SETTING;
3940
import static org.opensearch.node.remotestore.RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING;
4041
import static org.opensearch.repositories.fs.ReloadableFsRepository.REPOSITORIES_FAILRATE_SETTING;
@@ -78,10 +79,11 @@ protected Settings nodeSettings(int nodeOrdinal) {
7879
.put(super.nodeSettings(nodeOrdinal))
7980
.put(extraSettings)
8081
.put(remoteStoreClusterSettings(REPOSITORY_NAME, segmentRepoPath, REPOSITORY_2_NAME, translogRepoPath))
82+
.put(REMOTE_CLUSTER_STATE_ENABLED_SETTING.getKey(), true)
8183
.build();
8284
} else {
8385
logger.info("Adding docrep node");
84-
return Settings.builder().put(super.nodeSettings(nodeOrdinal)).build();
86+
return Settings.builder().put(super.nodeSettings(nodeOrdinal)).put(REMOTE_CLUSTER_STATE_ENABLED_SETTING.getKey(), true).build();
8587
}
8688
}
8789

server/src/internalClusterTest/java/org/opensearch/remotemigration/RemoteMigrationIndexMetadataUpdateIT.java

+86
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,21 @@
1515
import org.opensearch.cluster.routing.ShardRouting;
1616
import org.opensearch.cluster.routing.allocation.command.MoveAllocationCommand;
1717
import org.opensearch.common.settings.Settings;
18+
import org.opensearch.core.util.FileSystemUtils;
19+
import org.opensearch.index.remote.RemoteIndexPath;
20+
import org.opensearch.index.remote.RemoteIndexPathUploader;
21+
import org.opensearch.index.remote.RemoteStoreEnums;
1822
import org.opensearch.indices.replication.common.ReplicationType;
1923
import org.opensearch.test.InternalTestCluster;
2024
import org.opensearch.test.OpenSearchIntegTestCase;
2125

26+
import java.nio.file.Path;
27+
import java.util.Arrays;
2228
import java.util.List;
2329
import java.util.function.Function;
2430
import java.util.stream.Collectors;
2531

32+
import static org.opensearch.indices.RemoteStoreSettings.CLUSTER_REMOTE_STORE_PATH_TYPE_SETTING;
2633
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
2734

2835
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0)
@@ -454,6 +461,85 @@ public void testRemotePathMetadataAddedWithFirstPrimaryMovingToRemote() throws E
454461
assertRemoteProperties(indexName);
455462
}
456463

464+
/**
465+
* Scenario:
466+
* creates an index on docrep node with non-remote cluster-manager.
467+
* make the cluster mixed, add remote cluster-manager and data nodes.
468+
* <p>
469+
* exclude docrep nodes, assert that remote index path file exists
470+
* when shards start relocating to the remote nodes.
471+
*/
472+
public void testRemoteIndexPathFileExistsAfterMigration() throws Exception {
473+
String docrepClusterManager = internalCluster().startClusterManagerOnlyNode();
474+
475+
logger.info("---> Starting 2 docrep nodes");
476+
addRemote = false;
477+
internalCluster().startDataOnlyNodes(2, Settings.builder().put("node.attr._type", "docrep").build());
478+
internalCluster().validateClusterFormed();
479+
480+
logger.info("---> Creating index with 1 primary and 1 replica");
481+
String indexName = "migration-index";
482+
Settings oneReplica = Settings.builder()
483+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1)
484+
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
485+
.build();
486+
createIndexAndAssertDocrepProperties(indexName, oneReplica);
487+
488+
String indexUUID = internalCluster().client()
489+
.admin()
490+
.indices()
491+
.prepareGetSettings(indexName)
492+
.get()
493+
.getSetting(indexName, IndexMetadata.SETTING_INDEX_UUID);
494+
495+
logger.info("---> Starting indexing in parallel");
496+
AsyncIndexingService indexingService = new AsyncIndexingService(indexName);
497+
indexingService.startIndexing();
498+
499+
logger.info("---> Adding 2 remote enabled nodes to the cluster & cluster manager");
500+
initDocRepToRemoteMigration();
501+
addRemote = true;
502+
internalCluster().startClusterManagerOnlyNode();
503+
internalCluster().startDataOnlyNodes(2, Settings.builder().put("node.attr._type", "remote").build());
504+
internalCluster().validateClusterFormed();
505+
506+
assertTrue(
507+
internalCluster().client()
508+
.admin()
509+
.cluster()
510+
.prepareUpdateSettings()
511+
.setPersistentSettings(
512+
Settings.builder().put(CLUSTER_REMOTE_STORE_PATH_TYPE_SETTING.getKey(), RemoteStoreEnums.PathType.HASHED_PREFIX)
513+
)
514+
.get()
515+
.isAcknowledged()
516+
);
517+
518+
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(docrepClusterManager));
519+
internalCluster().validateClusterFormed();
520+
521+
logger.info("---> Excluding docrep nodes from allocation");
522+
excludeNodeSet("type", "docrep");
523+
524+
waitForRelocation();
525+
waitNoPendingTasksOnAll();
526+
indexingService.stopIndexing();
527+
528+
// validate remote index path file exists
529+
logger.info("---> Asserting remote index path file exists");
530+
String fileNamePrefix = String.join(RemoteIndexPathUploader.DELIMITER, indexUUID, "7", RemoteIndexPath.DEFAULT_VERSION);
531+
532+
assertTrue(FileSystemUtils.exists(translogRepoPath.resolve(RemoteIndexPath.DIR)));
533+
Path[] files = FileSystemUtils.files(translogRepoPath.resolve(RemoteIndexPath.DIR));
534+
assertEquals(1, files.length);
535+
assertTrue(Arrays.stream(files).anyMatch(file -> file.toString().contains(fileNamePrefix)));
536+
537+
assertTrue(FileSystemUtils.exists(segmentRepoPath.resolve(RemoteIndexPath.DIR)));
538+
files = FileSystemUtils.files(segmentRepoPath.resolve(RemoteIndexPath.DIR));
539+
assertEquals(1, files.length);
540+
assertTrue(Arrays.stream(files).anyMatch(file -> file.toString().contains(fileNamePrefix)));
541+
}
542+
457543
private void createIndexAndAssertDocrepProperties(String index, Settings settings) {
458544
createIndexAssertHealthAndDocrepProperties(index, settings, this::ensureGreen);
459545
}

0 commit comments

Comments
 (0)