|
15 | 15 | import org.opensearch.cluster.routing.ShardRouting;
|
16 | 16 | import org.opensearch.cluster.routing.allocation.command.MoveAllocationCommand;
|
17 | 17 | 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; |
18 | 22 | import org.opensearch.indices.replication.common.ReplicationType;
|
19 | 23 | import org.opensearch.test.InternalTestCluster;
|
20 | 24 | import org.opensearch.test.OpenSearchIntegTestCase;
|
21 | 25 |
|
| 26 | +import java.nio.file.Path; |
| 27 | +import java.util.Arrays; |
22 | 28 | import java.util.List;
|
23 | 29 | import java.util.function.Function;
|
24 | 30 | import java.util.stream.Collectors;
|
25 | 31 |
|
| 32 | +import static org.opensearch.indices.RemoteStoreSettings.CLUSTER_REMOTE_STORE_PATH_TYPE_SETTING; |
26 | 33 | import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
|
27 | 34 |
|
28 | 35 | @OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0)
|
@@ -454,6 +461,85 @@ public void testRemotePathMetadataAddedWithFirstPrimaryMovingToRemote() throws E
|
454 | 461 | assertRemoteProperties(indexName);
|
455 | 462 | }
|
456 | 463 |
|
| 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 | + |
457 | 543 | private void createIndexAndAssertDocrepProperties(String index, Settings settings) {
|
458 | 544 | createIndexAssertHealthAndDocrepProperties(index, settings, this::ensureGreen);
|
459 | 545 | }
|
|
0 commit comments