This is an automated email from the ASF dual-hosted git repository.

wonook pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nemo.git


The following commit(s) were added to refs/heads/master by this push:
     new 033d814  [NEMO-38] Fix bugs and vulnerabilities for RuntimeMaster and 
RuntimeCommon (#14)
033d814 is described below

commit 033d814d7c0426e6e44b2e031e0bfc5be1dd37e0
Author: JangHo Seo <[email protected]>
AuthorDate: Thu Apr 5 12:47:25 2018 +0900

    [NEMO-38] Fix bugs and vulnerabilities for RuntimeMaster and RuntimeCommon 
(#14)
    
    JIRA: [NEMO-38: SonarCloud Bugs and Vulnerabilities for RuntimeMaster and 
RuntimeCommon](https://issues.apache.org/jira/projects/NEMO/issues/NEMO-38)
    
    **Major changes:**
    - None
    
    **Minor changes to note:**
    - Add `Thread.currentThread().interrupt();` to InterruptedException handlers
    - NcsMessageContext: Suppress false positive Sonar warning (squid:S2095)
    - JobStateManager: Check return value of `Condition#await(timeout, unit)`
    - JobStateManager: Use try-with-resources for PrintWriter
    - SingleJobTaskGroupCollection: Resolve false positives
    
    **Tests for the changes:**
    - None
    
    **Other comments:**
    - None
    
    resolves 
[NEMO-38](https://issues.apache.org/jira/projects/NEMO/issues/NEMO-38)
---
 .../nemo/runtime/common/message/ncs/NcsMessageContext.java |  6 ++++--
 .../java/edu/snu/nemo/runtime/master/JobStateManager.java  | 12 +++++++-----
 .../snu/nemo/runtime/master/scheduler/SchedulerRunner.java |  1 +
 .../master/scheduler/SingleJobTaskGroupCollection.java     | 14 ++++++++------
 4 files changed, 20 insertions(+), 13 deletions(-)

diff --git 
a/runtime/common/src/main/java/edu/snu/nemo/runtime/common/message/ncs/NcsMessageContext.java
 
b/runtime/common/src/main/java/edu/snu/nemo/runtime/common/message/ncs/NcsMessageContext.java
index 7daec35..0a71d71 100644
--- 
a/runtime/common/src/main/java/edu/snu/nemo/runtime/common/message/ncs/NcsMessageContext.java
+++ 
b/runtime/common/src/main/java/edu/snu/nemo/runtime/common/message/ncs/NcsMessageContext.java
@@ -47,15 +47,17 @@ final class NcsMessageContext implements MessageContext {
   }
 
   @Override
+  @SuppressWarnings("squid:S2095")
   public <U> void reply(final U replyMessage) {
     LOG.debug("[REPLY]: {}", replyMessage);
     final Connection connection = 
connectionFactory.newConnection(idFactory.getNewInstance(senderId));
     try {
       connection.open();
+      connection.write(replyMessage);
+      // We do not call connection.close since NCS caches connection.
+      // Disabling Sonar warning (squid:S2095)
     } catch (final NetworkException e) {
       throw new RuntimeException("Cannot connect to " + senderId, e);
     }
-
-    connection.write(replyMessage);
   }
 }
diff --git 
a/runtime/master/src/main/java/edu/snu/nemo/runtime/master/JobStateManager.java 
b/runtime/master/src/main/java/edu/snu/nemo/runtime/master/JobStateManager.java
index 7f1dc91..6e0877e 100644
--- 
a/runtime/master/src/main/java/edu/snu/nemo/runtime/master/JobStateManager.java
+++ 
b/runtime/master/src/main/java/edu/snu/nemo/runtime/master/JobStateManager.java
@@ -372,6 +372,7 @@ public final class JobStateManager {
       }
     } catch (final InterruptedException e) {
       LOG.warn("Interrupted during waiting the finish of Job ID {}", jobId);
+      Thread.currentThread().interrupt();
     } finally {
       finishLock.unlock();
     }
@@ -390,10 +391,13 @@ public final class JobStateManager {
     finishLock.lock();
     try {
       if (!checkJobTermination()) {
-        jobFinishedCondition.await(timeout, unit);
+        if (!jobFinishedCondition.await(timeout, unit)) {
+          LOG.warn("Timeout during waiting the finish of Job ID {}", jobId);
+        }
       }
     } catch (final InterruptedException e) {
       LOG.warn("Interrupted during waiting the finish of Job ID {}", jobId);
+      Thread.currentThread().interrupt();
     } finally {
       finishLock.unlock();
     }
@@ -466,13 +470,11 @@ public final class JobStateManager {
 
     final File file = new File(directory, jobId + "-" + suffix + ".json");
     file.getParentFile().mkdirs();
-    try {
-      final PrintWriter printWriter = new PrintWriter(file);
+    try (final PrintWriter printWriter = new PrintWriter(file)) {
       printWriter.println(toStringWithPhysicalPlan());
-      printWriter.close();
       LOG.debug(String.format("JSON representation of job state for %s(%s) was 
saved to %s",
           jobId, suffix, file.getPath()));
-    } catch (IOException e) {
+    } catch (final IOException e) {
       LOG.warn(String.format("Cannot store JSON representation of job state 
for %s(%s) to %s: %s",
           jobId, suffix, file.getPath(), e.toString()));
     }
diff --git 
a/runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/SchedulerRunner.java
 
b/runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/SchedulerRunner.java
index 6806d74..4e08467 100644
--- 
a/runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/SchedulerRunner.java
+++ 
b/runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/SchedulerRunner.java
@@ -187,6 +187,7 @@ public final class SchedulerRunner {
         }
         hasDelayedSignal.set(false);
       } catch (final InterruptedException e) {
+        Thread.currentThread().interrupt();
         throw new RuntimeException(e);
       } finally {
         lock.unlock();
diff --git 
a/runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/SingleJobTaskGroupCollection.java
 
b/runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/SingleJobTaskGroupCollection.java
index 51c5db7..7300531 100644
--- 
a/runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/SingleJobTaskGroupCollection.java
+++ 
b/runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/SingleJobTaskGroupCollection.java
@@ -142,8 +142,9 @@ public final class SingleJobTaskGroupCollection implements 
PendingTaskGroupColle
    * @param stageId for the stage to begin the removal recursively.
    */
   private synchronized void removeStageAndChildren(final String stageId) {
-    schedulableStages.remove(stageId);
-    stageIdToPendingTaskGroups.remove(stageId);
+    if (schedulableStages.remove(stageId)) {
+      stageIdToPendingTaskGroups.remove(stageId);
+    }
 
     physicalPlan.getStageDAG().getChildren(stageId).forEach(
         physicalStage -> removeStageAndChildren(physicalStage.getId()));
@@ -165,10 +166,11 @@ public final class SingleJobTaskGroupCollection 
implements PendingTaskGroupColle
     if (isSchedulable(candidateStageId, candidateStageContainerType)) {
       // Check for ancestor stages that became schedulable due to 
candidateStage's absence from the queue.
       jobDAG.getAncestors(candidateStageId).forEach(ancestorStage -> {
-        if (schedulableStages.contains(ancestorStage.getId())) {
-          // Remove the ancestor stage if it is of the same container type.
-          if 
(candidateStageContainerType.equals(ancestorStage.getContainerType())) {
-            schedulableStages.remove(ancestorStage.getId());
+        // Remove the ancestor stage if it is of the same container type.
+        if (schedulableStages.contains(ancestorStage.getId())
+            && 
candidateStageContainerType.equals(ancestorStage.getContainerType())) {
+          if (!schedulableStages.remove(ancestorStage.getId())) {
+            throw new RuntimeException(String.format("No such stage: %s", 
ancestorStage.getId()));
           }
         }
       });

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to