SOLR-8995: Use lambdas for CacheRegenerator implementations

This commit is contained in:
Noble Paul 2016-08-11 12:48:21 +05:30
parent 4bd7d7fadb
commit 8412af5513
2 changed files with 33 additions and 45 deletions

View File

@ -38,5 +38,5 @@ public interface CacheRegenerator {
* @param oldVal the old value of the cache item * @param oldVal the old value of the cache item
* @return true to continue with autowarming, false to stop * @return true to continue with autowarming, false to stop
*/ */
public boolean regenerateItem(SolrIndexSearcher newSearcher, SolrCache newCache, SolrCache oldCache, Object oldKey, Object oldVal) throws IOException; boolean regenerateItem(SolrIndexSearcher newSearcher, SolrCache newCache, SolrCache oldCache, Object oldKey, Object oldVal) throws IOException;
} }

View File

@ -529,62 +529,50 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
// //
public static void initRegenerators(SolrConfig solrConfig) { public static void initRegenerators(SolrConfig solrConfig) {
if (solrConfig.fieldValueCacheConfig != null && solrConfig.fieldValueCacheConfig.getRegenerator() == null) { if (solrConfig.fieldValueCacheConfig != null && solrConfig.fieldValueCacheConfig.getRegenerator() == null) {
solrConfig.fieldValueCacheConfig.setRegenerator(new CacheRegenerator() { solrConfig.fieldValueCacheConfig.setRegenerator((newSearcher, newCache, oldCache, oldKey, oldVal) -> {
@Override if (oldVal instanceof UnInvertedField) {
public boolean regenerateItem(SolrIndexSearcher newSearcher, SolrCache newCache, SolrCache oldCache, UnInvertedField.getUnInvertedField((String) oldKey, newSearcher);
Object oldKey, Object oldVal) throws IOException {
if (oldVal instanceof UnInvertedField) {
UnInvertedField.getUnInvertedField((String) oldKey, newSearcher);
}
return true;
} }
return true;
}); });
} }
if (solrConfig.filterCacheConfig != null && solrConfig.filterCacheConfig.getRegenerator() == null) { if (solrConfig.filterCacheConfig != null && solrConfig.filterCacheConfig.getRegenerator() == null) {
solrConfig.filterCacheConfig.setRegenerator(new CacheRegenerator() { solrConfig.filterCacheConfig.setRegenerator((newSearcher, newCache, oldCache, oldKey, oldVal) -> {
@Override newSearcher.cacheDocSet((Query) oldKey, null, false);
public boolean regenerateItem(SolrIndexSearcher newSearcher, SolrCache newCache, SolrCache oldCache, return true;
Object oldKey, Object oldVal) throws IOException {
newSearcher.cacheDocSet((Query) oldKey, null, false);
return true;
}
}); });
} }
if (solrConfig.queryResultCacheConfig != null && solrConfig.queryResultCacheConfig.getRegenerator() == null) { if (solrConfig.queryResultCacheConfig != null && solrConfig.queryResultCacheConfig.getRegenerator() == null) {
final int queryResultWindowSize = solrConfig.queryResultWindowSize; final int queryResultWindowSize = solrConfig.queryResultWindowSize;
solrConfig.queryResultCacheConfig.setRegenerator(new CacheRegenerator() { solrConfig.queryResultCacheConfig.setRegenerator((newSearcher, newCache, oldCache, oldKey, oldVal) -> {
@Override QueryResultKey key = (QueryResultKey) oldKey;
public boolean regenerateItem(SolrIndexSearcher newSearcher, SolrCache newCache, SolrCache oldCache, int nDocs = 1;
Object oldKey, Object oldVal) throws IOException { // request 1 doc and let caching round up to the next window size...
QueryResultKey key = (QueryResultKey) oldKey; // unless the window size is <=1, in which case we will pick
int nDocs = 1; // the minimum of the number of documents requested last time and
// request 1 doc and let caching round up to the next window size... // a reasonable number such as 40.
// unless the window size is <=1, in which case we will pick // TODO: make more configurable later...
// the minimum of the number of documents requested last time and
// a reasonable number such as 40.
// TODO: make more configurable later...
if (queryResultWindowSize <= 1) { if (queryResultWindowSize <= 1) {
DocList oldList = (DocList) oldVal; DocList oldList = (DocList) oldVal;
int oldnDocs = oldList.offset() + oldList.size(); int oldnDocs = oldList.offset() + oldList.size();
// 40 has factors of 2,4,5,10,20 // 40 has factors of 2,4,5,10,20
nDocs = Math.min(oldnDocs, 40); nDocs = Math.min(oldnDocs, 40);
}
int flags = NO_CHECK_QCACHE | key.nc_flags;
QueryCommand qc = new QueryCommand();
qc.setQuery(key.query)
.setFilterList(key.filters)
.setSort(key.sort)
.setLen(nDocs)
.setSupersetMaxDoc(nDocs)
.setFlags(flags);
QueryResult qr = new QueryResult();
newSearcher.getDocListC(qr, qc);
return true;
} }
int flags = NO_CHECK_QCACHE | key.nc_flags;
QueryCommand qc = new QueryCommand();
qc.setQuery(key.query)
.setFilterList(key.filters)
.setSort(key.sort)
.setLen(nDocs)
.setSupersetMaxDoc(nDocs)
.setFlags(flags);
QueryResult qr = new QueryResult();
newSearcher.getDocListC(qr, qc);
return true;
}); });
} }
} }