use of org.elasticsearch.cluster.routing.UnassignedInfo in project elasticsearch by elastic.
the class ReplicaShardAllocatorTests method onePrimaryOnNode1And1Replica.
private RoutingAllocation onePrimaryOnNode1And1Replica(AllocationDeciders deciders, Settings settings, UnassignedInfo.Reason reason) {
ShardRouting primaryShard = TestShardRouting.newShardRouting(shardId, node1.getId(), true, ShardRoutingState.STARTED);
MetaData metaData = MetaData.builder().put(IndexMetaData.builder(shardId.getIndexName()).settings(settings(Version.CURRENT).put(settings)).numberOfShards(1).numberOfReplicas(1).putInSyncAllocationIds(0, Sets.newHashSet(primaryShard.allocationId().getId()))).build();
// mark shard as delayed if reason is NODE_LEFT
boolean delayed = reason == UnassignedInfo.Reason.NODE_LEFT && UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.get(settings).nanos() > 0;
int failedAllocations = reason == UnassignedInfo.Reason.ALLOCATION_FAILED ? 1 : 0;
RoutingTable routingTable = RoutingTable.builder().add(IndexRoutingTable.builder(shardId.getIndex()).addIndexShard(new IndexShardRoutingTable.Builder(shardId).addShard(primaryShard).addShard(ShardRouting.newUnassigned(shardId, false, RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(reason, null, null, failedAllocations, System.nanoTime(), System.currentTimeMillis(), delayed, UnassignedInfo.AllocationStatus.NO_ATTEMPT))).build())).build();
ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).nodes(DiscoveryNodes.builder().add(node1).add(node2).add(node3)).build();
return new RoutingAllocation(deciders, new RoutingNodes(state, false), state, ClusterInfo.EMPTY, System.nanoTime(), false);
}
use of org.elasticsearch.cluster.routing.UnassignedInfo in project elasticsearch by elastic.
the class IndexShardTests method testFailIfIndexNotPresentInRecoverFromStore.
public void testFailIfIndexNotPresentInRecoverFromStore() throws Exception {
final IndexShard shard = newStartedShard(true);
indexDoc(shard, "test", "0");
if (randomBoolean()) {
flushShard(shard);
}
Store store = shard.store();
store.incRef();
closeShards(shard);
cleanLuceneIndex(store.directory());
store.decRef();
IndexShard newShard = reinitShard(shard);
DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
ShardRouting routing = newShard.routingEntry();
newShard.markAsRecovering("store", new RecoveryState(routing, localNode, null));
try {
newShard.recoverFromStore();
fail("index not there!");
} catch (IndexShardRecoveryException ex) {
assertTrue(ex.getMessage().contains("failed to fetch index version after copying it over"));
}
routing = ShardRoutingHelper.moveToUnassigned(routing, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "because I say so"));
routing = ShardRoutingHelper.initialize(routing, newShard.routingEntry().currentNodeId());
assertTrue("it's already recovering, we should ignore new ones", newShard.ignoreRecoveryAttempt());
try {
newShard.markAsRecovering("store", new RecoveryState(routing, localNode, null));
fail("we are already recovering, can't mark again");
} catch (IllegalIndexShardStateException e) {
// OK!
}
newShard = reinitShard(newShard, ShardRoutingHelper.initWithSameId(routing, RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE));
newShard.markAsRecovering("store", new RecoveryState(newShard.routingEntry(), localNode, null));
assertTrue("recover even if there is nothing to recover", newShard.recoverFromStore());
newShard.updateRoutingEntry(newShard.routingEntry().moveToStarted());
assertDocCount(newShard, 0);
// we can't issue this request through a client because of the inconsistencies we created with the cluster state
// doing it directly instead
indexDoc(newShard, "test", "0");
newShard.refresh("test");
assertDocCount(newShard, 1);
closeShards(newShard);
}
use of org.elasticsearch.cluster.routing.UnassignedInfo in project elasticsearch by elastic.
the class IndicesStoreTests method testShardCanBeDeletedNoShardStarted.
public void testShardCanBeDeletedNoShardStarted() throws Exception {
int numShards = randomIntBetween(1, 7);
int numReplicas = randomInt(2);
IndexShardRoutingTable.Builder routingTable = new IndexShardRoutingTable.Builder(new ShardId("test", "_na_", 1));
for (int i = 0; i < numShards; i++) {
int unStartedShard = randomInt(numReplicas);
for (int j = 0; j <= numReplicas; j++) {
ShardRoutingState state;
if (j == unStartedShard) {
state = randomFrom(NOT_STARTED_STATES);
} else {
state = randomFrom(ShardRoutingState.values());
}
UnassignedInfo unassignedInfo = null;
if (state == ShardRoutingState.UNASSIGNED) {
unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null);
}
String relocatingNodeId = state == ShardRoutingState.RELOCATING ? randomAsciiOfLength(10) : null;
routingTable.addShard(TestShardRouting.newShardRouting("test", i, randomAsciiOfLength(10), relocatingNodeId, j == 0, state, unassignedInfo));
}
}
assertFalse(IndicesStore.shardCanBeDeleted(localNode.getId(), routingTable.build()));
}
use of org.elasticsearch.cluster.routing.UnassignedInfo in project crate by crate.
the class SysShardsExpressionsTest method mockIndexShard.
private IndexShard mockIndexShard() {
IndexService indexService = mock(IndexService.class);
Index index = new Index(indexName);
ShardId shardId = new ShardId(indexName, 1);
IndexShard indexShard = mock(IndexShard.class);
when(indexService.index()).thenReturn(index);
when(indexShard.indexService()).thenReturn(indexService);
when(indexShard.shardId()).thenReturn(shardId);
when(indexShard.state()).thenReturn(IndexShardState.STARTED);
StoreStats storeStats = mock(StoreStats.class);
when(storeStats.getSizeInBytes()).thenReturn(123456L);
when(indexShard.storeStats()).thenReturn(storeStats);
Path dataPath = Paths.get("/dummy/" + indexName + "/1");
when(indexShard.shardPath()).thenReturn(new ShardPath(false, dataPath, dataPath, "123", shardId));
DocsStats docsStats = new DocsStats(654321L, 0L);
when(indexShard.docStats()).thenReturn(docsStats).thenThrow(IllegalIndexShardStateException.class);
ShardRouting shardRouting = ShardRouting.newUnassigned(index.name(), shardId.id(), null, true, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
ShardRoutingHelper.initialize(shardRouting, "node1");
ShardRoutingHelper.moveToStarted(shardRouting);
ShardRoutingHelper.relocate(shardRouting, "node_X");
when(indexShard.routingEntry()).thenReturn(shardRouting);
when(indexShard.minimumCompatibleVersion()).thenReturn(Version.LATEST);
RecoveryState recoveryState = mock(RecoveryState.class);
when(indexShard.recoveryState()).thenReturn(recoveryState);
RecoveryState.Index recoveryStateIndex = mock(RecoveryState.Index.class);
RecoveryState.Timer recoveryStateTimer = mock(RecoveryState.Timer.class);
when(recoveryState.getIndex()).thenReturn(recoveryStateIndex);
when(recoveryState.getStage()).thenReturn(RecoveryState.Stage.DONE);
when(recoveryState.getTimer()).thenReturn(recoveryStateTimer);
when(recoveryState.getType()).thenReturn(RecoveryState.Type.REPLICA);
when(recoveryStateIndex.totalBytes()).thenReturn(2048L);
when(recoveryStateIndex.reusedBytes()).thenReturn(1024L);
when(recoveryStateIndex.recoveredBytes()).thenReturn(1024L);
when(recoveryStateIndex.totalFileCount()).thenReturn(2);
when(recoveryStateIndex.reusedFileCount()).thenReturn(1);
when(recoveryStateIndex.recoveredFileCount()).thenReturn(1);
when(recoveryStateTimer.time()).thenReturn(10000L);
return indexShard;
}
use of org.elasticsearch.cluster.routing.UnassignedInfo in project crate by crate.
the class DecommissionAllocationDeciderTest method init.
@Before
public void init() throws Exception {
routingAllocation = mock(RoutingAllocation.class);
when(routingAllocation.decision(any(Decision.class), anyString(), anyString())).then(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArguments()[0];
}
});
primaryShard = ShardRouting.newUnassigned(new ShardId("t", UUIDs.randomBase64UUID(), 0), true, RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "dummy"));
replicaShard = ShardRouting.newUnassigned(new ShardId("t", UUIDs.randomBase64UUID(), 0), false, RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "dummy"));
n1 = new RoutingNode("n1", mock(DiscoveryNode.class));
n2 = new RoutingNode("n2", mock(DiscoveryNode.class));
}
Aggregations