This is an automated email from the ASF dual-hosted git repository.

zhangduo pushed a commit to branch branch-2.5
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2.5 by this push:
     new 867a801a84a HBASE-28586 Backport HBASE-24791 Improve 
HFileOutputFormat2 to avoid always call getTableRelativePath method (#5888)
867a801a84a is described below

commit 867a801a84a073568ad0aa427a54f358a88c2e26
Author: szucsvillo <81696283+szucsvi...@users.noreply.github.com>
AuthorDate: Sun May 12 17:20:24 2024 +0200

    HBASE-28586 Backport HBASE-24791 Improve HFileOutputFormat2 to avoid always 
call getTableRelativePath method (#5888)
    
    Signed-off-by: Duo Zhang <zhang...@apache.org>
---
 .../hadoop/hbase/mapreduce/HFileOutputFormat2.java  | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git 
a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/HFileOutputFormat2.java
 
b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/HFileOutputFormat2.java
index 5627e02dc81..ca689488451 100644
--- 
a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/HFileOutputFormat2.java
+++ 
b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/HFileOutputFormat2.java
@@ -252,6 +252,7 @@ public class HFileOutputFormat2 extends 
FileOutputFormat<ImmutableBytesWritable,
       private final Map<byte[], WriterLength> writers = new 
TreeMap<>(Bytes.BYTES_COMPARATOR);
       private final Map<byte[], byte[]> previousRows = new 
TreeMap<>(Bytes.BYTES_COMPARATOR);
       private final long now = EnvironmentEdgeManager.currentTime();
+      private byte[] tableNameBytes = writeMultipleTables ? null : 
Bytes.toBytes(writeTableNames);
 
       @Override
       public void write(ImmutableBytesWritable row, V cell) throws IOException 
{
@@ -265,7 +266,6 @@ public class HFileOutputFormat2 extends 
FileOutputFormat<ImmutableBytesWritable,
         byte[] rowKey = CellUtil.cloneRow(kv);
         int length = (PrivateCellUtil.estimatedSerializedSizeOf(kv)) - 
Bytes.SIZEOF_INT;
         byte[] family = CellUtil.cloneFamily(kv);
-        byte[] tableNameBytes = null;
         if (writeMultipleTables) {
           tableNameBytes = MultiTableHFileOutputFormat.getTableName(row.get());
           tableNameBytes = TableName.valueOf(tableNameBytes).toBytes();
@@ -273,10 +273,7 @@ public class HFileOutputFormat2 extends 
FileOutputFormat<ImmutableBytesWritable,
             throw new IllegalArgumentException(
               "TableName " + Bytes.toString(tableNameBytes) + " not expected");
           }
-        } else {
-          tableNameBytes = Bytes.toBytes(writeTableNames);
         }
-        Path tableRelPath = getTableRelativePath(tableNameBytes);
         byte[] tableAndFamily = getTableNameSuffixedWithFamily(tableNameBytes, 
family);
         WriterLength wl = this.writers.get(tableAndFamily);
 
@@ -284,6 +281,7 @@ public class HFileOutputFormat2 extends 
FileOutputFormat<ImmutableBytesWritable,
         if (wl == null) {
           Path writerPath = null;
           if (writeMultipleTables) {
+            Path tableRelPath = getTableRelativePath(tableNameBytes);
             writerPath = new Path(outputDir, new Path(tableRelPath, 
Bytes.toString(family)));
           } else {
             writerPath = new Path(outputDir, Bytes.toString(family));
@@ -302,6 +300,7 @@ public class HFileOutputFormat2 extends 
FileOutputFormat<ImmutableBytesWritable,
 
         // create a new WAL writer, if necessary
         if (wl == null || wl.writer == null) {
+          InetSocketAddress[] favoredNodes = null;
           if (conf.getBoolean(LOCALITY_SENSITIVE_CONF_KEY, 
DEFAULT_LOCALITY_SENSITIVE)) {
             HRegionLocation loc = null;
 
@@ -318,26 +317,22 @@ public class HFileOutputFormat2 extends 
FileOutputFormat<ImmutableBytesWritable,
                 loc = null;
               }
             }
-
             if (null == loc) {
               LOG.trace("Failed get of location, use default writer {}", 
Bytes.toString(rowKey));
-              wl = getNewWriter(tableNameBytes, family, conf, null);
             } else {
               LOG.debug("First rowkey: [{}]", Bytes.toString(rowKey));
               InetSocketAddress initialIsa =
                 new InetSocketAddress(loc.getHostname(), loc.getPort());
               if (initialIsa.isUnresolved()) {
                 LOG.trace("Failed resolve address {}, use default writer", 
loc.getHostnamePort());
-                wl = getNewWriter(tableNameBytes, family, conf, null);
               } else {
                 LOG.debug("Use favored nodes writer: {}", 
initialIsa.getHostString());
-                wl = getNewWriter(tableNameBytes, family, conf,
-                  new InetSocketAddress[] { initialIsa });
+                favoredNodes = new InetSocketAddress[] { initialIsa };
               }
             }
-          } else {
-            wl = getNewWriter(tableNameBytes, family, conf, null);
           }
+          wl = getNewWriter(tableNameBytes, family, conf, favoredNodes);
+
         }
 
         // we now have the proper WAL writer. full steam ahead
@@ -352,9 +347,9 @@ public class HFileOutputFormat2 extends 
FileOutputFormat<ImmutableBytesWritable,
       private Path getTableRelativePath(byte[] tableNameBytes) {
         String tableName = Bytes.toString(tableNameBytes);
         String[] tableNameParts = tableName.split(":");
-        Path tableRelPath = new Path(tableName.split(":")[0]);
+        Path tableRelPath = new Path(tableNameParts[0]);
         if (tableNameParts.length > 1) {
-          tableRelPath = new Path(tableRelPath, tableName.split(":")[1]);
+          tableRelPath = new Path(tableRelPath, tableNameParts[1]);
         }
         return tableRelPath;
       }

Reply via email to