use of org.elasticsearch.indices.IndicesService in project crate by crate.
the class TransportShardDeleteActionTest method prepare.
@Before
public void prepare() throws Exception {
indexUUID = UUIDs.randomBase64UUID();
IndicesService indicesService = mock(IndicesService.class);
IndexService indexService = mock(IndexService.class);
when(indicesService.indexServiceSafe(new Index(TABLE_IDENT.indexNameOrAlias(), indexUUID))).thenReturn(indexService);
indexShard = mock(IndexShard.class);
when(indexService.getShard(0)).thenReturn(indexShard);
transportShardDeleteAction = new TransportShardDeleteAction(MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, THREAD_POOL, clusterService.getClusterSettings()), mock(ClusterService.class), indicesService, mock(TasksService.class), mock(ThreadPool.class), mock(ShardStateAction.class), mock(SchemaUpdateClient.class));
}
use of org.elasticsearch.indices.IndicesService in project crate by crate.
the class ClusterDisruptionIT method testRestartNodeWhileIndexing.
@Test
public void testRestartNodeWhileIndexing() throws Exception {
startCluster(3);
String index = toIndexName(sqlExecutor.getCurrentSchema(), "t", null);
int numberOfReplicas = between(1, 2);
logger.info("creating table with {} shards and {} replicas", 1, numberOfReplicas);
execute("create table t (id int primary key, x string) clustered into 1 shards with (number_of_replicas = 2, " + "\"write.wait_for_active_shards\" = 1)");
AtomicBoolean stopped = new AtomicBoolean();
Thread[] threads = new Thread[between(1, 4)];
AtomicInteger docID = new AtomicInteger();
Set<String> ackedDocs = ConcurrentCollections.newConcurrentSet();
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread(() -> {
while (stopped.get() == false && docID.get() < 5000) {
String id = Integer.toString(docID.incrementAndGet());
try {
execute("insert into t (id, x) values (?, ?)", new Object[] { id, randomInt(5000) });
logger.info("--> index id={}", id);
ackedDocs.add(id);
} catch (Exception ignore) {
logger.info("--> fail to index id={}", id);
}
}
});
threads[i].start();
}
ensureGreen();
assertBusy(() -> assertThat(docID.get(), greaterThanOrEqualTo(100)));
internalCluster().restartRandomDataNode(new InternalTestCluster.RestartCallback());
ensureGreen();
assertBusy(() -> assertThat(docID.get(), greaterThanOrEqualTo(200)));
stopped.set(true);
for (Thread thread : threads) {
thread.join();
}
ClusterState clusterState = internalCluster().clusterService().state();
for (ShardRouting shardRouting : clusterState.routingTable().allShards(index)) {
String nodeName = clusterState.nodes().get(shardRouting.currentNodeId()).getName();
IndicesService indicesService = internalCluster().getInstance(IndicesService.class, nodeName);
IndexShard shard = indicesService.getShardOrNull(shardRouting.shardId());
Set<String> docs = IndexShardTestCase.getShardDocUIDs(shard);
assertThat("shard [" + shard.routingEntry() + "] docIds [" + docs + "] vs " + " acked docIds [" + ackedDocs + "]", ackedDocs, everyItem(is(in(docs))));
}
}
use of org.elasticsearch.indices.IndicesService in project crate by crate.
the class InternalTestCluster method routingKeyForShard.
synchronized String routingKeyForShard(Index index, int shard, Random random) {
assertThat(shard, greaterThanOrEqualTo(0));
assertThat(shard, greaterThanOrEqualTo(0));
for (NodeAndClient n : nodes.values()) {
Node node = n.node;
IndicesService indicesService = getInstanceFromNode(IndicesService.class, node);
ClusterService clusterService = getInstanceFromNode(ClusterService.class, node);
IndexService indexService = indicesService.indexService(index);
if (indexService != null) {
assertThat(indexService.getIndexSettings().getSettings().getAsInt(IndexMetadata.SETTING_NUMBER_OF_SHARDS, -1), greaterThan(shard));
OperationRouting operationRouting = clusterService.operationRouting();
while (true) {
String routing = RandomStrings.randomAsciiLettersOfLength(random, 10);
final int targetShard = operationRouting.indexShards(clusterService.state(), index.getName(), null, routing).shardId().getId();
if (shard == targetShard) {
return routing;
}
}
}
}
fail("Could not find a node that holds " + index);
return null;
}
use of org.elasticsearch.indices.IndicesService in project crate by crate.
the class InternalTestCluster method assertSameSyncIdSameDocs.
private void assertSameSyncIdSameDocs() {
Map<String, Long> docsOnShards = new HashMap<>();
final Collection<NodeAndClient> nodesAndClients = nodes.values();
for (NodeAndClient nodeAndClient : nodesAndClients) {
IndicesService indexServices = getInstance(IndicesService.class, nodeAndClient.name);
for (IndexService indexService : indexServices) {
for (IndexShard indexShard : indexService) {
try {
CommitStats commitStats = indexShard.commitStats();
String syncId = commitStats.getUserData().get(Engine.SYNC_COMMIT_ID);
if (syncId != null) {
long liveDocsOnShard = commitStats.getNumDocs();
if (docsOnShards.get(syncId) != null) {
assertThat("sync id is equal but number of docs does not match on node " + nodeAndClient.name + ". expected " + docsOnShards.get(syncId) + " but got " + liveDocsOnShard, docsOnShards.get(syncId), equalTo(liveDocsOnShard));
} else {
docsOnShards.put(syncId, liveDocsOnShard);
}
}
} catch (AlreadyClosedException e) {
// the engine is closed or if the shard is recovering
}
}
}
}
}
use of org.elasticsearch.indices.IndicesService in project crate by crate.
the class GlobalCheckpointSyncIT method testPersistLocalCheckpoint.
public void testPersistLocalCheckpoint() {
internalCluster().ensureAtLeastNumDataNodes(2);
execute("create table test(id integer) clustered into 1 shards with" + "(\"global_checkpoint_sync.interval\" = ?, \"translog.durability\" = ?, number_of_replicas = ?)", new Object[] { "10ms", Translog.Durability.REQUEST.toString(), randomIntBetween(0, 1) });
var indexName = getFqn("test");
ensureGreen(indexName);
int numDocs = randomIntBetween(1, 20);
logger.info("numDocs {}", numDocs);
long maxSeqNo = 0;
for (int i = 0; i < numDocs; i++) {
maxSeqNo = (long) execute("insert into test(id) values(?) returning _seq_no", new Object[] { i }).rows()[0][0];
logger.info("got {}", maxSeqNo);
}
for (IndicesService indicesService : internalCluster().getDataNodeInstances(IndicesService.class)) {
for (IndexService indexService : indicesService) {
for (IndexShard shard : indexService) {
final SeqNoStats seqNoStats = shard.seqNoStats();
assertThat(maxSeqNo, equalTo(seqNoStats.getMaxSeqNo()));
assertThat(seqNoStats.getLocalCheckpoint(), equalTo(seqNoStats.getMaxSeqNo()));
;
}
}
}
}
Aggregations