Handle IndexMissingException when fetching the index size for an application.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/41702956 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/41702956 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/41702956 Branch: refs/heads/expose-reindex Commit: 41702956d5aedac5a8e8d44f8f3df7af5ec365b9 Parents: c860521 Author: Michael Russo <russomich...@google.com> Authored: Tue Sep 12 18:42:43 2017 -0700 Committer: Michael Russo <russomich...@google.com> Committed: Tue Sep 12 18:42:43 2017 -0700 ---------------------------------------------------------------------- .../index/impl/EsEntityIndexImpl.java | 29 ++++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/41702956/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java index f4fae2b..3d2f576 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java @@ -70,6 +70,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.query.*; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.indices.IndexAlreadyExistsException; +import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.aggregations.metrics.sum.Sum; @@ -804,15 +805,25 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData { } private long getIndexSize(){ - final IndicesStatsResponse statsResponse = esProvider.getClient() - .admin() - .indices() - .prepareStats(indexLocationStrategy.getIndexInitialName()) - .all() - .execute() - .actionGet(); - final CommonStats indexStats = statsResponse.getIndex(indexLocationStrategy.getIndexInitialName()).getTotal(); - return indexStats.getStore().getSizeInBytes(); + long indexSize = 0L; + final String indexName = indexLocationStrategy.getIndexInitialName(); + try { + final IndicesStatsResponse statsResponse = esProvider.getClient() + .admin() + .indices() + .prepareStats(indexName) + .all() + .execute() + .actionGet(); + final CommonStats indexStats = statsResponse.getIndex(indexName).getTotal(); + indexSize = indexStats.getStore().getSizeInBytes(); + } catch (IndexMissingException e) { + // if for some reason the index size does not exist, + // log an error and we can assume size is 0 as it doesn't exist + logger.error("Unable to get size for index {} due to IndexMissingException for app {}", + indexName, indexLocationStrategy.getApplicationScope().getApplication().getUuid()); + } + return indexSize; } @Override