-
Notifications
You must be signed in to change notification settings - Fork 751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GOBBLIN-2173] Avoid Adhoc flow spec addition for non leasable entity #4076
Changes from 7 commits
618f357
3fa68a1
30929f8
a782202
0981b82
7d2b49f
01cac22
b596948
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.runtime.api; | ||
|
||
import lombok.Getter; | ||
|
||
|
||
/** | ||
* An {@link RuntimeException} thrown when lease cannot be acquired on provided entity. | ||
*/ | ||
public class TooSoonToRerunSameFlowException extends RuntimeException { | ||
@Getter | ||
private final FlowSpec flowSpec; | ||
|
||
/** | ||
* Account for unwrapping within @{link FlowCatalog#updateOrAddSpecHelper}`s `CallbackResult` error handling for `SpecCatalogListener`s | ||
* @return `TooSoonToRerunSameFlowException` wrapped in another `TooSoonToRerunSameFlowException | ||
*/ | ||
public static TooSoonToRerunSameFlowException wrappedOnce(FlowSpec flowSpec) { | ||
return new TooSoonToRerunSameFlowException(flowSpec, new TooSoonToRerunSameFlowException(flowSpec)); | ||
} | ||
|
||
public TooSoonToRerunSameFlowException(FlowSpec flowSpec) { | ||
super("Lease already occupied by another recent execution of this flow: " + flowSpec); | ||
this.flowSpec = flowSpec; | ||
} | ||
|
||
/** restricted-access ctor: use {@link #wrappedOnce(FlowSpec)} instead */ | ||
private TooSoonToRerunSameFlowException(FlowSpec flowSpec, Throwable cause) { | ||
super("Lease already occupied by another recent execution of this flow: " + flowSpec, cause); | ||
this.flowSpec = flowSpec; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ | |
import org.apache.gobblin.runtime.api.SpecCatalogListener; | ||
import org.apache.gobblin.runtime.api.SpecProducer; | ||
import org.apache.gobblin.runtime.api.TopologySpec; | ||
import org.apache.gobblin.runtime.api.TooSoonToRerunSameFlowException; | ||
import org.apache.gobblin.runtime.spec_catalog.AddSpecResponse; | ||
import org.apache.gobblin.runtime.spec_catalog.TopologyCatalog; | ||
import org.apache.gobblin.service.modules.flow.FlowUtils; | ||
|
@@ -78,6 +79,7 @@ public class Orchestrator implements SpecCatalogListener, Instrumentable { | |
protected final SpecCompiler specCompiler; | ||
protected final TopologyCatalog topologyCatalog; | ||
private final JobStatusRetriever jobStatusRetriever; | ||
private final DagManagementStateStore dagManagementStateStore; | ||
|
||
protected final MetricContext metricContext; | ||
|
||
|
@@ -100,6 +102,7 @@ public Orchestrator(Config config, TopologyCatalog topologyCatalog, Optional<Log | |
this.topologyCatalog = topologyCatalog; | ||
this.flowLaunchHandler = flowLaunchHandler; | ||
this.sharedFlowMetricsSingleton = sharedFlowMetricsSingleton; | ||
this.dagManagementStateStore = dagManagementStateStore; | ||
this.jobStatusRetriever = jobStatusRetriever; | ||
this.specCompiler = flowCompilationValidationHelper.getSpecCompiler(); | ||
// todo remove the need to set topology factory outside of constructor GOBBLIN-2056 | ||
|
@@ -125,6 +128,7 @@ public AddSpecResponse onAddSpec(Spec addedSpec) { | |
_log.info("Orchestrator - onAdd[Topology]Spec: " + addedSpec); | ||
this.specCompiler.onAddSpec(addedSpec); | ||
} else if (addedSpec instanceof FlowSpec) { | ||
enforceNoRecentAdhocExecOfSameFlow((FlowSpec) addedSpec); | ||
_log.info("Orchestrator - onAdd[Flow]Spec: " + addedSpec); | ||
return this.specCompiler.onAddSpec(addedSpec); | ||
} else { | ||
|
@@ -133,6 +137,29 @@ public AddSpecResponse onAddSpec(Spec addedSpec) { | |
return new AddSpecResponse<>(null); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just an FYI, this also gets called during updating a flow. But since we have a condition of checking the flow is scheduled or not and we don't expect users to update an adhoc flow, we should be fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But since this can still be called for adhoc flows, it would be good to test what the behaviour is. No need to handle it specially, but to know what the behaviour is would be good. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the callout, will add it for the test suite |
||
|
||
/* | ||
enforces that a similar adhoc flow is not launching, | ||
else throw {@link TooSoonToRerunSameFlowException} | ||
*/ | ||
private void enforceNoRecentAdhocExecOfSameFlow(FlowSpec flowSpec) { | ||
if (!flowSpec.isScheduled()) { | ||
Config flowConfig = flowSpec.getConfig(); | ||
String flowGroup = flowConfig.getString(ConfigurationKeys.FLOW_GROUP_KEY); | ||
String flowName = flowConfig.getString(ConfigurationKeys.FLOW_NAME_KEY); | ||
|
||
_log.info("Checking existing adhoc flow entry for " + flowGroup + "." + flowName); | ||
try { | ||
if (dagManagementStateStore.existsCurrentlyLaunchingExecOfSameFlow(flowGroup, flowName, FlowUtils.getOrCreateFlowExecutionId(flowSpec))) { | ||
_log.warn("Another recent adhoc flow execution found for " + flowGroup + "." + flowName); | ||
throw TooSoonToRerunSameFlowException.wrappedOnce(flowSpec); | ||
} | ||
} catch (IOException exception) { | ||
_log.error("Unable to check whether similar flow exists " + flowGroup + "." + flowName); | ||
throw new RuntimeException("Unable to check whether similar flow exists " + flowGroup + "." + flowName, exception); | ||
} | ||
} | ||
} | ||
|
||
public void onDeleteSpec(URI deletedSpecURI, String deletedSpecVersion) { | ||
onDeleteSpec(deletedSpecURI, deletedSpecVersion, new Properties()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated javadoc