sv2000 commented on a change in pull request #2909: [GOBBLIN-1071] Retry task
initialization
URL: https://github.com/apache/incubator-gobblin/pull/2909#discussion_r388441943
##########
File path:
gobblin-cluster/src/main/java/org/apache/gobblin/cluster/SingleTask.java
##########
@@ -50,49 +54,74 @@
public class SingleTask {
private static final Logger _logger =
LoggerFactory.getLogger(SingleTask.class);
+ public static final String MAX_RETRY_WAITING_FOR_INIT_KEY =
"maxRetryBlockedOnTaskAttemptInit";
+ public static final int DEFAULT_MAX_RETRY_WAITING_FOR_INIT = 2;
- private GobblinMultiTaskAttempt _taskattempt;
+ private GobblinMultiTaskAttempt _taskAttempt;
private String _jobId;
private Path _workUnitFilePath;
private Path _jobStateFilePath;
private FileSystem _fs;
private TaskAttemptBuilder _taskAttemptBuilder;
private StateStores _stateStores;
private Config _dynamicConfig;
+ private List<WorkUnit> _workUnits;
+ private JobState _jobState;
+ // Preventing Helix calling cancel before taskAttempt is created
+ // Checking if taskAttempt is empty is not enough, since canceller runs in
different thread as runner, the case to
+ // to avoided here is taskAttempt being created and start to run after
cancel has been called.
+ private Condition _taskAttemptBuilt;
+ private Lock _lock;
+
+ /**
+ * Do all heavy-lifting of initialization in constructor which could be
retried if failed,
+ * see the example in {@link GobblinHelixTask}.
+ */
SingleTask(String jobId, Path workUnitFilePath, Path jobStateFilePath,
FileSystem fs,
- TaskAttemptBuilder taskAttemptBuilder, StateStores stateStores, Config
dynamicConfig) {
+ TaskAttemptBuilder taskAttemptBuilder, StateStores stateStores, Config
dynamicConfig) throws IOException {
_jobId = jobId;
_workUnitFilePath = workUnitFilePath;
_jobStateFilePath = jobStateFilePath;
_fs = fs;
_taskAttemptBuilder = taskAttemptBuilder;
_stateStores = stateStores;
_dynamicConfig = dynamicConfig;
+
+ _workUnits = getWorkUnits();
+ _jobState = getJobState();
+ _lock = new ReentrantLock();
+ _taskAttemptBuilt = _lock.newCondition();
}
public void run()
throws IOException, InterruptedException {
- List<WorkUnit> workUnits = getWorkUnits();
- JobState jobState = getJobState();
// Add dynamic configuration to the job state
- _dynamicConfig.entrySet().forEach(e -> jobState.setProp(e.getKey(),
e.getValue().unwrapped().toString()));
+ _dynamicConfig.entrySet().forEach(e -> _jobState.setProp(e.getKey(),
e.getValue().unwrapped().toString()));
- Config jobConfig = getConfigFromJobState(jobState);
+ Config jobConfig = getConfigFromJobState(_jobState);
_logger.debug("SingleTask.run: jobId {} workUnitFilePath {}
jobStateFilePath {} jobState {} jobConfig {}",
- _jobId, _workUnitFilePath, _jobStateFilePath, jobState, jobConfig);
+ _jobId, _workUnitFilePath, _jobStateFilePath, _jobState, jobConfig);
try (SharedResourcesBroker<GobblinScopeTypes> globalBroker =
SharedResourcesBrokerFactory
.createDefaultTopLevelBroker(jobConfig,
GobblinScopeTypes.GLOBAL.defaultScopeInstance())) {
- SharedResourcesBroker<GobblinScopeTypes> jobBroker =
getJobBroker(jobState, globalBroker);
+ SharedResourcesBroker<GobblinScopeTypes> jobBroker =
getJobBroker(_jobState, globalBroker);
+
+ // Secure atomicity of taskAttempt's execution.
+ _lock.lock();
+ try {
+ _taskAttempt = _taskAttemptBuilder.build(_workUnits.iterator(),
_jobId, _jobState, jobBroker);
+
_taskAttempt.runAndOptionallyCommitTaskAttempt(GobblinMultiTaskAttempt.CommitPolicy.IMMEDIATE);
+ _taskAttemptBuilt.signal();
Review comment:
How do we handle missed signals? Are we sure the thread waiting on the
signal is waiting?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services