This is an automated email from the ASF dual-hosted git repository.
wchevreuil pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2 by this push:
new 5bd4bfa0f64 HBASE-29160: Cache region name string in RegionInfo (#6742)
5bd4bfa0f64 is described below
commit 5bd4bfa0f6488399778d80da8676dd73132e0028
Author: Charles Connell <[email protected]>
AuthorDate: Wed Mar 5 09:22:31 2025 -0500
HBASE-29160: Cache region name string in RegionInfo (#6742)
Signed-off-by: Wellington Chevreuil <[email protected]>
(cherry picked from commit 7737ae18482daa2afd0db31581061ea49edae0ec)
Change-Id: I0229803f8b37473af5089967b48218a212b119c3
---
.../apache/hadoop/hbase/client/MutableRegionInfo.java | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git
a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MutableRegionInfo.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MutableRegionInfo.java
index 4217201b85e..d6d8e00f782 100644
---
a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MutableRegionInfo.java
+++
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MutableRegionInfo.java
@@ -64,6 +64,7 @@ class MutableRegionInfo implements RegionInfo {
private final int hashCode;
private final String encodedName;
private final byte[] encodedNameAsBytes;
+ private String nameAsString = null;
private final TableName tableName;
private static int generateHashCode(final TableName tableName, final byte[]
startKey,
@@ -149,10 +150,21 @@ class MutableRegionInfo implements RegionInfo {
return regionName;
}
- /** Returns Region name as a String for use in logging, etc. */
+ /**
+ * Returns region name as a String for use in logging, tracing, etc.
Expensive enough to compute
+ * that we do it on first request and save it. Used often because it's
included in trace of every
+ * RPC.
+ */
@Override
public String getRegionNameAsString() {
- return RegionInfo.getRegionNameAsString(this, this.regionName);
+ if (nameAsString == null) {
+ String name = RegionInfo.getRegionNameAsString(this, this.regionName);
+ // may race with other threads setting this, but that's ok
+ nameAsString = name;
+ return name;
+ } else {
+ return nameAsString;
+ }
}
/** Returns the encoded region name */