Search in sources :

Example 6 with IndexStats

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

the class RelocationIT method beforeIndexDeletion.

@Override
protected void beforeIndexDeletion() throws Exception {
    super.beforeIndexDeletion();
    assertBusy(() -> {
        IndicesStatsResponse stats = client().admin().indices().prepareStats().clear().get();
        for (IndexStats indexStats : stats.getIndices().values()) {
            for (IndexShardStats indexShardStats : indexStats.getIndexShards().values()) {
                Optional<ShardStats> maybePrimary = Stream.of(indexShardStats.getShards()).filter(s -> s.getShardRouting().active() && s.getShardRouting().primary()).findFirst();
                if (maybePrimary.isPresent() == false) {
                    continue;
                }
                ShardStats primary = maybePrimary.get();
                final SeqNoStats primarySeqNoStats = primary.getSeqNoStats();
                assertThat(primary.getShardRouting() + " should have set the global checkpoint", primarySeqNoStats.getGlobalCheckpoint(), not(equalTo(SequenceNumbersService.UNASSIGNED_SEQ_NO)));
                for (ShardStats shardStats : indexShardStats) {
                    final SeqNoStats seqNoStats = shardStats.getSeqNoStats();
                    assertThat(shardStats.getShardRouting() + " local checkpoint mismatch", seqNoStats.getLocalCheckpoint(), equalTo(primarySeqNoStats.getLocalCheckpoint()));
                    assertThat(shardStats.getShardRouting() + " global checkpoint mismatch", seqNoStats.getGlobalCheckpoint(), equalTo(primarySeqNoStats.getGlobalCheckpoint()));
                    assertThat(shardStats.getShardRouting() + " max seq no mismatch", seqNoStats.getMaxSeqNo(), equalTo(primarySeqNoStats.getMaxSeqNo()));
                }
            }
        }
    });
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Arrays(java.util.Arrays) TransportRequest(org.elasticsearch.transport.TransportRequest) Nullable(org.elasticsearch.common.Nullable) SearchHits(org.elasticsearch.search.SearchHits) Matchers.not(org.hamcrest.Matchers.not) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) SeqNoStats(org.elasticsearch.index.seqno.SeqNoStats) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) Scope(org.elasticsearch.test.ESIntegTestCase.Scope) SearchResponse(org.elasticsearch.action.search.SearchResponse) Path(java.nio.file.Path) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) SearchHit(org.elasticsearch.search.SearchHit) MockIndexEventListener(org.elasticsearch.test.MockIndexEventListener) Priority(org.elasticsearch.common.Priority) PeerRecoveryTargetService(org.elasticsearch.indices.recovery.PeerRecoveryTargetService) Transport(org.elasticsearch.transport.Transport) TestLogging(org.elasticsearch.test.junit.annotations.TestLogging) Collection(java.util.Collection) RecoveryFileChunkRequest(org.elasticsearch.indices.recovery.RecoveryFileChunkRequest) ElasticsearchAssertions.assertHitCount(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount) Matchers.startsWith(org.hamcrest.Matchers.startsWith) ElasticsearchAssertions.assertSearchHits(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits) FileVisitResult(java.nio.file.FileVisitResult) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Stream(java.util.stream.Stream) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) ESIntegTestCase(org.elasticsearch.test.ESIntegTestCase) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) INDEX_SEQ_NO_CHECKPOINT_SYNC_INTERVAL(org.elasticsearch.index.IndexSettings.INDEX_SEQ_NO_CHECKPOINT_SYNC_INTERVAL) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) IntProcedure(com.carrotsearch.hppc.procedures.IntProcedure) XContentType(org.elasticsearch.common.xcontent.XContentType) IndexShardStats(org.elasticsearch.action.admin.indices.stats.IndexShardStats) ClusterService(org.elasticsearch.cluster.service.ClusterService) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) ArrayList(java.util.ArrayList) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) SequenceNumbersService(org.elasticsearch.index.seqno.SequenceNumbersService) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) TimeValue(org.elasticsearch.common.unit.TimeValue) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) EnableAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider) ClusterScope(org.elasticsearch.test.ESIntegTestCase.ClusterScope) IndexShardState(org.elasticsearch.index.shard.IndexShardState) QueryBuilders.matchAllQuery(org.elasticsearch.index.query.QueryBuilders.matchAllQuery) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) Files(java.nio.file.Files) Semaphore(java.util.concurrent.Semaphore) Client(org.elasticsearch.client.Client) IndexShard(org.elasticsearch.index.shard.IndexShard) IntHashSet(com.carrotsearch.hppc.IntHashSet) IndexFileNames(org.apache.lucene.index.IndexFileNames) Plugin(org.elasticsearch.plugins.Plugin) BackgroundIndexer(org.elasticsearch.test.BackgroundIndexer) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) English(org.apache.lucene.util.English) ElasticsearchAssertions.assertAcked(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked) ElasticsearchAssertions.assertNoFailures(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures) IndexShardStats(org.elasticsearch.action.admin.indices.stats.IndexShardStats) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) SeqNoStats(org.elasticsearch.index.seqno.SeqNoStats) IndexShardStats(org.elasticsearch.action.admin.indices.stats.IndexShardStats) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats)

Example 7 with IndexStats

use of org.elasticsearch.action.admin.indices.stats.IndexStats 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 8 with IndexStats

use of org.elasticsearch.action.admin.indices.stats.IndexStats 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 9 with IndexStats

use of org.elasticsearch.action.admin.indices.stats.IndexStats 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)

Example 10 with IndexStats

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

the class Indices method numberOfMessages.

public long numberOfMessages(String indexName) throws IndexNotFoundException {
    final IndexStats index = indexStats(indexName);
    if (index == null) {
        throw new IndexNotFoundException("Couldn't find index " + indexName);
    }
    final DocsStats docsStats = index.getPrimaries().getDocs();
    return docsStats == null ? 0L : docsStats.getCount();
}
Also used : IndexNotFoundException(org.graylog2.indexer.IndexNotFoundException) DocsStats(org.elasticsearch.index.shard.DocsStats) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats)

Aggregations

IndexStats (org.elasticsearch.action.admin.indices.stats.IndexStats)11 ShardStats (org.elasticsearch.action.admin.indices.stats.ShardStats)7 IndicesStatsResponse (org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse)3 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)3 ImmutableList (com.google.common.collect.ImmutableList)2 IOException (java.io.IOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 SyncedFlushResponse (org.elasticsearch.action.admin.indices.flush.SyncedFlushResponse)2 IndexShardStats (org.elasticsearch.action.admin.indices.stats.IndexShardStats)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 Client (org.elasticsearch.client.Client)2 ClusterState (org.elasticsearch.cluster.ClusterState)2 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)2 Index (org.elasticsearch.index.Index)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntProcedure (com.carrotsearch.hppc.procedures.IntProcedure)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 FileVisitResult (java.nio.file.FileVisitResult)1 Files (java.nio.file.Files)1