From db102ed307e11467d2bc63379e482dbb700a046e Mon Sep 17 00:00:00 2001 From: Zhihong Yu Date: Fri, 16 Sep 2011 17:59:02 +0000 Subject: [PATCH] HBASE-4373 HBaseAdmin.assign() does not use force flag (Ramkrishna) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1171697 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../hadoop/hbase/client/HBaseAdmin.java | 27 +++++++++++++++---- .../hbase/coprocessor/BaseMasterObserver.java | 6 ++--- .../hbase/coprocessor/MasterObserver.java | 11 +++----- .../hadoop/hbase/ipc/HMasterInterface.java | 14 ++++++++++ .../apache/hadoop/hbase/master/HMaster.java | 16 ++++++++--- .../hbase/master/MasterCoprocessorHost.java | 9 +++---- .../hadoop/hbase/util/HBaseFsckRepair.java | 4 +-- src/main/ruby/hbase/admin.rb | 4 +-- src/main/ruby/shell/commands/assign.rb | 8 +++--- .../hbase/coprocessor/TestMasterObserver.java | 8 +++--- 11 files changed, 72 insertions(+), 36 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index cc1741acc59..31e7583e1b4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -494,6 +494,7 @@ Release 0.91.0 - Unreleased HBASE-4287 If region opening fails, change region in transition into a FAILED_OPEN state so that it can be retried quickly. (todd) HBASE-4381 Refactor split decisions into a split policy class. (todd) + HBASE-4373 HBaseAdmin.assign() does not use force flag (Ramkrishna) TASKS HBASE-3559 Move report of split to master OFF the heartbeat channel diff --git a/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java b/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java index c28ec8e975c..7805f1c16be 100644 --- a/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java +++ b/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java @@ -54,6 +54,7 @@ import org.apache.hadoop.hbase.ZooKeeperConnectionException; import org.apache.hadoop.hbase.catalog.CatalogTracker; import org.apache.hadoop.hbase.catalog.MetaReader; import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor; +import org.apache.hadoop.hbase.coprocessor.ObserverContext; import org.apache.hadoop.hbase.ipc.HMasterInterface; import org.apache.hadoop.hbase.ipc.HRegionInterface; import org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException; @@ -1303,15 +1304,31 @@ public class HBaseAdmin implements Abortable, Closeable { } /** - * @param regionName Region name to assign. - * @param force True to force assign. + * @param regionName + * Region name to assign. + * @param force + * True to force assign. + * @throws MasterNotRunningException + * @throws ZooKeeperConnectionException + * @throws IOException + * @deprecated The force is unused.Use {@link #assign(byte[])} + */ + public void assign(final byte[] regionName, final boolean force) + throws MasterNotRunningException, ZooKeeperConnectionException, + IOException { + getMaster().assign(regionName, force); + } + + /** + * @param regionName + * Region name to assign. * @throws MasterNotRunningException * @throws ZooKeeperConnectionException * @throws IOException */ - public void assign(final byte [] regionName, final boolean force) - throws MasterNotRunningException, ZooKeeperConnectionException, IOException { - getMaster().assign(regionName, force); + public void assign(final byte[] regionName) throws MasterNotRunningException, + ZooKeeperConnectionException, IOException { + getMaster().assign(regionName); } /** diff --git a/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java b/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java index c6374a07fc0..d6d487fb246 100644 --- a/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java +++ b/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java @@ -112,12 +112,12 @@ public class BaseMasterObserver implements MasterObserver { @Override public void preAssign(ObserverContext ctx, - HRegionInfo regionInfo, boolean force) throws IOException { + HRegionInfo regionInfo) throws IOException { } - + @Override public void postAssign(ObserverContext ctx, - HRegionInfo regionInfo, boolean force) throws IOException { + HRegionInfo regionInfo) throws IOException { } @Override diff --git a/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java b/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java index 96774d682a6..04fa4befd7d 100644 --- a/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java +++ b/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java @@ -205,21 +205,18 @@ public interface MasterObserver extends Coprocessor { * Called prior to assigning a specific region. * @param ctx the environment to interact with the framework and master * @param regionInfo the regionInfo of the region - * @param force whether to force assignment or not */ void preAssign(final ObserverContext ctx, - final HRegionInfo regionInfo, final boolean force) - throws IOException; - + final HRegionInfo regionInfo) throws IOException; + /** * Called after the region assignment has been requested. * @param ctx the environment to interact with the framework and master * @param regionInfo the regionInfo of the region - * @param force whether to force assignment or not */ void postAssign(final ObserverContext ctx, - final HRegionInfo regionInfo, final boolean force) throws IOException; - + final HRegionInfo regionInfo) throws IOException; + /** * Called prior to unassigning a given region. * @param ctx the environment to interact with the framework and master diff --git a/src/main/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java b/src/main/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java index f5dbfbd8645..85c78aa80fd 100644 --- a/src/main/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java +++ b/src/main/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java @@ -24,11 +24,15 @@ import java.util.List; import org.apache.hadoop.hbase.ClusterStatus; import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.UnknownRegionException; import org.apache.hadoop.hbase.util.Pair; +import org.apache.hadoop.hbase.coprocessor.ObserverContext; import org.apache.hadoop.hbase.ipc.VersionedProtocol; + + /** * Clients interact with the HMasterInterface to gain access to meta-level * HBase functionality, like finding an HRegionServer and creating/destroying @@ -180,10 +184,20 @@ public interface HMasterInterface extends VersionedProtocol { * found. * @param force If true, will force the assignment. * @throws IOException + * @deprecated The force is unused.Use {@link #assign(byte[])} */ public void assign(final byte [] regionName, final boolean force) throws IOException; + /** + * Assign a region to a server chosen at random. + * + * @param regionName + * Region to assign. Will use existing RegionPlan if one found. + * @throws IOException + */ + public void assign(final byte[] regionName) throws IOException; + /** * Unassign a region from current hosting regionserver. Region will then be * assigned to a regionserver chosen at random. Region could be reassigned diff --git a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index db680dcaadf..35eaa5a71ea 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -1330,23 +1330,31 @@ implements HMasterInterface, HMasterRegionInterface, MasterServices, Server { public boolean isInitialized() { return initialized; } + + @Override + @Deprecated + public void assign(final byte[] regionName, final boolean force) + throws IOException { + assign(regionName); + } @Override - public void assign(final byte [] regionName, final boolean force) - throws IOException { + public void assign(final byte [] regionName)throws IOException { Pair pair = MetaReader.getRegion(this.catalogTracker, regionName); if (pair == null) throw new UnknownRegionException(Bytes.toString(regionName)); if (cpHost != null) { - if (cpHost.preAssign(pair.getFirst(), force)) { + if (cpHost.preAssign(pair.getFirst())) { return; } } assignRegion(pair.getFirst()); if (cpHost != null) { - cpHost.postAssign(pair.getFirst(), force); + cpHost.postAssign(pair.getFirst()); } } + + public void assignRegion(HRegionInfo hri) { assignmentManager.assign(hri, true); diff --git a/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java b/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java index 3e87443ea32..f1b0e9f395b 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java +++ b/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java @@ -332,14 +332,13 @@ public class MasterCoprocessorHost } } - boolean preAssign(final HRegionInfo regionInfo, final boolean force) - throws IOException { + boolean preAssign(final HRegionInfo regionInfo) throws IOException { boolean bypass = false; ObserverContext ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); - ((MasterObserver)env.getInstance()).preAssign(ctx, regionInfo, force); + ((MasterObserver) env.getInstance()).preAssign(ctx, regionInfo); bypass |= ctx.shouldBypass(); if (ctx.shouldComplete()) { break; @@ -349,12 +348,12 @@ public class MasterCoprocessorHost return bypass; } - void postAssign(final HRegionInfo regionInfo, final boolean force) throws IOException { + void postAssign(final HRegionInfo regionInfo) throws IOException { ObserverContext ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); - ((MasterObserver)env.getInstance()).postAssign(ctx, regionInfo, force); + ((MasterObserver) env.getInstance()).postAssign(ctx, regionInfo); if (ctx.shouldComplete()) { break; } diff --git a/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java b/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java index 74d3cdb8c1d..77f60a021e7 100644 --- a/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java +++ b/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java @@ -80,7 +80,7 @@ public class HBaseFsckRepair { private static void forceOfflineInZK(HBaseAdmin admin, final HRegionInfo region) throws ZooKeeperConnectionException, KeeperException, IOException { - admin.assign(region.getRegionName(), true); + admin.assign(region.getRegionName()); } private static void closeRegionSilentlyAndWait(Configuration conf, @@ -117,4 +117,4 @@ public class HBaseFsckRepair { } } } -} \ No newline at end of file +} diff --git a/src/main/ruby/hbase/admin.rb b/src/main/ruby/hbase/admin.rb index 93a8029b7f5..b244ffeba3a 100644 --- a/src/main/ruby/hbase/admin.rb +++ b/src/main/ruby/hbase/admin.rb @@ -230,8 +230,8 @@ module Hbase #---------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------- # Assign a region - def assign(region_name, force) - @admin.assign(region_name.to_java_bytes, java.lang.Boolean::valueOf(force)) + def assign(region_name) + @admin.assign(region_name.to_java_bytes) end #---------------------------------------------------------------------------------------------- diff --git a/src/main/ruby/shell/commands/assign.rb b/src/main/ruby/shell/commands/assign.rb index 2fe4a7f7db4..4c83d3cf200 100644 --- a/src/main/ruby/shell/commands/assign.rb +++ b/src/main/ruby/shell/commands/assign.rb @@ -23,15 +23,15 @@ module Shell class Assign < Command def help return <<-EOF -Assign a region. Add 'true' to force assign of a region. Use with caution. -If region already assigned, this command will just go ahead and reassign +Assign a region.Use with caution.If region already assigned, +this command will just go ahead and reassign the region anyways. For experts only. EOF end - def command(region_name, force = 'false') + def command(region_name) format_simple_command do - admin.assign(region_name, force) + admin.assign(region_name) end end end diff --git a/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java b/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java index 6a84a7a2663..1868d1cca9b 100644 --- a/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java +++ b/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java @@ -333,10 +333,10 @@ public class TestMasterObserver { public boolean preMoveCalledOnly() { return preMoveCalled && !postMoveCalled; } - + @Override public void preAssign(ObserverContext env, - final HRegionInfo regionInfo, final boolean force) throws IOException { + final HRegionInfo regionInfo) throws IOException { if (bypass) { env.bypass(); } @@ -345,10 +345,10 @@ public class TestMasterObserver { @Override public void postAssign(ObserverContext env, - final HRegionInfo regionInfo, final boolean force) throws IOException { + final HRegionInfo regionInfo) throws IOException { postAssignCalled = true; } - + public boolean wasAssignCalled() { return preAssignCalled && postAssignCalled; }