You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zh...@apache.org on 2019/03/16 02:19:24 UTC

[hbase] branch master updated: HBASE-22039 Should add the synchronous parameter for the XXXSwitch method in AsyncAdmin

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

zhangduo 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 f1ebbb9  HBASE-22039 Should add the synchronous parameter for the XXXSwitch method in AsyncAdmin
f1ebbb9 is described below

commit f1ebbb928babab4225028559d4c16306e259f3fb
Author: Duo Zhang <zh...@apache.org>
AuthorDate: Wed Mar 13 17:32:45 2019 +0800

    HBASE-22039 Should add the synchronous parameter for the XXXSwitch method in AsyncAdmin
    
    Signed-off-by: Zheng Hu <op...@gmail.com>
---
 .../org/apache/hadoop/hbase/client/AsyncAdmin.java | 57 +++++++++++++++++++---
 .../hadoop/hbase/client/AsyncHBaseAdmin.java       | 12 ++---
 .../hadoop/hbase/client/RawAsyncHBaseAdmin.java    | 43 ++++++++--------
 3 files changed, 78 insertions(+), 34 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 5952821..623e4f8 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
@@ -435,10 +435,25 @@ public interface AsyncAdmin {
 
   /**
    * Turn the Merge switch on or off.
-   * @param on
+   * @param enabled enabled or not
+   * @return Previous switch value wrapped by a {@link CompletableFuture}
+   */
+  default CompletableFuture<Boolean> mergeSwitch(boolean enabled) {
+    return mergeSwitch(enabled, false);
+  }
+
+  /**
+   * Turn the Merge switch on or off.
+   * <p/>
+   * Notice that, the method itself is always non-blocking, which means it will always return
+   * immediately. The {@code drainMerges} parameter only effects when will we complete the returned
+   * {@link CompletableFuture}.
+   * @param enabled enabled or not
+   * @param drainMerges If <code>true</code>, it waits until current merge() call, if outstanding,
+   *          to return.
    * @return Previous switch value wrapped by a {@link CompletableFuture}
    */
-  CompletableFuture<Boolean> mergeSwitch(boolean on);
+  CompletableFuture<Boolean> mergeSwitch(boolean enabled, boolean drainMerges);
 
   /**
    * Query the current state of the Merge switch.
@@ -449,10 +464,25 @@ public interface AsyncAdmin {
 
   /**
    * Turn the Split switch on or off.
-   * @param on
+   * @param enabled enabled or not
+   * @return Previous switch value wrapped by a {@link CompletableFuture}
+   */
+  default CompletableFuture<Boolean> splitSwitch(boolean enabled) {
+    return splitSwitch(enabled, false);
+  }
+
+  /**
+   * Turn the Split switch on or off.
+   * <p/>
+   * Notice that, the method itself is always non-blocking, which means it will always return
+   * immediately. The {@code drainSplits} parameter only effects when will we complete the returned
+   * {@link CompletableFuture}.
+   * @param enabled enabled or not
+   * @param drainSplits If <code>true</code>, it waits until current split() call, if outstanding,
+   *          to return.
    * @return Previous switch value wrapped by a {@link CompletableFuture}
    */
-  CompletableFuture<Boolean> splitSwitch(boolean on);
+  CompletableFuture<Boolean> splitSwitch(boolean enabled, boolean drainSplits);
 
   /**
    * Query the current state of the Split switch.
@@ -1132,10 +1162,25 @@ public interface AsyncAdmin {
 
   /**
    * Turn the load balancer on or off.
-   * @param on
+   * @param on Set to <code>true</code> to enable, <code>false</code> to disable.
+   * @return Previous balancer value wrapped by a {@link CompletableFuture}.
+   */
+  default CompletableFuture<Boolean> balancerSwitch(boolean on) {
+    return balancerSwitch(on, false);
+  }
+
+  /**
+   * Turn the load balancer on or off.
+   * <p/>
+   * Notice that, the method itself is always non-blocking, which means it will always return
+   * immediately. The {@code drainRITs} parameter only effects when will we complete the returned
+   * {@link CompletableFuture}.
+   * @param on Set to <code>true</code> to enable, <code>false</code> to disable.
+   * @param drainRITs If <code>true</code>, it waits until current balance() call, if outstanding,
+   *          to return.
    * @return Previous balancer value wrapped by a {@link CompletableFuture}.
    */
-  CompletableFuture<Boolean> balancerSwitch(boolean on);
+  CompletableFuture<Boolean> balancerSwitch(boolean on, boolean drainRITs);
 
   /**
    * Invoke the balancer. Will run the balancer and if regions to move, it will go ahead and do the
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java
index 53eaec8..ab37b31 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java
@@ -296,8 +296,8 @@ class AsyncHBaseAdmin implements AsyncAdmin {
   }
 
   @Override
-  public CompletableFuture<Boolean> mergeSwitch(boolean on) {
-    return wrap(rawAdmin.mergeSwitch(on));
+  public CompletableFuture<Boolean> mergeSwitch(boolean enabled, boolean drainMerges) {
+    return wrap(rawAdmin.mergeSwitch(enabled, drainMerges));
   }
 
   @Override
@@ -306,8 +306,8 @@ class AsyncHBaseAdmin implements AsyncAdmin {
   }
 
   @Override
-  public CompletableFuture<Boolean> splitSwitch(boolean on) {
-    return wrap(rawAdmin.splitSwitch(on));
+  public CompletableFuture<Boolean> splitSwitch(boolean enabled, boolean drainSplits) {
+    return wrap(rawAdmin.splitSwitch(enabled, drainSplits));
   }
 
   @Override
@@ -664,8 +664,8 @@ class AsyncHBaseAdmin implements AsyncAdmin {
   }
 
   @Override
-  public CompletableFuture<Boolean> balancerSwitch(boolean on) {
-    return wrap(rawAdmin.balancerSwitch(on));
+  public CompletableFuture<Boolean> balancerSwitch(boolean on, boolean drainRITs) {
+    return wrap(rawAdmin.balancerSwitch(on, drainRITs));
   }
 
   @Override
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
index 1092332..c73eec4 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
@@ -1176,8 +1176,8 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
   }
 
   @Override
-  public CompletableFuture<Boolean> mergeSwitch(boolean on) {
-    return setSplitOrMergeOn(on, MasterSwitchType.MERGE);
+  public CompletableFuture<Boolean> mergeSwitch(boolean enabled, boolean drainMerges) {
+    return setSplitOrMergeOn(enabled, drainMerges, MasterSwitchType.MERGE);
   }
 
   @Override
@@ -1186,8 +1186,8 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
   }
 
   @Override
-  public CompletableFuture<Boolean> splitSwitch(boolean on) {
-    return setSplitOrMergeOn(on, MasterSwitchType.SPLIT);
+  public CompletableFuture<Boolean> splitSwitch(boolean enabled, boolean drainSplits) {
+    return setSplitOrMergeOn(enabled, drainSplits, MasterSwitchType.SPLIT);
   }
 
   @Override
@@ -1195,16 +1195,16 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
     return isSplitOrMergeOn(MasterSwitchType.SPLIT);
   }
 
-  private CompletableFuture<Boolean> setSplitOrMergeOn(boolean on, MasterSwitchType switchType) {
+  private CompletableFuture<Boolean> setSplitOrMergeOn(boolean enabled, boolean synchronous,
+      MasterSwitchType switchType) {
     SetSplitOrMergeEnabledRequest request =
-        RequestConverter.buildSetSplitOrMergeEnabledRequest(on, false, switchType);
-    return this
-        .<Boolean> newMasterCaller()
-        .action(
-          (controller, stub) -> this
-              .<SetSplitOrMergeEnabledRequest, SetSplitOrMergeEnabledResponse, Boolean> call(
-                controller, stub, request, (s, c, req, done) -> s.setSplitOrMergeEnabled(c, req,
-                  done), (resp) -> resp.getPrevValueList().get(0))).call();
+      RequestConverter.buildSetSplitOrMergeEnabledRequest(enabled, synchronous, switchType);
+    return this.<Boolean> newMasterCaller()
+      .action((controller, stub) -> this
+        .<SetSplitOrMergeEnabledRequest, SetSplitOrMergeEnabledResponse, Boolean> call(controller,
+          stub, request, (s, c, req, done) -> s.setSplitOrMergeEnabled(c, req, done),
+          (resp) -> resp.getPrevValueList().get(0)))
+      .call();
   }
 
   private CompletableFuture<Boolean> isSplitOrMergeOn(MasterSwitchType switchType) {
@@ -3127,15 +3127,14 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
   }
 
   @Override
-  public CompletableFuture<Boolean> balancerSwitch(final boolean on) {
-    return this
-        .<Boolean> newMasterCaller()
-        .action(
-          (controller, stub) -> this
-              .<SetBalancerRunningRequest, SetBalancerRunningResponse, Boolean> call(controller,
-                stub, RequestConverter.buildSetBalancerRunningRequest(on, true),
-                (s, c, req, done) -> s.setBalancerRunning(c, req, done),
-                (resp) -> resp.getPrevBalanceValue())).call();
+  public CompletableFuture<Boolean> balancerSwitch(boolean on, boolean drainRITs) {
+    return this.<Boolean> newMasterCaller()
+      .action((controller, stub) -> this
+        .<SetBalancerRunningRequest, SetBalancerRunningResponse, Boolean> call(controller, stub,
+          RequestConverter.buildSetBalancerRunningRequest(on, drainRITs),
+          (s, c, req, done) -> s.setBalancerRunning(c, req, done),
+          (resp) -> resp.getPrevBalanceValue()))
+      .call();
   }
 
   @Override