phet commented on code in PR #3896: URL: https://github.com/apache/gobblin/pull/3896#discussion_r1550086560
########## gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/proc/ReevaluateDagProc.java: ########## @@ -0,0 +1,194 @@ +/* + * 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.proc; + +import java.io.IOException; +import java.util.Optional; +import java.util.Set; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; + +import lombok.extern.slf4j.Slf4j; + +import org.apache.gobblin.metrics.event.TimingEvent; +import org.apache.gobblin.service.ExecutionStatus; +import org.apache.gobblin.service.modules.flowgraph.Dag; +import org.apache.gobblin.service.modules.flowgraph.DagNodeId; +import org.apache.gobblin.service.modules.orchestration.DagManagementStateStore; +import org.apache.gobblin.service.modules.orchestration.DagManagerUtils; +import org.apache.gobblin.service.modules.orchestration.task.ReevaluateDagTask; +import org.apache.gobblin.service.modules.spec.JobExecutionPlan; +import org.apache.gobblin.service.monitoring.FlowStatusGenerator; +import org.apache.gobblin.service.monitoring.JobStatus; + + +/** + * An implementation for {@link DagProc} that launches a new job if there exists a job whose pre-requisite jobs are + * completed successfully. If there are no more jobs to run and no job is running for the Dag, it cleans up the Dag. + * (In future), if there are multiple new jobs to be launched, separate launch dag actions are created for each of them. + */ +@Slf4j +public class ReevaluateDagProc extends DagProc<Pair<Optional<Dag.DagNode<JobExecutionPlan>>, Optional<JobStatus>>> { + + public ReevaluateDagProc(ReevaluateDagTask reEvaluateDagTask) { + super(reEvaluateDagTask); + } + + @Override + protected Pair<Optional<Dag.DagNode<JobExecutionPlan>>, Optional<JobStatus>> initialize(DagManagementStateStore dagManagementStateStore) + throws IOException { + Pair<Optional<Dag.DagNode<JobExecutionPlan>>, Optional<JobStatus>> dagNodeWithJobStatus = + dagManagementStateStore.getDagNodeWithJobStatus(this.dagNodeId); + + if (!dagNodeWithJobStatus.getLeft().isPresent() || !dagNodeWithJobStatus.getRight().isPresent()) { + // this is possible when MALA malfunctions and a duplicated reevaluate dag proc is launched for a dag node that is + // already "reevaluated" and cleaned up. + return ImmutablePair.of(Optional.empty(), Optional.empty()); + } + + ExecutionStatus executionStatus = ExecutionStatus.valueOf(dagNodeWithJobStatus.getRight().get().getEventName()); + if (!FlowStatusGenerator.FINISHED_STATUSES.contains(executionStatus.name())) { + log.warn("Job status for dagNode {} is {}. Re-evaluate dag action should have been created only for finished status - {}", + dagNodeId, executionStatus, FlowStatusGenerator.FINISHED_STATUSES); + return ImmutablePair.of(Optional.empty(), Optional.empty()); + } + + setStatus(dagManagementStateStore, dagNodeWithJobStatus.getLeft().get(), executionStatus); + return dagNodeWithJobStatus; + } + + @Override + protected void act(DagManagementStateStore dagManagementStateStore, Pair<Optional<Dag.DagNode<JobExecutionPlan>>, Optional<JobStatus>> dagNodeWithJobStatus) + throws IOException { + if (!dagNodeWithJobStatus.getLeft().isPresent()) { + log.error("DagNode or its job status not found for a Reevaluate DagAction with dag node id {}", this.dagNodeId); + return; Review Comment: I agree with logging at `ERROR`, also to still `return`, rather than throwing. given the severity, I suggest further to increment a metric for us to alert on. in addition, let's please add a code comment to capture the understanding for maintainers. did you say this arises when the MALA leasing doesn't work cleanly and another `DagProc::process` has cleaned up the Dag, yet did not complete the lease before this current one acquired its own? -- 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]
