|
@@ -18,27 +18,11 @@
|
|
|
*/
|
|
|
package org.elasticsearch.index.seqno;
|
|
|
|
|
|
-import org.elasticsearch.client.Request;
|
|
|
-import org.elasticsearch.client.RestClient;
|
|
|
-import org.elasticsearch.cluster.routing.RecoverySource;
|
|
|
-import org.elasticsearch.cluster.routing.ShardRouting;
|
|
|
-import org.elasticsearch.cluster.routing.UnassignedInfo;
|
|
|
-import org.elasticsearch.index.shard.ShardId;
|
|
|
-import org.elasticsearch.test.rest.yaml.ObjectPath;
|
|
|
-import org.junit.Assert;
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.HashSet;
|
|
|
import java.util.LinkedHashMap;
|
|
|
-import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Set;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-import static org.hamcrest.Matchers.hasItems;
|
|
|
-
|
|
|
public class RetentionLeaseUtils {
|
|
|
|
|
|
private RetentionLeaseUtils() {
|
|
@@ -61,39 +45,4 @@ public class RetentionLeaseUtils {
|
|
|
},
|
|
|
LinkedHashMap::new));
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * Asserts that every copy of every shard of the given index has a peer recovery retention lease according to the stats exposed by the
|
|
|
- * REST API
|
|
|
- */
|
|
|
- public static void assertAllCopiesHavePeerRecoveryRetentionLeases(RestClient restClient, String index) throws IOException {
|
|
|
- final Request statsRequest = new Request("GET", "/" + index + "/_stats");
|
|
|
- statsRequest.addParameter("level", "shards");
|
|
|
- final Map<?, ?> shardsStats = ObjectPath.createFromResponse(restClient.performRequest(statsRequest))
|
|
|
- .evaluate("indices." + index + ".shards");
|
|
|
- for (Map.Entry<?, ?> shardCopiesEntry : shardsStats.entrySet()) {
|
|
|
- final List<?> shardCopiesList = (List<?>) shardCopiesEntry.getValue();
|
|
|
-
|
|
|
- final Set<String> expectedLeaseIds = new HashSet<>();
|
|
|
- for (Object shardCopyStats : shardCopiesList) {
|
|
|
- final String nodeId
|
|
|
- = Objects.requireNonNull((String) ((Map<?, ?>) (((Map<?, ?>) shardCopyStats).get("routing"))).get("node"));
|
|
|
- expectedLeaseIds.add(ReplicationTracker.getPeerRecoveryRetentionLeaseId(
|
|
|
- ShardRouting.newUnassigned(new ShardId("_na_", "test", 0), false, RecoverySource.PeerRecoverySource.INSTANCE,
|
|
|
- new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "test")).initialize(nodeId, null, 0L)));
|
|
|
- }
|
|
|
-
|
|
|
- final Set<String> actualLeaseIds = new HashSet<>();
|
|
|
- for (Object shardCopyStats : shardCopiesList) {
|
|
|
- final List<?> leases
|
|
|
- = (List<?>) ((Map<?, ?>) (((Map<?, ?>) shardCopyStats).get("retention_leases"))).get("leases");
|
|
|
- for (Object lease : leases) {
|
|
|
- actualLeaseIds.add(Objects.requireNonNull((String) (((Map<?, ?>) lease).get("id"))));
|
|
|
- }
|
|
|
- }
|
|
|
- Assert.assertThat("[" + index + "][" + shardCopiesEntry.getKey() + "] has leases " + actualLeaseIds
|
|
|
- + " but expected " + expectedLeaseIds,
|
|
|
- actualLeaseIds, hasItems(expectedLeaseIds.toArray(new String[0])));
|
|
|
- }
|
|
|
- }
|
|
|
}
|