Percolator: improve logging and cleanup try-catch statement for percolator query loading.

This commit is contained in:
Martijn van Groningen 2014-07-02 22:36:02 +02:00
parent 63eaec6f48
commit 20a55c05df
1 changed files with 19 additions and 23 deletions

View File

@ -245,9 +245,9 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
if (hasPercolatorType(indexShard)) { if (hasPercolatorType(indexShard)) {
// percolator index has started, fetch what we can from it and initialize the indices // percolator index has started, fetch what we can from it and initialize the indices
// we have // we have
logger.debug("loading percolator queries for index [{}] and shard[{}]...", shardId.index(), shardId.id()); logger.trace("loading percolator queries for [{}]...", shardId);
loadQueries(indexShard); int loadedQueries = loadQueries(indexShard);
logger.trace("done loading percolator queries for index [{}] and shard[{}]", shardId.index(), shardId.id()); logger.debug("done loading [{}] percolator queries for [{}]", loadedQueries, shardId);
} }
} }
@ -256,12 +256,10 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
return shardId.equals(otherShardId) && mapperService.hasMapping(PercolatorService.TYPE_NAME); return shardId.equals(otherShardId) && mapperService.hasMapping(PercolatorService.TYPE_NAME);
} }
private void loadQueries(IndexShard shard) { private int loadQueries(IndexShard shard) {
try {
shard.refresh(new Engine.Refresh("percolator_load_queries").force(true)); shard.refresh(new Engine.Refresh("percolator_load_queries").force(true));
// Maybe add a mode load? This isn't really a write. We need write b/c state=post_recovery // Maybe add a mode load? This isn't really a write. We need write b/c state=post_recovery
Engine.Searcher searcher = shard.acquireSearcher("percolator_load_queries", IndexShard.Mode.WRITE); try (Engine.Searcher searcher = shard.acquireSearcher("percolator_load_queries", IndexShard.Mode.WRITE)) {
try {
Query query = new XConstantScoreQuery( Query query = new XConstantScoreQuery(
indexCache.filter().cache( indexCache.filter().cache(
new TermFilter(new Term(TypeFieldMapper.NAME, PercolatorService.TYPE_NAME)) new TermFilter(new Term(TypeFieldMapper.NAME, PercolatorService.TYPE_NAME))
@ -274,9 +272,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent {
Query previousQuery = percolateQueries.put(entry.getKey(), entry.getValue()); Query previousQuery = percolateQueries.put(entry.getKey(), entry.getValue());
shardPercolateService.addedQuery(entry.getKey(), previousQuery, entry.getValue()); shardPercolateService.addedQuery(entry.getKey(), previousQuery, entry.getValue());
} }
} finally { return queries.size();
searcher.close();
}
} catch (Exception e) { } catch (Exception e) {
throw new PercolatorException(shardId.index(), "failed to load queries from percolator index", e); throw new PercolatorException(shardId.index(), "failed to load queries from percolator index", e);
} }