Ver código fonte

HADOOP-2857. Allow libhdfs to set jvm options. Contributed by Craig Macdonald.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@652148 13f79535-47bb-0310-9956-ffa450edef68
Owen O'Malley 17 anos atrás
pai
commit
0b51dd3e25
3 arquivos alterados com 38 adições e 9 exclusões
  1. 3 0
      CHANGES.txt
  2. 29 9
      src/c++/libhdfs/hdfsJniHelper.c
  3. 6 0
      src/c++/libhdfs/hdfsJniHelper.h

+ 3 - 0
CHANGES.txt

@@ -28,6 +28,9 @@ Trunk (unreleased changes)
     HADOOP-3061. Writable types for doubles and bytes. (Andrzej
     Bialecki via omalley)
 
+    HADOOP-2857. Allow libhdfs to set jvm options. (Craig Macdonald
+    via omalley)
+
   IMPROVEMENTS
    
     HADOOP-2928. Remove deprecated FileSystem.getContentLength().

+ 29 - 9
src/c++/libhdfs/hdfsJniHelper.c

@@ -285,6 +285,9 @@ jclass globalClassReference(const char *className, JNIEnv *env)
 
 /**
  * getJNIEnv: A helper function to get the JNIEnv* for the given thread.
+ * If no JVM exists, then one will be created. JVM command line arguments
+ * are obtained from the LIBHDFS_OPTS environment variable.
+ *
  * @param: None.
  * @return The JNIEnv* corresponding to the thread.
  */
@@ -315,21 +318,38 @@ JNIEnv* getJNIEnv(void)
           strlen(hadoopClassPathVMArg) + 1;
         char *optHadoopClassPath = malloc(sizeof(char)*optHadoopClassPathLen);
         snprintf(optHadoopClassPath, optHadoopClassPathLen,
-        	"%s%s", hadoopClassPathVMArg, hadoopClassPath);
+                "%s%s", hadoopClassPathVMArg, hadoopClassPath);
+
+        int noArgs = 1;
+        //determine how many arguments were passed as LIBHDFS_OPTS env var
+        char *hadoopJvmArgs = getenv("LIBHDFS_OPTS");
+        char jvmArgDelims[] = " ";
+        if (hadoopJvmArgs != NULL)  {
+                char *result = NULL;
+                result = strtok( hadoopJvmArgs, jvmArgDelims );
+                while( result != NULL ) {
+                        noArgs++;
+        		result = strtok( NULL, jvmArgDelims);
+           	}
+        }
+        JavaVMOption options[noArgs];
+        options[0].optionString = optHadoopClassPath;
+		//fill in any specified arguments
+	if (hadoopJvmArgs != NULL)  {
+            char *result = NULL;
+            result = strtok( hadoopJvmArgs, jvmArgDelims );	
+            int argNum = 1;
+            for(;argNum < noArgs ; argNum++) {
+                options[argNum].optionString = result; //optHadoopArg;
+            }
+        }
 
         //Create the VM
         JavaVMInitArgs vm_args;
-        JavaVMOption options[1];
         JavaVM *vm;
-        
-        // User classes
-        options[0].optionString = optHadoopClassPath;
-        // Print JNI-related messages      
-        //options[2].optionString = "-verbose:jni";
-
         vm_args.version = JNI_VERSION_1_2;
         vm_args.options = options;
-        vm_args.nOptions = 1; 
+        vm_args.nOptions = noArgs; 
         vm_args.ignoreUnrecognized = 1;
 
         rv = JNI_CreateJavaVM(&vm, (void*)&env, &vm_args);

+ 6 - 0
src/c++/libhdfs/hdfsJniHelper.h

@@ -82,6 +82,12 @@ jmethodID methodIdFromClass(const char *className, const char *methName,
 
 jclass globalClassReference(const char *className, JNIEnv *env);
 
+/** getJNIEnv: A helper function to get the JNIEnv* for the given thread.
+ * If no JVM exists, then one will be created. JVM command line arguments
+ * are obtained from the LIBHDFS_OPTS environment variable.
+ * @param: None.
+ * @return The JNIEnv* corresponding to the thread.
+ * */
 JNIEnv* getJNIEnv(void);
 
 #endif /*LIBHDFS_JNI_HELPER_H*/