Skip to content

Commit

Permalink
Adding IT to validate if remote index path file exists
Browse files Browse the repository at this point in the history
Signed-off-by: Shubh Sahu <shubhvs@amazon.com>
  • Loading branch information
Shubh Sahu committed May 10, 2024
1 parent 4eedad9 commit d5bd0ca
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@
import org.opensearch.cluster.routing.ShardRouting;
import org.opensearch.cluster.routing.allocation.command.MoveAllocationCommand;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.util.FileSystemUtils;
import org.opensearch.index.remote.RemoteIndexPath;
import org.opensearch.index.remote.RemoteIndexPathUploader;
import org.opensearch.index.remote.RemoteStoreEnums;
import org.opensearch.indices.replication.common.ReplicationType;
import org.opensearch.test.InternalTestCluster;
import org.opensearch.test.OpenSearchIntegTestCase;

import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.opensearch.indices.RemoteStoreSettings.CLUSTER_REMOTE_STORE_PATH_TYPE_SETTING;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;

@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0)
Expand Down Expand Up @@ -454,6 +461,88 @@ public void testRemotePathMetadataAddedWithFirstPrimaryMovingToRemote() throws E
assertRemoteProperties(indexName);
}

/**
* Scenario:
* creates an index on docrep node with non-remote cluster-manager.
* make the cluster mixed, add remote cluster-manager and data nodes.
* <p>
* exclude docrep nodes, assert that remote index path file exists
* after all shards have been relocated to the remote nodes.
*/
public void testRemoteIndexPathFileExistsAfterMigration() throws Exception {
String docrepClusterManager = internalCluster().startClusterManagerOnlyNode();

logger.info("---> Starting 2 docrep nodes");
addRemote = false;
internalCluster().startDataOnlyNodes(2, Settings.builder().put("node.attr._type", "docrep").build());
internalCluster().validateClusterFormed();

logger.info("---> Creating index with 1 primary and 1 replica");
String indexName = "migration-index";
Settings oneReplica = Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.build();
createIndexAndAssertDocrepProperties(indexName, oneReplica);

String indexUUID = internalCluster().client()
.admin()
.indices()
.prepareGetSettings(indexName)
.get()
.getSetting(indexName, IndexMetadata.SETTING_INDEX_UUID);

logger.info("---> Starting indexing in parallel");
AsyncIndexingService indexingService = new AsyncIndexingService(indexName);
indexingService.startIndexing();

logger.info("---> Adding 2 remote enabled nodes to the cluster & cluster manager");
initDocRepToRemoteMigration();
addRemote = true;
internalCluster().startClusterManagerOnlyNode();
internalCluster().startDataOnlyNodes(2, Settings.builder().put("node.attr._type", "remote").build());
internalCluster().validateClusterFormed();

assertTrue(
internalCluster().client()
.admin()
.cluster()
.prepareUpdateSettings()
.setPersistentSettings(
Settings.builder().put(CLUSTER_REMOTE_STORE_PATH_TYPE_SETTING.getKey(), RemoteStoreEnums.PathType.HASHED_PREFIX)
)
.get()
.isAcknowledged()
);

internalCluster().stopRandomNode(InternalTestCluster.nameFilter(docrepClusterManager));
internalCluster().validateClusterFormed();

logger.info("---> Excluding docrep nodes from allocation");
excludeNodeSet("type", "docrep");

waitForRelocation();
waitNoPendingTasksOnAll();
indexingService.stopIndexing();

// validate remote index path file exists
logger.info("---> Asserting remote index path file exists");
String fileName = String.join(RemoteIndexPathUploader.DELIMITER, indexUUID, "7", RemoteIndexPath.DEFAULT_VERSION);
FileSystemUtils.files(translogRepoPath);
assertTrue(FileSystemUtils.exists(translogRepoPath.resolve(RemoteIndexPath.DIR)));

Path[] files = FileSystemUtils.files(translogRepoPath.resolve(RemoteIndexPath.DIR));
assertEquals(1, files.length);
assertTrue(Arrays.stream(files).anyMatch(file -> file.toString().contains(fileName)));
String translogPathFile = files[0].toString();
assertTrue(FileSystemUtils.exists(segmentRepoPath.resolve(RemoteIndexPath.DIR)));
files = FileSystemUtils.files(segmentRepoPath.resolve(RemoteIndexPath.DIR));
assertEquals(1, files.length);
assertTrue(Arrays.stream(files).anyMatch(file -> file.toString().contains(fileName)));
String segmentPathFile = files[0].toString();
assertNotEquals(translogPathFile, segmentPathFile);
}

private void createIndexAndAssertDocrepProperties(String index, Settings settings) {
createIndexAssertHealthAndDocrepProperties(index, settings, this::ensureGreen);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@
import java.util.Set;
import java.util.stream.Collectors;

import static org.opensearch.index.remote.RemoteMigrationIndexMetadataUpdater.indexHasAllRemoteStoreRelatedMetadata;

import static org.opensearch.gateway.remote.RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING;
import static org.opensearch.index.remote.RemoteMigrationIndexMetadataUpdater.indexHasAllRemoteStoreRelatedMetadata;
import static org.opensearch.node.remotestore.RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING;

/**
Expand Down Expand Up @@ -342,6 +341,7 @@ private void validateIndexSettings(ClusterState clusterState) {
);
}
}

/**
* Verifies that remote cluster state is enabled if the compatibility mode is set to MIXED
* and migration direction is getting updated to remote store
Expand Down

0 comments on commit d5bd0ca

Please sign in to comment.