Skip to content

Commit d0ae7d2

Browse files
Merge pull request #69 from freshertm/add_datanode_hostname_option
Added dfs.client.use.datanode.hostname config option
2 parents df854be + d6deab1 commit d0ae7d2

10 files changed

+52
-4
lines changed

src/client/RemoteBlockReader.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ RemoteBlockReader::RemoteBlockReader(const ExtendedBlock& eb,
6666
readTimeout = conf.getInputReadTimeout();
6767
writeTimeout = conf.getInputWriteTimeout();
6868
connTimeout = conf.getInputConnTimeout();
69-
sock = getNextPeer(datanode);
69+
sock = getNextPeer(datanode, conf.connectViaHostname());
7070
in = shared_ptr<BufferedSocketReader>(new BufferedSocketReaderImpl(*sock));
7171
sender = shared_ptr<DataTransferProtocol>(new DataTransferProtocolSender(
7272
*sock, writeTimeout, datanode.formatAddress()));
@@ -82,14 +82,21 @@ RemoteBlockReader::~RemoteBlockReader() {
8282
}
8383
}
8484

85-
shared_ptr<Socket> RemoteBlockReader::getNextPeer(const DatanodeInfo& dn) {
85+
shared_ptr<Socket> RemoteBlockReader::getNextPeer(const DatanodeInfo& dn, const bool connectToDnViaHostname) {
8686
shared_ptr<Socket> sock;
8787
try {
8888
sock = peerCache.getConnection(dn);
8989

9090
if (!sock) {
9191
sock = shared_ptr<Socket>(new TcpSocketImpl);
92-
sock->connect(dn.getIpAddr().c_str(), dn.getXferPort(),
92+
93+
std::string host;
94+
if(connectToDnViaHostname) {
95+
host = dn.getHostName();
96+
} else {
97+
host = dn.getIpAddr();
98+
}
99+
sock->connect(host.c_str(), dn.getXferPort(),
93100
connTimeout);
94101
sock->setNoDelay(true);
95102
}

src/client/RemoteBlockReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class RemoteBlockReader: public BlockReader {
7676
private:
7777
bool readTrailingEmptyPacket();
7878
shared_ptr<PacketHeader> readPacketHeader();
79-
shared_ptr<Socket> getNextPeer(const DatanodeInfo& dn);
79+
shared_ptr<Socket> getNextPeer(const DatanodeInfo& dn, const bool connectToDnViaHostname);
8080
void checkResponse();
8181
void readNextPacket();
8282
void sendStatus();

src/common/SessionConfig.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ SessionConfig::SessionConfig(const Config & conf) {
6969
&useMappedFile, "input.localread.mappedfile", true
7070
}, {
7171
&legacyLocalBlockReader, "dfs.client.use.legacy.blockreader.local", false
72+
}, {
73+
&connectToDnViaHostname, "dfs.client.use.datanode.hostname", false
7274
}
7375
};
7476
ConfigDefault<int32_t> i32Values[] = {

src/common/SessionConfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ class SessionConfig {
139139
return maxLocalBlockInfoCacheSize;
140140
}
141141

142+
bool connectViaHostname() const {
143+
return connectToDnViaHostname;
144+
}
145+
142146
/*
143147
* OutputStream configure
144148
*/
@@ -339,6 +343,7 @@ class SessionConfig {
339343
/*
340344
* InputStream configure
341345
*/
346+
bool connectToDnViaHostname;
342347
bool useMappedFile;
343348
bool readFromLocal;
344349
bool notRetryAnotherNode;

test/data/function-secure.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@
3939
<name>dfs.namenode.http-address.gphd-cluster.nn2</name>
4040
<value>mdw:50070</value>
4141
</property>
42+
43+
<property>
44+
<name>dfs.client.use.datanode.hostname</name>
45+
<value>true</value>
46+
</property>
4247

4348
</configuration>

test/data/function-secure.xml.sample

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@
3939
<name>dfs.namenode.http-address.gphd-cluster.nn2</name>
4040
<value>mdw:50070</value>
4141
</property>
42+
43+
<property>
44+
<name>dfs.client.use.datanode.hostname</name>
45+
<value>true</value>
46+
</property>
4247

4348
</configuration>

test/data/function-test.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,10 @@
119119
<name>dfs.client.read.striped.thread-pool.size</name>
120120
<value>64</value>
121121
</property>
122+
123+
<property>
124+
<name>dfs.client.use.datanode.hostname</name>
125+
<value>true</value>
126+
</property>
127+
122128
</configuration>

test/data/function-test.xml.sample

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,10 @@
104104
<name>test.get.confint32</name>
105105
<value>10</value>
106106
</property>
107+
108+
<property>
109+
<name>dfs.client.use.datanode.hostname</name>
110+
<value>true</value>
111+
</property>
112+
107113
</configuration>

test/data/invalidha.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@
2626
<name>dfs.client.failover.proxy.provider.phdcluster</name>
2727
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
2828
</property>
29+
30+
<property>
31+
<name>dfs.client.use.datanode.hostname</name>
32+
<value>true</value>
33+
</property>
34+
2935
</configuration>

test/data/validha.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,10 @@
3232
<name>dfs.client.failover.proxy.provider.phdcluster</name>
3333
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
3434
</property>
35+
36+
<property>
37+
<name>dfs.client.use.datanode.hostname</name>
38+
<value>true</value>
39+
</property>
40+
3541
</configuration>

0 commit comments

Comments
 (0)