mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 02:14:54 +00:00
Closed index noop recovery during upgrade (#44072)
Test that closed indices do noop recovery during rolling upgrade.
This commit is contained in:
parent
fd9eebae81
commit
859709cc94
@ -26,6 +26,7 @@ import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaDataIndexStateService;
|
||||
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider;
|
||||
import org.elasticsearch.common.Booleans;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
||||
@ -36,6 +37,7 @@ import org.elasticsearch.rest.action.document.RestIndexAction;
|
||||
import org.elasticsearch.rest.action.document.RestUpdateAction;
|
||||
import org.elasticsearch.test.rest.yaml.ObjectPath;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -448,6 +450,41 @@ public class RecoveryIT extends AbstractRollingTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We test that a closed index makes no-op replica allocation/recovery only.
|
||||
*/
|
||||
public void testClosedIndexNoopRecovery() throws Exception {
|
||||
final String indexName = "closed_index_replica_allocation";
|
||||
if (CLUSTER_TYPE == ClusterType.OLD) {
|
||||
createIndex(indexName, Settings.builder()
|
||||
.put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1)
|
||||
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 1)
|
||||
.put(EnableAllocationDecider.INDEX_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), "none")
|
||||
.put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "120s")
|
||||
.put("index.routing.allocation.include._name", "node-0")
|
||||
.build());
|
||||
indexDocs(indexName, 0, randomInt(10));
|
||||
// allocate replica to node-2
|
||||
updateIndexSettings(indexName,
|
||||
Settings.builder().put("index.routing.allocation.include._name", "node-0,node-2,upgraded-node-*"));
|
||||
ensureGreen(indexName);
|
||||
closeIndex(indexName);
|
||||
}
|
||||
|
||||
final Version indexVersionCreated = indexVersionCreated(indexName);
|
||||
if (indexVersionCreated.onOrAfter(Version.V_7_2_0)) {
|
||||
// index was created on a version that supports the replication of closed indices,
|
||||
// so we expect the index to be closed and replicated
|
||||
ensureGreen(indexName);
|
||||
assertClosedIndex(indexName, true);
|
||||
if (CLUSTER_TYPE != ClusterType.OLD && minimumNodeVersion().onOrAfter(Version.V_7_2_0)) {
|
||||
assertNoFileBasedRecovery(indexName, s-> s.startsWith("upgraded"));
|
||||
}
|
||||
} else {
|
||||
assertClosedIndex(indexName, false);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Returns the version in which the given index has been created
|
||||
*/
|
||||
@ -592,4 +629,36 @@ public class RecoveryIT extends AbstractRollingTestCase {
|
||||
client().performRequest(update);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertNoFileBasedRecovery(String indexName, Predicate<String> targetNode) throws IOException {
|
||||
Map<String, Object> recoveries = entityAsMap(client()
|
||||
.performRequest(new Request("GET", indexName + "/_recovery?detailed=true")));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, ?>> shards = (List<Map<String,?>>) XContentMapValues.extractValue(indexName + ".shards", recoveries);
|
||||
assertNotNull(shards);
|
||||
boolean foundReplica = false;
|
||||
for (Map<String, ?> shard : shards) {
|
||||
if (shard.get("primary") == Boolean.FALSE
|
||||
&& targetNode.test((String) XContentMapValues.extractValue("target.name", shard))) {
|
||||
List<?> details = (List<?>) XContentMapValues.extractValue("index.files.details", shard);
|
||||
// once detailed recoveries works, remove this if.
|
||||
if (details == null) {
|
||||
long totalFiles = ((Number) XContentMapValues.extractValue("index.files.total", shard)).longValue();
|
||||
long reusedFiles = ((Number) XContentMapValues.extractValue("index.files.reused", shard)).longValue();
|
||||
logger.info("total [{}] reused [{}]", totalFiles, reusedFiles);
|
||||
assertEquals("must reuse all files, recoveries [" + recoveries + "]", totalFiles, reusedFiles);
|
||||
} else {
|
||||
assertNotNull(details);
|
||||
assertThat(details, Matchers.empty());
|
||||
}
|
||||
|
||||
long translogRecovered = ((Number) XContentMapValues.extractValue("translog.recovered", shard)).longValue();
|
||||
assertEquals("must be noop, recoveries [" + recoveries + "]", 0, translogRecovered);
|
||||
foundReplica = true;
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("must find replica", foundReplica);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user