Search in sources :

Example 6 with IllegalIndexShardStateException

use of org.elasticsearch.index.shard.IllegalIndexShardStateException in project elasticsearch by elastic.

the class IndicesService method stats.

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 = new HashMap<>();
    for (IndexService indexService : this) {
        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(indicesQueryCache, indexShard, flags), indexShard.commitStats(), indexShard.seqNoStats()) });
                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((Supplier<?>) () -> new ParameterizedMessage("{} ignoring shard stats", indexShard.shardId()), e);
            }
        }
    }
    return new NodeIndicesStats(oldStats, statsByShard);
}
Also used : IndexShardStats(org.elasticsearch.action.admin.indices.stats.IndexShardStats) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) HashMap(java.util.HashMap) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) Index(org.elasticsearch.index.Index) IndexShardStats(org.elasticsearch.action.admin.indices.stats.IndexShardStats) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) Flag(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags.Flag) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) CollectionUtils.arrayAsArrayList(org.elasticsearch.common.util.CollectionUtils.arrayAsArrayList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Supplier(java.util.function.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage)

Example 7 with IllegalIndexShardStateException

use of org.elasticsearch.index.shard.IllegalIndexShardStateException in project elasticsearch by elastic.

the class ExceptionSerializationTests method testIllegalIndexShardStateException.

public void testIllegalIndexShardStateException() throws IOException {
    ShardId id = new ShardId("foo", "_na_", 1);
    IndexShardState state = randomFrom(IndexShardState.values());
    IllegalIndexShardStateException ex = serialize(new IllegalIndexShardStateException(id, state, "come back later buddy"));
    assertEquals(id, ex.getShardId());
    assertEquals("CurrentState[" + state.name() + "] come back later buddy", ex.getMessage());
    assertEquals(state, ex.currentState());
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) IndexShardState(org.elasticsearch.index.shard.IndexShardState)

Aggregations

IllegalIndexShardStateException (org.elasticsearch.index.shard.IllegalIndexShardStateException)7 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ShardId (org.elasticsearch.index.shard.ShardId)4 ShardNotFoundException (org.elasticsearch.index.shard.ShardNotFoundException)4 UnhandledServerException (io.crate.exceptions.UnhandledServerException)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)3 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)2 IndexService (org.elasticsearch.index.IndexService)2 SharedShardContext (io.crate.action.job.SharedShardContext)1 SharedShardContexts (io.crate.action.job.SharedShardContexts)1 OrderBy (io.crate.analyze.OrderBy)1 LuceneQueryBuilder (io.crate.lucene.LuceneQueryBuilder)1 UnassignedShard (io.crate.metadata.shard.unassigned.UnassignedShard)1 OrderedDocCollector (io.crate.operation.collect.collectors.OrderedDocCollector)1 IOException (java.io.IOException)1 Collections.emptyList (java.util.Collections.emptyList)1 HashMap (java.util.HashMap)1