hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhr...@apache.org
Subject svn commit: r752555 - in /hadoop/core/trunk: CHANGES.txt src/c++/libhdfs/hdfs.c src/c++/libhdfs/hdfsJniHelper.c src/c++/libhdfs/tests/test-libhdfs.sh
Date Wed, 11 Mar 2009 18:37:54 GMT
Author: dhruba
Date: Wed Mar 11 18:37:54 2009
New Revision: 752555

URL: http://svn.apache.org/viewvc?rev=752555&view=rev
Log:
HADOOP-5333. libhdfs supports appending to files. (dhruba)


Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/c++/libhdfs/hdfs.c
    hadoop/core/trunk/src/c++/libhdfs/hdfsJniHelper.c
    hadoop/core/trunk/src/c++/libhdfs/tests/test-libhdfs.sh

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=752555&r1=752554&r2=752555&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Wed Mar 11 18:37:54 2009
@@ -995,6 +995,8 @@
 
     HADOOP-5332. Appending to files is not allowed (by default) unless
     dfs.support.append is set to true. (dhruba)
+
+    HADOOP-5333. libhdfs supports appending to files. (dhruba)
  
 Release 0.19.1 - Unreleased
 

Modified: hadoop/core/trunk/src/c++/libhdfs/hdfs.c
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/c%2B%2B/libhdfs/hdfs.c?rev=752555&r1=752554&r2=752555&view=diff
==============================================================================
--- hadoop/core/trunk/src/c++/libhdfs/hdfs.c (original)
+++ hadoop/core/trunk/src/c++/libhdfs/hdfs.c Wed Mar 11 18:37:54 2009
@@ -394,7 +394,6 @@
        FSData{Input|Output}Stream f{is|os} = fs.create(f);
        return f{is|os};
     */
-
     /* Get the JNIEnv* corresponding to current thread */
     JNIEnv* env = getJNIEnv();
 
@@ -505,20 +504,17 @@
                                    signature);
         goto done;
       }
+    }  else if ((flags & O_WRONLY) && (flags & O_APPEND)) {
       // WRITE/APPEND?
-      else if ((flags & O_WRONLY) && (flags & O_APPEND)) {
-        if (invokeMethod(env, &jVal, &jExc, INSTANCE, jFS, HADOOP_FS,
-                         method, signature, jPath)) {
-          errno = errnoFromException(jExc, env, "org.apache.hadoop.conf."
-                                     "FileSystem::%s(%s)", method,
-                                     signature);
-          goto done;
-        }
+       if (invokeMethod(env, &jVal, &jExc, INSTANCE, jFS, HADOOP_FS,
+                       method, signature, jPath)) {
+        errno = errnoFromException(jExc, env, "org.apache.hadoop.conf."
+                                   "FileSystem::%s(%s)", method,
+                                   signature);
+        goto done;
       }
-
-    }
-    // WRITE/CREATE
-    else {
+    } else {
+        // WRITE/CREATE
         jboolean jOverWrite = 1;
         if (invokeMethod(env, &jVal, &jExc, INSTANCE, jFS, HADOOP_FS,
                          method, signature, jPath, jOverWrite,

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=752555&r1=752554&r2=752555&view=diff
==============================================================================
--- hadoop/core/trunk/src/c++/libhdfs/hdfsJniHelper.c (original)
+++ hadoop/core/trunk/src/c++/libhdfs/hdfsJniHelper.c Wed Mar 11 18:37:54 2009
@@ -20,10 +20,13 @@
 #include "hdfsJniHelper.h"
 
 static pthread_mutex_t hdfsHashMutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t jvmMutex = PTHREAD_MUTEX_INITIALIZER;
 static volatile int hashTableInited = 0;
 
 #define LOCK_HASH_TABLE() pthread_mutex_lock(&hdfsHashMutex)
 #define UNLOCK_HASH_TABLE() pthread_mutex_unlock(&hdfsHashMutex)
+#define LOCK_JVM_MUTEX() pthread_mutex_lock(&jvmMutex)
+#define UNLOCK_JVM_MUTEX() pthread_mutex_unlock(&jvmMutex)
 
 
 /** The Native return types that methods could return */
@@ -392,9 +395,14 @@
     jint rv = 0; 
     jint noVMs = 0;
 
+    // Only the first thread should create the JVM. The other trheads should
+    // just use the JVM created by the first thread.
+    LOCK_JVM_MUTEX();
+
     rv = JNI_GetCreatedJavaVMs(&(vmBuf[0]), vmBufLength, &noVMs);
     if (rv != 0) {
         fprintf(stderr, "JNI_GetCreatedJavaVMs failed with error: %d\n", rv);
+        UNLOCK_JVM_MUTEX();
         return NULL;
     }
 
@@ -403,6 +411,7 @@
         char *hadoopClassPath = getenv("CLASSPATH");
         if (hadoopClassPath == NULL) {
             fprintf(stderr, "Environment variable CLASSPATH not set!\n");
+            UNLOCK_JVM_MUTEX();
             return NULL;
         } 
         char *hadoopClassPathVMArg = "-Djava.class.path=";
@@ -448,6 +457,7 @@
         if (rv != 0) {
             fprintf(stderr, "Call to JNI_CreateJavaVM failed "
                     "with error: %d\n", rv);
+            UNLOCK_JVM_MUTEX();
             return NULL;
         }
 
@@ -460,9 +470,11 @@
         if (rv != 0) {
             fprintf(stderr, "Call to AttachCurrentThread "
                     "failed with error: %d\n", rv);
+            UNLOCK_JVM_MUTEX();
             return NULL;
         }
     }
+    UNLOCK_JVM_MUTEX();
 
     return env;
 }

Modified: hadoop/core/trunk/src/c++/libhdfs/tests/test-libhdfs.sh
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/c%2B%2B/libhdfs/tests/test-libhdfs.sh?rev=752555&r1=752554&r2=752555&view=diff
==============================================================================
--- hadoop/core/trunk/src/c++/libhdfs/tests/test-libhdfs.sh (original)
+++ hadoop/core/trunk/src/c++/libhdfs/tests/test-libhdfs.sh Wed Mar 11 18:37:54 2009
@@ -116,14 +116,15 @@
 # after the tests are complete
 cd $HADOOP_HOME
 echo Y | $HADOOP_BIN_DIR/hadoop namenode -format &&
-$HADOOP_BIN_DIR/hadoop-daemon.sh $HADOOP_BIN_DIR/hdfs start namenode && sleep 2 &&

-$HADOOP_BIN_DIR/hadoop-daemon.sh $HADOOP_BIN_DIR/hdfs start datanode && sleep 2 &&

+$HADOOP_BIN_DIR/hadoop-daemon.sh --script $HADOOP_BIN_DIR/hdfs start namenode &&
sleep 2 && 
+$HADOOP_BIN_DIR/hadoop-daemon.sh --script $HADOOP_BIN_DIR/hdfs start datanode &&
sleep 2 && 
+sleep 20
 echo CLASSPATH=$HADOOP_CONF_DIR:$CLASSPATH LD_PRELOAD="$LIBHDFS_INSTALL_DIR/libhdfs.so:$LIB_JVM_DIR/libjvm.so"
$LIBHDFS_BUILD_DIR/$HDFS_TEST && 
 CLASSPATH=$HADOOP_CONF_DIR:$CLASSPATH LD_PRELOAD="$LIB_JVM_DIR/libjvm.so:$LIBHDFS_INSTALL_DIR/libhdfs.so:"
$LIBHDFS_BUILD_DIR/$HDFS_TEST
 BUILD_STATUS=$?
 sleep 3
-$HADOOP_BIN_DIR/hadoop-daemon.sh $HADOOP_BIN_DIR/hdfs stop datanode && sleep 2 &&

-$HADOOP_BIN_DIR/hadoop-daemon.sh $HADOOP_BIN_DIR/hdfs stop namenode && sleep 2 
+$HADOOP_BIN_DIR/hadoop-daemon.sh --script $HADOOP_BIN_DIR/hdfs stop datanode && sleep
2 && 
+$HADOOP_BIN_DIR/hadoop-daemon.sh --script $HADOOP_BIN_DIR/hdfs stop namenode && sleep
2 
 
 echo exiting with $BUILD_STATUS
 exit $BUILD_STATUS



Mime
View raw message