From commits-return-94745-archive-asf-public=cust-asf.ponee.io@hbase.apache.org Mon Aug 3 08:03:14 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mailroute1-lw-us.apache.org (mailroute1-lw-us.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with ESMTPS id 15EBC180642 for ; Mon, 3 Aug 2020 10:03:14 +0200 (CEST) Received: from mail.apache.org (localhost [127.0.0.1]) by mailroute1-lw-us.apache.org (ASF Mail Server at mailroute1-lw-us.apache.org) with SMTP id 2E74A124428 for ; Mon, 3 Aug 2020 08:03:13 +0000 (UTC) Received: (qmail 7507 invoked by uid 500); 3 Aug 2020 08:03:12 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 7498 invoked by uid 99); 3 Aug 2020 08:03:12 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Aug 2020 08:03:12 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 3E0EB8242E; Mon, 3 Aug 2020 08:03:12 +0000 (UTC) Date: Mon, 03 Aug 2020 08:03:11 +0000 To: "commits@hbase.apache.org" Subject: [hbase] branch master updated: HBASE-24791 Improve HFileOutputFormat2 to avoid always call getTableRelativePath method (#2167) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <159644179054.21087.14590326686303840092@gitbox.apache.org> From: anoopsamjohn@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: hbase X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 9a1bad84bf44cc737926c56592a485c606d63529 X-Git-Newrev: 8e33bb04bc2058c33750a1ad40f4188bd96926c3 X-Git-Rev: 8e33bb04bc2058c33750a1ad40f4188bd96926c3 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. anoopsamjohn pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/hbase.git The following commit(s) were added to refs/heads/master by this push: new 8e33bb0 HBASE-24791 Improve HFileOutputFormat2 to avoid always call getTableRelativePath method (#2167) 8e33bb0 is described below commit 8e33bb04bc2058c33750a1ad40f4188bd96926c3 Author: YeChao Chen AuthorDate: Mon Aug 3 16:02:48 2020 +0800 HBASE-24791 Improve HFileOutputFormat2 to avoid always call getTableRelativePath method (#2167) Signed-off-by: Anoop Signed-off-by: Ted Yu --- .../hadoop/hbase/mapreduce/HFileOutputFormat2.java | 49 ++++++++++------------ 1 file changed, 21 insertions(+), 28 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 daad1e7..08752c1 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 @@ -222,6 +222,7 @@ public class HFileOutputFormat2 private final Map writers = new TreeMap<>(Bytes.BYTES_COMPARATOR); private final Map 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 { @@ -235,7 +236,6 @@ public class HFileOutputFormat2 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).getNameWithNamespaceInclAsString() @@ -244,11 +244,7 @@ public class HFileOutputFormat2 throw new IllegalArgumentException("TableName " + Bytes.toString(tableNameBytes) + " not expected"); } - } else { - tableNameBytes = Bytes.toBytes(writeTableNames); } - String tableName = Bytes.toString(tableNameBytes); - Path tableRelPath = getTableRelativePath(tableNameBytes); byte[] tableAndFamily = getTableNameSuffixedWithFamily(tableNameBytes, family); WriterLength wl = this.writers.get(tableAndFamily); @@ -257,9 +253,9 @@ public class HFileOutputFormat2 if (wl == null) { Path writerPath = null; if (writeMultipleTables) { - writerPath = new Path(outputDir,new Path(tableRelPath, Bytes.toString(family))); - } - else { + Path tableRelPath = getTableRelativePath(tableNameBytes); + writerPath = new Path(outputDir, new Path(tableRelPath, Bytes.toString(family))); + } else { writerPath = new Path(outputDir, Bytes.toString(family)); } fs.mkdirs(writerPath); @@ -274,39 +270,37 @@ public class HFileOutputFormat2 // 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; - + String tableName = Bytes.toString(tableNameBytes); if (tableName != null) { try (Connection connection = ConnectionFactory.createConnection(conf); - RegionLocator locator = - connection.getRegionLocator(TableName.valueOf(tableName))) { + RegionLocator locator = + connection.getRegionLocator(TableName.valueOf(tableName))) { loc = locator.getRegionLocation(rowKey); } catch (Throwable e) { - LOG.warn("Something wrong locating rowkey {} in {}", - Bytes.toString(rowKey), tableName, e); + LOG.warn("Something wrong locating rowkey {} in {}", Bytes.toString(rowKey), + tableName, e); 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 @@ -321,9 +315,9 @@ public class HFileOutputFormat2 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; } @@ -376,16 +370,15 @@ public class HFileOutputFormat2 DataBlockEncoding encoding = overriddenEncoding; encoding = encoding == null ? datablockEncodingMap.get(tableAndFamily) : encoding; encoding = encoding == null ? DataBlockEncoding.NONE : encoding; - HFileContextBuilder contextBuilder = new HFileContextBuilder() - .withCompression(compression).withChecksumType(HStore.getChecksumType(conf)) - .withBytesPerCheckSum(HStore.getBytesPerChecksum(conf)).withBlockSize(blockSize) - .withColumnFamily(family).withTableName(tableName); + HFileContextBuilder contextBuilder = new HFileContextBuilder().withCompression(compression) + .withDataBlockEncoding(encoding).withChecksumType(HStore.getChecksumType(conf)) + .withBytesPerCheckSum(HStore.getBytesPerChecksum(conf)).withBlockSize(blockSize) + .withColumnFamily(family).withTableName(tableName); if (HFile.getFormatVersion(conf) >= HFile.MIN_FORMAT_VERSION_WITH_TAGS) { contextBuilder.withIncludesTags(true); } - contextBuilder.withDataBlockEncoding(encoding); HFileContext hFileContext = contextBuilder.build(); if (null == favoredNodes) { wl.writer = new StoreFileWriter.Builder(conf, CacheConfig.DISABLED, fs)