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

zhangduo 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 f60ace04d19 HBASE-28707 Backport the code changes in HBASE-28675 to 
branch-2.x (#6043)
f60ace04d19 is described below

commit f60ace04d1937d068d8ad26c0d44a7d2048cfd8a
Author: Duo Zhang <zhang...@apache.org>
AuthorDate: Thu Jul 11 16:20:39 2024 +0800

    HBASE-28707 Backport the code changes in HBASE-28675 to branch-2.x (#6043)
    
    Signed-off-by: Nick Dimiduk <ndimi...@apache.org>
---
 .../org/apache/hadoop/hbase/client/AsyncAdmin.java |  1 +
 hbase-common/pom.xml                               |  5 +++
 .../hadoop/hbase/io/compress/Compression.java      |  1 +
 .../hadoop/hbase/io/hfile/bucket/BucketCache.java  | 52 ++--------------------
 .../hbase/regionserver/ServerNonceManager.java     | 10 +++--
 .../throttle/StoreHotnessProtector.java            |  9 ++--
 6 files changed, 22 insertions(+), 56 deletions(-)

diff --git 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java
index 3742fffc256..ae651c3e007 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java
@@ -1364,6 +1364,7 @@ public interface AsyncAdmin {
    * @deprecated Since 2.5.0. Will be removed in 4.0.0. Use {@link 
#balance(BalanceRequest)}
    *             instead.
    */
+  @Deprecated
   default CompletableFuture<Boolean> balance(boolean forcible) {
     return 
balance(BalanceRequest.newBuilder().setIgnoreRegionsInTransition(forcible).build())
       .thenApply(BalanceResponse::isBalancerRan);
diff --git a/hbase-common/pom.xml b/hbase-common/pom.xml
index c6edd80faa3..42322451155 100644
--- a/hbase-common/pom.xml
+++ b/hbase-common/pom.xml
@@ -130,6 +130,11 @@
       <artifactId>mockito-core</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-inline</artifactId>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>jcl-over-slf4j</artifactId>
diff --git 
a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/compress/Compression.java
 
b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/compress/Compression.java
index c55cdaa1f30..7f73cd2f004 100644
--- 
a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/compress/Compression.java
+++ 
b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/compress/Compression.java
@@ -554,6 +554,7 @@ public final class Compression {
         throw new RuntimeException("No codec configured for " + algo.confKey);
       }
       Class<?> codecClass = getClassLoaderForCodec().loadClass(codecClassName);
+      // The class is from hadoop so we use hadoop's ReflectionUtils to create 
it
       CompressionCodec codec =
         (CompressionCodec) ReflectionUtils.newInstance(codecClass, new 
Configuration(conf));
       LOG.info("Loaded codec {} for compression algorithm {}", 
codec.getClass().getCanonicalName(),
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java
index 0f4142c39e3..9446c662aff 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java
@@ -553,10 +553,10 @@ public class BucketCache implements BlockCache, HeapSize {
   }
 
   /**
-   * If the passed cache key relates to a reference 
(<hfile>.<parentEncRegion>), this method looks
-   * for the block from the referred file, in the cache. If present in the 
cache, the block for the
-   * referred file is returned, otherwise, this method returns null. It will 
also return null if the
-   * passed cache key doesn't relate to a reference.
+   * If the passed cache key relates to a reference 
(&lt;hfile&gt;.&lt;parentEncRegion&gt;), this
+   * method looks for the block from the referred file, in the cache. If 
present in the cache, the
+   * block for the referred file is returned, otherwise, this method returns 
null. It will also
+   * return null if the passed cache key doesn't relate to a reference.
    * @param key the BlockCacheKey instance to look for in the cache.
    * @return the cached block from the referred file, null if there's no such 
block in the cache or
    *         the passed key doesn't relate to a reference.
@@ -1425,50 +1425,6 @@ public class BucketCache implements BlockCache, HeapSize 
{
     }
   }
 
-  /**
-   * Create an input stream that deletes the file after reading it. Use in 
try-with-resources to
-   * avoid this pattern where an exception thrown from a finally block may 
mask earlier exceptions:
-   *
-   * <pre>
-   *   File f = ...
-   *   try (FileInputStream fis = new FileInputStream(f)) {
-   *     // use the input stream
-   *   } finally {
-   *     if (!f.delete()) throw new IOException("failed to delete");
-   *   }
-   * </pre>
-   *
-   * @param file the file to read and delete
-   * @return a FileInputStream for the given file
-   * @throws IOException if there is a problem creating the stream
-   */
-  private FileInputStream deleteFileOnClose(final File file) throws 
IOException {
-    return new FileInputStream(file) {
-      private File myFile;
-
-      private FileInputStream init(File file) {
-        myFile = file;
-        return this;
-      }
-
-      @Override
-      public void close() throws IOException {
-        // close() will be called during try-with-resources and it will be
-        // called by finalizer thread during GC. To avoid double-free resource,
-        // set myFile to null after the first call.
-        if (myFile == null) {
-          return;
-        }
-
-        super.close();
-        if (!myFile.delete()) {
-          throw new IOException("Failed deleting persistence file " + 
myFile.getAbsolutePath());
-        }
-        myFile = null;
-      }
-    }.init(file);
-  }
-
   private void verifyCapacityAndClasses(long capacitySize, String ioclass, 
String mapclass)
     throws IOException {
     if (capacitySize != cacheCapacity) {
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ServerNonceManager.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ServerNonceManager.java
index 72e7a6bdd81..a3ba4ff9db5 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ServerNonceManager.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ServerNonceManager.java
@@ -17,8 +17,9 @@
  */
 package org.apache.hadoop.hbase.regionserver;
 
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import org.apache.hadoop.conf.Configuration;
@@ -46,7 +47,8 @@ public class ServerNonceManager {
    */
   private int conflictWaitIterationMs = 30000;
 
-  private static final SimpleDateFormat tsFormat = new 
SimpleDateFormat("HH:mm:ss.SSS");
+  private static final DateTimeFormatter TS_FORMAT =
+    
DateTimeFormatter.ofPattern("HH:mm:ss.SSS").withZone(ZoneId.systemDefault());
 
   // This object is used to synchronize on in case of collisions, and for 
cleanup.
   private static class OperationContext {
@@ -65,7 +67,7 @@ public class ServerNonceManager {
     @Override
     public String toString() {
       return "[state " + getState() + ", hasWait " + hasWait() + ", activity "
-        + tsFormat.format(new Date(getActivityTime())) + "]";
+        + TS_FORMAT.format(Instant.ofEpochMilli(getActivityTime())) + "]";
     }
 
     public OperationContext() {
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/throttle/StoreHotnessProtector.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/throttle/StoreHotnessProtector.java
index 70683cb4572..6a6f52ebf29 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/throttle/StoreHotnessProtector.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/throttle/StoreHotnessProtector.java
@@ -128,7 +128,7 @@ public class StoreHotnessProtector {
       return;
     }
 
-    String tooBusyStore = null;
+    StringBuilder tooBusyStore = new StringBuilder();
     boolean aboveParallelThreadLimit = false;
     boolean aboveParallelPrePutLimit = false;
 
@@ -148,9 +148,10 @@ public class StoreHotnessProtector {
           store.getCurrentParallelPutCount() > 
this.parallelPutToStoreThreadLimit;
         boolean storeAbovePrePut = preparePutCount > 
this.parallelPreparePutToStoreThreadLimit;
         if (storeAboveThread || storeAbovePrePut) {
-          tooBusyStore = (tooBusyStore == null
-            ? store.getColumnFamilyName()
-            : tooBusyStore + "," + store.getColumnFamilyName());
+          if (tooBusyStore.length() > 0) {
+            tooBusyStore.append(',');
+          }
+          tooBusyStore.append(store.getColumnFamilyName());
         }
         aboveParallelThreadLimit |= storeAboveThread;
         aboveParallelPrePutLimit |= storeAbovePrePut;

Reply via email to