use of org.elasticsearch.cluster.routing.allocation.FailedShard in project elasticsearch by elastic.
the class PrimaryTermsTests method failSomePrimaries.
private void failSomePrimaries(String index) {
final IndexRoutingTable indexShardRoutingTable = clusterState.routingTable().index(index);
Set<Integer> shardIdsToFail = new HashSet<>();
for (int i = 1 + randomInt(numberOfShards - 1); i > 0; i--) {
shardIdsToFail.add(randomInt(numberOfShards - 1));
}
logger.info("failing primary shards {} for index [{}]", shardIdsToFail, index);
List<FailedShard> failedShards = new ArrayList<>();
for (int shard : shardIdsToFail) {
failedShards.add(new FailedShard(indexShardRoutingTable.shard(shard).primaryShard(), "test", null));
// the primary failure should increment the primary term;
incrementPrimaryTerm(index, shard);
}
applyRerouteResult(allocationService.applyFailedShards(this.clusterState, failedShards, Collections.emptyList()));
}
use of org.elasticsearch.cluster.routing.allocation.FailedShard in project elasticsearch by elastic.
the class TestGatewayAllocator method applyFailedShards.
@Override
public void applyFailedShards(RoutingAllocation allocation, List<FailedShard> failedShards) {
currentNodes = allocation.nodes();
for (FailedShard failedShard : failedShards) {
final ShardRouting failedRouting = failedShard.getRoutingEntry();
Map<ShardId, ShardRouting> nodeAllocations = knownAllocations.get(failedRouting.currentNodeId());
if (nodeAllocations != null) {
nodeAllocations.remove(failedRouting.shardId());
if (nodeAllocations.isEmpty()) {
knownAllocations.remove(failedRouting.currentNodeId());
}
}
}
}
Aggregations