關(guān)于timeAllowed
TimeLimitingCollector
FilterLeafCollector在collect每個(gè)doc的時(shí)候判斷是否超時(shí)
SolrQueryTimeoutImpl
如果參數(shù)設(shè)置了timeAllowed胁黑,還會(huì)設(shè)置一個(gè)SolrQueryTimeoutImpl
SearchHandler:
long timeAllowed = req.getParams().getLong(CommonParams.TIME_ALLOWED, -1L);
if (timeAllowed >= 0L) {
SolrQueryTimeoutImpl.set(timeAllowed);
}
那么在執(zhí)行reader在執(zhí)行加載term的時(shí)候就會(huì)進(jìn)行時(shí)間檢查废封,超時(shí)則會(huì)拋出ExitingReaderException異常。
ExitableFilterAtomicReader:
/**
* Throws {@link ExitingReaderException} if {@link QueryTimeout#shouldExit()} returns true,
* or if {@link Thread#interrupted()} returns true.
*/
private void checkAndThrow() {
if (queryTimeout.shouldExit()) {
throw new ExitingReaderException("The request took too long to iterate over point values. Timeout: "
+ queryTimeout.toString()
+ ", PointValues=" + in
);
} else if (Thread.interrupted()) {
throw new ExitingReaderException("Interrupted while iterating over point values. PointValues=" + in);
}
}
主要是在IndexSearch.search方法中加載term的時(shí)候丧蘸。
public void search(Query query, Collector results) throws IOException {
query = rewrite(query);
search(leafContexts, createWeight(query, results.scoreMode(), 1), results);
}
createWeight會(huì)調(diào)用
IndexSearch.createNormalizedWeight
TermQuery.createWeight
TermContext.build
-
ExitableTermsEnum
類所有過程會(huì)調(diào)用checkAndThrow檢查超時(shí)漂洋。
TermContext.build方法:
for (final LeafReaderContext ctx : context.leaves()) {
final Terms terms = ctx.reader().terms(field);
if (terms != null) {
final TermsEnum termsEnum = terms.iterator();
if (termsEnum.seekExact(bytes)) {
final TermState termState = termsEnum.termState();
perReaderTermState.register(termState, ctx.ord, termsEnum.docFreq(), termsEnum.totalTermFreq());
}
}
}
召回階段
如果召回階段超時(shí),拋出 ExitableDirectoryReader.ExitingReaderException 異常力喷,在SearchHandler.handleRequestBody方法里會(huì)捕獲這個(gè)異常刽漂,增加partialResults=trued的標(biāo)識(shí),并返回已經(jīng)收集的結(jié)果弟孟。
rerank階段
topCollector.topDocs
如果rerank階段超時(shí)贝咙,由于ReRankCollector.topDocs捕獲了所有異常,然后拋出SolrException披蕉,導(dǎo)致無結(jié)果
rerank有兩處會(huì)排除ExitingReaderException異常颈畸。
1. scorer階段
scorer = modelWeight.scorer(readerContext);
一般語法為正常的召回,都會(huì)在scorer階段創(chuàng)建weight没讲。同時(shí)加載term眯娱。
2. score階段
一般是函數(shù)計(jì)算階段發(fā)生term加載。例如:
FloatPayloadValueSource.getValues
public void reset() throws IOException {
if (terms != null) {
final TermsEnum termsEnum = terms.iterator();
if (termsEnum.seekExact(indexedBytes)) {
docs = termsEnum.postings(null, PostingsEnum.ALL);
} else {
docs = null;
}
} else {
docs = null;
}
...
}