From 047e412f6f0eace2135c5492fdb39d288f49235a Mon Sep 17 00:00:00 2001 From: Shailendra Singh Date: Tue, 2 Jul 2024 17:20:55 +0530 Subject: [PATCH] Add integration tests for RemoteRouting Table --- .../remote/RemoteRoutingTableServiceIT.java | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteRoutingTableServiceIT.java diff --git a/server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteRoutingTableServiceIT.java b/server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteRoutingTableServiceIT.java new file mode 100644 index 0000000000000..642f0274f653c --- /dev/null +++ b/server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteRoutingTableServiceIT.java @@ -0,0 +1,116 @@ +/* + * 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.gateway.remote; + +import org.junit.Before; +import org.opensearch.action.admin.cluster.state.ClusterStateRequest; +import org.opensearch.action.admin.cluster.state.ClusterStateResponse; +import org.opensearch.cluster.routing.IndexRoutingTable; +import org.opensearch.cluster.routing.RoutingTable; +import org.opensearch.common.blobstore.BlobPath; +import org.opensearch.common.settings.Settings; +import org.opensearch.index.remote.RemoteStoreEnums; +import org.opensearch.index.remote.RemoteStorePathStrategy; +import org.opensearch.remotestore.RemoteStoreBaseIntegTestCase; + +import static org.opensearch.cluster.routing.remote.InternalRemoteRoutingTableService.*; +import static org.opensearch.common.util.FeatureFlags.REMOTE_PUBLICATION_EXPERIMENTAL; +import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY; + +import org.opensearch.repositories.RepositoriesService; +import org.opensearch.repositories.blobstore.BlobStoreRepository; +import org.opensearch.test.OpenSearchIntegTestCase; + +import java.nio.charset.StandardCharsets; +import java.util.*; + +import static org.opensearch.gateway.remote.RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING; + +@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) +public class RemoteRoutingTableServiceIT extends RemoteStoreBaseIntegTestCase { + private static String INDEX_NAME = "test-index"; + + @Before + public void setup() { + asyncUploadMockFsRepo = false; + } + + @Override + protected Settings nodeSettings(int nodeOrdinal) { + return Settings.builder().put(super.nodeSettings(nodeOrdinal)) + .put(REMOTE_CLUSTER_STATE_ENABLED_SETTING.getKey(), true) + .put(REMOTE_ROUTING_TABLE_PATH_TYPE_SETTING.getKey(), RemoteStoreEnums.PathType.HASHED_PREFIX.toString()) + .put("node.attr." + REMOTE_STORE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY, REPOSITORY_NAME) + .put(REMOTE_PUBLICATION_EXPERIMENTAL, true) + .build(); + } + + private RemoteStoreEnums.PathType pathType = RemoteStoreEnums.PathType.HASHED_PREFIX; + + public void testRemoteRoutingTableCreateIndex() throws Exception { + prepareCluster(1, 3, INDEX_NAME, 1, 1); + ensureGreen(INDEX_NAME); + createIndex("index-2", remoteStoreIndexSettings(2, 5)); + + RepositoriesService repositoriesService = internalCluster().getClusterManagerNodeInstance(RepositoriesService.class); + BlobStoreRepository repository = (BlobStoreRepository) repositoriesService.repository(REPOSITORY_NAME); + + BlobPath baseMetadataPath = repository.basePath() + .add( + Base64.getUrlEncoder() + .withoutPadding() + .encodeToString(getClusterState().getClusterName().value().getBytes(StandardCharsets.UTF_8)) + ) + .add("cluster-state") + .add(getClusterState().metadata().clusterUUID()); + + BlobPath indexRoutingPath = baseMetadataPath.add(INDEX_ROUTING_PATH_TOKEN); + List indexRoutingTable = new ArrayList<>(getClusterState().routingTable().indicesRouting().values()); + RemoteStoreEnums.PathHashAlgorithm pathHashAlgo = RemoteStoreEnums.PathHashAlgorithm.FNV_1A_BASE64; + BlobPath path = pathType.path( + RemoteStorePathStrategy.PathInput.builder().basePath(indexRoutingPath).indexUUID(indexRoutingTable.get(0).getIndex().getUUID()).build(), + pathHashAlgo + ); + assertBusy(() -> { + int indexRoutingFiles = repository.blobStore().blobContainer(path).listBlobs().size(); + assertTrue(indexRoutingFiles>0); + logger.info("number of index routing files {}", indexRoutingFiles); + }); + + String[] allNodes = internalCluster().getNodeNames(); + List routingTableVersions = new ArrayList<>(); + + // get cluster state from all the nodes + for (String node : allNodes) { + RoutingTable routingTable = internalCluster().client(node) + .admin() + .cluster() + .state(new ClusterStateRequest().local(true)) + .get().getState().routingTable(); + routingTableVersions.add(routingTable.version()); + } + assertTrue(areRoutingTableVersionsSame(routingTableVersions)); + } + + private boolean areRoutingTableVersionsSame(List routingTableVersions) { + if (routingTableVersions == null || routingTableVersions.isEmpty()) { + return false; + } + + Long firstVersion = routingTableVersions.get(0); + for (Long routingTableVersion : routingTableVersions) { + if (!firstVersion.equals(routingTableVersion)) { + logger.info("Responses are not same {} {}", firstVersion, routingTableVersion); + + return false; + } + } + return true; + } +}