use of org.elasticsearch.cluster.action.shard.ShardStateAction.ShardEntry in project elasticsearch by elastic.
the class InSyncAllocationIdTests method testPrimaryAllocationIdNotRemovedFromInSyncSetWhenNoFailOver.
/**
* Don't remove allocation id of failed active primary if there is no replica to promote as primary.
*/
public void testPrimaryAllocationIdNotRemovedFromInSyncSetWhenNoFailOver() throws Exception {
ClusterState clusterState = createOnePrimaryOneReplicaClusterState(allocation);
Set<String> inSyncSet = clusterState.metaData().index("test").inSyncAllocationIds(0);
assertThat(inSyncSet.size(), equalTo(2));
IndexShardRoutingTable shardRoutingTable = clusterState.routingTable().index("test").shard(0);
ShardRouting primaryShard = shardRoutingTable.primaryShard();
ShardRouting replicaShard = shardRoutingTable.replicaShards().get(0);
logger.info("remove replica node");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove(replicaShard.currentNodeId())).build();
clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
// in-sync allocation ids should not be updated
assertEquals(inSyncSet, clusterState.metaData().index("test").inSyncAllocationIds(0));
logger.info("fail primary shard");
clusterState = failedClusterStateTaskExecutor.execute(clusterState, Collections.singletonList(new ShardEntry(shardRoutingTable.shardId(), primaryShard.allocationId().getId(), 0L, "dummy", null))).resultingState;
assertThat(clusterState.routingTable().index("test").shard(0).assignedShards().size(), equalTo(0));
// in-sync allocation ids should not be updated
assertEquals(inSyncSet, clusterState.metaData().index("test").inSyncAllocationIds(0));
}
use of org.elasticsearch.cluster.action.shard.ShardStateAction.ShardEntry in project elasticsearch by elastic.
the class InSyncAllocationIdTests method testDeadNodesBeforeReplicaFailed.
/**
* Assume following scenario: indexing request is written to primary, but fails to be replicated to active replica.
* The primary instructs master to fail replica before acknowledging write to client. In the meanwhile, the node of the replica was
* removed from the cluster (deassociateDeadNodes). This means that the ShardRouting of the replica was failed, but it's allocation
* id is still part of the in-sync set. We have to make sure that the failShard request from the primary removes the allocation id
* from the in-sync set.
*/
public void testDeadNodesBeforeReplicaFailed() throws Exception {
ClusterState clusterState = createOnePrimaryOneReplicaClusterState(allocation);
logger.info("remove replica node");
IndexShardRoutingTable shardRoutingTable = clusterState.routingTable().index("test").shard(0);
ShardRouting replicaShard = shardRoutingTable.replicaShards().get(0);
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove(replicaShard.currentNodeId())).build();
clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(2));
logger.info("fail replica (for which there is no shard routing in the CS anymore)");
assertNull(clusterState.getRoutingNodes().getByAllocationId(replicaShard.shardId(), replicaShard.allocationId().getId()));
ShardStateAction.ShardFailedClusterStateTaskExecutor failedClusterStateTaskExecutor = new ShardStateAction.ShardFailedClusterStateTaskExecutor(allocation, null, logger);
long primaryTerm = clusterState.metaData().index("test").primaryTerm(0);
clusterState = failedClusterStateTaskExecutor.execute(clusterState, Arrays.asList(new ShardEntry(shardRoutingTable.shardId(), replicaShard.allocationId().getId(), primaryTerm, "dummy", null))).resultingState;
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(1));
}
use of org.elasticsearch.cluster.action.shard.ShardStateAction.ShardEntry in project elasticsearch by elastic.
the class InSyncAllocationIdTests method testPrimaryFailureBatchedWithReplicaFailure.
/**
* Assume following scenario: indexing request is written to primary, but fails to be replicated to active replica.
* The primary instructs master to fail replica before acknowledging write to client. In the meanwhile, primary fails for an unrelated
* reason. Master now batches both requests to fail primary and replica. We have to make sure that only the allocation id of the primary
* is kept in the in-sync allocation set before we acknowledge request to client. Otherwise we would acknowledge a write that made it
* into the primary but not the replica but the replica is still considered non-stale.
*/
public void testPrimaryFailureBatchedWithReplicaFailure() throws Exception {
ClusterState clusterState = createOnePrimaryOneReplicaClusterState(allocation);
IndexShardRoutingTable shardRoutingTable = clusterState.routingTable().index("test").shard(0);
ShardRouting primaryShard = shardRoutingTable.primaryShard();
ShardRouting replicaShard = shardRoutingTable.replicaShards().get(0);
long primaryTerm = clusterState.metaData().index("test").primaryTerm(0);
List<ShardEntry> failureEntries = new ArrayList<>();
failureEntries.add(new ShardEntry(shardRoutingTable.shardId(), primaryShard.allocationId().getId(), 0L, "dummy", null));
failureEntries.add(new ShardEntry(shardRoutingTable.shardId(), replicaShard.allocationId().getId(), primaryTerm, "dummy", null));
Collections.shuffle(failureEntries, random());
logger.info("Failing {}", failureEntries);
clusterState = failedClusterStateTaskExecutor.execute(clusterState, failureEntries).resultingState;
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0), equalTo(Collections.singleton(primaryShard.allocationId().getId())));
// resend shard failures to check if they are ignored
clusterState = failedClusterStateTaskExecutor.execute(clusterState, failureEntries).resultingState;
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0), equalTo(Collections.singleton(primaryShard.allocationId().getId())));
}
Aggregations