Apache Lucene open-source search software
SOLR-8856: Do not cache merge or 'read once' contexts in the hdfs block cache.
markrmiller574da7667f57
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 3647bf7f319..a789881f42a 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -64,9 +64,13 @@ Optimizations----------------------* SOLR-8722: Don't force a full ZkStateReader refresh on every Overseer operation.(Scott Blum via shalin)++* SOLR-8856: Do not cache merge or 'read once' contexts in the hdfs block cache. (Mark Miller)* SOLR-8745: Deprecate costly ZkStateReader.updateClusterState(), replace with a narrowforceUpdateCollection(collection) (Scott Blum via shalin)++* SOLR-8856: Do not cache merge or 'read once' contexts in the hdfs block cache. (Mark Miller, Mike Drob)Other Changes----------------------diff --git a/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.javaindex 6a37a6a650a..9d6797a4fb8 100644--- a/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java@@ -90,12 +90,19 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements Solpublic static final String CONFIG_DIRECTORY = "solr.hdfs.confdir";+ public static final String CACHE_MERGES = "solr.hdfs.blockcache.cachemerges";+ public static final String CACHE_READONCE = "solr.hdfs.blockcache.cachereadonce";+private SolrParams params;private String hdfsDataDir;private String confDir;+ private boolean cacheReadOnce;++ private boolean cacheMerges;+private static BlockCache globalBlockCache;public static Metrics metrics;@@ -144,6 +151,8 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements Sol} else {LOG.info(HDFS_HOME + "=" + this.hdfsDataDir);}+ cacheMerges = getConfig(CACHE_MERGES, false);+ cacheReadOnce = getConfig(CACHE_READONCE, false);boolean kerberosEnabled = getConfig(KERBEROS_ENABLED, false);LOG.info("Solr Kerberos Authentication "+ (kerberosEnabled ? "enabled" : "disabled"));@@ -215,7 +224,7 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements SolCache cache = new BlockDirectoryCache(blockCache, path, metrics, blockCacheGlobal);hdfsDir = new HdfsDirectory(new Path(path), lockFactory, conf);- dir = new BlockDirectory(path, hdfsDir, cache, null, blockCacheReadEnabled, false);+ dir = new BlockDirectory(path, hdfsDir, cache, null, blockCacheReadEnabled, false, cacheMerges, cacheReadOnce);} else {hdfsDir = new HdfsDirectory(new Path(path), lockFactory, conf);dir = hdfsDir;diff --git a/solr/core/src/java/org/apache/solr/store/blockcache/BlockDirectory.java b/solr/core/src/java/org/apache/solr/store/blockcache/BlockDirectory.javaindex c1b46841bea..209d6d157ae 100644--- a/solr/core/src/java/org/apache/solr/store/blockcache/BlockDirectory.java+++ b/solr/core/src/java/org/apache/solr/store/blockcache/BlockDirectory.java@@ -92,10 +92,21 @@ public class BlockDirectory extends FilterDirectory implements ShutdownAwareDireprivate final boolean blockCacheReadEnabled;private final boolean blockCacheWriteEnabled;+ private boolean cacheMerges;+ private boolean cacheReadOnce;+public BlockDirectory(String dirName, Directory directory, Cache cache,Set<String> blockCacheFileTypes, boolean blockCacheReadEnabled,boolean blockCacheWriteEnabled) throws IOException {+ this(dirName, directory, cache, blockCacheFileTypes, blockCacheReadEnabled, blockCacheWriteEnabled, true, true);+ }++ public BlockDirectory(String dirName, Directory directory, Cache cache,+ Set<String> blockCacheFileTypes, boolean blockCacheReadEnabled,+ boolean blockCacheWriteEnabled, boolean cacheMerges, boolean cacheReadOnce) throws IOException {super(directory);+ this.cacheMerges = cacheMerges;+ this.cacheReadOnce = cacheReadOnce;this.dirName = dirName;blockSize = BLOCK_SIZE;this.cache = cache;@@ -292,6 +303,17 @@ public class BlockDirectory extends FilterDirectory implements ShutdownAwareDirereturn false;}switch (context.context) {+ // depending on params, we don't cache on merges or when only reading once+ case MERGE: {+ return cacheMerges;+ }+ case READ: {+ if (context.readOnce) {+ return cacheReadOnce;+ } else {+ return true;+ }+ }default: {return true;}