Search in sources :

Example 1 with ReplicationTask

use of org.elasticsearch.action.support.replication.ReplicationTask 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)

Aggregations

RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)1 SeedUtils (com.carrotsearch.randomizedtesting.SeedUtils)1 SysGlobals (com.carrotsearch.randomizedtesting.SysGlobals)1 RandomNumbers (com.carrotsearch.randomizedtesting.generators.RandomNumbers)1 RandomPicks (com.carrotsearch.randomizedtesting.generators.RandomPicks)1 RandomStrings (com.carrotsearch.randomizedtesting.generators.RandomStrings)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1