Author: omalley
Date: Tue Apr 29 14:28:49 2008
New Revision: 652148
URL: http://svn.apache.org/viewvc?rev=652148&view=rev
Log:
HADOOP-2857. Allow libhdfs to set jvm options. Contributed by Craig Macdonald.
Modified:
hadoop/core/trunk/CHANGES.txt
hadoop/core/trunk/src/c++/libhdfs/hdfsJniHelper.c
hadoop/core/trunk/src/c++/libhdfs/hdfsJniHelper.h
Modified: hadoop/core/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=652148&r1=652147&r2=652148&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Tue Apr 29 14:28:49 2008
@@ -28,6 +28,9 @@
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().
Modified: hadoop/core/trunk/src/c++/libhdfs/hdfsJniHelper.c
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/c%2B%2B/libhdfs/hdfsJniHelper.c?rev=652148&r1=652147&r2=652148&view=diff
==============================================================================
--- hadoop/core/trunk/src/c++/libhdfs/hdfsJniHelper.c (original)
+++ hadoop/core/trunk/src/c++/libhdfs/hdfsJniHelper.c Tue Apr 29 14:28:49 2008
@@ -285,6 +285,9 @@
/**
* 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 @@
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);
Modified: hadoop/core/trunk/src/c++/libhdfs/hdfsJniHelper.h
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/c%2B%2B/libhdfs/hdfsJniHelper.h?rev=652148&r1=652147&r2=652148&view=diff
==============================================================================
--- hadoop/core/trunk/src/c++/libhdfs/hdfsJniHelper.h (original)
+++ hadoop/core/trunk/src/c++/libhdfs/hdfsJniHelper.h Tue Apr 29 14:28:49 2008
@@ -82,6 +82,12 @@
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*/