hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acmur...@apache.org
Subject svn commit: r1382882 - in /hadoop/common/branches/branch-1-win: ./ src/core/org/apache/hadoop/util/ src/test/org/apache/hadoop/mapred/ src/winutils/
Date Mon, 10 Sep 2012 14:32:28 GMT
Author: acmurthy
Date: Mon Sep 10 14:32:28 2012
New Revision: 1382882

URL: http://svn.apache.org/viewvc?rev=1382882&view=rev
Log:
MAPREDUCE-4564. Fix issues with timing out shell processes. Contributed by Bikas Saha.

Modified:
    hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt
    hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/util/ProcessTree.java
    hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestKillSubProcesses.java
    hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestNodeHealthService.java
    hadoop/common/branches/branch-1-win/src/winutils/task.c

Modified: hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt?rev=1382882&r1=1382881&r2=1382882&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt (original)
+++ hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt Mon Sep 10 14:32:28 2012
@@ -113,3 +113,6 @@ BUG FIXES
 
     HADOOP-8664. hadoop streaming job need the full path to commands even 
     when they are in the path. (Bikas Saha via suresh)
+
+    MAPREDUCE-4564. Fix issues with timing out shell processes. (Bikas Saha
+    via acmurthy)

Modified: hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/util/ProcessTree.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/util/ProcessTree.java?rev=1382882&r1=1382881&r2=1382882&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/util/ProcessTree.java (original)
+++ hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/util/ProcessTree.java Mon
Sep 10 14:32:28 2012
@@ -232,8 +232,10 @@ public class ProcessTree {
   public static boolean isProcessGroupAlive(String pgrpId) {
     if (Shell.WINDOWS) {
       try {
-        String result = Shell.execCommand("cmd", "/c", Shell.WINUTILS
-            + " task isAlive " + pgrpId);
+        ShellCommandExecutor shexec = 
+            new ShellCommandExecutor(new String[] {Shell.WINUTILS, "task", "isAlive", pgrpId});
+        shexec.execute();
+        String result = shexec.getOutput();
         return (result.contains("IsAlive"));
       } catch (IOException ioe) {
         LOG.warn("Error executing shell command", ioe);

Modified: hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestKillSubProcesses.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestKillSubProcesses.java?rev=1382882&r1=1382881&r2=1382882&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestKillSubProcesses.java
(original)
+++ hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestKillSubProcesses.java
Mon Sep 10 14:32:28 2012
@@ -207,8 +207,7 @@ public class TestKillSubProcesses extend
           int numChildren = 0;
           while(sleepCount-- > 0) {
             Thread.sleep(1000);
-            String result = Shell.execCommand("cmd", "/c", Shell.WINUTILS
-                + " task isAlive " + pid);
+            String result = runAliveCommand(pid);
             assertTrue("Map process tree not alive", result.contains("IsAlive"));
             String[] parts = result.split("[,\r\n]");
             assertTrue(parts.length >= 2);
@@ -285,8 +284,7 @@ public class TestKillSubProcesses extend
     // Checking if the descendant processes of map task are killed properly
     if(ProcessTree.isSetsidAvailable) {
       if(Shell.WINDOWS) {
-        String result = Shell.execCommand("cmd", "/c", Shell.WINUTILS
-            + " task isAlive " + pid);
+        String result = runAliveCommand(pid);
         assertTrue("Map process tree not alive", !result.contains("IsAlive"));
       } else {
         for(int i=0; i <= numLevelsOfSubProcesses; i++) {
@@ -307,6 +305,14 @@ public class TestKillSubProcesses extend
     }
   }
   
+  private static String runAliveCommand(String pid) throws IOException {
+    ShellCommandExecutor shexec = 
+        new ShellCommandExecutor(
+            new String[] {Shell.WINUTILS, "task", "isAlive", pid});
+    shexec.execute();
+    return shexec.getOutput();
+  }
+  
   private static RunningJob runJob(JobConf conf) throws IOException {
 
     final Path inDir;

Modified: hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestNodeHealthService.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestNodeHealthService.java?rev=1382882&r1=1382881&r2=1382882&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestNodeHealthService.java
(original)
+++ hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestNodeHealthService.java
Mon Sep 10 14:32:28 2012
@@ -108,7 +108,9 @@ public class TestNodeHealthService exten
     TaskTrackerHealthStatus healthStatus = new TaskTrackerHealthStatus();
     String errorScript = "echo ERROR\n echo \"Tracker not healthy\"";
     String normalScript = "echo \"I am all fine\"";
-    String timeOutScript = "sleep 4\n echo \"I am fine\"";
+    // use extremely large sleep time in script to make sure junit test times
+    // out if script termination fails upon timeout.
+    String timeOutScript = "sleep 60000\n echo \" I am fine\"";
     Configuration conf = getConfForNodeHealthScript();
     conf.writeXml(new FileOutputStream(nodeHealthConfigFile));
 

Modified: hadoop/common/branches/branch-1-win/src/winutils/task.c
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/winutils/task.c?rev=1382882&r1=1382881&r2=1382882&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/winutils/task.c (original)
+++ hadoop/common/branches/branch-1-win/src/winutils/task.c Mon Sep 10 14:32:28 2012
@@ -101,21 +101,29 @@ DWORD createTask(_TCHAR* jobObjName, _TC
   PROCESS_INFORMATION pi;
   SECURITY_ATTRIBUTES sa;
   HANDLE jobObject = NULL;
+  JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = { 0 };
 
-  // make the job object handle inheritable so that it can be inherited 
-  // via CreateProcess. If CreateProcess is used in this manner, then spawned 
-  // processes will keep the handle to the job object alive and it can be 
-  // manipulated via name by another process (say winutils task kill)
-  sa.nLength = sizeof(SECURITY_ATTRIBUTES);
-  sa.lpSecurityDescriptor = NULL;
-  sa.bInheritHandle = TRUE;
-  jobObject = CreateJobObject(&sa, jobObjName);
+  // Create un-inheritable job object handle and set job object to terminate 
+  // when last handle is closed. So winutils.exe invocation has the only open 
+  // job object handle. Exit of winutils.exe ensures termination of job object.
+  // Either a clean exit of winutils or crash or external termination.
+  jobObject = CreateJobObject(NULL, jobObjName);
   err = GetLastError();
   if(jobObject == NULL || err ==  ERROR_ALREADY_EXISTS)
   {
     return err;
   }
-  
+  jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
+  if(SetInformationJobObject(jobObject, 
+                             JobObjectExtendedLimitInformation, 
+                             &jeli, 
+                             sizeof(jeli)) == 0)
+  {
+    err = GetLastError();
+    CloseHandle(jobObject);
+    return err;
+  }      
+
   if(AssignProcessToJobObject(jobObject, GetCurrentProcess()) == 0)
   {
     err = GetLastError();
@@ -135,8 +143,6 @@ DWORD createTask(_TCHAR* jobObjName, _TC
   ZeroMemory( &si, sizeof(si) );
   si.cb = sizeof(si);
   ZeroMemory( &pi, sizeof(pi) );
-  // inherit the job object handle so that it can be manipulated via its name 
-  // by another program (say winutils task kill) even if winutils crashes.
   if(CreateProcess(NULL, cmdLine, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi) == 0)
   {
     err = GetLastError();



Mime
View raw message