HDFS-11099: libhdfs++: Expose rack id in hdfsDNInfo. Contributed by Xiaowei Zhu.
This commit is contained in:
parent
b7d9a0f827
commit
2524afbc20
@ -41,6 +41,14 @@ public:
|
|||||||
this->ip_addr = ip_addr;
|
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 {
|
int getXferPort() const {
|
||||||
return xfer_port;
|
return xfer_port;
|
||||||
}
|
}
|
||||||
@ -75,6 +83,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::string hostname;
|
std::string hostname;
|
||||||
std::string ip_addr;
|
std::string ip_addr;
|
||||||
|
std::string network_location;
|
||||||
int xfer_port;
|
int xfer_port;
|
||||||
int info_port;
|
int info_port;
|
||||||
int IPC_port;
|
int IPC_port;
|
||||||
|
@ -132,6 +132,7 @@ int hdfsBuilderConfGetLong(struct hdfsBuilder *bld, const char *key, int64_t *va
|
|||||||
struct hdfsDNInfo {
|
struct hdfsDNInfo {
|
||||||
const char * ip_address;
|
const char * ip_address;
|
||||||
const char * hostname;
|
const char * hostname;
|
||||||
|
const char * network_location;
|
||||||
int xfer_port;
|
int xfer_port;
|
||||||
int info_port;
|
int info_port;
|
||||||
int IPC_port;
|
int IPC_port;
|
||||||
|
@ -1248,6 +1248,10 @@ int hdfsGetBlockLocations(hdfsFS fs, const char *path, struct hdfsBlockLocations
|
|||||||
buf = new char[ppDNInfo.getIPAddr().size() + 1];
|
buf = new char[ppDNInfo.getIPAddr().size() + 1];
|
||||||
strncpy(buf, ppDNInfo.getIPAddr().c_str(), ppDNInfo.getIPAddr().size() + 1);
|
strncpy(buf, ppDNInfo.getIPAddr().c_str(), ppDNInfo.getIPAddr().size() + 1);
|
||||||
dn_info->ip_address = buf;
|
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];
|
auto location = &block->locations[j];
|
||||||
delete[] location->hostname;
|
delete[] location->hostname;
|
||||||
delete[] location->ip_address;
|
delete[] location->ip_address;
|
||||||
|
delete[] location->network_location;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete[] blockLocations->blocks;
|
delete[] blockLocations->blocks;
|
||||||
|
@ -354,6 +354,8 @@ BlockLocation LocatedBlockToBlockLocation(const hadoop::hdfs::LocatedBlockProto
|
|||||||
newInfo.setIPCPort(id.ipcport());
|
newInfo.setIPCPort(id.ipcport());
|
||||||
if (id.has_infosecureport())
|
if (id.has_infosecureport())
|
||||||
newInfo.setInfoSecurePort(id.infosecureport());
|
newInfo.setInfoSecurePort(id.infosecureport());
|
||||||
|
if (datanode_info.has_location())
|
||||||
|
newInfo.setNetworkLocation(datanode_info.location());
|
||||||
dn_info.push_back(newInfo);
|
dn_info.push_back(newInfo);
|
||||||
}
|
}
|
||||||
result.setDataNodes(dn_info);
|
result.setDataNodes(dn_info);
|
||||||
|
@ -56,6 +56,7 @@ TEST_F(HdfsExtTest, TestGetBlockLocations) {
|
|||||||
EXPECT_EQ(1, blocks->blocks->num_locations);
|
EXPECT_EQ(1, blocks->blocks->num_locations);
|
||||||
EXPECT_NE(nullptr, blocks->blocks->locations->hostname);
|
EXPECT_NE(nullptr, blocks->blocks->locations->hostname);
|
||||||
EXPECT_NE(nullptr, blocks->blocks->locations->ip_address);
|
EXPECT_NE(nullptr, blocks->blocks->locations->ip_address);
|
||||||
|
EXPECT_NE(nullptr, blocks->blocks->locations->network_location);
|
||||||
EXPECT_NE(0, blocks->blocks->locations->xfer_port);
|
EXPECT_NE(0, blocks->blocks->locations->xfer_port);
|
||||||
|
|
||||||
result = hdfsFreeBlockLocations(blocks);
|
result = hdfsFreeBlockLocations(blocks);
|
||||||
|
Loading…
Reference in New Issue
Block a user