SOLR: What does an autoSoftCommit maxtime of -1 me

2019-04-19 19:03发布

问题:

Here's the default setting from my solrconfig.xml file:

 <autoSoftCommit> 
   <maxTime>${solr.autoSoftCommit.maxTime:-1}</maxTime> 
 </autoSoftCommit>

Does the maxTime of '-1' mean that automatic soft commits are off? If so, would I get the same result if I deleted the tag altogether? And if I have to manually do the soft commits, can that be done with 'commitWithin' (I googled this but got conflicting answers)?

Oh, and I'm using Solr 4.5.0

回答1:

First off, you can see the expression ${solr.autoSoftCommit.maxTime:-1} within the tag. This allows you to make use of Solr's variable substitution. That feature is described in detail here in the reference. If that variable has not been substituted by any of those means -1 is taken as value for that configuration.

Turning commitMaxTime to -1 effectively turns autocommit off. If you have a look at the relevant code below, you can see that commitMaxTime overrules any value of maxDocs, as the scheduleCommitWithin method returns immediately. I have not found this behaviour documented, so I looked up the code.

private void _scheduleCommitWithin(long commitMaxTime) {
    if (commitMaxTime <= 0) return;
    synchronized (this) {
      if (pending != null && pending.getDelay(TimeUnit.MILLISECONDS) <= commitMaxTime) {
        // There is already a pending commit that will happen first, so
        // nothing else to do here.
        // log.info("###returning since getDelay()==" + pending.getDelay(TimeUnit.MILLISECONDS) + " less than " + commitMaxTime);

        return;
      }

      if (pending != null) {
        // we need to schedule a commit to happen sooner than the existing one,
        // so lets try to cancel the existing one first.
        boolean canceled = pending.cancel(false);
        if (!canceled) {
          // It looks like we can't cancel... it must have just started running!
          // this is possible due to thread scheduling delays and a low commitMaxTime.
          // Nothing else to do since we obviously can't schedule our commit *before*
          // the one that just started running (or has just completed).
          // log.info("###returning since cancel failed");
          return;
        }
      }

      // log.info("###scheduling for " + commitMaxTime);

      // schedule our new commit
      pending = scheduler.schedule(this, commitMaxTime, TimeUnit.MILLISECONDS);
    }
}

Taken from https://github.com/apache/lucene-solr/blob/lucene_solr_4_5/solr/core/src/java/org/apache/solr/update/CommitTracker.java

To the second part of your question, if you remove the tag all together this will have the same result as setting the value to -1. As you can see below, if the xpath expression returns null, you will get -1 as default value.

But removing the whole expression from the configuration will also remove the option to override that configuration via Solr's variable substitution.

protected UpdateHandlerInfo loadUpdatehandlerInfo() {
  return new UpdateHandlerInfo(get("updateHandler/@class",null),
    getInt("updateHandler/autoCommit/maxDocs",-1),
    getInt("updateHandler/autoCommit/maxTime",-1),
    getBool("updateHandler/autoCommit/openSearcher",true),
    getInt("updateHandler/commitIntervalLowerBound",-1),
    getInt("updateHandler/autoSoftCommit/maxDocs",-1),
    getInt("updateHandler/autoSoftCommit/maxTime",-1),
    getBool("updateHandler/commitWithin/softCommit",true));
}

Taken from https://github.com/apache/lucene-solr/blob/lucene_solr_4_5/solr/core/src/java/org/apache/solr/core/SolrConfig.java



标签: solr