Search in sources :

Example 16 with ShardStats

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

the class IndexStatsIT method assertCumulativeQueryCacheStats.

private void assertCumulativeQueryCacheStats(IndicesStatsResponse response) {
    assertAllSuccessful(response);
    QueryCacheStats total = response.getTotal().queryCache;
    QueryCacheStats indexTotal = new QueryCacheStats();
    QueryCacheStats shardTotal = new QueryCacheStats();
    for (IndexStats indexStats : response.getIndices().values()) {
        indexTotal.add(indexStats.getTotal().queryCache);
        for (ShardStats shardStats : response.getShards()) {
            shardTotal.add(shardStats.getStats().queryCache);
        }
    }
    assertEquals(total, indexTotal);
    assertEquals(total, shardTotal);
}
Also used : ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) QueryCacheStats(org.elasticsearch.index.cache.query.QueryCacheStats) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats)

Example 17 with ShardStats

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

the class FlushIT method testSyncedFlushWithConcurrentIndexing.

public void testSyncedFlushWithConcurrentIndexing() throws Exception {
    internalCluster().ensureAtLeastNumDataNodes(3);
    createIndex("test");
    client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(), new ByteSizeValue(1, ByteSizeUnit.PB)).put("index.refresh_interval", -1).put("index.number_of_replicas", internalCluster().numDataNodes() - 1)).get();
    ensureGreen();
    final AtomicBoolean stop = new AtomicBoolean(false);
    final AtomicInteger numDocs = new AtomicInteger(0);
    Thread indexingThread = new Thread() {

        @Override
        public void run() {
            while (stop.get() == false) {
                client().prepareIndex().setIndex("test").setType("doc").setSource("{}", XContentType.JSON).get();
                numDocs.incrementAndGet();
            }
        }
    };
    indexingThread.start();
    IndexStats indexStats = client().admin().indices().prepareStats("test").get().getIndex("test");
    for (ShardStats shardStats : indexStats.getShards()) {
        assertNull(shardStats.getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID));
    }
    logger.info("--> trying sync flush");
    SyncedFlushResponse syncedFlushResult = client().admin().indices().prepareSyncedFlush("test").get();
    logger.info("--> sync flush done");
    stop.set(true);
    indexingThread.join();
    indexStats = client().admin().indices().prepareStats("test").get().getIndex("test");
    assertFlushResponseEqualsShardStats(indexStats.getShards(), syncedFlushResult.getShardsResultPerIndex().get("test"));
    refresh();
    assertThat(client().prepareSearch().setSize(0).get().getHits().getTotalHits(), equalTo((long) numDocs.get()));
    logger.info("indexed {} docs", client().prepareSearch().setSize(0).get().getHits().getTotalHits());
    logClusterState();
    internalCluster().fullRestart();
    ensureGreen();
    assertThat(client().prepareSearch().setSize(0).get().getHits().getTotalHits(), equalTo((long) numDocs.get()));
}
Also used : ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) SyncedFlushResponse(org.elasticsearch.action.admin.indices.flush.SyncedFlushResponse) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats)

Example 18 with ShardStats

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

the class InternalClusterInfoService method buildShardLevelInfo.

static void buildShardLevelInfo(Logger logger, ShardStats[] stats, ImmutableOpenMap.Builder<String, Long> newShardSizes, ImmutableOpenMap.Builder<ShardRouting, String> newShardRoutingToDataPath, ClusterState state) {
    MetaData meta = state.getMetaData();
    for (ShardStats s : stats) {
        IndexMetaData indexMeta = meta.index(s.getShardRouting().index());
        newShardRoutingToDataPath.put(s.getShardRouting(), s.getDataPath());
        long size = s.getStats().getStore().sizeInBytes();
        String sid = ClusterInfo.shardIdentifierFromRouting(s.getShardRouting());
        if (logger.isTraceEnabled()) {
            logger.trace("shard: {} size: {}", sid, size);
        }
        if (indexMeta != null && indexMeta.isIndexUsingShadowReplicas()) {
            // Shards on a shared filesystem should be considered of size 0
            if (logger.isTraceEnabled()) {
                logger.trace("shard: {} is using shadow replicas and will be treated as size 0", sid);
            }
            size = 0;
        }
        newShardSizes.put(sid, size);
    }
}
Also used : ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 19 with ShardStats

use of org.elasticsearch.action.admin.indices.stats.ShardStats in project graylog2-server by Graylog2.

the class Indices method getIndexStats.

@Nullable
public IndexStatistics getIndexStats(String index) {
    final IndexStats indexStats;
    try {
        indexStats = indexStats(index);
    } catch (ElasticsearchException e) {
        return null;
    }
    if (indexStats == null) {
        return null;
    }
    final ImmutableList.Builder<ShardRouting> shardRouting = ImmutableList.builder();
    for (ShardStats shardStats : indexStats.getShards()) {
        shardRouting.add(shardStats.getShardRouting());
    }
    return IndexStatistics.create(indexStats.getIndex(), indexStats.getPrimaries(), indexStats.getTotal(), shardRouting.build());
}
Also used : ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) ImmutableList(com.google.common.collect.ImmutableList) ElasticsearchException(org.elasticsearch.ElasticsearchException) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Nullable(javax.annotation.Nullable)

Aggregations

ShardStats (org.elasticsearch.action.admin.indices.stats.ShardStats)19 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)9 CommonStats (org.elasticsearch.action.admin.indices.stats.CommonStats)7 IndexStats (org.elasticsearch.action.admin.indices.stats.IndexStats)7 ShardId (org.elasticsearch.index.shard.ShardId)6 Index (org.elasticsearch.index.Index)5 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 IndexShardStats (org.elasticsearch.action.admin.indices.stats.IndexShardStats)3 IndicesStatsResponse (org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse)3 SearchResponse (org.elasticsearch.action.search.SearchResponse)3 ClusterState (org.elasticsearch.cluster.ClusterState)3 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)3 ImmutableList (com.google.common.collect.ImmutableList)2 IOException (java.io.IOException)2 List (java.util.List)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)2 UnassignedInfo (org.elasticsearch.cluster.routing.UnassignedInfo)2 ClusterService (org.elasticsearch.cluster.service.ClusterService)2