Skip to content

Commit

Permalink
Add integration tests for RemoteRoutingTable.
Browse files Browse the repository at this point in the history
Signed-off-by: Shailendra Singh <[email protected]>
  • Loading branch information
Shailendra Singh committed Jul 3, 2024
1 parent 047e412 commit 99c2142
Showing 1 changed file with 54 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import org.junit.Before;
import org.opensearch.action.admin.cluster.state.ClusterStateRequest;
import org.opensearch.action.admin.cluster.state.ClusterStateResponse;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.cluster.routing.IndexRoutingTable;
import org.opensearch.cluster.routing.RoutingTable;
import org.opensearch.common.blobstore.BlobPath;
Expand All @@ -28,7 +28,10 @@
import org.opensearch.test.OpenSearchIntegTestCase;

import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import static org.opensearch.gateway.remote.RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING;

Expand All @@ -53,10 +56,9 @@ protected Settings nodeSettings(int nodeOrdinal) {

private RemoteStoreEnums.PathType pathType = RemoteStoreEnums.PathType.HASHED_PREFIX;

public void testRemoteRoutingTableCreateIndex() throws Exception {
public void testRemoteRoutingTableIndexLifecycle() 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);
Expand All @@ -77,16 +79,17 @@ public void testRemoteRoutingTableCreateIndex() throws Exception {
RemoteStorePathStrategy.PathInput.builder().basePath(indexRoutingPath).indexUUID(indexRoutingTable.get(0).getIndex().getUUID()).build(),
pathHashAlgo
);
AtomicInteger indexRoutingFiles = new AtomicInteger();
assertBusy(() -> {
int indexRoutingFiles = repository.blobStore().blobContainer(path).listBlobs().size();
assertTrue(indexRoutingFiles>0);
indexRoutingFiles.set(repository.blobStore().blobContainer(path).listBlobs().size());
assertTrue(indexRoutingFiles.get() >0);
logger.info("number of index routing files {}", indexRoutingFiles);
});

String[] allNodes = internalCluster().getNodeNames();
List<Long> routingTableVersions = new ArrayList<>();

// get cluster state from all the nodes
// Retrieve cluster state from all nodes
for (String node : allNodes) {
RoutingTable routingTable = internalCluster().client(node)
.admin()
Expand All @@ -96,6 +99,50 @@ public void testRemoteRoutingTableCreateIndex() throws Exception {
routingTableVersions.add(routingTable.version());
}
assertTrue(areRoutingTableVersionsSame(routingTableVersions));

// Update index settings
client().admin()
.indices()
.prepareUpdateSettings(INDEX_NAME)
.setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2))
.execute()
.actionGet();
assertBusy(() -> {
int indexRoutingFilesAfterUpdate = repository.blobStore().blobContainer(path).listBlobs().size();
assertTrue(indexRoutingFilesAfterUpdate > indexRoutingFiles.get());
logger.info("number of index routing files {} {}", indexRoutingFiles, indexRoutingFilesAfterUpdate);
});

allNodes = internalCluster().getNodeNames();
routingTableVersions = new ArrayList<>();
// Retrieve updated cluster state from all nodes again
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));

// Delete the index and assert its deletion
client().admin().indices().prepareDelete(INDEX_NAME).execute().actionGet();
assertFalse(client().admin().indices().prepareExists(INDEX_NAME).get().isExists());

allNodes = internalCluster().getNodeNames();
routingTableVersions = new ArrayList<>();
// Retrieve updated cluster state from all nodes again
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<Long> routingTableVersions) {
Expand Down

0 comments on commit 99c2142

Please sign in to comment.