From e0c1dded33bc985356b68dbd2cfa449f4089d33a Mon Sep 17 00:00:00 2001 From: Zhihong Yu Date: Thu, 13 Dec 2012 21:11:43 +0000 Subject: [PATCH] HBASE-7340 Master coprocessor notification for assignmentManager.balance() is inconsistent (Ted Yu) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1421537 13f79535-47bb-0310-9956-ffa450edef68 --- .../hbase/coprocessor/BaseMasterObserver.java | 4 +++- .../hbase/coprocessor/MasterObserver.java | 17 +++++++++++++---- .../org/apache/hadoop/hbase/master/HMaster.java | 2 +- .../hbase/master/MasterCoprocessorHost.java | 5 +++-- .../apache/hadoop/hbase/master/RegionPlan.java | 4 +++- .../hbase/security/access/AccessController.java | 3 ++- .../hbase/coprocessor/TestMasterObserver.java | 5 +++-- 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java index 6937d632078..39bc832b0fa 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java @@ -27,8 +27,10 @@ import org.apache.hadoop.hbase.CoprocessorEnvironment; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.UnknownRegionException; +import org.apache.hadoop.hbase.master.RegionPlan; import java.io.IOException; +import java.util.List; @InterfaceAudience.Public @InterfaceStability.Evolving @@ -236,7 +238,7 @@ public class BaseMasterObserver implements MasterObserver { } @Override - public void postBalance(ObserverContext ctx) + public void postBalance(ObserverContext ctx, List plans) throws IOException { } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java index 515c4bf4937..7dbe1a8f4e6 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java @@ -19,11 +19,17 @@ package org.apache.hadoop.hbase.coprocessor; +import java.io.IOException; +import java.util.List; + import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; -import org.apache.hadoop.hbase.*; - -import java.io.IOException; +import org.apache.hadoop.hbase.Coprocessor; +import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.HRegionInfo; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.master.RegionPlan; /** * Defines coprocessor hooks for interacting with operations on the @@ -444,8 +450,11 @@ public interface MasterObserver extends Coprocessor { /** * Called after the balancing plan has been submitted. * @param ctx the environment to interact with the framework and master + * @param plans the RegionPlans which master has executed. RegionPlan serves as hint + * as for the final destination for the underlying region but may not represent the + * final state of assignment */ - void postBalance(final ObserverContext ctx) + void postBalance(final ObserverContext ctx, List plans) throws IOException; /** diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 0c428f36bb5..6b2950a76e5 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -1332,7 +1332,7 @@ Server { } } if (this.cpHost != null) { - this.cpHost.postBalance(); + this.cpHost.postBalance(rpCount < plans.size() ? plans.subList(0, rpCount) : plans); } } return balancerRan; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java index 6548963b6c0..de93998310b 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java @@ -27,6 +27,7 @@ import org.apache.hadoop.hbase.*; import org.apache.hadoop.hbase.coprocessor.*; import java.io.IOException; +import java.util.List; /** * Provides the coprocessor framework and environment for master oriented @@ -827,13 +828,13 @@ public class MasterCoprocessorHost return bypass; } - void postBalance() throws IOException { + void postBalance(List plans) throws IOException { ObserverContext ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { - ((MasterObserver)env.getInstance()).postBalance(ctx); + ((MasterObserver)env.getInstance()).postBalance(ctx, plans); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionPlan.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionPlan.java index 6d85dc81be9..fc012f3052b 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionPlan.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionPlan.java @@ -21,6 +21,7 @@ import java.io.Serializable; import java.util.Comparator; import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.ServerName; @@ -34,7 +35,8 @@ import org.apache.hadoop.hbase.ServerName; * The comparable implementation of this class compares only the region * information and not the source/dest server info. */ -@InterfaceAudience.Private +@InterfaceAudience.LimitedPrivate("Coprocessors") +@InterfaceStability.Evolving public class RegionPlan implements Comparable { private final HRegionInfo hri; private final ServerName source; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java index 2dd977149d1..73d091a8e78 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java @@ -50,6 +50,7 @@ import org.apache.hadoop.hbase.filter.ByteArrayComparable; import org.apache.hadoop.hbase.ipc.HBaseRPC; import org.apache.hadoop.hbase.ipc.ProtocolSignature; import org.apache.hadoop.hbase.ipc.RequestContext; +import org.apache.hadoop.hbase.master.RegionPlan; import org.apache.hadoop.hbase.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.protobuf.ResponseConverter; import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos; @@ -727,7 +728,7 @@ public class AccessController extends BaseRegionObserver requirePermission(Permission.Action.ADMIN); } @Override - public void postBalance(ObserverContext c) + public void postBalance(ObserverContext c, List plans) throws IOException {} @Override diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java index dd099fb0ff1..a39f1f03548 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java @@ -42,6 +42,7 @@ import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.master.AssignmentManager; import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.master.MasterCoprocessorHost; +import org.apache.hadoop.hbase.master.RegionPlan; import org.apache.hadoop.hbase.master.RegionState; import org.apache.hadoop.hbase.protobuf.RequestConverter; import org.apache.hadoop.hbase.protobuf.ProtobufUtil; @@ -434,8 +435,8 @@ public class TestMasterObserver { } @Override - public void postBalance(ObserverContext env) - throws IOException { + public void postBalance(ObserverContext env, + List plans) throws IOException { postBalanceCalled = true; }