Java Code Examples for org.elasticsearch.index.shard.IndexShard#commitStats()
The following examples show how to use
org.elasticsearch.index.shard.IndexShard#commitStats() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransportIndexShardStatsAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override protected ShardStats shardOperation(IndexShardStatsRequest request, ShardRouting shardRouting) { IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()); IndexShard indexShard = indexService.shardSafe(shardRouting.shardId().id()); // if we don't have the routing entry yet, we need it stats wise, we treat it as if the shard is not ready yet if (indexShard.routingEntry() == null) { throw new ShardNotFoundException(indexShard.shardId()); } if (!indexShard.state().equals(IndexShardState.STARTED)) { throw new ElasticsearchException(indexShard.shardId().toString() + " state is " + indexShard.state() + ", not started"); } CommonStatsFlags flags = new CommonStatsFlags().clear(); if (request.dl()) { flags.set(CommonStatsFlags.Flag.DL); } return new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indexShard, flags), indexShard.commitStats()); }
Example 2
Source File: SyncedFlushService.java From crate with Apache License 2.0 | 5 votes |
private PreSyncedFlushResponse performPreSyncedFlush(PreShardSyncedFlushRequest request) { IndexShard indexShard = indicesService.indexServiceSafe(request.shardId().getIndex()).getShard(request.shardId().id()); FlushRequest flushRequest = new FlushRequest().force(false).waitIfOngoing(true); LOGGER.trace("{} performing pre sync flush", request.shardId()); indexShard.flush(flushRequest); final CommitStats commitStats = indexShard.commitStats(); final Engine.CommitId commitId = commitStats.getRawCommitId(); LOGGER.trace("{} pre sync flush done. commit id {}, num docs {}", request.shardId(), commitId, commitStats.getNumDocs()); return new PreSyncedFlushResponse(commitId, commitStats.getNumDocs(), commitStats.syncId()); }
Example 3
Source File: InternalTestCluster.java From crate with Apache License 2.0 | 5 votes |
private void assertSameSyncIdSameDocs() { Map<String, Long> docsOnShards = new HashMap<>(); 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) { try { CommitStats commitStats = indexShard.commitStats(); String syncId = commitStats.getUserData().get(Engine.SYNC_COMMIT_ID); if (syncId != null) { long liveDocsOnShard = commitStats.getNumDocs(); if (docsOnShards.get(syncId) != null) { assertThat("sync id is equal but number of docs does not match on node " + nodeAndClient.name + ". expected " + docsOnShards.get(syncId) + " but got " + liveDocsOnShard, docsOnShards.get(syncId), equalTo(liveDocsOnShard)); } else { docsOnShards.put(syncId, liveDocsOnShard); } } } catch (AlreadyClosedException e) { // the engine is closed or if the shard is recovering } } } } }
Example 4
Source File: IndicesService.java From Elasticsearch with Apache License 2.0 | 4 votes |
public NodeIndicesStats stats(boolean includePrevious, CommonStatsFlags flags) { CommonStats oldStats = new CommonStats(flags); if (includePrevious) { Flag[] setFlags = flags.getFlags(); for (Flag flag : setFlags) { switch (flag) { case Get: oldStats.get.add(oldShardsStats.getStats); break; case Indexing: oldStats.indexing.add(oldShardsStats.indexingStats); break; case Search: oldStats.search.add(oldShardsStats.searchStats); break; case Merge: oldStats.merge.add(oldShardsStats.mergeStats); break; case Refresh: oldStats.refresh.add(oldShardsStats.refreshStats); break; case Recovery: oldStats.recoveryStats.add(oldShardsStats.recoveryStats); break; case Flush: oldStats.flush.add(oldShardsStats.flushStats); break; } } } Map<Index, List<IndexShardStats>> statsByShard = Maps.newHashMap(); for (IndexServiceInjectorPair value : indices.values()) { IndexService indexService = value.getIndexService(); for (IndexShard indexShard : indexService) { try { if (indexShard.routingEntry() == null) { continue; } IndexShardStats indexShardStats = new IndexShardStats(indexShard.shardId(), new ShardStats[] { new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indexShard, flags), indexShard.commitStats()) }); if (!statsByShard.containsKey(indexService.index())) { statsByShard.put(indexService.index(), arrayAsArrayList(indexShardStats)); } else { statsByShard.get(indexService.index()).add(indexShardStats); } } catch (IllegalIndexShardStateException e) { // we can safely ignore illegal state on ones that are closing for example logger.trace("{} ignoring shard stats", e, indexShard.shardId()); } } } return new NodeIndicesStats(oldStats, statsByShard); }
Example 5
Source File: TransportIndicesStatsAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override protected ShardStats shardOperation(IndicesStatsRequest request, ShardRouting shardRouting) { IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()); IndexShard indexShard = indexService.shardSafe(shardRouting.shardId().id()); // if we don't have the routing entry yet, we need it stats wise, we treat it as if the shard is not ready yet if (indexShard.routingEntry() == null) { throw new ShardNotFoundException(indexShard.shardId()); } CommonStatsFlags flags = new CommonStatsFlags().clear(); if (request.docs()) { flags.set(CommonStatsFlags.Flag.Docs); } if (request.store()) { flags.set(CommonStatsFlags.Flag.Store); } if (request.indexing()) { flags.set(CommonStatsFlags.Flag.Indexing); flags.types(request.types()); } if (request.get()) { flags.set(CommonStatsFlags.Flag.Get); } if (request.search()) { flags.set(CommonStatsFlags.Flag.Search); flags.groups(request.groups()); } if (request.merge()) { flags.set(CommonStatsFlags.Flag.Merge); } if (request.refresh()) { flags.set(CommonStatsFlags.Flag.Refresh); } if (request.flush()) { flags.set(CommonStatsFlags.Flag.Flush); } if (request.warmer()) { flags.set(CommonStatsFlags.Flag.Warmer); } if (request.queryCache()) { flags.set(CommonStatsFlags.Flag.QueryCache); } if (request.fieldData()) { flags.set(CommonStatsFlags.Flag.FieldData); flags.fieldDataFields(request.fieldDataFields()); } if (request.percolate()) { flags.set(CommonStatsFlags.Flag.Percolate); } if (request.segments()) { flags.set(CommonStatsFlags.Flag.Segments); } if (request.completion()) { flags.set(CommonStatsFlags.Flag.Completion); flags.completionDataFields(request.completionFields()); } if (request.translog()) { flags.set(CommonStatsFlags.Flag.Translog); } if (request.suggest()) { flags.set(CommonStatsFlags.Flag.Suggest); } if (request.requestCache()) { flags.set(CommonStatsFlags.Flag.RequestCache); } if (request.recovery()) { flags.set(CommonStatsFlags.Flag.Recovery); } if (request.dl()) { flags.set(CommonStatsFlags.Flag.DL); } if (request.reindex()) { flags.set(CommonStatsFlags.Flag.Reindex); } return new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indexShard, flags), indexShard.commitStats()); }
Example 6
Source File: TransportIndicesStatsAction.java From crate with Apache License 2.0 | 4 votes |
@Override protected ShardStats shardOperation(IndicesStatsRequest request, ShardRouting shardRouting) { IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()); IndexShard indexShard = indexService.getShard(shardRouting.shardId().id()); // if we don't have the routing entry yet, we need it stats wise, we treat it as if the shard is not ready yet if (indexShard.routingEntry() == null) { throw new ShardNotFoundException(indexShard.shardId()); } CommonStatsFlags flags = new CommonStatsFlags().clear(); if (request.docs()) { flags.set(CommonStatsFlags.Flag.Docs); } if (request.store()) { flags.set(CommonStatsFlags.Flag.Store); } if (request.completion()) { flags.set(CommonStatsFlags.Flag.Completion); flags.completionDataFields(request.completionFields()); } CommitStats commitStats; SeqNoStats seqNoStats; try { commitStats = indexShard.commitStats(); seqNoStats = indexShard.seqNoStats(); } catch (AlreadyClosedException e) { // shard is closed - no stats is fine commitStats = null; seqNoStats = null; } return new ShardStats( indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indexShard, flags), commitStats, seqNoStats ); }