Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky RemoteStoreStatsIT.testStatsOnShardUnassigned integ test #9063

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.opensearch.remotestore;

import org.junit.After;
import org.junit.Before;
import org.opensearch.action.admin.cluster.remotestore.restore.RestoreRemoteStoreRequest;
import org.opensearch.action.admin.cluster.remotestore.stats.RemoteStoreStats;
Expand Down Expand Up @@ -46,6 +47,11 @@ public void setup() {
setupRepo();
}

@After
public void removeAllIndices() {
assertAcked(client().admin().indices().prepareDelete("*").get());
}

public void testStatsResponseFromAllNodes() {

// Step 1 - We create cluster, create an index, and then index documents into. We also do multiple refreshes/flushes
Expand Down Expand Up @@ -432,22 +438,32 @@ public void testStatsOnShardRelocation() {
assertEquals(destinationNode, replicaShardStat.getShardRouting().currentNodeId());
}

public void testStatsOnShardUnassigned() throws IOException {
public void testStatsOnShardUnassigned() throws Exception {
// Scenario:
// - Create index with single primary and two replica shard
// - Create index with single primary and N-1 replica shard (N = number of data nodes)
// - Index documents
// - Stop one data node
// - Assert:
// a. Total shard Count in the response object is equal to the previous node count
// b. Successful shard count in the response object is equal to the new node count
createIndex(INDEX_NAME, remoteStoreIndexSettings(2, 1));
int initialDataNodeCount = client().admin().cluster().prepareHealth().get().getNumberOfDataNodes();
createIndex(INDEX_NAME, remoteStoreIndexSettings(initialDataNodeCount - 1, 1));
ensureGreen(INDEX_NAME);
indexDocs();
int dataNodeCountBeforeStop = client().admin().cluster().prepareHealth().get().getNumberOfDataNodes();
internalCluster().stopRandomDataNode();

// Recording stats before stopping node
RemoteStoreStatsResponse response = client().admin().cluster().prepareRemoteStoreStats(INDEX_NAME, "0").get();
int totalShardsBeforeStop = response.getTotalShards();

// Stop one data node
internalCluster().stopRandomDataNode();
ensureYellowAndNoInitializingShards(INDEX_NAME);
int dataNodeCountAfterStop = client().admin().cluster().prepareHealth().get().getNumberOfDataNodes();
assertEquals(dataNodeCountBeforeStop, response.getTotalShards());
assertEquals(initialDataNodeCount - 1, dataNodeCountAfterStop);

// Recording stats again
response = client().admin().cluster().prepareRemoteStoreStats(INDEX_NAME, "0").get();
assertEquals(totalShardsBeforeStop, response.getTotalShards());
assertEquals(dataNodeCountAfterStop, response.getSuccessfulShards());
}

Expand Down