Search in sources :

Example 41 with IndicesService

use of org.elasticsearch.indices.IndicesService in project elasticsearch by elastic.

the class TransportWriteActionTests method mockIndicesService.

final IndicesService mockIndicesService(ClusterService clusterService) {
    final IndicesService indicesService = mock(IndicesService.class);
    when(indicesService.indexServiceSafe(any(Index.class))).then(invocation -> {
        Index index = (Index) invocation.getArguments()[0];
        final ClusterState state = clusterService.state();
        final IndexMetaData indexSafe = state.metaData().getIndexSafe(index);
        return mockIndexService(indexSafe, clusterService);
    });
    when(indicesService.indexService(any(Index.class))).then(invocation -> {
        Index index = (Index) invocation.getArguments()[0];
        final ClusterState state = clusterService.state();
        if (state.metaData().hasIndex(index.getName())) {
            final IndexMetaData indexSafe = state.metaData().getIndexSafe(index);
            return mockIndexService(clusterService.state().metaData().getIndexSafe(index), clusterService);
        } else {
            return null;
        }
    });
    return indicesService;
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndicesService(org.elasticsearch.indices.IndicesService) Index(org.elasticsearch.index.Index) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 42 with IndicesService

use of org.elasticsearch.indices.IndicesService in project elasticsearch by elastic.

the class ESTestCase method assertAllIndicesRemovedAndDeletionCompleted.

public void assertAllIndicesRemovedAndDeletionCompleted(Iterable<IndicesService> indicesServices) throws Exception {
    for (IndicesService indicesService : indicesServices) {
        assertBusy(() -> assertFalse(indicesService.iterator().hasNext()), 1, TimeUnit.MINUTES);
        assertBusy(() -> assertFalse(indicesService.hasUncompletedPendingDeletes()), 1, TimeUnit.MINUTES);
    }
}
Also used : IndicesService(org.elasticsearch.indices.IndicesService)

Example 43 with IndicesService

use of org.elasticsearch.indices.IndicesService in project elasticsearch by elastic.

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.randomAsciiOfLength(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;
}
Also used : ClusterService(org.elasticsearch.cluster.service.ClusterService) IndexService(org.elasticsearch.index.IndexService) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Node(org.elasticsearch.node.Node) MockNode(org.elasticsearch.node.MockNode) OperationRouting(org.elasticsearch.cluster.routing.OperationRouting) IndicesService(org.elasticsearch.indices.IndicesService)

Example 44 with IndicesService

use of org.elasticsearch.indices.IndicesService in project elasticsearch by elastic.

the class InternalTestCluster method assertShardIndexCounter.

private void assertShardIndexCounter() throws Exception {
    assertBusy(() -> {
        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) {
                    int activeOperationsCount = indexShard.getActiveOperationsCount();
                    if (activeOperationsCount > 0) {
                        TaskManager taskManager = getInstance(TransportService.class, nodeAndClient.name).getTaskManager();
                        DiscoveryNode localNode = getInstance(ClusterService.class, nodeAndClient.name).localNode();
                        List<TaskInfo> taskInfos = taskManager.getTasks().values().stream().filter(task -> task instanceof ReplicationTask).map(task -> task.taskInfo(localNode.getId(), true)).collect(Collectors.toList());
                        ListTasksResponse response = new ListTasksResponse(taskInfos, Collections.emptyList(), Collections.emptyList());
                        try {
                            XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint().value(response);
                            throw new AssertionError("expected index shard counter on shard " + indexShard.shardId() + " on node " + nodeAndClient.name + " to be 0 but was " + activeOperationsCount + ". Current replication tasks on node:\n" + builder.string());
                        } catch (IOException e) {
                            throw new RuntimeException("caught exception while building response [" + response + "]", e);
                        }
                    }
                }
            }
        }
    });
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ByteSizeUnit(org.elasticsearch.common.unit.ByteSizeUnit) Arrays(java.util.Arrays) Nullable(org.elasticsearch.common.Nullable) Releasables(org.elasticsearch.common.lease.Releasables) NetworkModule(org.elasticsearch.common.network.NetworkModule) ZenDiscovery(org.elasticsearch.discovery.zen.ZenDiscovery) ThreadContext(org.elasticsearch.common.util.concurrent.ThreadContext) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) NodeValidationException(org.elasticsearch.node.NodeValidationException) SearchService(org.elasticsearch.search.SearchService) RecoverySettings(org.elasticsearch.indices.recovery.RecoverySettings) ClusterState(org.elasticsearch.cluster.ClusterState) Future(java.util.concurrent.Future) RandomNumbers(com.carrotsearch.randomizedtesting.generators.RandomNumbers) Map(java.util.Map) Role(org.elasticsearch.cluster.node.DiscoveryNode.Role) Path(java.nio.file.Path) RandomStrings(com.carrotsearch.randomizedtesting.generators.RandomStrings) ServiceDisruptionScheme(org.elasticsearch.test.disruption.ServiceDisruptionScheme) Transport(org.elasticsearch.transport.Transport) MappingUpdatedAction(org.elasticsearch.cluster.action.index.MappingUpdatedAction) Set(java.util.Set) PageCacheRecycler(org.elasticsearch.common.util.PageCacheRecycler) ESTestCase.assertBusy(org.elasticsearch.test.ESTestCase.assertBusy) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) TransportSettings(org.elasticsearch.transport.TransportSettings) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) XContentFactory(org.elasticsearch.common.xcontent.XContentFactory) ThrottlingAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider) RandomPicks(com.carrotsearch.randomizedtesting.generators.RandomPicks) DiskThresholdSettings(org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings) TransportClient(org.elasticsearch.client.transport.TransportClient) ClusterService(org.elasticsearch.cluster.service.ClusterService) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) ArrayList(java.util.ArrayList) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TcpTransport(org.elasticsearch.transport.TcpTransport) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) IndicesService(org.elasticsearch.indices.IndicesService) TransportService(org.elasticsearch.transport.TransportService) Loggers(org.elasticsearch.common.logging.Loggers) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) FileSystemUtils(org.elasticsearch.common.io.FileSystemUtils) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) OperationRouting(org.elasticsearch.cluster.routing.OperationRouting) Client(org.elasticsearch.client.Client) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IOUtils(org.apache.lucene.util.IOUtils) IOException(java.io.IOException) NodeService(org.elasticsearch.node.NodeService) SeedUtils(com.carrotsearch.randomizedtesting.SeedUtils) ExecutionException(java.util.concurrent.ExecutionException) LuceneTestCase.rarely(org.apache.lucene.util.LuceneTestCase.rarely) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) TreeMap(java.util.TreeMap) CommonStatsFlags(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags) Assert(org.junit.Assert) ScriptService(org.elasticsearch.script.ScriptService) Builder(org.elasticsearch.common.settings.Settings.Builder) ElasticsearchAssertions.assertAcked(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked) ElasticsearchException(org.elasticsearch.ElasticsearchException) Environment(org.elasticsearch.env.Environment) Random(java.util.Random) TEST_NIGHTLY(org.apache.lucene.util.LuceneTestCase.TEST_NIGHTLY) Assert.assertThat(org.junit.Assert.assertThat) Settings(org.elasticsearch.common.settings.Settings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SysGlobals(com.carrotsearch.randomizedtesting.SysGlobals) Assert.fail(org.junit.Assert.fail) ClusterName(org.elasticsearch.cluster.ClusterName) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException) Flag(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags.Flag) NavigableMap(java.util.NavigableMap) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) Engine(org.elasticsearch.index.engine.Engine) ESTestCase.randomFrom(org.elasticsearch.test.ESTestCase.randomFrom) MockTransportClient(org.elasticsearch.transport.MockTransportClient) List(java.util.List) TransportAddress(org.elasticsearch.common.transport.TransportAddress) Matchers.equalTo(org.hamcrest.Matchers.equalTo) DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING(org.elasticsearch.discovery.zen.ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING) ElectMasterService(org.elasticsearch.discovery.zen.ElectMasterService) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) CommitStats(org.elasticsearch.index.engine.CommitStats) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Index(org.elasticsearch.index.Index) Function(java.util.function.Function) Strings(org.elasticsearch.common.Strings) ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse) HashSet(java.util.HashSet) TimeValue(org.elasticsearch.common.unit.TimeValue) Node(org.elasticsearch.node.Node) MockTransportService(org.elasticsearch.test.transport.MockTransportService) ExecutorService(java.util.concurrent.ExecutorService) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) TaskInfo(org.elasticsearch.tasks.TaskInfo) MockNode(org.elasticsearch.node.MockNode) EsExecutors(org.elasticsearch.common.util.concurrent.EsExecutors) Iterator(java.util.Iterator) Plugin(org.elasticsearch.plugins.Plugin) ESTestCase.awaitBusy(org.elasticsearch.test.ESTestCase.awaitBusy) TimeUnit(java.util.concurrent.TimeUnit) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) Closeable(java.io.Closeable) TaskManager(org.elasticsearch.tasks.TaskManager) Collections(java.util.Collections) ReplicationTask(org.elasticsearch.action.support.replication.ReplicationTask) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IndicesService(org.elasticsearch.indices.IndicesService) IOException(java.io.IOException) ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse) TaskInfo(org.elasticsearch.tasks.TaskInfo) TaskManager(org.elasticsearch.tasks.TaskManager) ClusterService(org.elasticsearch.cluster.service.ClusterService) ReplicationTask(org.elasticsearch.action.support.replication.ReplicationTask) TransportService(org.elasticsearch.transport.TransportService) MockTransportService(org.elasticsearch.test.transport.MockTransportService) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 45 with IndicesService

use of org.elasticsearch.indices.IndicesService in project elasticsearch by elastic.

the class ESSingleNodeTestCase method createIndex.

protected IndexService createIndex(String index, CreateIndexRequestBuilder createIndexRequestBuilder) {
    assertAcked(createIndexRequestBuilder.get());
    // Wait for the index to be allocated so that cluster state updates don't override
    // changes that would have been done locally
    ClusterHealthResponse health = client().admin().cluster().health(Requests.clusterHealthRequest(index).waitForYellowStatus().waitForEvents(Priority.LANGUID).waitForNoRelocatingShards(true)).actionGet();
    assertThat(health.getStatus(), lessThanOrEqualTo(ClusterHealthStatus.YELLOW));
    assertThat("Cluster must be a single node cluster", health.getNumberOfDataNodes(), equalTo(1));
    IndicesService instanceFromNode = getInstanceFromNode(IndicesService.class);
    return instanceFromNode.indexServiceSafe(resolveIndex(index));
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) IndicesService(org.elasticsearch.indices.IndicesService)

Aggregations

IndicesService (org.elasticsearch.indices.IndicesService)57 IndexService (org.elasticsearch.index.IndexService)41 IndexShard (org.elasticsearch.index.shard.IndexShard)29 Index (org.elasticsearch.index.Index)21 ClusterState (org.elasticsearch.cluster.ClusterState)12 Settings (org.elasticsearch.common.settings.Settings)12 ClusterService (org.elasticsearch.cluster.service.ClusterService)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)9 ShardId (org.elasticsearch.index.shard.ShardId)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)7 Test (org.junit.Test)7 List (java.util.List)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)6 HashMap (java.util.HashMap)5 Set (java.util.Set)5 ActionListener (org.elasticsearch.action.ActionListener)5