Percolator: improve logging and cleanup try-catch statement for percolator query loading.
This commit is contained in:
parent
63eaec6f48
commit
20a55c05df
|
@ -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,27 +256,23 @@ 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
|
try (Engine.Searcher searcher = shard.acquireSearcher("percolator_load_queries", IndexShard.Mode.WRITE)) {
|
||||||
Engine.Searcher searcher = shard.acquireSearcher("percolator_load_queries", IndexShard.Mode.WRITE);
|
Query query = new XConstantScoreQuery(
|
||||||
try {
|
indexCache.filter().cache(
|
||||||
Query query = new XConstantScoreQuery(
|
new TermFilter(new Term(TypeFieldMapper.NAME, PercolatorService.TYPE_NAME))
|
||||||
indexCache.filter().cache(
|
)
|
||||||
new TermFilter(new Term(TypeFieldMapper.NAME, PercolatorService.TYPE_NAME))
|
);
|
||||||
)
|
QueriesLoaderCollector queryCollector = new QueriesLoaderCollector(PercolatorQueriesRegistry.this, logger, mapperService, indexFieldDataService);
|
||||||
);
|
searcher.searcher().search(query, queryCollector);
|
||||||
QueriesLoaderCollector queryCollector = new QueriesLoaderCollector(PercolatorQueriesRegistry.this, logger, mapperService, indexFieldDataService);
|
Map<BytesRef, Query> queries = queryCollector.queries();
|
||||||
searcher.searcher().search(query, queryCollector);
|
for (Map.Entry<BytesRef, Query> entry : queries.entrySet()) {
|
||||||
Map<BytesRef, Query> queries = queryCollector.queries();
|
Query previousQuery = percolateQueries.put(entry.getKey(), entry.getValue());
|
||||||
for (Map.Entry<BytesRef, Query> entry : queries.entrySet()) {
|
shardPercolateService.addedQuery(entry.getKey(), previousQuery, entry.getValue());
|
||||||
Query previousQuery = percolateQueries.put(entry.getKey(), entry.getValue());
|
|
||||||
shardPercolateService.addedQuery(entry.getKey(), previousQuery, entry.getValue());
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
searcher.close();
|
|
||||||
}
|
}
|
||||||
|
return queries.size();
|
||||||
} 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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue