umustafi commented on code in PR #3890:
URL: https://github.com/apache/gobblin/pull/3890#discussion_r1526722966
##########
gobblin-runtime/src/main/java/org/apache/gobblin/scheduler/SchedulerService.java:
##########
@@ -43,33 +43,40 @@
@Singleton
public class SchedulerService extends AbstractIdleService {
+ private StdSchedulerFactory schedulerFactory;
Review Comment:
It doesn't quite suffice bc we utilize the property of this implementation
which loads the quartz properties using the `initialize` method not provided in
the `org.quartz.SchedulerFactory` interface
https://www.quartz-scheduler.org/api/2.3.0/org/quartz/impl/StdSchedulerFactory.html
##########
gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/Orchestrator.java:
##########
@@ -230,15 +230,16 @@ public void orchestrate(Spec spec, Properties jobProps,
long triggerTimestampMil
Map<String, String> flowMetadata =
TimingEventUtils.getFlowMetadata(flowSpec);
String flowExecutionId =
String.valueOf(FlowUtils.getOrCreateFlowExecutionId(flowSpec));
+ // Note we use "" as jobName for lease arbitration since orchestration
is at a flow level
DagActionStore.DagAction flowAction =
- new DagActionStore.DagAction(flowGroup, flowName, flowExecutionId,
DagActionStore.FlowActionType.LAUNCH);
+ new DagActionStore.DagAction(flowGroup, flowName, flowExecutionId,
"", DagActionStore.DagActionType.LAUNCH);
// If multi-active scheduler is enabled do not pass onto DagManager,
otherwise scheduler forwards it directly
// Skip flow compilation as well, since we recompile after receiving
event from DagActionStoreChangeMonitor later
- if (flowTriggerHandler.isPresent()) {
+ if (flowTriggerDecorator.isPresent()) {
// Adopt consensus flowExecutionId for scheduled flows
- flowTriggerHandler.get().handleTriggerEvent(jobProps, flowAction,
triggerTimestampMillis, isReminderEvent,
+ flowTriggerDecorator.get().handleTriggerEvent(jobProps, flowAction,
triggerTimestampMillis, isReminderEvent,
Review Comment:
Updated to call class and method `FlowLaunchHandler` and
`handleFlowLaunchTrigger`
##########
gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/InstrumentedLeaseArbiter.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gobblin.service.modules.orchestration;
+
+import java.io.IOException;
+
+import com.typesafe.config.Config;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.gobblin.instrumented.Instrumented;
+import org.apache.gobblin.metrics.ContextAwareCounter;
+import org.apache.gobblin.metrics.ContextAwareMeter;
+import org.apache.gobblin.metrics.MetricContext;
+import org.apache.gobblin.metrics.ServiceMetricNames;
+import org.apache.gobblin.runtime.api.DagActionStore;
+import org.apache.gobblin.runtime.api.MultiActiveLeaseArbiter;
+import org.apache.gobblin.util.ConfigUtils;
+
+
+/*
+ A generic lease arbitration decorator built upon the {@link
MultiActiveLeaseArbiter} which encapsulates common
+ functionality desired by lease arbiter users to track metrics on all lease
attempts made by the arbiter. The metrics
+ can be used to compare relative performance among arbitration participants.
+ */
+@Slf4j
+public class InstrumentedLeaseArbiter implements MultiActiveLeaseArbiter {
+ protected MultiActiveLeaseArbiter decoratedMultiActiveLeaseArbiter;
+ @Getter
+ protected MetricContext metricContext;
+ private ContextAwareCounter leaseObtainedCount;
+
+ private ContextAwareCounter leasedToAnotherStatusCount;
+
+ private ContextAwareCounter noLongerLeasingStatusCount;
+ private ContextAwareMeter leasesObtainedDueToReminderCount;
+
+ public InstrumentedLeaseArbiter(Config config, MultiActiveLeaseArbiter
leaseDeterminationStore,
+ String metricsPrefix) {
+ this.decoratedMultiActiveLeaseArbiter = leaseDeterminationStore;
+ this.metricContext = Instrumented.getMetricContext(new
org.apache.gobblin.configuration.State(ConfigUtils.configToProperties(config)),
+ this.getClass());
+ initializeMetrics(metricsPrefix);
+ }
+
+ private void initializeMetrics(String metricsPrefix) {
+ // If a valid metrics prefix is provided then add a delimiter after it
+ if (!metricsPrefix.equals("")) {
+ metricsPrefix += ".";
+ }
+ this.leaseObtainedCount =
this.metricContext.contextAwareCounter(metricsPrefix +
ServiceMetricNames.FLOW_TRIGGER_HANDLER_LEASE_OBTAINED_COUNT);
+ this.leasedToAnotherStatusCount =
this.metricContext.contextAwareCounter(metricsPrefix +
ServiceMetricNames.FLOW_TRIGGER_HANDLER_LEASED_TO_ANOTHER_COUNT);
+ this.noLongerLeasingStatusCount =
this.metricContext.contextAwareCounter(metricsPrefix +
ServiceMetricNames.FLOW_TRIGGER_HANDLER_NO_LONGER_LEASING_COUNT);
+ this.leasesObtainedDueToReminderCount =
this.metricContext.contextAwareMeter(metricsPrefix +
ServiceMetricNames.FLOW_TRIGGER_HANDLER_LEASES_OBTAINED_DUE_TO_REMINDER_COUNT);
+ }
+
+ @Override
+ public MultiActiveLeaseArbiter.LeaseAttemptStatus
tryAcquireLease(DagActionStore.DagAction flowAction, long eventTimeMillis,
+ boolean isReminderEvent, boolean skipFlowExecutionIdReplacement) throws
IOException {
+
+ MultiActiveLeaseArbiter.LeaseAttemptStatus leaseAttemptStatus =
+ decoratedMultiActiveLeaseArbiter.tryAcquireLease(flowAction,
eventTimeMillis, isReminderEvent,
+ skipFlowExecutionIdReplacement);
+ log.info("Multi-active scheduler lease attempt for dagAction: {} received
type of leaseAttemptStatus: [{}, "
+ + "eventTimestamp: {}] ", flowAction,
leaseAttemptStatus.getClass().getName(), eventTimeMillis);
+ if (leaseAttemptStatus instanceof
MultiActiveLeaseArbiter.LeaseObtainedStatus) {
+ if (isReminderEvent) {
+ this.leasesObtainedDueToReminderCount.mark();
+ }
+ this.leaseObtainedCount.inc();
+ return leaseAttemptStatus;
+ } else if (leaseAttemptStatus instanceof
MultiActiveLeaseArbiter.LeasedToAnotherStatus) {
+ this.leasedToAnotherStatusCount.inc();
+ return leaseAttemptStatus;
+ } else if (leaseAttemptStatus instanceof
MultiActiveLeaseArbiter.NoLongerLeasingStatus) {
+ this.noLongerLeasingStatusCount.inc();
+ return leaseAttemptStatus;
+ }
+ throw new RuntimeException(String.format("Received type of
leaseAttemptStatus: %s not handled by this method",
+ leaseAttemptStatus.getClass().getName()));
+ }
+
+ @Override
+ public boolean recordLeaseSuccess(LeaseObtainedStatus status)
+ throws IOException {
+ return this.decoratedMultiActiveLeaseArbiter.recordLeaseSuccess(status);
Review Comment:
Moved metrics to this class
##########
gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/InstrumentedLeaseArbiter.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gobblin.service.modules.orchestration;
+
+import java.io.IOException;
+
+import com.typesafe.config.Config;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.gobblin.instrumented.Instrumented;
+import org.apache.gobblin.metrics.ContextAwareCounter;
+import org.apache.gobblin.metrics.ContextAwareMeter;
+import org.apache.gobblin.metrics.MetricContext;
+import org.apache.gobblin.metrics.ServiceMetricNames;
+import org.apache.gobblin.runtime.api.DagActionStore;
+import org.apache.gobblin.runtime.api.MultiActiveLeaseArbiter;
+import org.apache.gobblin.util.ConfigUtils;
+
+
+/*
+ A generic lease arbitration decorator built upon the {@link
MultiActiveLeaseArbiter} which encapsulates common
+ functionality desired by lease arbiter users to track metrics on all lease
attempts made by the arbiter. The metrics
+ can be used to compare relative performance among arbitration participants.
+ */
+@Slf4j
+public class InstrumentedLeaseArbiter implements MultiActiveLeaseArbiter {
+ protected MultiActiveLeaseArbiter decoratedMultiActiveLeaseArbiter;
+ @Getter
+ protected MetricContext metricContext;
+ private ContextAwareCounter leaseObtainedCount;
+
+ private ContextAwareCounter leasedToAnotherStatusCount;
+
+ private ContextAwareCounter noLongerLeasingStatusCount;
+ private ContextAwareMeter leasesObtainedDueToReminderCount;
+
+ public InstrumentedLeaseArbiter(Config config, MultiActiveLeaseArbiter
leaseDeterminationStore,
+ String metricsPrefix) {
+ this.decoratedMultiActiveLeaseArbiter = leaseDeterminationStore;
+ this.metricContext = Instrumented.getMetricContext(new
org.apache.gobblin.configuration.State(ConfigUtils.configToProperties(config)),
+ this.getClass());
+ initializeMetrics(metricsPrefix);
+ }
+
+ private void initializeMetrics(String metricsPrefix) {
+ // If a valid metrics prefix is provided then add a delimiter after it
+ if (!metricsPrefix.equals("")) {
+ metricsPrefix += ".";
+ }
+ this.leaseObtainedCount =
this.metricContext.contextAwareCounter(metricsPrefix +
ServiceMetricNames.FLOW_TRIGGER_HANDLER_LEASE_OBTAINED_COUNT);
+ this.leasedToAnotherStatusCount =
this.metricContext.contextAwareCounter(metricsPrefix +
ServiceMetricNames.FLOW_TRIGGER_HANDLER_LEASED_TO_ANOTHER_COUNT);
+ this.noLongerLeasingStatusCount =
this.metricContext.contextAwareCounter(metricsPrefix +
ServiceMetricNames.FLOW_TRIGGER_HANDLER_NO_LONGER_LEASING_COUNT);
+ this.leasesObtainedDueToReminderCount =
this.metricContext.contextAwareMeter(metricsPrefix +
ServiceMetricNames.FLOW_TRIGGER_HANDLER_LEASES_OBTAINED_DUE_TO_REMINDER_COUNT);
+ }
+
+ @Override
+ public MultiActiveLeaseArbiter.LeaseAttemptStatus
tryAcquireLease(DagActionStore.DagAction flowAction, long eventTimeMillis,
+ boolean isReminderEvent, boolean skipFlowExecutionIdReplacement) throws
IOException {
+
+ MultiActiveLeaseArbiter.LeaseAttemptStatus leaseAttemptStatus =
+ decoratedMultiActiveLeaseArbiter.tryAcquireLease(flowAction,
eventTimeMillis, isReminderEvent,
+ skipFlowExecutionIdReplacement);
+ log.info("Multi-active scheduler lease attempt for dagAction: {} received
type of leaseAttemptStatus: [{}, "
+ + "eventTimestamp: {}] ", flowAction,
leaseAttemptStatus.getClass().getName(), eventTimeMillis);
Review Comment:
So the logging should be moved to the DagProc/FlowTrigger arbiters? In
`MysqlMALA` we don't have this particular logging around the result of a lease
attempt
##########
gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/proc/LaunchDagProc.java:
##########
@@ -193,6 +193,14 @@ private void submitJobToExecutor(DagManagementStateStore
dagManagementStateStore
}
@Override
+ protected void commit(DagManagementStateStore dagManagementStateStore,
Optional<Dag<JobExecutionPlan>> dag) {
+ try {
+ this.launchDagTask.getLeaseObtainedStatus().completeLease();
Review Comment:
moved it to `DagTask::conclude`. If additional work needed for each type of
task we can override
##########
gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/DagManagementTaskStreamImpl.java:
##########
@@ -83,16 +84,14 @@ public boolean hasNext() {
@Override
public DagTask next() {
try {
- DagActionStore.DagAction dagAction = this.dagActionQueue.take();
//`take` blocks till element is not available
- // todo reconsider the use of MultiActiveLeaseArbiter
- //MultiActiveLeaseArbiter.LeaseAttemptStatus leaseAttemptStatus = new
MultiActiveLeaseArbiter.LeaseObtainedStatus(dagAction);
- // todo - uncomment after flow trigger handler provides such an api
- //Properties jobProps = getJobProperties(dagAction);
- //flowTriggerHandler.getLeaseOnDagAction(jobProps, dagAction,
System.currentTimeMillis());
- //if (leaseAttemptStatus instanceof
MultiActiveLeaseArbiter.LeaseObtainedStatus) {
- // can it return null? is this iterator allowed to return null?
- return createDagTask(dagAction, new
MultiActiveLeaseArbiter.LeaseObtainedStatus(dagAction,
System.currentTimeMillis()));
- //}
+ MultiActiveLeaseArbiter.LeaseAttemptStatus leaseAttemptStatus = null;
+ DagActionStore.DagAction dagAction = null;
+// while (!(leaseAttemptStatus instanceof
MultiActiveLeaseArbiter.LeaseObtainedStatus)) {
+ dagAction = this.dagActionQueue.take(); //`take` blocks till element
is not available
+// multiActiveLeaseArbiter.tryAcquireLease(dagAction);
+// }
+
+ return createDagTask(dagAction,
(MultiActiveLeaseArbiter.LeaseObtainedStatus) leaseAttemptStatus);
Review Comment:
Good pt, I uncommented the while loop even though I have not setup the guice
initialization correctly.
##########
gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/ReminderSettingDagProcLeaseArbiter.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gobblin.service.modules.orchestration;
+
+import java.io.IOException;
+import java.util.Date;
+
+import org.quartz.Job;
+import org.quartz.JobBuilder;
+import org.quartz.JobDataMap;
+import org.quartz.JobDetail;
+import org.quartz.JobExecutionContext;
+import org.quartz.SchedulerException;
+import org.quartz.Trigger;
+import org.quartz.TriggerBuilder;
+
+import com.typesafe.config.Config;
+
+import javax.inject.Inject;
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.gobblin.configuration.ConfigurationKeys;
+import org.apache.gobblin.runtime.api.DagActionStore;
+import org.apache.gobblin.runtime.api.MultiActiveLeaseArbiter;
+
+
+/**
+ * Decorator used to coordinate multiple hosts with execution components
enabled to respond to flow action events with
+ * added capabilities to properly handle the result of attempted ownership
over these flow action events. It uses the
+ * {@link MultiActiveLeaseArbiter} to determine a single lease owner at a
given event time for a flow action event.
+ * After acquiring the lease, the host can pursue executing the action. Once
it has completed this action, it
+ * marks the lease as completed by calling the
+ * {@link
MultiActiveLeaseArbiter#recordLeaseSuccess(MultiActiveLeaseArbiter.LeaseObtainedStatus)}
method. Hosts
+ * that fail to acquire a lease will use the {@link
DagActionReminderScheduler} to set a reminder for the flow action
+ * event to check back in on the previous lease owner's completion status.
+ */
+@Slf4j
+public class ReminderSettingDagProcLeaseArbiter implements
MultiActiveLeaseArbiter {
+ private final MultiActiveLeaseArbiter decoratedLeaseArbiter;
+ private final DagActionReminderScheduler _dagActionReminderScheduler;
+ private final Config config;
+
+ @Inject
+ public ReminderSettingDagProcLeaseArbiter(Config config,
MultiActiveLeaseArbiter leaseArbiter, DagActionReminderScheduler
dagActionReminderScheduler) throws IOException {
+ this.decoratedLeaseArbiter = leaseArbiter;
+ this._dagActionReminderScheduler = dagActionReminderScheduler;
+ this.config = config;
+ }
+
+ /**
+ * This method is used by the multi-active scheduler and multi-active
execution classes (DagTaskStream) to attempt a
+ * lease for a particular job event and return the status of the attempt.
+ * @param flowAction
+ * @param eventTimeMillis
+ * @param isReminderEvent
+ * @param skipFlowExecutionIdReplacement
+ * @return
+ */
+ @Override
+ public MultiActiveLeaseArbiter.LeaseAttemptStatus
tryAcquireLease(DagActionStore.DagAction flowAction, long eventTimeMillis,
+ boolean isReminderEvent, boolean skipFlowExecutionIdReplacement) {
+ try {
+ MultiActiveLeaseArbiter.LeaseAttemptStatus leaseAttemptStatus =
this.tryAcquireLease(flowAction, eventTimeMillis, isReminderEvent,
skipFlowExecutionIdReplacement);
+ /* Schedule a reminder for the event unless the lease has been completed
to safeguard against case lease owner
+ fails to complete lease
+ */
+ if (leaseAttemptStatus instanceof
MultiActiveLeaseArbiter.LeaseObtainedStatus) {
+ scheduleReminderForEvent((LeaseObtainedStatus) leaseAttemptStatus);
+ } else if (leaseAttemptStatus instanceof
MultiActiveLeaseArbiter.LeasedToAnotherStatus) {
+ scheduleReminderForEvent((LeasedToAnotherStatus) leaseAttemptStatus);
+ }
+ return leaseAttemptStatus;
+ } catch (SchedulerException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public boolean recordLeaseSuccess(LeaseObtainedStatus status)
+ throws IOException {
+ return this.decoratedLeaseArbiter.recordLeaseSuccess(status);
+ }
+
+ protected void
scheduleReminderForEvent(MultiActiveLeaseArbiter.LeasedToAnotherStatus
leaseStatus)
+ throws SchedulerException {
+ _dagActionReminderScheduler.scheduleReminder(leaseStatus.getDagAction(),
leaseStatus.getMinimumLingerDurationMillis());
+ }
+
+ protected void
scheduleReminderForEvent(MultiActiveLeaseArbiter.LeaseObtainedStatus
leaseStatus)
+ throws SchedulerException {
+ _dagActionReminderScheduler.scheduleReminder(leaseStatus.getDagAction(),
leaseStatus.getMinimumLingerDurationMillis());
+ }
+
+ @Slf4j
+ public static class ReminderJob implements Job {
+ public static final String FLOW_ACTION_TYPE_KEY = "flow.actionType";
+ public static final String DAG_MANAGEMENT_KEY = "dag.management";
+
+ @Override
+ public void execute(JobExecutionContext context) {
+ // Get properties from the trigger to create a dagAction
+ JobDataMap jobDataMap = context.getTrigger().getJobDataMap();
+ String flowName = jobDataMap.getString(ConfigurationKeys.FLOW_NAME_KEY);
+ String flowGroup =
jobDataMap.getString(ConfigurationKeys.FLOW_GROUP_KEY);
+ String jobName = jobDataMap.getString(ConfigurationKeys.JOB_NAME_KEY);
+ String flowId =
jobDataMap.getString(ConfigurationKeys.FLOW_EXECUTION_ID_KEY);
+ DagActionStore.DagActionType dagActionType =
DagActionStore.DagActionType.valueOf(
+ jobDataMap.getString(FLOW_ACTION_TYPE_KEY));
+ DagManagement dagManagement = (DagManagement)
jobDataMap.get(DAG_MANAGEMENT_KEY);
Review Comment:
It's already a singleton class but the issue lies in `ReminderJob` class &
methods being static so there's no reference to `DagManagement ` passed directly
##########
gobblin-runtime/src/main/java/org/apache/gobblin/runtime/api/MysqlMultiActiveLeaseArbiter.java:
##########
@@ -489,78 +492,81 @@ protected static SelectInfoResult
createSelectInfoResult(ResultSet resultSet) th
* @throws IOException
*/
protected LeaseAttemptStatus evaluateStatusAfterLeaseAttempt(int
numRowsUpdated,
- DagActionStore.DagAction flowAction, Optional<Timestamp>
dbCurrentTimestamp, boolean isReminderEvent,
+ DagActionStore.DagAction dagAction, Optional<Timestamp>
dbCurrentTimestamp, boolean isReminderEvent,
boolean adoptConsensusFlowExecutionId)
throws SQLException, IOException {
// Fetch values in row after attempted insert
- SelectInfoResult selectInfoResult = getRowInfo(flowAction);
+ SelectInfoResult selectInfoResult = getRowInfo(dagAction);
// Another participant won the lease in between
if (!selectInfoResult.getLeaseAcquisitionTimeMillis().isPresent()) {
return new NoLongerLeasingStatus();
}
- DagActionStore.DagAction updatedFlowAction =
- adoptConsensusFlowExecutionId ?
flowAction.updateFlowExecutionId(selectInfoResult.eventTimeMillis) : flowAction;
+ DagActionStore.DagAction updatedDagAction =
+ adoptConsensusFlowExecutionId ?
dagAction.updateFlowExecutionId(selectInfoResult.eventTimeMillis) : dagAction;
+ long minimumLingerDurationMillis =
selectInfoResult.getLeaseAcquisitionTimeMillis().get() +
selectInfoResult.getDbLinger()
+ - (dbCurrentTimestamp.isPresent() ? dbCurrentTimestamp.get().getTime()
: System.currentTimeMillis());
Review Comment:
I agree, we use `CURRENT_TIMESTAMP` if there's an existing row in the db.
When there is no existing row to match the lease we don't retrieve any values
presently so we don't retrieve current ts so could probably just return
`selectInfoResult.getDbLinger()` instead of subtracting any time from the
previous lease time. What do you think of that change?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]