Search in sources :

Example 6 with ShardStats

use of org.opensearch.action.admin.indices.stats.ShardStats in project OpenSearch by opensearch-project.

the class ShardIndexingPressureSettingsIT method getPrimaryReplicaNodeNames.

private Tuple<String, String> getPrimaryReplicaNodeNames(String indexName) {
    IndicesStatsResponse response = client().admin().indices().prepareStats(indexName).get();
    String primaryId = Stream.of(response.getShards()).map(ShardStats::getShardRouting).filter(ShardRouting::primary).findAny().get().currentNodeId();
    String replicaId = Stream.of(response.getShards()).map(ShardStats::getShardRouting).filter(sr -> sr.primary() == false).findAny().get().currentNodeId();
    DiscoveryNodes nodes = client().admin().cluster().prepareState().get().getState().nodes();
    String primaryName = nodes.get(primaryId).getName();
    String replicaName = nodes.get(replicaId).getName();
    return new Tuple<>(primaryName, replicaName);
}
Also used : ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) Arrays(java.util.Arrays) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ThreadPool(org.opensearch.threadpool.ThreadPool) BulkRequest(org.opensearch.action.bulk.BulkRequest) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) Releasable(org.opensearch.common.lease.Releasable) MockTransportService(org.opensearch.test.transport.MockTransportService) InternalTestCluster(org.opensearch.test.InternalTestCluster) TransportShardBulkAction(org.opensearch.action.bulk.TransportShardBulkAction) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) InternalSettingsPlugin(org.opensearch.test.InternalSettingsPlugin) UUIDs(org.opensearch.common.UUIDs) BulkItemRequest(org.opensearch.action.bulk.BulkItemRequest) OpenSearchAssertions.assertAcked(org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked) BulkShardRequest(org.opensearch.action.bulk.BulkShardRequest) Collection(java.util.Collection) IndicesService(org.opensearch.indices.IndicesService) Settings(org.opensearch.common.settings.Settings) TransportService(org.opensearch.transport.TransportService) Plugin(org.opensearch.plugins.Plugin) ActionFuture(org.opensearch.action.ActionFuture) Tuple(org.opensearch.common.collect.Tuple) ShardRouting(org.opensearch.cluster.routing.ShardRouting) ShardId(org.opensearch.index.shard.ShardId) RamUsageEstimator(org.apache.lucene.util.RamUsageEstimator) CountDownLatch(java.util.concurrent.CountDownLatch) Stream(java.util.stream.Stream) BulkResponse(org.opensearch.action.bulk.BulkResponse) IndicesStatsResponse(org.opensearch.action.admin.indices.stats.IndicesStatsResponse) ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) IndexRequest(org.opensearch.action.index.IndexRequest) OpenSearchIntegTestCase(org.opensearch.test.OpenSearchIntegTestCase) Collections(java.util.Collections) IndicesStatsResponse(org.opensearch.action.admin.indices.stats.IndicesStatsResponse) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) Tuple(org.opensearch.common.collect.Tuple)

Example 7 with ShardStats

use of org.opensearch.action.admin.indices.stats.ShardStats in project OpenSearch by opensearch-project.

the class MasterDisruptionIT method testMappingTimeout.

public void testMappingTimeout() throws Exception {
    startCluster(3);
    createIndex("test", Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 1).put("index.routing.allocation.exclude._name", internalCluster().getMasterName()).build());
    // create one field
    index("test", "doc", "1", "{ \"f\": 1 }");
    ensureGreen();
    assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put("indices.mapping.dynamic_timeout", "1ms")));
    ServiceDisruptionScheme disruption = new BlockMasterServiceOnMaster(random());
    setDisruptionScheme(disruption);
    disruption.startDisrupting();
    BulkRequestBuilder bulk = client().prepareBulk();
    bulk.add(client().prepareIndex("test").setId("2").setSource("{ \"f\": 1 }", XContentType.JSON));
    bulk.add(client().prepareIndex("test").setId("3").setSource("{ \"g\": 1 }", XContentType.JSON));
    bulk.add(client().prepareIndex("test").setId("4").setSource("{ \"f\": 1 }", XContentType.JSON));
    BulkResponse bulkResponse = bulk.get();
    assertTrue(bulkResponse.hasFailures());
    disruption.stopDisrupting();
    assertBusy(() -> {
        IndicesStatsResponse stats = client().admin().indices().prepareStats("test").clear().get();
        for (ShardStats shardStats : stats.getShards()) {
            assertThat(shardStats.getShardRouting().toString(), shardStats.getSeqNoStats().getGlobalCheckpoint(), equalTo(shardStats.getSeqNoStats().getLocalCheckpoint()));
        }
    });
}
Also used : ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) IndicesStatsResponse(org.opensearch.action.admin.indices.stats.IndicesStatsResponse) ServiceDisruptionScheme(org.opensearch.test.disruption.ServiceDisruptionScheme) BulkResponse(org.opensearch.action.bulk.BulkResponse) BulkRequestBuilder(org.opensearch.action.bulk.BulkRequestBuilder) BlockMasterServiceOnMaster(org.opensearch.test.disruption.BlockMasterServiceOnMaster)

Example 8 with ShardStats

use of org.opensearch.action.admin.indices.stats.ShardStats in project OpenSearch by opensearch-project.

the class ReplicaShardAllocatorIT method testRecentPrimaryInformation.

/**
 * Ensure that we fetch the latest shard store from the primary when a new node joins so we won't cancel the current recovery
 * for the copy on the newly joined node unless we can perform a noop recovery with that node.
 */
public void testRecentPrimaryInformation() throws Exception {
    String indexName = "test";
    String nodeWithPrimary = internalCluster().startNode();
    assertAcked(client().admin().indices().prepareCreate(indexName).setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1).put(IndexSettings.FILE_BASED_RECOVERY_THRESHOLD_SETTING.getKey(), 0.1f).put(IndexService.GLOBAL_CHECKPOINT_SYNC_INTERVAL_SETTING.getKey(), "100ms").put(IndexService.RETENTION_LEASE_SYNC_INTERVAL_SETTING.getKey(), "100ms").put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "1ms")));
    String nodeWithReplica = internalCluster().startDataOnlyNode();
    DiscoveryNode discoNodeWithReplica = internalCluster().getInstance(ClusterService.class, nodeWithReplica).localNode();
    Settings nodeWithReplicaSettings = internalCluster().dataPathSettings(nodeWithReplica);
    ensureGreen(indexName);
    indexRandom(randomBoolean(), false, randomBoolean(), IntStream.range(0, between(10, 100)).mapToObj(n -> client().prepareIndex(indexName).setSource("f", "v")).collect(Collectors.toList()));
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodeWithReplica));
    if (randomBoolean()) {
        indexRandom(randomBoolean(), false, randomBoolean(), IntStream.range(0, between(10, 100)).mapToObj(n -> client().prepareIndex(indexName).setSource("f", "v")).collect(Collectors.toList()));
    }
    CountDownLatch blockRecovery = new CountDownLatch(1);
    CountDownLatch recoveryStarted = new CountDownLatch(1);
    MockTransportService transportServiceOnPrimary = (MockTransportService) internalCluster().getInstance(TransportService.class, nodeWithPrimary);
    transportServiceOnPrimary.addSendBehavior((connection, requestId, action, request, options) -> {
        if (PeerRecoveryTargetService.Actions.FILES_INFO.equals(action)) {
            recoveryStarted.countDown();
            try {
                blockRecovery.await();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
        connection.sendRequest(requestId, action, request, options);
    });
    String newNode = internalCluster().startDataOnlyNode();
    recoveryStarted.await();
    // Index more documents and flush to destroy sync_id and remove the retention lease (as file_based_recovery_threshold reached).
    indexRandom(randomBoolean(), randomBoolean(), randomBoolean(), IntStream.range(0, between(50, 200)).mapToObj(n -> client().prepareIndex(indexName).setSource("f", "v")).collect(Collectors.toList()));
    client().admin().indices().prepareFlush(indexName).get();
    assertBusy(() -> {
        for (ShardStats shardStats : client().admin().indices().prepareStats(indexName).get().getShards()) {
            for (RetentionLease lease : shardStats.getRetentionLeaseStats().retentionLeases().leases()) {
                assertThat(lease.id(), not(equalTo(ReplicationTracker.getPeerRecoveryRetentionLeaseId(discoNodeWithReplica.getId()))));
            }
        }
    });
    // AllocationService only calls GatewayAllocator if there are unassigned shards
    assertAcked(client().admin().indices().prepareCreate("dummy-index").setWaitForActiveShards(0).setSettings(Settings.builder().put("index.routing.allocation.require.attr", "not-found")));
    internalCluster().startDataOnlyNode(nodeWithReplicaSettings);
    // need to wait for events to ensure the reroute has happened since we perform it async when a new node joins.
    client().admin().cluster().prepareHealth(indexName).setWaitForYellowStatus().setWaitForEvents(Priority.LANGUID).get();
    blockRecovery.countDown();
    ensureGreen(indexName);
    assertThat(internalCluster().nodesInclude(indexName), hasItem(newNode));
    for (RecoveryState recovery : client().admin().indices().prepareRecoveries(indexName).get().shardRecoveryStates().get(indexName)) {
        if (recovery.getPrimary() == false) {
            assertThat(recovery.getIndex().fileDetails(), not(empty()));
        }
    }
    transportServiceOnPrimary.clearAllRules();
}
Also used : ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ClusterService(org.opensearch.cluster.service.ClusterService) MockTransportService(org.opensearch.test.transport.MockTransportService) MockTransportService(org.opensearch.test.transport.MockTransportService) TransportService(org.opensearch.transport.TransportService) RetentionLease(org.opensearch.index.seqno.RetentionLease) CountDownLatch(java.util.concurrent.CountDownLatch) RecoveryState(org.opensearch.indices.recovery.RecoveryState) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 9 with ShardStats

use of org.opensearch.action.admin.indices.stats.ShardStats in project OpenSearch by opensearch-project.

the class TransportClusterStatsAction method nodeOperation.

@Override
protected ClusterStatsNodeResponse nodeOperation(ClusterStatsNodeRequest nodeRequest) {
    NodeInfo nodeInfo = nodeService.info(true, true, false, true, false, true, false, true, false, false, false);
    NodeStats nodeStats = nodeService.stats(CommonStatsFlags.NONE, true, true, true, false, true, false, false, false, false, false, true, false, false, false, false);
    List<ShardStats> shardsStats = new ArrayList<>();
    for (IndexService indexService : indicesService) {
        for (IndexShard indexShard : indexService) {
            if (indexShard.routingEntry() != null && indexShard.routingEntry().active()) {
                // only report on fully started shards
                CommitStats commitStats;
                SeqNoStats seqNoStats;
                RetentionLeaseStats retentionLeaseStats;
                try {
                    commitStats = indexShard.commitStats();
                    seqNoStats = indexShard.seqNoStats();
                    retentionLeaseStats = indexShard.getRetentionLeaseStats();
                } catch (final AlreadyClosedException e) {
                    // shard is closed - no stats is fine
                    commitStats = null;
                    seqNoStats = null;
                    retentionLeaseStats = null;
                }
                shardsStats.add(new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indicesService.getIndicesQueryCache(), indexShard, SHARD_STATS_FLAGS), commitStats, seqNoStats, retentionLeaseStats));
            }
        }
    }
    ClusterHealthStatus clusterStatus = null;
    if (clusterService.state().nodes().isLocalNodeElectedMaster()) {
        clusterStatus = new ClusterStateHealth(clusterService.state()).getStatus();
    }
    return new ClusterStatsNodeResponse(nodeInfo.getNode(), clusterStatus, nodeInfo, nodeStats, shardsStats.toArray(new ShardStats[shardsStats.size()]));
}
Also used : ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) ClusterStateHealth(org.opensearch.cluster.health.ClusterStateHealth) IndexService(org.opensearch.index.IndexService) IndexShard(org.opensearch.index.shard.IndexShard) RetentionLeaseStats(org.opensearch.index.seqno.RetentionLeaseStats) ArrayList(java.util.ArrayList) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) ClusterHealthStatus(org.opensearch.cluster.health.ClusterHealthStatus) NodeStats(org.opensearch.action.admin.cluster.node.stats.NodeStats) CommonStats(org.opensearch.action.admin.indices.stats.CommonStats) SeqNoStats(org.opensearch.index.seqno.SeqNoStats) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) CommitStats(org.opensearch.index.engine.CommitStats)

Example 10 with ShardStats

use of org.opensearch.action.admin.indices.stats.ShardStats in project OpenSearch by opensearch-project.

the class InternalClusterInfoService method buildShardLevelInfo.

static void buildShardLevelInfo(Logger logger, ShardStats[] stats, ImmutableOpenMap.Builder<String, Long> shardSizes, ImmutableOpenMap.Builder<ShardRouting, String> newShardRoutingToDataPath, Map<ClusterInfo.NodeAndPath, ClusterInfo.ReservedSpace.Builder> reservedSpaceByShard) {
    for (ShardStats s : stats) {
        final ShardRouting shardRouting = s.getShardRouting();
        newShardRoutingToDataPath.put(shardRouting, s.getDataPath());
        final StoreStats storeStats = s.getStats().getStore();
        if (storeStats == null) {
            continue;
        }
        final long size = storeStats.sizeInBytes();
        final long reserved = storeStats.getReservedSize().getBytes();
        final String shardIdentifier = ClusterInfo.shardIdentifierFromRouting(shardRouting);
        logger.trace("shard: {} size: {} reserved: {}", shardIdentifier, size, reserved);
        shardSizes.put(shardIdentifier, size);
        if (reserved != StoreStats.UNKNOWN_RESERVED_BYTES) {
            final ClusterInfo.ReservedSpace.Builder reservedSpaceBuilder = reservedSpaceByShard.computeIfAbsent(new ClusterInfo.NodeAndPath(shardRouting.currentNodeId(), s.getDataPath()), t -> new ClusterInfo.ReservedSpace.Builder());
            reservedSpaceBuilder.add(shardRouting.shardId(), reserved);
        }
    }
}
Also used : ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) StoreStats(org.opensearch.index.store.StoreStats) ShardRouting(org.opensearch.cluster.routing.ShardRouting)

Aggregations

ShardStats (org.opensearch.action.admin.indices.stats.ShardStats)32 IndicesStatsResponse (org.opensearch.action.admin.indices.stats.IndicesStatsResponse)16 ShardRouting (org.opensearch.cluster.routing.ShardRouting)15 Settings (org.opensearch.common.settings.Settings)15 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)13 ShardId (org.opensearch.index.shard.ShardId)13 Arrays (java.util.Arrays)12 OpenSearchIntegTestCase (org.opensearch.test.OpenSearchIntegTestCase)12 OpenSearchAssertions.assertAcked (org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked)12 ArrayList (java.util.ArrayList)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 ClusterState (org.opensearch.cluster.ClusterState)11 Collection (java.util.Collection)10 List (java.util.List)10 Matchers.equalTo (org.hamcrest.Matchers.equalTo)10 TimeValue (org.opensearch.common.unit.TimeValue)10 IndexShard (org.opensearch.index.shard.IndexShard)10 IndicesService (org.opensearch.indices.IndicesService)10 Plugin (org.opensearch.plugins.Plugin)10 MockTransportService (org.opensearch.test.transport.MockTransportService)10