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 3e80dda5315 HBASE-29160: Cache region name string in RegionInfo, 
additional branch-2 changes (#6756)
3e80dda5315 is described below

commit 3e80dda53155cb44f268ed1c1e2b940cdd852319
Author: Charles Connell <[email protected]>
AuthorDate: Thu Mar 20 08:53:12 2025 -0400

    HBASE-29160: Cache region name string in RegionInfo, additional branch-2 
changes (#6756)
    
    Signed-off-by: Wellington Chevreuil <[email protected]>
---
 .../java/org/apache/hadoop/hbase/HRegionInfo.java  | 23 ++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java
index 33d7d98c61e..41aca85f537 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java
@@ -161,6 +161,7 @@ public class HRegionInfo implements RegionInfo {
   public static final String NO_HASH = null;
   private String encodedName = null;
   private byte[] encodedNameAsBytes = null;
+  private String nameAsString = null;
   private int replicaId = DEFAULT_REPLICA_ID;
 
   // Current TableName
@@ -455,15 +456,21 @@ public class HRegionInfo implements RegionInfo {
   /** Returns Region name as a String for use in logging, etc. */
   @Override
   public String getRegionNameAsString() {
-    if (RegionInfo.hasEncodedName(this.regionName)) {
-      // new format region names already have their encoded name.
-      return Bytes.toStringBinary(this.regionName);
+    if (nameAsString == null) {
+      String name;
+      if (RegionInfo.hasEncodedName(this.regionName)) {
+        // new format region names already have their encoded name.
+        name = Bytes.toStringBinary(this.regionName);
+      } else {
+        // old format. regionNameStr doesn't have the region name.
+        name = Bytes.toStringBinary(this.regionName) + "." + 
this.getEncodedName();
+      }
+      // may race with other threads setting this, but that's ok
+      nameAsString = name;
+      return name;
+    } else {
+      return nameAsString;
     }
-
-    // old format. regionNameStr doesn't have the region name.
-    //
-    //
-    return Bytes.toStringBinary(this.regionName) + "." + this.getEncodedName();
   }
 
   /** Returns the encoded region name */

Reply via email to