You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2018/03/06 17:28:44 UTC

[7/8] lucene-solr:jira/solr-11670-2: SOLR-11066: Added examples of startTime in ref guide. Added null check for processor and code comments to explain skipped events and lastRunAt initialization. Moved default preferredOp value to ComputePlanAction. Extr

SOLR-11066: Added examples of startTime in ref guide. Added null check for processor and code comments to explain skipped events and lastRunAt initialization. Moved default preferredOp value to ComputePlanAction. Extracted a constant.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/9cec2221
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/9cec2221
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/9cec2221

Branch: refs/heads/jira/solr-11670-2
Commit: 9cec2221a66ee7c1571531c4ce1342f51288c38d
Parents: 122271f
Author: Shalin Shekhar Mangar <sh...@apache.org>
Authored: Tue Mar 6 21:27:05 2018 +0530
Committer: Shalin Shekhar Mangar <sh...@apache.org>
Committed: Tue Mar 6 21:27:05 2018 +0530

----------------------------------------------------------------------
 .../cloud/autoscaling/ComputePlanAction.java    |  2 +-
 .../cloud/autoscaling/ScheduledTrigger.java     | 25 +++++++++++++-------
 .../src/solrcloud-autoscaling-triggers.adoc     |  5 +++-
 3 files changed, 22 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9cec2221/solr/core/src/java/org/apache/solr/cloud/autoscaling/ComputePlanAction.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/autoscaling/ComputePlanAction.java b/solr/core/src/java/org/apache/solr/cloud/autoscaling/ComputePlanAction.java
index 9eb6382..aed821a 100644
--- a/solr/core/src/java/org/apache/solr/cloud/autoscaling/ComputePlanAction.java
+++ b/solr/core/src/java/org/apache/solr/cloud/autoscaling/ComputePlanAction.java
@@ -209,7 +209,7 @@ public class ComputePlanAction extends TriggerActionBase {
         }
         break;
       case SCHEDULED:
-        String preferredOp = (String) event.getProperty(AutoScalingParams.PREFERRED_OP);
+        String preferredOp = (String) event.getProperty(AutoScalingParams.PREFERRED_OP, CollectionParams.CollectionAction.MOVEREPLICA.toLower());
         CollectionParams.CollectionAction action = CollectionParams.CollectionAction.get(preferredOp);
         suggester = session.getSuggester(action);
         break;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9cec2221/solr/core/src/java/org/apache/solr/cloud/autoscaling/ScheduledTrigger.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/autoscaling/ScheduledTrigger.java b/solr/core/src/java/org/apache/solr/cloud/autoscaling/ScheduledTrigger.java
index 9c8ee6d..1aa7a0a 100644
--- a/solr/core/src/java/org/apache/solr/cloud/autoscaling/ScheduledTrigger.java
+++ b/solr/core/src/java/org/apache/solr/cloud/autoscaling/ScheduledTrigger.java
@@ -33,7 +33,6 @@ import java.util.TimeZone;
 import org.apache.solr.client.solrj.cloud.autoscaling.SolrCloudManager;
 import org.apache.solr.client.solrj.cloud.autoscaling.TriggerEventType;
 import org.apache.solr.common.SolrException;
-import org.apache.solr.common.params.CollectionParams;
 import org.apache.solr.core.SolrResourceLoader;
 import org.apache.solr.util.DateMathParser;
 import org.apache.solr.util.TimeZoneUtils;
@@ -49,6 +48,7 @@ public class ScheduledTrigger extends TriggerBase {
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   private static final String DEFAULT_GRACE_DURATION = "+15MINUTES";
+  private static final String LAST_RUN_AT = "lastRunAt";
   static final String ACTUAL_EVENT_TIME = "actualEventTime";
 
   private final String everyStr;
@@ -72,13 +72,18 @@ public class ScheduledTrigger extends TriggerBase {
     this.everyStr = (String) properties.get("every");
     this.graceDurationStr = (String) properties.getOrDefault("graceDuration", DEFAULT_GRACE_DURATION);
 
-    preferredOp = (String) properties.getOrDefault(PREFERRED_OP, CollectionParams.CollectionAction.MOVEREPLICA.toLower());
+    preferredOp = (String) properties.get(PREFERRED_OP);
 
     // attempt parsing to validate date math strings
     Instant startTime = parseStartTime(startTimeStr, timeZoneStr);
     DateMathParser.parseMath(null, startTime + everyStr, timeZone);
     DateMathParser.parseMath(null, startTime + graceDurationStr, timeZone);
 
+    // We set lastRunAt to be the startTime (which could be a date math expression such as 'NOW')
+    // Ordinarily, NOW will always be evaluated in this constructor so it may seem that
+    // the trigger will always fire the first time.
+    // However, the lastRunAt is overwritten with the value from ZK
+    // during restoreState() operation (which is performed before run()) so the trigger works correctly
     this.lastRunAt = startTime;
   }
 
@@ -107,13 +112,13 @@ public class ScheduledTrigger extends TriggerBase {
 
   @Override
   protected Map<String, Object> getState() {
-    return Collections.singletonMap("lastRunAt", lastRunAt.toEpochMilli());
+    return Collections.singletonMap(LAST_RUN_AT, lastRunAt.toEpochMilli());
   }
 
   @Override
   protected void setState(Map<String, Object> state) {
-    if (state.containsKey("lastRunAt")) {
-      this.lastRunAt = Instant.ofEpochMilli((Long) state.get("lastRunAt"));
+    if (state.containsKey(LAST_RUN_AT)) {
+      this.lastRunAt = Instant.ofEpochMilli((Long) state.get(LAST_RUN_AT));
     }
   }
 
@@ -163,8 +168,10 @@ public class ScheduledTrigger extends TriggerBase {
         log.warn("ScheduledTrigger was not able to run event at scheduled time: {}. Now: {}",
             nextRunTime, now);
       }
-      if (processor.process(new ScheduledEvent(getEventType(), getName(), nextRunTime.toEpochMilli(),
-          preferredOp, now.toEpochMilli(), true)))  {
+      // Even though we are skipping the event, we need to notify any listeners of the IGNORED stage
+      // so we create a dummy event with the ignored=true flag and ScheduledTriggers will do the rest
+      if (processor != null && processor.process(new ScheduledEvent(getEventType(), getName(), nextRunTime.toEpochMilli(),
+          preferredOp, now.toEpochMilli(), true))) {
         lastRunAt = nextRunTime;
         return;
       }
@@ -191,7 +198,9 @@ public class ScheduledTrigger extends TriggerBase {
 
     public ScheduledEvent(TriggerEventType eventType, String source, long eventTime, String preferredOp, long actualEventTime, boolean ignored) {
       super(eventType, source, eventTime, null, ignored);
-      properties.put(PREFERRED_OP, preferredOp);
+      if (preferredOp != null)  {
+        properties.put(PREFERRED_OP, preferredOp);
+      }
       properties.put(ACTUAL_EVENT_TIME, actualEventTime);
     }
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9cec2221/solr/solr-ref-guide/src/solrcloud-autoscaling-triggers.adoc
----------------------------------------------------------------------
diff --git a/solr/solr-ref-guide/src/solrcloud-autoscaling-triggers.adoc b/solr/solr-ref-guide/src/solrcloud-autoscaling-triggers.adoc
index ec09a79..08e0085 100644
--- a/solr/solr-ref-guide/src/solrcloud-autoscaling-triggers.adoc
+++ b/solr/solr-ref-guide/src/solrcloud-autoscaling-triggers.adoc
@@ -159,7 +159,10 @@ The Scheduled trigger generates events according to a fixed rate schedule.
 
 The trigger supports the following configuration:
 
-* `startTime` - (string, required) the start date/time of the schedule. This should either be an ISO-8601 date time string (the same standard used during search and indexing in Solr, thus defaulting to UTC) or be specified with the `timeZone` parameter.
+* `startTime` - (string, required) the start date/time of the schedule. This should either be a DateMath string e.g. 'NOW' or be an ISO-8601 date time string (the same standard used during search and indexing in Solr, thus defaulting to UTC) or be specified without the trailing 'Z' accompanied with the `timeZone` parameter. For example, each of the following values are acceptable:
+  ** `2018-01-31T15:30:00Z` - ISO-8601 date time string. The trailing `Z` signals that the time is in UTC
+  ** `NOW+5MINUTES` - Solr's date math string
+  ** `2018-01-31T15:30:00` - No trailing 'Z' signals that the `timeZone` parameter must be specified to avoid ambiguity
 * `every` - (string, required) a positive Solr date math string which is added to the `startTime` or the last run time to arrive at the next scheduled time
 * `graceTime` - (string, optional) a positive Solr date math string. This is the additional grace time over the scheduled time within which the trigger is allowed to generate an event.
 * `timeZone` - (string, optional) a time zone string which is used for calculating the scheduled times