Skip to content

Commit 8c7d1e4

Browse files
HBASE-29285 Use DataNode port as favored-node port to make bulk load follow locality
1 parent 5dafa9e commit 8c7d1e4

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/HFileOutputFormat2.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
import org.apache.hadoop.hbase.util.CommonFSUtils;
8080
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
8181
import org.apache.hadoop.hbase.util.MapReduceExtendedCell;
82+
import org.apache.hadoop.hdfs.DFSConfigKeys;
83+
import org.apache.hadoop.hdfs.HdfsConfiguration;
8284
import org.apache.hadoop.io.NullWritable;
8385
import org.apache.hadoop.io.SequenceFile;
8486
import org.apache.hadoop.io.Text;
@@ -90,6 +92,7 @@
9092
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
9193
import org.apache.hadoop.mapreduce.lib.output.PathOutputCommitter;
9294
import org.apache.hadoop.mapreduce.lib.partition.TotalOrderPartitioner;
95+
import org.apache.hadoop.net.NetUtils;
9396
import org.apache.yetus.audience.InterfaceAudience;
9497
import org.slf4j.Logger;
9598
import org.slf4j.LoggerFactory;
@@ -306,8 +309,7 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
306309
LOG.trace("Failed get of location, use default writer {}", Bytes.toString(rowKey));
307310
} else {
308311
LOG.debug("First rowkey: [{}]", Bytes.toString(rowKey));
309-
InetSocketAddress initialIsa =
310-
new InetSocketAddress(loc.getHostname(), loc.getPort());
312+
InetSocketAddress initialIsa = getDNFavoredNode(conf, loc);
311313
if (initialIsa.isUnresolved()) {
312314
LOG.trace("Failed resolve address {}, use default writer", loc.getHostnamePort());
313315
} else {
@@ -329,6 +331,14 @@ public void write(ImmutableBytesWritable row, V cell) throws IOException {
329331
this.previousRows.put(family, rowKey);
330332
}
331333

334+
private InetSocketAddress getDNFavoredNode(Configuration conf, HRegionLocation loc) {
335+
HdfsConfiguration.init();
336+
Configuration dnConf = new HdfsConfiguration(conf);
337+
int dnPort = NetUtils.createSocketAddr(dnConf.get(DFSConfigKeys.DFS_DATANODE_ADDRESS_KEY,
338+
DFSConfigKeys.DFS_DATANODE_ADDRESS_DEFAULT)).getPort();
339+
return new InetSocketAddress(loc.getHostname(), dnPort);
340+
}
341+
332342
private Path getTableRelativePath(byte[] tableNameBytes) {
333343
String tableName = Bytes.toString(tableNameBytes);
334344
String[] tableNameParts = tableName.split(":");

0 commit comments

Comments
 (0)