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.

This commit is contained in:
Shalin Shekhar Mangar 2018-03-06 21:27:05 +05:30
parent 122271f28d
commit 9cec2221a6
3 changed files with 22 additions and 10 deletions

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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