Solr
  1. Solr
  2. SOLR-4426

NRTCachingDirectoryFactory does not initialize maxCachedMB and maxMergeSizeMB if <directoryFactory> is not present in solrconfig.xml

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.1
    • Fix Version/s: 4.2, 6.0
    • Component/s: Schema and Analysis
    • Labels:
      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.

      1. SOLR-4426.patch
        2 kB
        Shalin Shekhar Mangar

        Activity

        Hide
        Commit Tag Bot added a comment -

        [trunk commit] Shalin Shekhar Mangar
        http://svn.apache.org/viewvc?view=revision&revision=1444782

        SOLR-4426: NRTCachingDirectoryFactory does not initialize maxCachedMB and maxMergeSizeMB if <directoryFactory> is not present in solrconfig.xml

        Show
        Commit Tag Bot added a comment - [trunk commit] Shalin Shekhar Mangar http://svn.apache.org/viewvc?view=revision&revision=1444782 SOLR-4426 : NRTCachingDirectoryFactory does not initialize maxCachedMB and maxMergeSizeMB if <directoryFactory> is not present in solrconfig.xml
        Hide
        Commit Tag Bot added a comment -

        [branch_4x commit] Shalin Shekhar Mangar
        http://svn.apache.org/viewvc?view=revision&revision=1444786

        SOLR-4426: NRTCachingDirectoryFactory does not initialize maxCachedMB and maxMergeSizeMB if <directoryFactory> is not present in solrconfig.xml

        Show
        Commit Tag Bot added a comment - [branch_4x commit] Shalin Shekhar Mangar http://svn.apache.org/viewvc?view=revision&revision=1444786 SOLR-4426 : NRTCachingDirectoryFactory does not initialize maxCachedMB and maxMergeSizeMB if <directoryFactory> is not present in solrconfig.xml
        Hide
        Uwe Schindler added a comment -

        Closed after release.

        Show
        Uwe Schindler added a comment - Closed after release.

          People

          • Assignee:
            Shalin Shekhar Mangar
            Reporter:
            Jack Krupansky
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development