فهرست منبع

HDFS-11099: libhdfs++: Expose rack id in hdfsDNInfo. Contributed by Xiaowei Zhu.

James 8 سال پیش
والد
کامیت
2524afbc20

+ 9 - 0
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/include/hdfspp/block_location.h

@@ -41,6 +41,14 @@ public:
     this->ip_addr = ip_addr;
   }
 
+  std::string getNetworkLocation() const {
+    return network_location;
+  }
+
+  void setNetworkLocation(const std::string & location) {
+    this->network_location = location;
+  }
+
   int getXferPort() const {
     return xfer_port;
   }
@@ -75,6 +83,7 @@ public:
 private:
   std::string hostname;
   std::string ip_addr;
+  std::string network_location;
   int         xfer_port;
   int         info_port;
   int         IPC_port;

+ 1 - 0
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/include/hdfspp/hdfs_ext.h

@@ -132,6 +132,7 @@ int hdfsBuilderConfGetLong(struct hdfsBuilder *bld, const char *key, int64_t *va
 struct hdfsDNInfo {
   const char *    ip_address;
   const char *    hostname;
+  const char *    network_location;
   int             xfer_port;
   int             info_port;
   int             IPC_port;

+ 5 - 0
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/bindings/c/hdfs.cc

@@ -1248,6 +1248,10 @@ int hdfsGetBlockLocations(hdfsFS fs, const char *path, struct hdfsBlockLocations
         buf = new char[ppDNInfo.getIPAddr().size() + 1];
         strncpy(buf, ppDNInfo.getIPAddr().c_str(), ppDNInfo.getIPAddr().size() + 1);
         dn_info->ip_address = buf;
+
+        buf = new char[ppDNInfo.getNetworkLocation().size() + 1];
+        strncpy(buf, ppDNInfo.getNetworkLocation().c_str(), ppDNInfo.getNetworkLocation().size() + 1);
+        dn_info->network_location = buf;
       }
     }
 
@@ -1270,6 +1274,7 @@ int hdfsFreeBlockLocations(struct hdfsBlockLocations * blockLocations) {
       auto location = &block->locations[j];
       delete[] location->hostname;
       delete[] location->ip_address;
+      delete[] location->network_location;
     }
   }
   delete[] blockLocations->blocks;

+ 2 - 0
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filesystem.cc

@@ -354,6 +354,8 @@ BlockLocation LocatedBlockToBlockLocation(const hadoop::hdfs::LocatedBlockProto
         newInfo.setIPCPort(id.ipcport());
     if (id.has_infosecureport())
       newInfo.setInfoSecurePort(id.infosecureport());
+    if (datanode_info.has_location())
+      newInfo.setNetworkLocation(datanode_info.location());
     dn_info.push_back(newInfo);
   }
   result.setDataNodes(dn_info);

+ 1 - 0
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/hdfs_ext_test.cc

@@ -56,6 +56,7 @@ TEST_F(HdfsExtTest, TestGetBlockLocations) {
   EXPECT_EQ(1, blocks->blocks->num_locations);
   EXPECT_NE(nullptr, blocks->blocks->locations->hostname);
   EXPECT_NE(nullptr, blocks->blocks->locations->ip_address);
+  EXPECT_NE(nullptr, blocks->blocks->locations->network_location);
   EXPECT_NE(0, blocks->blocks->locations->xfer_port);
 
   result = hdfsFreeBlockLocations(blocks);