SOLR-8856: Do not cache merge or 'read once' contexts in the hdfs block cache.

This commit is contained in:
markrmiller 2016-03-22 23:05:13 -04:00
parent 99c3bb2371
commit 574da7667f
3 changed files with 36 additions and 1 deletions

View File

@ -65,9 +65,13 @@ Optimizations
* SOLR-8722: Don't force a full ZkStateReader refresh on every Overseer operation. * SOLR-8722: Don't force a full ZkStateReader refresh on every Overseer operation.
(Scott Blum via shalin) (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 narrow * SOLR-8745: Deprecate costly ZkStateReader.updateClusterState(), replace with a narrow
forceUpdateCollection(collection) (Scott Blum via shalin) forceUpdateCollection(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 Other Changes
---------------------- ----------------------
* SOLR-7516: Improve javadocs for JavaBinCodec, ObjectResolver and enforce the single-usage policy. * SOLR-7516: Improve javadocs for JavaBinCodec, ObjectResolver and enforce the single-usage policy.

View File

@ -90,12 +90,19 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements Sol
public static final String CONFIG_DIRECTORY = "solr.hdfs.confdir"; public 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 SolrParams params;
private String hdfsDataDir; private String hdfsDataDir;
private String confDir; private String confDir;
private boolean cacheReadOnce;
private boolean cacheMerges;
private static BlockCache globalBlockCache; private static BlockCache globalBlockCache;
public static Metrics metrics; public static Metrics metrics;
@ -144,6 +151,8 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements Sol
} else { } else {
LOG.info(HDFS_HOME + "=" + this.hdfsDataDir); LOG.info(HDFS_HOME + "=" + this.hdfsDataDir);
} }
cacheMerges = getConfig(CACHE_MERGES, false);
cacheReadOnce = getConfig(CACHE_READONCE, false);
boolean kerberosEnabled = getConfig(KERBEROS_ENABLED, false); boolean kerberosEnabled = getConfig(KERBEROS_ENABLED, false);
LOG.info("Solr Kerberos Authentication " LOG.info("Solr Kerberos Authentication "
+ (kerberosEnabled ? "enabled" : "disabled")); + (kerberosEnabled ? "enabled" : "disabled"));
@ -215,7 +224,7 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements Sol
Cache cache = new BlockDirectoryCache(blockCache, path, metrics, blockCacheGlobal); Cache cache = new BlockDirectoryCache(blockCache, path, metrics, blockCacheGlobal);
hdfsDir = new HdfsDirectory(new Path(path), lockFactory, conf); 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 { } else {
hdfsDir = new HdfsDirectory(new Path(path), lockFactory, conf); hdfsDir = new HdfsDirectory(new Path(path), lockFactory, conf);
dir = hdfsDir; dir = hdfsDir;

View File

@ -92,10 +92,21 @@ public class BlockDirectory extends FilterDirectory implements ShutdownAwareDire
private final boolean blockCacheReadEnabled; private final boolean blockCacheReadEnabled;
private final boolean blockCacheWriteEnabled; private final boolean blockCacheWriteEnabled;
private boolean cacheMerges;
private boolean cacheReadOnce;
public BlockDirectory(String dirName, Directory directory, Cache cache, public BlockDirectory(String dirName, Directory directory, Cache cache,
Set<String> blockCacheFileTypes, boolean blockCacheReadEnabled, Set<String> blockCacheFileTypes, boolean blockCacheReadEnabled,
boolean blockCacheWriteEnabled) throws IOException { 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); super(directory);
this.cacheMerges = cacheMerges;
this.cacheReadOnce = cacheReadOnce;
this.dirName = dirName; this.dirName = dirName;
blockSize = BLOCK_SIZE; blockSize = BLOCK_SIZE;
this.cache = cache; this.cache = cache;
@ -292,6 +303,17 @@ public class BlockDirectory extends FilterDirectory implements ShutdownAwareDire
return false; return false;
} }
switch (context.context) { 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: { default: {
return true; return true;
} }