sv2000 commented on a change in pull request #2919: [GOBBLIN-1078] Coordination 
between task cancel and initialization in Helix Task
URL: https://github.com/apache/incubator-gobblin/pull/2919#discussion_r404242206
 
 

 ##########
 File path: 
gobblin-cluster/src/main/java/org/apache/gobblin/cluster/SingleTask.java
 ##########
 @@ -164,16 +192,31 @@ protected JobState getJobState()
   }
 
   public void cancel() {
-    if (_taskAttempt != null) {
+    int retryCount = 0 ;
+    int maxRetry = ConfigUtils.getInt(_dynamicConfig, 
MAX_RETRY_WAITING_FOR_INIT_KEY, DEFAULT_MAX_RETRY_WAITING_FOR_INIT);
+
+    try {
+      _lock.lock();
       try {
+        while (_taskAttempt == null) {
+          // await return false if timeout on this around
+          if (!_taskAttemptBuilt.await(5, TimeUnit.SECONDS) && ++retryCount > 
maxRetry) {
+            throw new IllegalStateException("Failed to initialize taskAttempt 
object before cancel");
+          }
+        }
+      } finally {
+        _lock.unlock();
+      }
+
+      if (_taskAttempt != null) {
         _logger.info("Task cancelled: Shutdown starting for tasks with jobId: 
{}", _jobId);
         _taskAttempt.shutdownTasks();
         _logger.info("Task cancelled: Shutdown complete for tasks with jobId: 
{}", _jobId);
-      } catch (InterruptedException e) {
-        throw new RuntimeException("Interrupted while shutting down task with 
jobId: " + _jobId, e);
+      } else {
+        throw new IllegalStateException("This should never happen: TaskAttempt 
not initialized while passing conditional barrier");
 
 Review comment:
   Drop "This should never happen" from the message.

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

Reply via email to