wchevreuil commented on code in PR #5121:
URL: https://github.com/apache/hbase/pull/5121#discussion_r1143340584


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/tool/BulkLoadHFilesTool.java:
##########
@@ -769,12 +784,48 @@ private static void copyHFileHalf(Configuration conf, 
Path inFile, Path outFile,
         
.withBytesPerCheckSum(StoreUtils.getBytesPerChecksum(conf)).withBlockSize(blocksize)
         
.withDataBlockEncoding(familyDescriptor.getDataBlockEncoding()).withIncludesTags(true)
         .withCreateTime(EnvironmentEdgeManager.currentTime()).build();
-      halfWriter = new StoreFileWriter.Builder(conf, cacheConf, 
fs).withFilePath(outFile)
-        .withBloomType(bloomFilterType).withFileContext(hFileContext).build();
+
       HFileScanner scanner = halfReader.getScanner(false, false, false);
       scanner.seekTo();
       do {
-        halfWriter.append(scanner.getCell());
+        final Cell cell = scanner.getCell();
+        if (null != halfWriter) {
+          halfWriter.append(cell);
+        } else {
+
+          // init halfwriter
+          if (conf.getBoolean(LOCALITY_SENSITIVE_CONF_KEY, 
DEFAULT_LOCALITY_SENSITIVE)) {
+            byte[] rowKey = CellUtil.cloneRow(cell);
+            HRegionLocation hRegionLocation = 
FutureUtils.get(loc.getRegionLocation(rowKey));
+            InetSocketAddress[] favoredNodes = null;
+            if (null == hRegionLocation) {
+              LOG.warn("Failed get of location, use default writer {}", 
Bytes.toString(rowKey));

Review Comment:
   nit: Can we log the following message, instead? I think it's more clear 
about what happened here. 
   
   "Failed to get location for region {}. Using writer without favoured nodes.



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/tool/BulkLoadHFilesTool.java:
##########
@@ -769,12 +784,48 @@ private static void copyHFileHalf(Configuration conf, 
Path inFile, Path outFile,
         
.withBytesPerCheckSum(StoreUtils.getBytesPerChecksum(conf)).withBlockSize(blocksize)
         
.withDataBlockEncoding(familyDescriptor.getDataBlockEncoding()).withIncludesTags(true)
         .withCreateTime(EnvironmentEdgeManager.currentTime()).build();
-      halfWriter = new StoreFileWriter.Builder(conf, cacheConf, 
fs).withFilePath(outFile)
-        .withBloomType(bloomFilterType).withFileContext(hFileContext).build();
+
       HFileScanner scanner = halfReader.getScanner(false, false, false);
       scanner.seekTo();
       do {
-        halfWriter.append(scanner.getCell());
+        final Cell cell = scanner.getCell();
+        if (null != halfWriter) {
+          halfWriter.append(cell);
+        } else {
+
+          // init halfwriter
+          if (conf.getBoolean(LOCALITY_SENSITIVE_CONF_KEY, 
DEFAULT_LOCALITY_SENSITIVE)) {
+            byte[] rowKey = CellUtil.cloneRow(cell);
+            HRegionLocation hRegionLocation = 
FutureUtils.get(loc.getRegionLocation(rowKey));
+            InetSocketAddress[] favoredNodes = null;
+            if (null == hRegionLocation) {
+              LOG.warn("Failed get of location, use default writer {}", 
Bytes.toString(rowKey));
+              halfWriter = new StoreFileWriter.Builder(conf, cacheConf, 
fs).withFilePath(outFile)
+                
.withBloomType(bloomFilterType).withFileContext(hFileContext).build();
+            } else {
+              LOG.debug("First rowkey: [{}]", Bytes.toString(rowKey));
+              InetSocketAddress initialIsa =
+                new InetSocketAddress(hRegionLocation.getHostname(), 
hRegionLocation.getPort());
+              if (initialIsa.isUnresolved()) {
+                LOG.warn("Failed resolve address {}, use default writer",

Review Comment:
   nit: Can we log the following message, instead? I think it's more clear 
about what happened here.
   
   "Failed to get location for region {}. Using writer without favoured nodes.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@hbase.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to