use of org.elasticsearch.cluster.routing.UnassignedInfo in project elasticsearch by elastic.
the class PriorityComparatorTests method testPreferPriorityIndices.
public void testPreferPriorityIndices() {
RoutingNodes.UnassignedShards shards = new RoutingNodes.UnassignedShards(mock(RoutingNodes.class));
List<ShardRouting> shardRoutings = Arrays.asList(TestShardRouting.newShardRouting("oldest", 0, null, null, randomBoolean(), ShardRoutingState.UNASSIGNED, new UnassignedInfo(randomFrom(UnassignedInfo.Reason.values()), "foobar")), TestShardRouting.newShardRouting("newest", 0, null, null, randomBoolean(), ShardRoutingState.UNASSIGNED, new UnassignedInfo(randomFrom(UnassignedInfo.Reason.values()), "foobar")));
Collections.shuffle(shardRoutings, random());
for (ShardRouting routing : shardRoutings) {
shards.add(routing);
}
shards.sort(new PriorityComparator() {
@Override
protected Settings getIndexSettings(Index index) {
if ("oldest".equals(index.getName())) {
return Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 10).put(IndexMetaData.SETTING_PRIORITY, 100).build();
} else if ("newest".equals(index.getName())) {
return Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 100).put(IndexMetaData.SETTING_PRIORITY, 1).build();
}
return Settings.EMPTY;
}
});
RoutingNodes.UnassignedShards.UnassignedIterator iterator = shards.iterator();
ShardRouting next = iterator.next();
assertEquals("oldest", next.getIndexName());
next = iterator.next();
assertEquals("newest", next.getIndexName());
assertFalse(iterator.hasNext());
}
use of org.elasticsearch.cluster.routing.UnassignedInfo in project elasticsearch by elastic.
the class SearchAsyncActionTests method getShardsIter.
private GroupShardsIterator getShardsIter(String index, int numShards, boolean doReplicas, DiscoveryNode primaryNode, DiscoveryNode replicaNode) {
ArrayList<ShardIterator> list = new ArrayList<>();
for (int i = 0; i < numShards; i++) {
ArrayList<ShardRouting> started = new ArrayList<>();
ArrayList<ShardRouting> initializing = new ArrayList<>();
ArrayList<ShardRouting> unassigned = new ArrayList<>();
ShardRouting routing = ShardRouting.newUnassigned(new ShardId(new Index(index, "_na_"), i), true, RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foobar"));
routing = routing.initialize(primaryNode.getId(), i + "p", 0);
routing.started();
started.add(routing);
if (doReplicas) {
routing = ShardRouting.newUnassigned(new ShardId(new Index(index, "_na_"), i), false, RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foobar"));
if (replicaNode != null) {
routing = routing.initialize(replicaNode.getId(), i + "r", 0);
if (randomBoolean()) {
routing.started();
started.add(routing);
} else {
initializing.add(routing);
}
} else {
// unused yet
unassigned.add(routing);
}
}
Collections.shuffle(started, random());
started.addAll(initializing);
list.add(new PlainShardIterator(new ShardId(new Index(index, "_na_"), i), started));
}
return new GroupShardsIterator(list);
}
use of org.elasticsearch.cluster.routing.UnassignedInfo in project elasticsearch by elastic.
the class IndexShardIT method getInitializingShardRouting.
private static ShardRouting getInitializingShardRouting(ShardRouting existingShardRouting) {
ShardRouting shardRouting = TestShardRouting.newShardRouting(existingShardRouting.shardId(), existingShardRouting.currentNodeId(), null, existingShardRouting.primary(), ShardRoutingState.INITIALIZING, existingShardRouting.allocationId());
shardRouting = shardRouting.updateUnassigned(new UnassignedInfo(UnassignedInfo.Reason.INDEX_REOPENED, "fake recovery"), RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE);
return shardRouting;
}
use of org.elasticsearch.cluster.routing.UnassignedInfo in project elasticsearch by elastic.
the class ThrottlingAllocationTests method addInSyncAllocationIds.
private void addInSyncAllocationIds(Index index, IndexMetaData.Builder indexMetaData, TestGatewayAllocator gatewayAllocator, DiscoveryNode node1) {
for (int shard = 0; shard < indexMetaData.numberOfShards(); shard++) {
final boolean primary = randomBoolean();
final ShardRouting unassigned = ShardRouting.newUnassigned(new ShardId(index, shard), primary, primary ? RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "test"));
ShardRouting started = ShardRoutingHelper.moveToStarted(ShardRoutingHelper.initialize(unassigned, node1.getId()));
indexMetaData.putInSyncAllocationIds(shard, Collections.singleton(started.allocationId().getId()));
gatewayAllocator.addKnownAllocation(started);
}
}
use of org.elasticsearch.cluster.routing.UnassignedInfo in project elasticsearch by elastic.
the class IndicesLifecycleListenerSingleNodeTests method testStartDeleteIndexEventCallback.
public void testStartDeleteIndexEventCallback() throws Throwable {
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
assertAcked(client().admin().indices().prepareCreate("test").setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0));
ensureGreen();
Index idx = resolveIndex("test");
IndexMetaData metaData = indicesService.indexService(idx).getMetaData();
ShardRouting shardRouting = indicesService.indexService(idx).getShard(0).routingEntry();
final AtomicInteger counter = new AtomicInteger(1);
IndexEventListener countingListener = new IndexEventListener() {
@Override
public void beforeIndexCreated(Index index, Settings indexSettings) {
assertEquals("test", index.getName());
assertEquals(1, counter.get());
counter.incrementAndGet();
}
@Override
public void afterIndexCreated(IndexService indexService) {
assertEquals("test", indexService.index().getName());
assertEquals(2, counter.get());
counter.incrementAndGet();
}
@Override
public void beforeIndexShardCreated(ShardId shardId, Settings indexSettings) {
assertEquals(3, counter.get());
counter.incrementAndGet();
}
@Override
public void afterIndexShardCreated(IndexShard indexShard) {
assertEquals(4, counter.get());
counter.incrementAndGet();
}
@Override
public void afterIndexShardStarted(IndexShard indexShard) {
assertEquals(5, counter.get());
counter.incrementAndGet();
}
@Override
public void beforeIndexRemoved(IndexService indexService, IndexRemovalReason reason) {
assertEquals(DELETED, reason);
assertEquals(6, counter.get());
counter.incrementAndGet();
}
@Override
public void beforeIndexShardDeleted(ShardId shardId, Settings indexSettings) {
assertEquals(7, counter.get());
counter.incrementAndGet();
}
@Override
public void afterIndexShardDeleted(ShardId shardId, Settings indexSettings) {
assertEquals(8, counter.get());
counter.incrementAndGet();
}
@Override
public void afterIndexRemoved(Index index, IndexSettings indexSettings, IndexRemovalReason reason) {
assertEquals(DELETED, reason);
assertEquals(9, counter.get());
counter.incrementAndGet();
}
};
indicesService.removeIndex(idx, DELETED, "simon says");
try {
IndexService index = indicesService.createIndex(metaData, Arrays.asList(countingListener), s -> {
});
assertEquals(3, counter.get());
idx = index.index();
ShardRouting newRouting = shardRouting;
String nodeId = newRouting.currentNodeId();
UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "boom");
newRouting = newRouting.moveToUnassigned(unassignedInfo).updateUnassigned(unassignedInfo, RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE);
newRouting = ShardRoutingHelper.initialize(newRouting, nodeId);
IndexShard shard = index.createShard(newRouting);
shard.updateRoutingEntry(newRouting);
assertEquals(5, counter.get());
final DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
shard.markAsRecovering("store", new RecoveryState(newRouting, localNode, null));
shard.recoverFromStore();
newRouting = ShardRoutingHelper.moveToStarted(newRouting);
shard.updateRoutingEntry(newRouting);
assertEquals(6, counter.get());
} finally {
indicesService.removeIndex(idx, DELETED, "simon says");
}
assertEquals(10, counter.get());
}
Aggregations