Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
4.1
-
None
Description
SolrCore correctly defaults to a NRTCachingDirectoryFactory if no <cirectoryFactory> is explicitly specified in solrconfig.xml, but the maxCachedMB and maxMergeSizeMB parameters are not initialized with the same default values as when an explicit directory factory is specified with no argument values given.
Repro:
Remove the explicit directory factory from the Solr 4.1 example solrconfig.xml:
<directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.NRTCachingDirectoryFactory}"/>
Start Solr.
In the console output you will see:
Feb 10, 2013 7:28:55 PM org.apache.solr.core.SolrDeletionPolicy onCommit INFO: SolrDeletionPolicy.onCommit: commits:num=1 commit{dir=NRTCachingDirectory(org.apache.lucene.store.SimpleFSDirectory@C:\cygwin\home\projects\solr-4.1.0\solr-4.1.0\example-solrconfig\solr\collection1\data\index lockFactory=org.apache.lucene.store.NativeFSLockFactory@a93430; maxCacheMB=0.0 maxMergeSizeMB=0.0),segFN=segments_1,generation=1,filenames=[segments_1] F
Note the "maxCacheMB=0.0" and "maxMergeSizeMB=0.0". These should be defaulting to values of 48.0 and 4.0, respectively.
In SolrCore.java we have:
private void initDirectoryFactory() { DirectoryFactory dirFactory; PluginInfo info = solrConfig.getPluginInfo(DirectoryFactory.class.getName()); if (info != null) { log.info(info.className); dirFactory = getResourceLoader().newInstance(info.className, DirectoryFactory.class); dirFactory.init(info.initArgs); } else { log.info("solr.NRTCachingDirectoryFactory"); dirFactory = new NRTCachingDirectoryFactory(); } // And set it directoryFactory = dirFactory; }
The difference between an explicit directory factory with no arguments and the implicit directory factory default is that the "init" method is not called for the latter. It is only in the init method that the default values are set.
I suggest changing NRTCachingDirectoryFactory.java from:
public class NRTCachingDirectoryFactory extends StandardDirectoryFactory { private double maxMergeSizeMB; private double maxCachedMB; @Override public void init(NamedList args) { super.init(args); SolrParams params = SolrParams.toSolrParams(args); maxMergeSizeMB = params.getDouble("maxMergeSizeMB", 4); if (maxMergeSizeMB <= 0){ throw new IllegalArgumentException("maxMergeSizeMB must be greater than 0"); } maxCachedMB = params.getDouble("maxCachedMB", 48); if (maxCachedMB <= 0){ throw new IllegalArgumentException("maxCachedMB must be greater than 0"); } }
to:
public class NRTCachingDirectoryFactory extends StandardDirectoryFactory { public static final int DEFAULT_MAX_MERGE_SIZE_MB = 4; private double maxMergeSizeMB = DEFAULT_MAX_MERGE_SIZE_MB; public static final int DEFAULT_MAX_CACHED_MB = 48; private double maxCachedMB = DEFAULT_MAX_CACHED_MB; @Override public void init(NamedList args) { super.init(args); SolrParams params = SolrParams.toSolrParams(args); maxMergeSizeMB = params.getDouble("maxMergeSizeMB", DEFAULT_MAX_MERGE_SIZE_MB); if (maxMergeSizeMB <= 0){ throw new IllegalArgumentException("maxMergeSizeMB must be greater than 0"); } maxCachedMB = params.getDouble("maxCachedMB", DEFAULT_MAX_CACHED_MB); if (maxCachedMB <= 0){ throw new IllegalArgumentException("maxCachedMB must be greater than 0"); } }
Note: This issue is not present in Solr 4.0 since the two parameters were hardwired in the NRTCachingDirectoryFactory.create method.