Browse Source

HADOOP-3451. Update libhdfs to use FileSystem::getFileBlockLocations
instead of removed getFileCacheHints. Contributed by lohit vijayarenu.



git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@661099 13f79535-47bb-0310-9956-ffa450edef68

Christopher Douglas 17 years ago
parent
commit
7c411aa151
2 changed files with 33 additions and 14 deletions
  1. 3 0
      CHANGES.txt
  2. 30 14
      src/c++/libhdfs/hdfs.c

+ 3 - 0
CHANGES.txt

@@ -345,6 +345,9 @@ Trunk (unreleased changes)
     HADOOP-3259. Makes failure to read system properties due to a
     security manager non-fatal. (Edward Yoon via omalley)
 
+    HADOOP-3451. Update libhdfs to use FileSystem::getFileBlockLocations
+    instead of removed getFileCacheHints. (lohit vijayarenu via cdouglas)
+
 Release 0.17.0 - 2008-05-18
 
   INCOMPATIBLE CHANGES

+ 30 - 14
src/c++/libhdfs/hdfs.c

@@ -25,6 +25,7 @@
 #define HADOOP_PATH     "org/apache/hadoop/fs/Path"
 #define HADOOP_LOCALFS  "org/apache/hadoop/fs/LocalFileSystem"
 #define HADOOP_FS       "org/apache/hadoop/fs/FileSystem"
+#define HADOOP_BLK_LOC  "org/apache/hadoop/fs/BlockLocation"
 #define HADOOP_DFS      "org/apache/hadoop/dfs/DistributedFileSystem"
 #define HADOOP_ISTRM    "org/apache/hadoop/fs/FSDataInputStream"
 #define HADOOP_OSTRM    "org/apache/hadoop/fs/FSDataOutputStream"
@@ -1118,7 +1119,7 @@ char***
 hdfsGetHosts(hdfsFS fs, const char* path, tOffset start, tOffset length)
 {
     // JAVA EQUIVALENT:
-    //  fs.getFileCacheHints(new Path(path), start, length);
+    //  fs.getFileBlockLoctions(new Path(path), start, length);
 
     //Get the JNIEnv* corresponding to current thread
     JNIEnv* env = getJNIEnv();
@@ -1131,25 +1132,26 @@ hdfsGetHosts(hdfsFS fs, const char* path, tOffset start, tOffset length)
         return NULL;
     }
 
-    //org.apache.hadoop.fs.FileSystem::getFileCacheHints
+    //org.apache.hadoop.fs.FileSystem::getFileBlockLocations
     char*** blockHosts = NULL;
-    jobjectArray jFileCacheHints;
+    jobjectArray jBlockLocations;;
     jvalue jVal;
     if (invokeMethod(env, &jVal, INSTANCE, jFS,
-                     HADOOP_FS, "getFileCacheHints", 
-                     "(Lorg/apache/hadoop/fs/Path;JJ)[[Ljava/lang/String;",
+                     HADOOP_FS, "getFileBlockLocations", 
+                     "(Lorg/apache/hadoop/fs/Path;JJ)"
+                     "[Lorg/apache/hadoop/fs/BlockLocation;",
                      jPath, start, length) != 0) {
         fprintf(stderr, "Call to org.apache.hadoop.fs."
-                "FileSystem::getFileCacheHints failed!\n");
+                "FileSystem::getFileBlockLocations failed!\n");
         errno = EINTERNAL;
         destroyLocalReference(env, jPath);
         return NULL;
     }
-    jFileCacheHints = jVal.l;
+    jBlockLocations = jVal.l;
 
-    //Figure out no of entries in jFileCacheHints 
+    //Figure out no of entries in jBlockLocations
     //Allocate memory and add NULL at the end
-    jsize jNumFileBlocks = (*env)->GetArrayLength(env, jFileCacheHints);
+    jsize jNumFileBlocks = (*env)->GetArrayLength(env, jBlockLocations);
 
     blockHosts = malloc(sizeof(char**) * (jNumFileBlocks+1));
     if (blockHosts == NULL) {
@@ -1165,10 +1167,24 @@ hdfsGetHosts(hdfsFS fs, const char* path, tOffset start, tOffset length)
     //Now parse each block to get hostnames
     int i = 0;
     for (i=0; i < jNumFileBlocks; ++i) {
-        jobjectArray jFileBlockHosts =
-            (*env)->GetObjectArrayElement(env, jFileCacheHints, i);
-
-        //Figure out no of entries in jFileCacheHints 
+        jobject jFileBlock =
+            (*env)->GetObjectArrayElement(env, jBlockLocations, i);
+        
+        jvalue jVal;
+        jobjectArray jFileBlockHosts;
+        if (invokeMethod(env, &jVal, INSTANCE, jFileBlock, HADOOP_BLK_LOC,
+                         "getHosts", "()[Ljava/lang/String;") ||
+                jVal.l == NULL) {
+            fprintf(stderr, "Call to org.apache.hadoop.fs.BlockLocation::"
+                    "getHosts failed!\n");
+            errno = EINTERNAL;
+            destroyLocalReference(env, jPath);
+            destroyLocalReference(env, jBlockLocations);
+            return NULL;
+        }
+        
+        jFileBlockHosts = jVal.l;
+        //Figure out no of hosts in jFileBlockHosts
         //Allocate memory and add NULL at the end
         jsize jNumBlockHosts = (*env)->GetArrayLength(env, jFileBlockHosts);
         blockHosts[i] = malloc(sizeof(char*) * (jNumBlockHosts+1));
@@ -1205,7 +1221,7 @@ hdfsGetHosts(hdfsFS fs, const char* path, tOffset start, tOffset length)
 
     //Delete unnecessary local references
     destroyLocalReference(env, jPath);
-    destroyLocalReference(env, jFileCacheHints);
+    destroyLocalReference(env, jBlockLocations);
 
     return blockHosts;
 }