diff options
author | Chris Earle <pickypg@users.noreply.github.com> | 2017-06-28 10:08:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-28 10:08:45 -0400 |
commit | f2eeceb10dab1a7ebe736dfd32333bd0886e43d8 (patch) | |
tree | dd90dfcd616548014868681d75dc4f157a90c583 /core/src/main/java | |
parent | 5a4a47332c5a9a21531eb29c3ab4fd264e7fcf36 (diff) |
_nodes/stats should not fail due to concurrent AlreadyClosedException (#25016)
This catches `AlreadyClosedException` during `stats` calls to avoid failing a `_nodes/stats` request because of the ignorable, concurrent index closure.
Diffstat (limited to 'core/src/main/java')
-rw-r--r-- | core/src/main/java/org/elasticsearch/indices/IndicesService.java | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java index e486aede53..eb138a0458 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -22,6 +22,7 @@ package org.elasticsearch.indices; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.lucene.index.DirectoryReader; +import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.store.LockObtainFailedException; import org.apache.lucene.util.CollectionUtil; import org.apache.lucene.util.IOUtils; @@ -292,35 +293,49 @@ public class IndicesService extends AbstractLifecycleComponent } } - Map<Index, List<IndexShardStats>> statsByShard = new HashMap<>(); - for (IndexService indexService : this) { - for (IndexShard indexShard : indexService) { + return new NodeIndicesStats(oldStats, statsByShard(this, flags)); + } + + Map<Index, List<IndexShardStats>> statsByShard(final IndicesService indicesService, final CommonStatsFlags flags) { + final Map<Index, List<IndexShardStats>> statsByShard = new HashMap<>(); + + for (final IndexService indexService : indicesService) { + for (final IndexShard indexShard : indexService) { try { - if (indexShard.routingEntry() == null) { + final IndexShardStats indexShardStats = indicesService.indexShardStats(indicesService, indexShard, flags); + + if (indexShardStats == 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())) { + + if (statsByShard.containsKey(indexService.index()) == false) { statsByShard.put(indexService.index(), arrayAsArrayList(indexShardStats)); } else { statsByShard.get(indexService.index()).add(indexShardStats); } - } catch (IllegalIndexShardStateException e) { + } catch (IllegalIndexShardStateException | AlreadyClosedException 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); + + return statsByShard; + } + + IndexShardStats indexShardStats(final IndicesService indicesService, final IndexShard indexShard, final CommonStatsFlags flags) { + if (indexShard.routingEntry() == null) { + return null; + } + + return new IndexShardStats(indexShard.shardId(), + new ShardStats[] { + new ShardStats(indexShard.routingEntry(), + indexShard.shardPath(), + new CommonStats(indicesService.getIndicesQueryCache(), indexShard, flags), + indexShard.commitStats(), + indexShard.seqNoStats()) + }); } /** |