From d58864745c6788dd2c2fa288e789d1d05abcf3e4 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Tue, 19 Mar 2019 11:40:27 -0400 Subject: [PATCH] Dump recovery if fail to get doc count with preference (#40168) With this change, we will dump the recovery state if we fail to get doc count for a given index with a preference in rolling upgrade tests. We should have more information to look into why the provided preference is not valid. I also unmuted `testRelocationWithConcurrentIndexing` in this change. Relates #34950 --- .../elasticsearch/upgrades/RecoveryIT.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java index 684b7b8ef76..ec95c0eec5c 100644 --- a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java +++ b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.upgrades; +import org.apache.http.util.EntityUtils; import org.elasticsearch.Version; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.client.Request; @@ -171,14 +172,27 @@ public class RecoveryIT extends AbstractRollingTestCase { } private void assertCount(final String index, final String preference, final int expectedCount) throws IOException { - final Request request = new Request("GET", index + "/_count"); - request.addParameter("preference", preference); - final Response response = client().performRequest(request); - final int actualCount = Integer.parseInt(ObjectPath.createFromResponse(response).evaluate("count").toString()); - assertThat("preference [" + preference + "]", actualCount, equalTo(expectedCount)); + final int actualDocs; + try { + final Request request = new Request("GET", index + "/_count"); + if (preference != null) { + request.addParameter("preference", preference); + } + final Response response = client().performRequest(request); + actualDocs = Integer.parseInt(ObjectPath.createFromResponse(response).evaluate("count").toString()); + } catch (ResponseException e) { + try { + final Response recoveryStateResponse = client().performRequest(new Request("GET", index + "/_recovery")); + fail("failed to get doc count for index [" + index + "] with preference [" + preference + "]" + " response [" + e + "]" + + " recovery [" + EntityUtils.toString(recoveryStateResponse.getEntity()) + "]"); + } catch (Exception inner) { + e.addSuppressed(inner); + } + throw e; + } + assertThat("preference [" + preference + "]", actualDocs, equalTo(expectedCount)); } - private String getNodeId(Predicate versionPredicate) throws IOException { Response response = client().performRequest(new Request("GET", "_nodes")); ObjectPath objectPath = ObjectPath.createFromResponse(response); @@ -192,7 +206,6 @@ public class RecoveryIT extends AbstractRollingTestCase { return null; } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/34950") public void testRelocationWithConcurrentIndexing() throws Exception { final String index = "relocation_with_concurrent_indexing"; switch (CLUSTER_TYPE) {