Search in sources :

Example 1 with ShardStats

use of org.elasticsearch.action.admin.indices.stats.ShardStats in project elasticsearch by elastic.

the class FlushIT method testSyncedFlush.

public void testSyncedFlush() throws ExecutionException, InterruptedException, IOException {
    internalCluster().ensureAtLeastNumDataNodes(2);
    prepareCreate("test").setSettings(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).get();
    ensureGreen();
    final Index index = client().admin().cluster().prepareState().get().getState().metaData().index("test").getIndex();
    IndexStats indexStats = client().admin().indices().prepareStats("test").get().getIndex("test");
    for (ShardStats shardStats : indexStats.getShards()) {
        assertNull(shardStats.getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID));
    }
    ShardsSyncedFlushResult result;
    if (randomBoolean()) {
        logger.info("--> sync flushing shard 0");
        result = SyncedFlushUtil.attemptSyncedFlush(internalCluster(), new ShardId(index, 0));
    } else {
        logger.info("--> sync flushing index [test]");
        SyncedFlushResponse indicesResult = client().admin().indices().prepareSyncedFlush("test").get();
        result = indicesResult.getShardsResultPerIndex().get("test").get(0);
    }
    assertFalse(result.failed());
    assertThat(result.totalShards(), equalTo(indexStats.getShards().length));
    assertThat(result.successfulShards(), equalTo(indexStats.getShards().length));
    indexStats = client().admin().indices().prepareStats("test").get().getIndex("test");
    String syncId = result.syncId();
    for (ShardStats shardStats : indexStats.getShards()) {
        final String shardSyncId = shardStats.getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID);
        assertThat(shardSyncId, equalTo(syncId));
    }
    // now, start new node and relocate a shard there and see if sync id still there
    String newNodeName = internalCluster().startNode();
    ClusterState clusterState = client().admin().cluster().prepareState().get().getState();
    ShardRouting shardRouting = clusterState.getRoutingTable().index("test").shard(0).iterator().next();
    String currentNodeName = clusterState.nodes().resolveNode(shardRouting.currentNodeId()).getName();
    assertFalse(currentNodeName.equals(newNodeName));
    internalCluster().client().admin().cluster().prepareReroute().add(new MoveAllocationCommand("test", 0, currentNodeName, newNodeName)).get();
    client().admin().cluster().prepareHealth().setWaitForNoRelocatingShards(true).get();
    indexStats = client().admin().indices().prepareStats("test").get().getIndex("test");
    for (ShardStats shardStats : indexStats.getShards()) {
        assertNotNull(shardStats.getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID));
    }
    client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).build()).get();
    ensureGreen("test");
    indexStats = client().admin().indices().prepareStats("test").get().getIndex("test");
    for (ShardStats shardStats : indexStats.getShards()) {
        assertNotNull(shardStats.getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID));
    }
    client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, internalCluster().numDataNodes() - 1).build()).get();
    ensureGreen("test");
    indexStats = client().admin().indices().prepareStats("test").get().getIndex("test");
    for (ShardStats shardStats : indexStats.getShards()) {
        assertNotNull(shardStats.getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID));
    }
}
Also used : ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) ShardId(org.elasticsearch.index.shard.ShardId) ClusterState(org.elasticsearch.cluster.ClusterState) SyncedFlushResponse(org.elasticsearch.action.admin.indices.flush.SyncedFlushResponse) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) Index(org.elasticsearch.index.Index) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 2 with ShardStats

use of org.elasticsearch.action.admin.indices.stats.ShardStats in project elasticsearch by elastic.

the class FlushIT method assertFlushResponseEqualsShardStats.

private void assertFlushResponseEqualsShardStats(ShardStats[] shardsStats, List<ShardsSyncedFlushResult> syncedFlushResults) {
    for (final ShardStats shardStats : shardsStats) {
        for (final ShardsSyncedFlushResult shardResult : syncedFlushResults) {
            if (shardStats.getShardRouting().getId() == shardResult.shardId().getId()) {
                for (Map.Entry<ShardRouting, SyncedFlushService.ShardSyncedFlushResponse> singleResponse : shardResult.shardResponses().entrySet()) {
                    if (singleResponse.getKey().currentNodeId().equals(shardStats.getShardRouting().currentNodeId())) {
                        if (singleResponse.getValue().success()) {
                            logger.info("{} sync flushed on node {}", singleResponse.getKey().shardId(), singleResponse.getKey().currentNodeId());
                            assertNotNull(shardStats.getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID));
                        } else {
                            logger.info("{} sync flush failed for on node {}", singleResponse.getKey().shardId(), singleResponse.getKey().currentNodeId());
                            assertNull(shardStats.getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID));
                        }
                    }
                }
            }
        }
    }
}
Also used : ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Map(java.util.Map)

Example 3 with ShardStats

use of org.elasticsearch.action.admin.indices.stats.ShardStats in project elasticsearch by elastic.

the class RestIndicesActionTests method randomIndicesStatsResponse.

private IndicesStatsResponse randomIndicesStatsResponse(final Index[] indices) {
    List<ShardStats> shardStats = new ArrayList<>();
    for (final Index index : indices) {
        for (int i = 0; i < 2; i++) {
            ShardId shardId = new ShardId(index, i);
            Path path = createTempDir().resolve("indices").resolve(index.getUUID()).resolve(String.valueOf(i));
            ShardRouting shardRouting = ShardRouting.newUnassigned(shardId, i == 0, i == 0 ? StoreRecoverySource.EMPTY_STORE_INSTANCE : PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null));
            shardRouting = shardRouting.initialize("node-0", null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE);
            shardRouting = shardRouting.moveToStarted();
            CommonStats stats = new CommonStats();
            stats.fieldData = new FieldDataStats();
            stats.queryCache = new QueryCacheStats();
            stats.docs = new DocsStats();
            stats.store = new StoreStats();
            stats.indexing = new IndexingStats();
            stats.search = new SearchStats();
            stats.segments = new SegmentsStats();
            stats.merge = new MergeStats();
            stats.refresh = new RefreshStats();
            stats.completion = new CompletionStats();
            stats.requestCache = new RequestCacheStats();
            stats.get = new GetStats();
            stats.flush = new FlushStats();
            stats.warmer = new WarmerStats();
            shardStats.add(new ShardStats(shardRouting, new ShardPath(false, path, path, shardId), stats, null, null));
        }
    }
    return IndicesStatsTests.newIndicesStatsResponse(shardStats.toArray(new ShardStats[shardStats.size()]), shardStats.size(), shardStats.size(), 0, emptyList());
}
Also used : StoreStats(org.elasticsearch.index.store.StoreStats) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) RefreshStats(org.elasticsearch.index.refresh.RefreshStats) ArrayList(java.util.ArrayList) Index(org.elasticsearch.index.Index) GetStats(org.elasticsearch.index.get.GetStats) SegmentsStats(org.elasticsearch.index.engine.SegmentsStats) ShardId(org.elasticsearch.index.shard.ShardId) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) FlushStats(org.elasticsearch.index.flush.FlushStats) ShardPath(org.elasticsearch.index.shard.ShardPath) QueryCacheStats(org.elasticsearch.index.cache.query.QueryCacheStats) DocsStats(org.elasticsearch.index.shard.DocsStats) FieldDataStats(org.elasticsearch.index.fielddata.FieldDataStats) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) Path(java.nio.file.Path) ShardPath(org.elasticsearch.index.shard.ShardPath) IndexingStats(org.elasticsearch.index.shard.IndexingStats) WarmerStats(org.elasticsearch.index.warmer.WarmerStats) SearchStats(org.elasticsearch.index.search.stats.SearchStats) MergeStats(org.elasticsearch.index.merge.MergeStats) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) RequestCacheStats(org.elasticsearch.index.cache.request.RequestCacheStats) CompletionStats(org.elasticsearch.search.suggest.completion.CompletionStats)

Example 4 with ShardStats

use of org.elasticsearch.action.admin.indices.stats.ShardStats in project elasticsearch by elastic.

the class ClusterStatsNodeResponse method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    if (clusterStatus == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        out.writeByte(clusterStatus.value());
    }
    nodeInfo.writeTo(out);
    nodeStats.writeTo(out);
    out.writeVInt(shardsStats.length);
    for (ShardStats ss : shardsStats) {
        ss.writeTo(out);
    }
}
Also used : ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats)

Example 5 with ShardStats

use of org.elasticsearch.action.admin.indices.stats.ShardStats in project elasticsearch by elastic.

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);
    NodeStats nodeStats = nodeService.stats(CommonStatsFlags.NONE, true, true, true, false, true, false, false, 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
                shardsStats.add(new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indicesService.getIndicesQueryCache(), indexShard, SHARD_STATS_FLAGS), indexShard.commitStats(), indexShard.seqNoStats()));
            }
        }
    }
    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.elasticsearch.action.admin.indices.stats.ShardStats) ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) ClusterStateHealth(org.elasticsearch.cluster.health.ClusterStateHealth) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) IndexService(org.elasticsearch.index.IndexService) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) IndexShard(org.elasticsearch.index.shard.IndexShard) ArrayList(java.util.ArrayList)

Aggregations

ShardStats (org.elasticsearch.action.admin.indices.stats.ShardStats)23 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)11 ShardId (org.elasticsearch.index.shard.ShardId)8 IndexStats (org.elasticsearch.action.admin.indices.stats.IndexStats)7 Index (org.elasticsearch.index.Index)7 ArrayList (java.util.ArrayList)6 CommonStats (org.elasticsearch.action.admin.indices.stats.CommonStats)5 ClusterState (org.elasticsearch.cluster.ClusterState)5 IOException (java.io.IOException)4 List (java.util.List)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 IndicesStatsResponse (org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse)4 MoveAllocationCommand (org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand)4 ClusterService (org.elasticsearch.cluster.service.ClusterService)4 IndexShard (org.elasticsearch.index.shard.IndexShard)4 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Semaphore (java.util.concurrent.Semaphore)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3