You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@storm.apache.org by GitBox <gi...@apache.org> on 2020/07/16 06:17:31 UTC

[GitHub] [storm] bipinprasad opened a new pull request #3309: [STORM-3675] Check worker process death using /proc/ directory

bipinprasad opened a new pull request #3309:
URL: https://github.com/apache/storm/pull/3309


   ## What is the purpose of the change
   
   *This function can replace a system "ps" command with existence/ownership check on /proc/ directory. In additional, on loaded nodes, ps command can take a few seconds. java.io.File.exists() is expected to be much faster. Note that File watcher does not work on /proc file system and the event based approach was coded/tested and then discarded.*
   
   ## How was the change tested
   
   *new test methods in ServerUtilsTest. Also run storm, kill worker and observe log to ensure proper detection*


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [storm] Ethanlm commented on pull request #3309: [STORM-3675] Check worker process death using /proc/ directory

Posted by GitBox <gi...@apache.org>.
Ethanlm commented on pull request #3309:
URL: https://github.com/apache/storm/pull/3309#issuecomment-682049893


   Unit test is failing 
   ```
   classname: org.apache.storm.utils.ServerUtilsTest / testname: testIsAnyProcessPosixProcessPidDirAlive
   java.lang.AssertionError: There are 5 failures in test
   ```


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [storm] Ethanlm commented on a change in pull request #3309: [STORM-3675] Check worker process death using /proc/ directory

Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3309:
URL: https://github.com/apache/storm/pull/3309#discussion_r480197968



##########
File path: storm-server/src/test/java/org/apache/storm/utils/ServerUtilsTest.java
##########
@@ -162,6 +174,163 @@ public void testGetUserId() throws Exception {
         int uid1 = ServerUtils.getUserId(null);
         Path p = Files.createTempFile("testGetUser", ".txt");
         int uid2 = ServerUtils.getPathOwnerUid(p.toString());
+        if (!p.toFile().delete()) {
+            LOG.warn("Could not delete tempoary file {}", p);
+        }
         assertEquals("User UID " + uid1 + " is not same as file " + p.toString() + " owner UID of " + uid2, uid1, uid2);
     }
+
+    @Test
+    public void testIsAnyProcessPosixProcessPidDirAlive() throws IOException {
+        final String testName = "testIsAnyProcessPosixProcessPidDirAlive";
+        List<String> errors = new ArrayList<>();
+        int maxPidCnt = 5;
+        if (ServerUtils.IS_ON_WINDOWS) {
+            LOG.info("{}: test cannot be run on Windows. Marked as successful", testName);
+            return;
+        }
+        final Path parentDir = Paths.get("/proc");
+        if (!parentDir.toFile().exists()) {
+            LOG.info("{}: test cannot be run on system without process directory {}, os.name={}",
+                    testName, parentDir, System.getProperty("os.name"));
+            {
+                // check if we can get process id on this Posix system - testing test code, useful on Mac

Review comment:
       Can you please explain why is it "useful on Mac"?

##########
File path: storm-server/src/test/java/org/apache/storm/utils/ServerUtilsTest.java
##########
@@ -162,6 +174,163 @@ public void testGetUserId() throws Exception {
         int uid1 = ServerUtils.getUserId(null);
         Path p = Files.createTempFile("testGetUser", ".txt");
         int uid2 = ServerUtils.getPathOwnerUid(p.toString());
+        if (!p.toFile().delete()) {
+            LOG.warn("Could not delete tempoary file {}", p);
+        }
         assertEquals("User UID " + uid1 + " is not same as file " + p.toString() + " owner UID of " + uid2, uid1, uid2);
     }
+
+    @Test
+    public void testIsAnyProcessPosixProcessPidDirAlive() throws IOException {
+        final String testName = "testIsAnyProcessPosixProcessPidDirAlive";
+        List<String> errors = new ArrayList<>();
+        int maxPidCnt = 5;
+        if (ServerUtils.IS_ON_WINDOWS) {
+            LOG.info("{}: test cannot be run on Windows. Marked as successful", testName);
+            return;
+        }
+        final Path parentDir = Paths.get("/proc");
+        if (!parentDir.toFile().exists()) {
+            LOG.info("{}: test cannot be run on system without process directory {}, os.name={}",
+                    testName, parentDir, System.getProperty("os.name"));
+            {
+                // check if we can get process id on this Posix system - testing test code, useful on Mac
+                String cmd = "/bin/sleep 10";
+                if (getPidOfPosixProcess(Runtime.getRuntime().exec(cmd), errors) < 0) {
+                    fail(String.format("%s: Cannot obtain process id for executed command \"%s\"\n%s",
+                            testName, cmd, String.join("\n\t", errors)));
+                }
+            }
+            return;
+        }
+        // Create processes and wait for their termination
+        Set<Long> observables = new HashSet<>();
+
+        for (int i = 0 ; i < maxPidCnt ; i++) {
+            String cmd = "sleep 2000";
+            Process process = Runtime.getRuntime().exec(cmd);
+            long pid = getPidOfPosixProcess(process, errors);
+            LOG.info("{}: ({}) ran process \"{}\" with pid={}", testName, i, cmd, pid);
+            if (pid < 0) {
+                String e = String.format("%s: (%d) Cannot obtain process id for executed command \"%s\"", testName, i, cmd);
+                errors.add(e);
+                LOG.error(e);
+                continue;
+            }
+            observables.add(pid);
+        }
+        String userName = System.getProperty("user.name");
+        // now kill processes one by one
+        List<Long> pidList = new ArrayList<>(observables);
+        final long processKillIntervalMs = 2000;
+        for (int i = 0 ; i < pidList.size() ; i++) {

Review comment:
       nit: space before ";" can be removed

##########
File path: storm-server/src/test/java/org/apache/storm/utils/ServerUtilsTest.java
##########
@@ -162,6 +174,163 @@ public void testGetUserId() throws Exception {
         int uid1 = ServerUtils.getUserId(null);
         Path p = Files.createTempFile("testGetUser", ".txt");
         int uid2 = ServerUtils.getPathOwnerUid(p.toString());
+        if (!p.toFile().delete()) {
+            LOG.warn("Could not delete tempoary file {}", p);
+        }
         assertEquals("User UID " + uid1 + " is not same as file " + p.toString() + " owner UID of " + uid2, uid1, uid2);
     }
+
+    @Test
+    public void testIsAnyProcessPosixProcessPidDirAlive() throws IOException {
+        final String testName = "testIsAnyProcessPosixProcessPidDirAlive";
+        List<String> errors = new ArrayList<>();
+        int maxPidCnt = 5;
+        if (ServerUtils.IS_ON_WINDOWS) {
+            LOG.info("{}: test cannot be run on Windows. Marked as successful", testName);
+            return;
+        }
+        final Path parentDir = Paths.get("/proc");
+        if (!parentDir.toFile().exists()) {
+            LOG.info("{}: test cannot be run on system without process directory {}, os.name={}",
+                    testName, parentDir, System.getProperty("os.name"));
+            {

Review comment:
       I would remove "{". It doesn't seem necessary




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [storm] bipinprasad commented on a change in pull request #3309: [STORM-3675] Check worker process death using /proc/ directory

Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3309:
URL: https://github.com/apache/storm/pull/3309#discussion_r480206177



##########
File path: storm-server/src/test/java/org/apache/storm/utils/ServerUtilsTest.java
##########
@@ -162,6 +174,163 @@ public void testGetUserId() throws Exception {
         int uid1 = ServerUtils.getUserId(null);
         Path p = Files.createTempFile("testGetUser", ".txt");
         int uid2 = ServerUtils.getPathOwnerUid(p.toString());
+        if (!p.toFile().delete()) {
+            LOG.warn("Could not delete tempoary file {}", p);
+        }
         assertEquals("User UID " + uid1 + " is not same as file " + p.toString() + " owner UID of " + uid2, uid1, uid2);
     }
+
+    @Test
+    public void testIsAnyProcessPosixProcessPidDirAlive() throws IOException {
+        final String testName = "testIsAnyProcessPosixProcessPidDirAlive";
+        List<String> errors = new ArrayList<>();
+        int maxPidCnt = 5;
+        if (ServerUtils.IS_ON_WINDOWS) {
+            LOG.info("{}: test cannot be run on Windows. Marked as successful", testName);
+            return;
+        }
+        final Path parentDir = Paths.get("/proc");
+        if (!parentDir.toFile().exists()) {
+            LOG.info("{}: test cannot be run on system without process directory {}, os.name={}",
+                    testName, parentDir, System.getProperty("os.name"));
+            {
+                // check if we can get process id on this Posix system - testing test code, useful on Mac

Review comment:
       Rest of test will not get exercised on Mac (no /proc dir), but at least the getPidOfPosixProcess() will be validated locally.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [storm] bipinprasad commented on a change in pull request #3309: [STORM-3675] Check worker process death using /proc/ directory

Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3309:
URL: https://github.com/apache/storm/pull/3309#discussion_r480209827



##########
File path: storm-server/src/test/java/org/apache/storm/utils/ServerUtilsTest.java
##########
@@ -162,6 +174,163 @@ public void testGetUserId() throws Exception {
         int uid1 = ServerUtils.getUserId(null);
         Path p = Files.createTempFile("testGetUser", ".txt");
         int uid2 = ServerUtils.getPathOwnerUid(p.toString());
+        if (!p.toFile().delete()) {
+            LOG.warn("Could not delete tempoary file {}", p);
+        }
         assertEquals("User UID " + uid1 + " is not same as file " + p.toString() + " owner UID of " + uid2, uid1, uid2);
     }
+
+    @Test
+    public void testIsAnyProcessPosixProcessPidDirAlive() throws IOException {
+        final String testName = "testIsAnyProcessPosixProcessPidDirAlive";
+        List<String> errors = new ArrayList<>();
+        int maxPidCnt = 5;
+        if (ServerUtils.IS_ON_WINDOWS) {
+            LOG.info("{}: test cannot be run on Windows. Marked as successful", testName);
+            return;
+        }
+        final Path parentDir = Paths.get("/proc");
+        if (!parentDir.toFile().exists()) {
+            LOG.info("{}: test cannot be run on system without process directory {}, os.name={}",
+                    testName, parentDir, System.getProperty("os.name"));
+            {

Review comment:
       fixed




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [storm] Ethanlm merged pull request #3309: [STORM-3675] Check worker process death using /proc/ directory

Posted by GitBox <gi...@apache.org>.
Ethanlm merged pull request #3309:
URL: https://github.com/apache/storm/pull/3309


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [storm] bipinprasad commented on a change in pull request #3309: [STORM-3675] Check worker process death using /proc/ directory

Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3309:
URL: https://github.com/apache/storm/pull/3309#discussion_r480209305



##########
File path: storm-server/src/test/java/org/apache/storm/utils/ServerUtilsTest.java
##########
@@ -162,6 +174,163 @@ public void testGetUserId() throws Exception {
         int uid1 = ServerUtils.getUserId(null);
         Path p = Files.createTempFile("testGetUser", ".txt");
         int uid2 = ServerUtils.getPathOwnerUid(p.toString());
+        if (!p.toFile().delete()) {
+            LOG.warn("Could not delete tempoary file {}", p);
+        }
         assertEquals("User UID " + uid1 + " is not same as file " + p.toString() + " owner UID of " + uid2, uid1, uid2);
     }
+
+    @Test
+    public void testIsAnyProcessPosixProcessPidDirAlive() throws IOException {
+        final String testName = "testIsAnyProcessPosixProcessPidDirAlive";
+        List<String> errors = new ArrayList<>();
+        int maxPidCnt = 5;
+        if (ServerUtils.IS_ON_WINDOWS) {
+            LOG.info("{}: test cannot be run on Windows. Marked as successful", testName);
+            return;
+        }
+        final Path parentDir = Paths.get("/proc");
+        if (!parentDir.toFile().exists()) {
+            LOG.info("{}: test cannot be run on system without process directory {}, os.name={}",
+                    testName, parentDir, System.getProperty("os.name"));
+            {
+                // check if we can get process id on this Posix system - testing test code, useful on Mac
+                String cmd = "/bin/sleep 10";
+                if (getPidOfPosixProcess(Runtime.getRuntime().exec(cmd), errors) < 0) {
+                    fail(String.format("%s: Cannot obtain process id for executed command \"%s\"\n%s",
+                            testName, cmd, String.join("\n\t", errors)));
+                }
+            }
+            return;
+        }
+        // Create processes and wait for their termination
+        Set<Long> observables = new HashSet<>();
+
+        for (int i = 0 ; i < maxPidCnt ; i++) {
+            String cmd = "sleep 2000";
+            Process process = Runtime.getRuntime().exec(cmd);
+            long pid = getPidOfPosixProcess(process, errors);
+            LOG.info("{}: ({}) ran process \"{}\" with pid={}", testName, i, cmd, pid);
+            if (pid < 0) {
+                String e = String.format("%s: (%d) Cannot obtain process id for executed command \"%s\"", testName, i, cmd);
+                errors.add(e);
+                LOG.error(e);
+                continue;
+            }
+            observables.add(pid);
+        }
+        String userName = System.getProperty("user.name");
+        // now kill processes one by one
+        List<Long> pidList = new ArrayList<>(observables);
+        final long processKillIntervalMs = 2000;
+        for (int i = 0 ; i < pidList.size() ; i++) {

Review comment:
       fixed




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [storm] bipinprasad commented on pull request #3309: [STORM-3675] Check worker process death using /proc/ directory

Posted by GitBox <gi...@apache.org>.
bipinprasad commented on pull request #3309:
URL: https://github.com/apache/storm/pull/3309#issuecomment-682296978


   Fixed the test for JDK11.


----------------------------------------------------------------
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:
users@infra.apache.org