hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [21/29] hadoop git commit: HDFS-11851. getGlobalJNIEnv() may deadlock if exception is thrown. Contributed by Sailesh Mukil.
Date Fri, 09 Jun 2017 03:04:36 GMT
HDFS-11851. getGlobalJNIEnv() may deadlock if exception is thrown. Contributed by Sailesh Mukil.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/164c222c
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/164c222c
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/164c222c

Branch: refs/heads/YARN-5734
Commit: 164c222c4aa697c3acbaa6f34c59a23177d7f3cd
Parents: a062374
Author: John Zhuge <jzhuge@apache.org>
Authored: Thu Jun 8 14:15:09 2017 -0700
Committer: John Zhuge <jzhuge@apache.org>
Committed: Thu Jun 8 14:15:09 2017 -0700

----------------------------------------------------------------------
 .../libhdfs-tests/test_libhdfs_threaded.c       | 26 ++++++++++++++++++++
 .../src/main/native/libhdfs/os/posix/mutexes.c  |  9 ++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/164c222c/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/test_libhdfs_threaded.c
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/test_libhdfs_threaded.c
b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/test_libhdfs_threaded.c
index f80200d..8d4b743 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/test_libhdfs_threaded.c
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/test_libhdfs_threaded.c
@@ -17,8 +17,11 @@
  */
 
 #include "expect.h"
+#include "exception.h"
 #include "hdfs/hdfs.h"
+#include "jni_helper.h"
 #include "native_mini_dfs.h"
+#include "os/mutexes.h"
 #include "os/thread.h"
 
 #include <errno.h>
@@ -329,6 +332,23 @@ static int checkFailures(struct tlhThreadInfo *ti, int tlhNumThreads)
     return EXIT_FAILURE;
 }
 
+int testRecursiveJvmMutex() {
+    jthrowable jthr;
+    JNIEnv *env = getJNIEnv();
+    if (!env) {
+        fprintf(stderr, "testRecursiveJvmMutex: getJNIEnv failed\n");
+        return -EIO;
+    }
+    jthr = newRuntimeError(env, "Dummy error to print for testing");
+
+    /* printExceptionAndFree() takes the jvmMutex within */
+    mutexLock(&jvmMutex);
+    printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "testRecursiveJvmMutex");
+    mutexUnlock(&jvmMutex);
+
+    return 0;
+}
+
 /**
  * Test that we can write a file with libhdfs and then read it back
  */
@@ -341,6 +361,12 @@ int main(void)
         1, /* doFormat */
     };
 
+    /* Check that the recursive mutex works as expected */
+    if (testRecursiveJvmMutex() < 0) {
+        fprintf(stderr, "testRecursiveJvmMutex failed\n");
+        return EXIT_FAILURE;
+    }
+
     tlhNumThreadsStr = getenv("TLH_NUM_THREADS");
     if (!tlhNumThreadsStr) {
         tlhNumThreadsStr = "3";

http://git-wip-us.apache.org/repos/asf/hadoop/blob/164c222c/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/posix/mutexes.c
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/posix/mutexes.c
b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/posix/mutexes.c
index c4c2f26..20dafaa 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/posix/mutexes.c
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/posix/mutexes.c
@@ -22,7 +22,14 @@
 #include <stdio.h>
 
 mutex hdfsHashMutex = PTHREAD_MUTEX_INITIALIZER;
-mutex jvmMutex = PTHREAD_MUTEX_INITIALIZER;
+mutex jvmMutex;
+pthread_mutexattr_t jvmMutexAttr;
+
+__attribute__((constructor)) static void init() {
+  pthread_mutexattr_init(&jvmMutexAttr);
+  pthread_mutexattr_settype(&jvmMutexAttr, PTHREAD_MUTEX_RECURSIVE);
+  pthread_mutex_init(&jvmMutex, &jvmMutexAttr);
+}
 
 int mutexLock(mutex *m) {
   int ret = pthread_mutex_lock(m);


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message