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,35 +529,24 @@ 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
public boolean regenerateItem(SolrIndexSearcher newSearcher, SolrCache newCache, SolrCache oldCache,
Object oldKey, Object oldVal) throws IOException {
if (oldVal instanceof UnInvertedField) { if (oldVal instanceof UnInvertedField) {
UnInvertedField.getUnInvertedField((String) oldKey, newSearcher); 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
public boolean regenerateItem(SolrIndexSearcher newSearcher, SolrCache newCache, SolrCache oldCache,
Object oldKey, Object oldVal) throws IOException {
newSearcher.cacheDocSet((Query) oldKey, null, false); newSearcher.cacheDocSet((Query) oldKey, null, false);
return true; 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
public boolean regenerateItem(SolrIndexSearcher newSearcher, SolrCache newCache, SolrCache oldCache,
Object oldKey, Object oldVal) throws IOException {
QueryResultKey key = (QueryResultKey) oldKey; QueryResultKey key = (QueryResultKey) oldKey;
int nDocs = 1; int nDocs = 1;
// request 1 doc and let caching round up to the next window size... // request 1 doc and let caching round up to the next window size...
@ -584,7 +573,6 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
QueryResult qr = new QueryResult(); QueryResult qr = new QueryResult();
newSearcher.getDocListC(qr, qc); newSearcher.getDocListC(qr, qc);
return true; return true;
}
}); });
} }
} }