You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by jx...@apache.org on 2014/08/07 01:22:49 UTC
[05/10] HBASE-11611 Clean up ZK-based region assignment
http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRegionHandler.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRegionHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRegionHandler.java
index 07313db..77d8167 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRegionHandler.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/CloseRegionHandler.java
@@ -26,13 +26,11 @@ import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.Server;
import org.apache.hadoop.hbase.ServerName;
-import org.apache.hadoop.hbase.coordination.CloseRegionCoordination;
import org.apache.hadoop.hbase.executor.EventHandler;
import org.apache.hadoop.hbase.executor.EventType;
import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode;
import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.regionserver.RegionServerServices;
-import org.apache.hadoop.hbase.util.ConfigUtil;
/**
* Handles closing of a region on a region server.
@@ -41,7 +39,7 @@ import org.apache.hadoop.hbase.util.ConfigUtil;
public class CloseRegionHandler extends EventHandler {
// NOTE on priorities shutting down. There are none for close. There are some
// for open. I think that is right. On shutdown, we want the meta to close
- // before root and both to close after the user regions have closed. What
+ // after the user regions have closed. What
// about the case where master tells us to shutdown a catalog region and we
// have a running queue of user regions to close?
private static final Log LOG = LogFactory.getLog(CloseRegionHandler.class);
@@ -53,9 +51,6 @@ public class CloseRegionHandler extends EventHandler {
// when we are aborting.
private final boolean abort;
private ServerName destination;
- private CloseRegionCoordination closeRegionCoordination;
- private CloseRegionCoordination.CloseRegionDetails closeRegionDetails;
- private final boolean useZKForAssignment;
/**
* This method used internally by the RegionServer to close out regions.
@@ -63,49 +58,25 @@ public class CloseRegionHandler extends EventHandler {
* @param rsServices
* @param regionInfo
* @param abort If the regionserver is aborting.
- * @param closeRegionCoordination consensus for closing regions
- * @param crd object carrying details about region close task.
+ * @param destination
*/
public CloseRegionHandler(final Server server,
final RegionServerServices rsServices,
final HRegionInfo regionInfo, final boolean abort,
- CloseRegionCoordination closeRegionCoordination,
- CloseRegionCoordination.CloseRegionDetails crd) {
- this(server, rsServices, regionInfo, abort, closeRegionCoordination, crd,
- EventType.M_RS_CLOSE_REGION, null);
- }
-
- public CloseRegionHandler(final Server server,
- final RegionServerServices rsServices,
- final HRegionInfo regionInfo, final boolean abort,
- CloseRegionCoordination closeRegionCoordination,
- CloseRegionCoordination.CloseRegionDetails crd,
ServerName destination) {
- this(server, rsServices, regionInfo, abort, closeRegionCoordination, crd,
+ this(server, rsServices, regionInfo, abort,
EventType.M_RS_CLOSE_REGION, destination);
}
- public CloseRegionHandler(final Server server,
+ protected CloseRegionHandler(final Server server,
final RegionServerServices rsServices, HRegionInfo regionInfo,
- boolean abort, CloseRegionCoordination closeRegionCoordination,
- CloseRegionCoordination.CloseRegionDetails crd, EventType eventType) {
- this(server, rsServices, regionInfo, abort, closeRegionCoordination, crd, eventType, null);
- }
-
- protected CloseRegionHandler(final Server server,
- final RegionServerServices rsServices, HRegionInfo regionInfo,
- boolean abort, CloseRegionCoordination closeRegionCoordination,
- CloseRegionCoordination.CloseRegionDetails crd,
- EventType eventType, ServerName destination) {
+ boolean abort, EventType eventType, ServerName destination) {
super(server, eventType);
this.server = server;
this.rsServices = rsServices;
this.regionInfo = regionInfo;
this.abort = abort;
this.destination = destination;
- this.closeRegionCoordination = closeRegionCoordination;
- this.closeRegionDetails = crd;
- useZKForAssignment = ConfigUtil.useZKForAssignment(server.getConfiguration());
}
public HRegionInfo getRegionInfo() {
@@ -128,16 +99,8 @@ public class CloseRegionHandler extends EventHandler {
// Close the region
try {
- if (useZKForAssignment && closeRegionCoordination.checkClosingState(
- regionInfo, closeRegionDetails)) {
- return;
- }
-
- // TODO: If we need to keep updating CLOSING stamp to prevent against
- // a timeout if this is long-running, need to spin up a thread?
if (region.close(abort) == null) {
- // This region got closed. Most likely due to a split. So instead
- // of doing the setClosedState() below, let's just ignore cont
+ // This region got closed. Most likely due to a split.
// The split message will clean up the master state.
LOG.warn("Can't close region: was already closed during close(): " +
regionInfo.getRegionNameAsString());
@@ -153,12 +116,7 @@ public class CloseRegionHandler extends EventHandler {
}
this.rsServices.removeFromOnlineRegions(region, destination);
- if (!useZKForAssignment) {
- rsServices.reportRegionStateTransition(TransitionCode.CLOSED, regionInfo);
- } else {
- closeRegionCoordination.setClosedState(region, this.server.getServerName(),
- closeRegionDetails);
- }
+ rsServices.reportRegionStateTransition(TransitionCode.CLOSED, regionInfo);
// Done! Region is closed on this RS
LOG.debug("Closed " + region.getRegionNameAsString());
http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenMetaHandler.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenMetaHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenMetaHandler.java
index f2d5f1f..21e84ae 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenMetaHandler.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenMetaHandler.java
@@ -24,7 +24,6 @@ import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.Server;
import org.apache.hadoop.hbase.executor.EventType;
import org.apache.hadoop.hbase.regionserver.RegionServerServices;
-import org.apache.hadoop.hbase.coordination.OpenRegionCoordination;
/**
* Handles opening of a meta region on a region server.
@@ -35,9 +34,7 @@ import org.apache.hadoop.hbase.coordination.OpenRegionCoordination;
public class OpenMetaHandler extends OpenRegionHandler {
public OpenMetaHandler(final Server server,
final RegionServerServices rsServices, HRegionInfo regionInfo,
- final HTableDescriptor htd, OpenRegionCoordination coordination,
- OpenRegionCoordination.OpenRegionDetails ord) {
- super(server, rsServices, regionInfo, htd, EventType.M_RS_OPEN_META,
- coordination, ord);
+ final HTableDescriptor htd) {
+ super(server, rsServices, regionInfo, htd, EventType.M_RS_OPEN_META);
}
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRegionHandler.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRegionHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRegionHandler.java
index ef30f08..20e0970 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRegionHandler.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRegionHandler.java
@@ -27,7 +27,6 @@ import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.Server;
-import org.apache.hadoop.hbase.coordination.OpenRegionCoordination;
import org.apache.hadoop.hbase.executor.EventHandler;
import org.apache.hadoop.hbase.executor.EventType;
import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode;
@@ -35,7 +34,6 @@ import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.regionserver.RegionServerAccounting;
import org.apache.hadoop.hbase.regionserver.RegionServerServices;
import org.apache.hadoop.hbase.util.CancelableProgressable;
-import org.apache.hadoop.hbase.util.ConfigUtil;
/**
* Handles opening of a region on a region server.
* <p>
@@ -50,30 +48,19 @@ public class OpenRegionHandler extends EventHandler {
private final HRegionInfo regionInfo;
private final HTableDescriptor htd;
- private OpenRegionCoordination coordination;
- private OpenRegionCoordination.OpenRegionDetails ord;
-
- private final boolean useZKForAssignment;
-
public OpenRegionHandler(final Server server,
final RegionServerServices rsServices, HRegionInfo regionInfo,
- HTableDescriptor htd, OpenRegionCoordination coordination,
- OpenRegionCoordination.OpenRegionDetails ord) {
- this(server, rsServices, regionInfo, htd, EventType.M_RS_OPEN_REGION,
- coordination, ord);
+ HTableDescriptor htd) {
+ this(server, rsServices, regionInfo, htd, EventType.M_RS_OPEN_REGION);
}
protected OpenRegionHandler(final Server server,
final RegionServerServices rsServices, final HRegionInfo regionInfo,
- final HTableDescriptor htd, EventType eventType,
- OpenRegionCoordination coordination, OpenRegionCoordination.OpenRegionDetails ord) {
+ final HTableDescriptor htd, EventType eventType) {
super(server, eventType);
this.rsServices = rsServices;
this.regionInfo = regionInfo;
this.htd = htd;
- this.coordination = coordination;
- this.ord = ord;
- useZKForAssignment = ConfigUtil.useZKForAssignment(server.getConfiguration());
}
public HRegionInfo getRegionInfo() {
@@ -83,7 +70,6 @@ public class OpenRegionHandler extends EventHandler {
@Override
public void process() throws IOException {
boolean openSuccessful = false;
- boolean transitionedToOpening = false;
final String regionName = regionInfo.getRegionNameAsString();
HRegion region = null;
@@ -93,10 +79,9 @@ public class OpenRegionHandler extends EventHandler {
}
final String encodedName = regionInfo.getEncodedName();
- // 3 different difficult situations can occur
+ // 2 different difficult situations can occur
// 1) The opening was cancelled. This is an expected situation
- // 2) The region was hijacked, we no longer have the znode
- // 3) The region is now marked as online while we're suppose to open. This would be a bug.
+ // 2) The region is now marked as online while we're suppose to open. This would be a bug.
// Check that this region is not already online
if (this.rsServices.getFromOnlineRegions(encodedName) != null) {
@@ -106,21 +91,13 @@ public class OpenRegionHandler extends EventHandler {
return;
}
- // Check that we're still supposed to open the region and transition.
+ // Check that we're still supposed to open the region.
// If fails, just return. Someone stole the region from under us.
- // Calling transitionFromOfflineToOpening initializes this.version.
if (!isRegionStillOpening()){
LOG.error("Region " + encodedName + " opening cancelled");
return;
}
- if (useZKForAssignment
- && !coordination.transitionFromOfflineToOpening(regionInfo, ord)) {
- LOG.warn("Region was hijacked? Opening cancelled for encodedName=" + encodedName);
- // This is a desperate attempt: the znode is unlikely to be ours. But we can't do more.
- return;
- }
- transitionedToOpening = true;
// Open region. After a successful open, failures in subsequent
// processing needs to do a close as part of cleanup.
region = openRegion();
@@ -128,37 +105,15 @@ public class OpenRegionHandler extends EventHandler {
return;
}
- boolean failed = true;
- if (!useZKForAssignment ||
- coordination.tickleOpening(ord, regionInfo, rsServices, "post_region_open")) {
- if (updateMeta(region)) {
- failed = false;
- }
- }
- if (failed || this.server.isStopped() ||
+ if (!updateMeta(region) || this.server.isStopped() ||
this.rsServices.isStopping()) {
return;
}
- if (!isRegionStillOpening() ||
- (useZKForAssignment && !coordination.transitionToOpened(region, ord))) {
- // If we fail to transition to opened, it's because of one of two cases:
- // (a) we lost our ZK lease
- // OR (b) someone else opened the region before us
- // OR (c) someone cancelled the open
- // In all cases, we try to transition to failed_open to be safe.
+ if (!isRegionStillOpening()) {
return;
}
- // We have a znode in the opened state now. We can't really delete it as the master job.
- // Transitioning to failed open would create a race condition if the master has already
- // acted the transition to opened.
- // Cancelling the open is dangerous, because we would have a state where the master thinks
- // the region is opened while the region is actually closed. It is a dangerous state
- // to be in. For this reason, from now on, we're not going back. There is a message in the
- // finally close to let the admin knows where we stand.
-
-
// Successful region open, and add it to OnlineRegions
this.rsServices.addToOnlineRegions(region);
openSuccessful = true;
@@ -166,12 +121,10 @@ public class OpenRegionHandler extends EventHandler {
// Done! Successful region open
LOG.debug("Opened " + regionName + " on " +
this.server.getServerName());
-
-
} finally {
// Do all clean up here
if (!openSuccessful) {
- doCleanUpOnFailedOpen(region, transitionedToOpening, ord);
+ doCleanUpOnFailedOpen(region);
}
final Boolean current = this.rsServices.getRegionsInTransitionInRS().
remove(this.regionInfo.getEncodedNameAsBytes());
@@ -180,9 +133,7 @@ public class OpenRegionHandler extends EventHandler {
// A better solution would be to not have any race condition.
// this.rsServices.getRegionsInTransitionInRS().remove(
// this.regionInfo.getEncodedNameAsBytes(), Boolean.TRUE);
- // would help, but we would still have a consistency issue to manage with
- // 1) this.rsServices.addToOnlineRegions(region);
- // 2) the ZK state.
+ // would help.
if (openSuccessful) {
if (current == null) { // Should NEVER happen, but let's be paranoid.
LOG.error("Bad state: we've just opened a region that was NOT in transition. Region="
@@ -198,29 +149,14 @@ public class OpenRegionHandler extends EventHandler {
}
}
- private void doCleanUpOnFailedOpen(HRegion region, boolean transitionedToOpening,
- OpenRegionCoordination.OpenRegionDetails ord)
+ private void doCleanUpOnFailedOpen(HRegion region)
throws IOException {
- if (transitionedToOpening) {
- try {
- if (region != null) {
- cleanupFailedOpen(region);
- }
- } finally {
- if (!useZKForAssignment) {
- rsServices.reportRegionStateTransition(TransitionCode.FAILED_OPEN, regionInfo);
- } else {
- // Even if cleanupFailed open fails we need to do this transition
- // See HBASE-7698
- coordination.tryTransitionFromOpeningToFailedOpen(regionInfo, ord);
- }
+ try {
+ if (region != null) {
+ cleanupFailedOpen(region);
}
- } else if (!useZKForAssignment) {
+ } finally {
rsServices.reportRegionStateTransition(TransitionCode.FAILED_OPEN, regionInfo);
- } else {
- // If still transition to OPENING is not done, we need to transition znode
- // to FAILED_OPEN
- coordination.tryTransitionFromOfflineToFailedOpen(this.rsServices, regionInfo, ord);
}
}
@@ -244,8 +180,6 @@ public class OpenRegionHandler extends EventHandler {
// Post open deploy task:
// meta => update meta location in ZK
// other region => update meta
- // It could fail if ZK/meta is not available and
- // the update runs out of retries.
long now = System.currentTimeMillis();
long lastUpdate = now;
boolean tickleOpening = true;
@@ -255,10 +189,6 @@ public class OpenRegionHandler extends EventHandler {
if (elapsed > 120000) { // 2 minutes, no need to tickleOpening too often
// Only tickle OPENING if postOpenDeployTasks is taking some time.
lastUpdate = now;
- if (useZKForAssignment) {
- tickleOpening = coordination.tickleOpening(
- ord, regionInfo, rsServices, "post_open_deploy");
- }
}
synchronized (signaller) {
try {
@@ -356,11 +286,6 @@ public class OpenRegionHandler extends EventHandler {
this.rsServices,
new CancelableProgressable() {
public boolean progress() {
- if (useZKForAssignment) {
- // if tickle failed, we need to cancel opening region.
- return coordination.tickleOpening(ord, regionInfo,
- rsServices, "open_region_progress");
- }
if (!isRegionStillOpening()) {
LOG.warn("Open region aborted since it isn't opening any more");
return false;
http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-server/src/main/java/org/apache/hadoop/hbase/util/ConfigUtil.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/ConfigUtil.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/ConfigUtil.java
deleted file mode 100644
index 0f9b713..0000000
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/ConfigUtil.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.hbase.util;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.conf.Configuration;
-
-/**
- * Some configuration related utilities
- */
-@InterfaceAudience.Private
-public class ConfigUtil {
-
- public static boolean useZKForAssignment(Configuration conf) {
- // To change the default, please also update ZooKeeperWatcher.java
- return conf.getBoolean("hbase.assignment.usezk", false);
- }
-}
http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java
index 84ffec8..960d69c 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java
@@ -147,12 +147,13 @@ public class HBaseFsckRepair {
* Contacts a region server and waits up to hbase.hbck.close.timeout ms
* (default 120s) to close the region. This bypasses the active hmaster.
*/
+ @SuppressWarnings("deprecation")
public static void closeRegionSilentlyAndWait(Admin admin,
ServerName server, HRegionInfo region) throws IOException, InterruptedException {
HConnection connection = admin.getConnection();
AdminService.BlockingInterface rs = connection.getAdmin(server);
try {
- ProtobufUtil.closeRegion(rs, server, region.getRegionName(), false);
+ ProtobufUtil.closeRegion(rs, server, region.getRegionName());
} catch (IOException e) {
LOG.warn("Exception when closing region: " + region.getRegionNameAsString(), e);
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-server/src/test/data/TestNamespaceUpgrade.tgz
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/data/TestNamespaceUpgrade.tgz b/hbase-server/src/test/data/TestNamespaceUpgrade.tgz
deleted file mode 100644
index db6e9c3..0000000
Binary files a/hbase-server/src/test/data/TestNamespaceUpgrade.tgz and /dev/null differ
http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
index c67f3f8..7aeb778 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
@@ -99,7 +99,6 @@ import org.apache.hadoop.hbase.util.RetryCounter;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.zookeeper.EmptyWatcher;
import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
-import org.apache.hadoop.hbase.zookeeper.ZKAssign;
import org.apache.hadoop.hbase.zookeeper.ZKConfig;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
import org.apache.hadoop.hdfs.DFSClient;
@@ -109,8 +108,6 @@ import org.apache.hadoop.hdfs.server.namenode.EditLogFileOutputStream;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.MiniMRCluster;
import org.apache.hadoop.mapred.TaskLog;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.KeeperException.NodeExistsException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.ZooKeeper.States;
@@ -1470,6 +1467,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
/**
* Modify a table, synchronous. Waiting logic similar to that of {@code admin.rb#alter_status}.
*/
+ @SuppressWarnings("serial")
public static void modifyTableSync(Admin admin, HTableDescriptor desc)
throws IOException, InterruptedException {
admin.modifyTable(desc.getTableName(), desc);
@@ -3009,30 +3007,6 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
return zkw;
}
- /**
- * Creates a znode with OPENED state.
- * @param TEST_UTIL
- * @param region
- * @param serverName
- * @return
- * @throws IOException
- * @throws org.apache.hadoop.hbase.ZooKeeperConnectionException
- * @throws KeeperException
- * @throws NodeExistsException
- */
- public static ZooKeeperWatcher createAndForceNodeToOpenedState(
- HBaseTestingUtility TEST_UTIL, HRegion region,
- ServerName serverName) throws ZooKeeperConnectionException,
- IOException, KeeperException, NodeExistsException {
- ZooKeeperWatcher zkw = getZooKeeperWatcher(TEST_UTIL);
- ZKAssign.createNodeOffline(zkw, region.getRegionInfo(), serverName);
- int version = ZKAssign.transitionNodeOpening(zkw, region
- .getRegionInfo(), serverName);
- ZKAssign.transitionNodeOpened(zkw, region.getRegionInfo(), serverName,
- version);
- return zkw;
- }
-
public static void assertKVListsEqual(String additionalMsg,
final List<? extends Cell> expected,
final List<? extends Cell> actual) {
@@ -3441,6 +3415,16 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
}
/**
+ * Wait until no regions in transition.
+ * @param timeout How long to wait.
+ * @throws Exception
+ */
+ public void waitUntilNoRegionsInTransition(
+ final long timeout) throws Exception {
+ waitFor(timeout, predicateNoRegionsInTransition());
+ }
+
+ /**
* Create a set of column descriptors with the combination of compression,
* encoding, bloom codecs available.
* @return the list of column descriptors
http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-server/src/test/java/org/apache/hadoop/hbase/TestDrainingServer.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestDrainingServer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestDrainingServer.java
deleted file mode 100644
index db087ff..0000000
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestDrainingServer.java
+++ /dev/null
@@ -1,305 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.hbase;
-
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager;
-import org.apache.hadoop.hbase.executor.EventType;
-import org.apache.hadoop.hbase.executor.ExecutorService;
-import org.apache.hadoop.hbase.executor.ExecutorType;
-import org.apache.hadoop.hbase.master.AssignmentManager;
-import org.apache.hadoop.hbase.master.HMaster;
-import org.apache.hadoop.hbase.master.LoadBalancer;
-import org.apache.hadoop.hbase.master.RegionPlan;
-import org.apache.hadoop.hbase.master.RegionState;
-import org.apache.hadoop.hbase.master.ServerManager;
-import org.apache.hadoop.hbase.master.balancer.LoadBalancerFactory;
-import org.apache.hadoop.hbase.regionserver.RegionOpeningState;
-import org.apache.hadoop.hbase.zookeeper.ZKAssign;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.mockito.Mockito;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
-
-
-/**
- * Test the draining servers feature.
- */
-@Category(MediumTests.class)
-public class TestDrainingServer {
- private static final Log LOG = LogFactory.getLog(TestDrainingServer.class);
- private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
- private Abortable abortable = new Abortable() {
- @Override
- public boolean isAborted() {
- return false;
- }
-
- @Override
- public void abort(String why, Throwable e) {
- }
- };
-
- @AfterClass
- public static void afterClass() throws Exception {
- TEST_UTIL.shutdownMiniZKCluster();
- }
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- TEST_UTIL.getConfiguration().setBoolean("hbase.assignment.usezk", true);
- TEST_UTIL.startMiniZKCluster();
- }
-
- @Test
- public void testAssignmentManagerDoesntUseDrainingServer() throws Exception {
- AssignmentManager am;
- Configuration conf = TEST_UTIL.getConfiguration();
- final HMaster master = Mockito.mock(HMaster.class);
- final Server server = Mockito.mock(Server.class);
- final ServerManager serverManager = Mockito.mock(ServerManager.class);
- final ServerName SERVERNAME_A = ServerName.valueOf("mockserver_a.org", 1000, 8000);
- final ServerName SERVERNAME_B = ServerName.valueOf("mockserver_b.org", 1001, 8000);
- LoadBalancer balancer = LoadBalancerFactory.getLoadBalancer(conf);
- final HRegionInfo REGIONINFO = new HRegionInfo(TableName.valueOf("table_test"),
- HConstants.EMPTY_START_ROW, HConstants.EMPTY_START_ROW);
-
- ZooKeeperWatcher zkWatcher = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(),
- "zkWatcher-Test", abortable, true);
-
- Map<ServerName, ServerLoad> onlineServers = new HashMap<ServerName, ServerLoad>();
-
- onlineServers.put(SERVERNAME_A, ServerLoad.EMPTY_SERVERLOAD);
- onlineServers.put(SERVERNAME_B, ServerLoad.EMPTY_SERVERLOAD);
-
- Mockito.when(server.getConfiguration()).thenReturn(conf);
- Mockito.when(server.getServerName()).thenReturn(ServerName.valueOf("masterMock,1,1"));
- Mockito.when(server.getZooKeeper()).thenReturn(zkWatcher);
-
- CoordinatedStateManager cp = new ZkCoordinatedStateManager();
- cp.initialize(server);
- cp.start();
-
- Mockito.when(server.getCoordinatedStateManager()).thenReturn(cp);
-
- Mockito.when(serverManager.getOnlineServers()).thenReturn(onlineServers);
- Mockito.when(serverManager.getOnlineServersList())
- .thenReturn(new ArrayList<ServerName>(onlineServers.keySet()));
-
- Mockito.when(serverManager.createDestinationServersList())
- .thenReturn(new ArrayList<ServerName>(onlineServers.keySet()));
- Mockito.when(serverManager.createDestinationServersList(null))
- .thenReturn(new ArrayList<ServerName>(onlineServers.keySet()));
-
- for (ServerName sn : onlineServers.keySet()) {
- Mockito.when(serverManager.isServerOnline(sn)).thenReturn(true);
- Mockito.when(serverManager.sendRegionClose(sn, REGIONINFO, -1)).thenReturn(true);
- Mockito.when(serverManager.sendRegionClose(sn, REGIONINFO, -1, null, false)).thenReturn(true);
- Mockito.when(serverManager.sendRegionOpen(sn, REGIONINFO, -1, new ArrayList<ServerName>()))
- .thenReturn(RegionOpeningState.OPENED);
- Mockito.when(serverManager.sendRegionOpen(sn, REGIONINFO, -1, null))
- .thenReturn(RegionOpeningState.OPENED);
- Mockito.when(serverManager.addServerToDrainList(sn)).thenReturn(true);
- }
-
- Mockito.when(master.getServerManager()).thenReturn(serverManager);
-
- am = new AssignmentManager(server, serverManager,
- balancer, startupMasterExecutor("mockExecutorService"), null, null);
-
- Mockito.when(master.getAssignmentManager()).thenReturn(am);
- Mockito.when(master.getZooKeeper()).thenReturn(zkWatcher);
-
- am.addPlan(REGIONINFO.getEncodedName(), new RegionPlan(REGIONINFO, null, SERVERNAME_A));
-
- zkWatcher.registerListenerFirst(am);
-
- addServerToDrainedList(SERVERNAME_A, onlineServers, serverManager);
-
- am.assign(REGIONINFO, true);
-
- setRegionOpenedOnZK(zkWatcher, SERVERNAME_A, REGIONINFO);
- setRegionOpenedOnZK(zkWatcher, SERVERNAME_B, REGIONINFO);
-
- am.waitForAssignment(REGIONINFO);
-
- assertTrue(am.getRegionStates().isRegionOnline(REGIONINFO));
- assertNotEquals(am.getRegionStates().getRegionServerOfRegion(REGIONINFO), SERVERNAME_A);
- }
-
- @Test
- public void testAssignmentManagerDoesntUseDrainedServerWithBulkAssign() throws Exception {
- Configuration conf = TEST_UTIL.getConfiguration();
- LoadBalancer balancer = LoadBalancerFactory.getLoadBalancer(conf);
- AssignmentManager am;
- final HMaster master = Mockito.mock(HMaster.class);
- final Server server = Mockito.mock(Server.class);
- final ServerManager serverManager = Mockito.mock(ServerManager.class);
- final ServerName SERVERNAME_A = ServerName.valueOf("mockserverbulk_a.org", 1000, 8000);
- final ServerName SERVERNAME_B = ServerName.valueOf("mockserverbulk_b.org", 1001, 8000);
- final ServerName SERVERNAME_C = ServerName.valueOf("mockserverbulk_c.org", 1002, 8000);
- final ServerName SERVERNAME_D = ServerName.valueOf("mockserverbulk_d.org", 1003, 8000);
- final ServerName SERVERNAME_E = ServerName.valueOf("mockserverbulk_e.org", 1004, 8000);
- final Map<HRegionInfo, ServerName> bulk = new HashMap<HRegionInfo, ServerName>();
-
- Set<ServerName> bunchServersAssigned = new HashSet<ServerName>();
-
- HRegionInfo REGIONINFO_A = new HRegionInfo(TableName.valueOf("table_A"),
- HConstants.EMPTY_START_ROW, HConstants.EMPTY_START_ROW);
- HRegionInfo REGIONINFO_B = new HRegionInfo(TableName.valueOf("table_B"),
- HConstants.EMPTY_START_ROW, HConstants.EMPTY_START_ROW);
- HRegionInfo REGIONINFO_C = new HRegionInfo(TableName.valueOf("table_C"),
- HConstants.EMPTY_START_ROW, HConstants.EMPTY_START_ROW);
- HRegionInfo REGIONINFO_D = new HRegionInfo(TableName.valueOf("table_D"),
- HConstants.EMPTY_START_ROW, HConstants.EMPTY_START_ROW);
- HRegionInfo REGIONINFO_E = new HRegionInfo(TableName.valueOf("table_E"),
- HConstants.EMPTY_START_ROW, HConstants.EMPTY_START_ROW);
-
- Map<ServerName, ServerLoad> onlineServers = new HashMap<ServerName, ServerLoad>();
- List<ServerName> drainedServers = new ArrayList<ServerName>();
-
- onlineServers.put(SERVERNAME_A, ServerLoad.EMPTY_SERVERLOAD);
- onlineServers.put(SERVERNAME_B, ServerLoad.EMPTY_SERVERLOAD);
- onlineServers.put(SERVERNAME_C, ServerLoad.EMPTY_SERVERLOAD);
- onlineServers.put(SERVERNAME_D, ServerLoad.EMPTY_SERVERLOAD);
- onlineServers.put(SERVERNAME_E, ServerLoad.EMPTY_SERVERLOAD);
-
- bulk.put(REGIONINFO_A, SERVERNAME_A);
- bulk.put(REGIONINFO_B, SERVERNAME_B);
- bulk.put(REGIONINFO_C, SERVERNAME_C);
- bulk.put(REGIONINFO_D, SERVERNAME_D);
- bulk.put(REGIONINFO_E, SERVERNAME_E);
-
- ZooKeeperWatcher zkWatcher = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(),
- "zkWatcher-BulkAssignTest", abortable, true);
-
- Mockito.when(server.getConfiguration()).thenReturn(conf);
- Mockito.when(server.getServerName()).thenReturn(ServerName.valueOf("masterMock,1,1"));
- Mockito.when(server.getZooKeeper()).thenReturn(zkWatcher);
-
- CoordinatedStateManager cp = new ZkCoordinatedStateManager();
- cp.initialize(server);
- cp.start();
-
- Mockito.when(server.getCoordinatedStateManager()).thenReturn(cp);
-
- Mockito.when(serverManager.getOnlineServers()).thenReturn(onlineServers);
- Mockito.when(serverManager.getOnlineServersList()).thenReturn(
- new ArrayList<ServerName>(onlineServers.keySet()));
-
- Mockito.when(serverManager.createDestinationServersList()).thenReturn(
- new ArrayList<ServerName>(onlineServers.keySet()));
- Mockito.when(serverManager.createDestinationServersList(null)).thenReturn(
- new ArrayList<ServerName>(onlineServers.keySet()));
-
- for (Entry<HRegionInfo, ServerName> entry : bulk.entrySet()) {
- Mockito.when(serverManager.isServerOnline(entry.getValue())).thenReturn(true);
- Mockito.when(serverManager.sendRegionClose(entry.getValue(),
- entry.getKey(), -1)).thenReturn(true);
- Mockito.when(serverManager.sendRegionOpen(entry.getValue(),
- entry.getKey(), -1, null)).thenReturn(RegionOpeningState.OPENED);
- Mockito.when(serverManager.addServerToDrainList(entry.getValue())).thenReturn(true);
- }
-
- Mockito.when(master.getServerManager()).thenReturn(serverManager);
-
- drainedServers.add(SERVERNAME_A);
- drainedServers.add(SERVERNAME_B);
- drainedServers.add(SERVERNAME_C);
- drainedServers.add(SERVERNAME_D);
-
- am = new AssignmentManager(server, serverManager,
- balancer, startupMasterExecutor("mockExecutorServiceBulk"), null, null);
-
- Mockito.when(master.getAssignmentManager()).thenReturn(am);
-
- zkWatcher.registerListener(am);
-
- for (ServerName drained : drainedServers) {
- addServerToDrainedList(drained, onlineServers, serverManager);
- }
-
- am.assign(bulk);
-
- Map<String, RegionState> regionsInTransition = am.getRegionStates().getRegionsInTransition();
- for (Entry<String, RegionState> entry : regionsInTransition.entrySet()) {
- setRegionOpenedOnZK(zkWatcher, entry.getValue().getServerName(),
- entry.getValue().getRegion());
- }
-
- am.waitForAssignment(REGIONINFO_A);
- am.waitForAssignment(REGIONINFO_B);
- am.waitForAssignment(REGIONINFO_C);
- am.waitForAssignment(REGIONINFO_D);
- am.waitForAssignment(REGIONINFO_E);
-
- Map<HRegionInfo, ServerName> regionAssignments = am.getRegionStates().getRegionAssignments();
- for (Entry<HRegionInfo, ServerName> entry : regionAssignments.entrySet()) {
- LOG.info("Region Assignment: "
- + entry.getKey().getRegionNameAsString() + " Server: " + entry.getValue());
- bunchServersAssigned.add(entry.getValue());
- }
-
- for (ServerName sn : drainedServers) {
- assertFalse(bunchServersAssigned.contains(sn));
- }
- }
-
- private void addServerToDrainedList(ServerName serverName,
- Map<ServerName, ServerLoad> onlineServers, ServerManager serverManager) {
- onlineServers.remove(serverName);
- List<ServerName> availableServers = new ArrayList<ServerName>(onlineServers.keySet());
- Mockito.when(serverManager.createDestinationServersList()).thenReturn(availableServers);
- Mockito.when(serverManager.createDestinationServersList(null)).thenReturn(availableServers);
- }
-
- private void setRegionOpenedOnZK(final ZooKeeperWatcher zkWatcher, final ServerName serverName,
- HRegionInfo hregionInfo) throws Exception {
- int version = ZKAssign.getVersion(zkWatcher, hregionInfo);
- int versionTransition = ZKAssign.transitionNode(zkWatcher,
- hregionInfo, serverName, EventType.M_ZK_REGION_OFFLINE,
- EventType.RS_ZK_REGION_OPENING, version);
- ZKAssign.transitionNodeOpened(zkWatcher, hregionInfo, serverName, versionTransition);
- }
-
- private ExecutorService startupMasterExecutor(final String name) {
- ExecutorService executor = new ExecutorService(name);
- executor.startExecutorService(ExecutorType.MASTER_OPEN_REGION, 3);
- executor.startExecutorService(ExecutorType.MASTER_CLOSE_REGION, 3);
- executor.startExecutorService(ExecutorType.MASTER_SERVER_OPERATIONS, 3);
- executor.startExecutorService(ExecutorType.MASTER_META_SERVER_OPERATIONS, 3);
- return executor;
- }
-}
http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-server/src/test/java/org/apache/hadoop/hbase/TestIOFencing.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestIOFencing.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestIOFencing.java
index 1e3e3af..990de0f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestIOFencing.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestIOFencing.java
@@ -244,7 +244,7 @@ public class TestIOFencing {
c.setClass(HConstants.REGION_IMPL, regionClass, HRegion.class);
c.setBoolean("dfs.support.append", true);
// Encourage plenty of flushes
- c.setLong("hbase.hregion.memstore.flush.size", 200000);
+ c.setLong("hbase.hregion.memstore.flush.size", 100000);
c.set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY, ConstantSizeRegionSplitPolicy.class.getName());
// Only run compaction when we tell it to
c.setInt("hbase.hstore.compaction.min",1);
http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java
index 1448bf2..359bb0a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java
@@ -26,12 +26,12 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import java.util.Random;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Get;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.client.HTable;
@@ -48,6 +48,7 @@ import org.junit.experimental.categories.Category;
* Test {@link org.apache.hadoop.hbase.MetaTableAccessor}.
*/
@Category(MediumTests.class)
+@SuppressWarnings("deprecation")
public class TestMetaTableAccessor {
private static final Log LOG = LogFactory.getLog(TestMetaTableAccessor.class);
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java
index e65430b..9d502d0 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java
@@ -50,7 +50,6 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.FSUtils;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.zookeeper.EmptyWatcher;
-import org.apache.hadoop.hbase.zookeeper.ZKAssign;
import org.apache.hadoop.hbase.zookeeper.ZKConfig;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
@@ -500,8 +499,7 @@ public class TestZooKeeper {
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
htd.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
admin.createTable(htd, SPLIT_KEYS);
- ZooKeeperWatcher zooKeeperWatcher = HBaseTestingUtility.getZooKeeperWatcher(TEST_UTIL);
- ZKAssign.blockUntilNoRIT(zooKeeperWatcher);
+ TEST_UTIL.waitUntilNoRegionsInTransition(60000);
m.getZooKeeper().close();
MockLoadBalancer.retainAssignCalled = false;
m.abort("Test recovery from zk session expired",
@@ -524,8 +522,7 @@ public class TestZooKeeper {
* RS goes down.
*/
@Test(timeout = 300000)
- public void testLogSplittingAfterMasterRecoveryDueToZKExpiry() throws IOException,
- KeeperException, InterruptedException {
+ public void testLogSplittingAfterMasterRecoveryDueToZKExpiry() throws Exception {
MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
cluster.startRegionServer();
HMaster m = cluster.getMaster();
@@ -541,8 +538,7 @@ public class TestZooKeeper {
HColumnDescriptor hcd = new HColumnDescriptor("col");
htd.addFamily(hcd);
admin.createTable(htd, SPLIT_KEYS);
- ZooKeeperWatcher zooKeeperWatcher = HBaseTestingUtility.getZooKeeperWatcher(TEST_UTIL);
- ZKAssign.blockUntilNoRIT(zooKeeperWatcher);
+ TEST_UTIL.waitUntilNoRegionsInTransition(60000);
table = new HTable(TEST_UTIL.getConfiguration(), tableName);
Put p;
int numberOfPuts;
http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicasClient.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicasClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicasClient.java
index bc3a1f8..02fd1c4 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicasClient.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicasClient.java
@@ -19,6 +19,18 @@
package org.apache.hadoop.hbase.client;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
@@ -43,7 +55,6 @@ import org.apache.hadoop.hbase.regionserver.RegionScanner;
import org.apache.hadoop.hbase.regionserver.StorefileRefresherChore;
import org.apache.hadoop.hbase.regionserver.TestRegionServerNoMaster;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.zookeeper.ZKAssign;
import org.apache.zookeeper.KeeperException;
import org.junit.After;
import org.junit.AfterClass;
@@ -53,23 +64,12 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Random;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.atomic.AtomicReference;
-
/**
* Tests for region replicas. Sad that we cannot isolate these without bringing up a whole
* cluster. See {@link org.apache.hadoop.hbase.regionserver.TestRegionServerNoMaster}.
*/
@Category(MediumTests.class)
+@SuppressWarnings("deprecation")
public class TestReplicasClient {
private static final Log LOG = LogFactory.getLog(TestReplicasClient.class);
@@ -187,11 +187,13 @@ public class TestReplicasClient {
} catch (MasterNotRunningException ignored) {
}
}
+ ha.close();
LOG.info("Master has stopped");
}
@AfterClass
public static void afterClass() throws Exception {
+ HRegionServer.TEST_SKIP_REPORTING_TRANSITION = false;
if (table != null) table.close();
HTU.shutdownMiniCluster();
}
@@ -219,8 +221,6 @@ public class TestReplicasClient {
closeRegion(hriPrimary);
} catch (Exception ignored) {
}
- ZKAssign.deleteNodeFailSilent(HTU.getZooKeeperWatcher(), hriPrimary);
- ZKAssign.deleteNodeFailSilent(HTU.getZooKeeperWatcher(), hriSecondary);
HTU.getHBaseAdmin().getConnection().clearRegionCache();
}
@@ -233,10 +233,9 @@ public class TestReplicasClient {
try {
if (isRegionOpened(hri)) return;
} catch (Exception e){}
- ZKAssign.createNodeOffline(HTU.getZooKeeperWatcher(), hri, getRS().getServerName());
// first version is '0'
AdminProtos.OpenRegionRequest orr = RequestConverter.buildOpenRegionRequest(
- getRS().getServerName(), hri, 0, null, null);
+ getRS().getServerName(), hri, null, null);
AdminProtos.OpenRegionResponse responseOpen = getRS().getRSRpcServices().openRegion(null, orr);
Assert.assertEquals(responseOpen.getOpeningStateCount(), 1);
Assert.assertEquals(responseOpen.getOpeningState(0),
@@ -245,27 +244,19 @@ public class TestReplicasClient {
}
private void closeRegion(HRegionInfo hri) throws Exception {
- ZKAssign.createNodeClosing(HTU.getZooKeeperWatcher(), hri, getRS().getServerName());
-
AdminProtos.CloseRegionRequest crr = RequestConverter.buildCloseRegionRequest(
- getRS().getServerName(), hri.getEncodedName(), true);
+ getRS().getServerName(), hri.getEncodedName());
AdminProtos.CloseRegionResponse responseClose = getRS()
.getRSRpcServices().closeRegion(null, crr);
Assert.assertTrue(responseClose.getClosed());
checkRegionIsClosed(hri.getEncodedName());
-
- ZKAssign.deleteClosedNode(HTU.getZooKeeperWatcher(), hri.getEncodedName(), null);
}
private void checkRegionIsOpened(HRegionInfo hri) throws Exception {
-
while (!getRS().getRegionsInTransitionInRS().isEmpty()) {
Thread.sleep(1);
}
-
- Assert.assertTrue(
- ZKAssign.deleteOpenedNode(HTU.getZooKeeperWatcher(), hri.getEncodedName(), null));
}
private boolean isRegionOpened(HRegionInfo hri) throws Exception {
http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java
index 380b337..a7b3319 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java
@@ -40,10 +40,7 @@ import org.apache.hadoop.hbase.master.RegionStates;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.regionserver.HRegionServer;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.ConfigUtil;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
-import org.apache.hadoop.hbase.zookeeper.ZKAssign;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -474,7 +471,7 @@ public class TestScannersFromClientSide {
int i = cluster.getServerWith(regionName);
HRegionServer rs = cluster.getRegionServer(i);
ProtobufUtil.closeRegion(
- rs.getRSRpcServices(), rs.getServerName(), regionName, false);
+ rs.getRSRpcServices(), rs.getServerName(), regionName);
long startTime = EnvironmentEdgeManager.currentTimeMillis();
long timeOut = 300000;
while (true) {
@@ -487,27 +484,19 @@ public class TestScannersFromClientSide {
}
// Now open the region again.
- ZooKeeperWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
- try {
- HMaster master = cluster.getMaster();
- RegionStates states = master.getAssignmentManager().getRegionStates();
- states.regionOffline(hri);
- states.updateRegionState(hri, State.OPENING);
- if (ConfigUtil.useZKForAssignment(TEST_UTIL.getConfiguration())) {
- ZKAssign.createNodeOffline(zkw, hri, loc.getServerName());
- }
- ProtobufUtil.openRegion(rs.getRSRpcServices(), rs.getServerName(), hri);
- startTime = EnvironmentEdgeManager.currentTimeMillis();
- while (true) {
- if (rs.getOnlineRegion(regionName) != null) {
- break;
- }
- assertTrue("Timed out in open the testing region",
- EnvironmentEdgeManager.currentTimeMillis() < startTime + timeOut);
- Thread.sleep(500);
+ HMaster master = cluster.getMaster();
+ RegionStates states = master.getAssignmentManager().getRegionStates();
+ states.regionOffline(hri);
+ states.updateRegionState(hri, State.OPENING);
+ ProtobufUtil.openRegion(rs.getRSRpcServices(), rs.getServerName(), hri);
+ startTime = EnvironmentEdgeManager.currentTimeMillis();
+ while (true) {
+ if (rs.getOnlineRegion(regionName) != null) {
+ break;
}
- } finally {
- ZKAssign.deleteNodeFailSilent(zkw, hri);
+ assertTrue("Timed out in open the testing region",
+ EnvironmentEdgeManager.currentTimeMillis() < startTime + timeOut);
+ Thread.sleep(500);
}
// c0:0, c1:1
http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestChangingEncoding.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestChangingEncoding.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestChangingEncoding.java
index 0ceb953..2b1f6f6 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestChangingEncoding.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestChangingEncoding.java
@@ -45,7 +45,6 @@ import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.regionserver.HRegionServer;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Threads;
-import org.apache.hadoop.hbase.zookeeper.ZKAssign;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -194,7 +193,7 @@ public class TestChangingEncoding {
// wait for regions out of transition. Otherwise, for online
// encoding change, verification phase may be flaky because
// regions could be still in transition.
- ZKAssign.blockUntilNoRIT(TEST_UTIL.getZooKeeperWatcher());
+ TEST_UTIL.waitUntilNoRegionsInTransition(TIMEOUT_MS);
}
@Test(timeout=TIMEOUT_MS)
http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-server/src/test/java/org/apache/hadoop/hbase/master/Mocking.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/Mocking.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/Mocking.java
deleted file mode 100644
index 10127c8..0000000
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/Mocking.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.hbase.master;
-
-import static org.junit.Assert.assertNotSame;
-
-import org.apache.hadoop.hbase.exceptions.DeserializationException;
-import org.apache.hadoop.hbase.HRegionInfo;
-import org.apache.hadoop.hbase.RegionTransition;
-import org.apache.hadoop.hbase.ServerName;
-import org.apache.hadoop.hbase.executor.EventType;
-import org.apache.hadoop.hbase.master.RegionState.State;
-import org.apache.hadoop.hbase.zookeeper.ZKAssign;
-import org.apache.hadoop.hbase.zookeeper.ZKUtil;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
-import org.apache.zookeeper.KeeperException;
-
-/**
- * Package scoped mocking utility.
- */
-public class Mocking {
-
- static void waitForRegionFailedToCloseAndSetToPendingClose(
- AssignmentManager am, HRegionInfo hri) throws InterruptedException {
- // Since region server is fake, sendRegionClose will fail, and closing
- // region will fail. For testing purpose, moving it back to pending close
- boolean wait = true;
- while (wait) {
- RegionState state = am.getRegionStates().getRegionState(hri);
- if (state != null && state.isFailedClose()){
- am.getRegionStates().updateRegionState(hri, State.PENDING_CLOSE);
- wait = false;
- } else {
- Thread.sleep(1);
- }
- }
- }
-
- static void waitForRegionPendingOpenInRIT(AssignmentManager am, String encodedName)
- throws InterruptedException {
- // We used to do a check like this:
- //!Mocking.verifyRegionState(this.watcher, REGIONINFO, EventType.M_ZK_REGION_OFFLINE)) {
- // There is a race condition with this: because we may do the transition to
- // RS_ZK_REGION_OPENING before the RIT is internally updated. We need to wait for the
- // RIT to be as we need it to be instead. This cannot happen in a real cluster as we
- // update the RIT before sending the openRegion request.
-
- boolean wait = true;
- while (wait) {
- RegionState state = am.getRegionStates()
- .getRegionsInTransition().get(encodedName);
- if (state != null && state.isPendingOpen()){
- wait = false;
- } else {
- Thread.sleep(1);
- }
- }
- }
-
- /**
- * Verifies that the specified region is in the specified state in ZooKeeper.
- * <p>
- * Returns true if region is in transition and in the specified state in
- * ZooKeeper. Returns false if the region does not exist in ZK or is in
- * a different state.
- * <p>
- * Method synchronizes() with ZK so will yield an up-to-date result but is
- * a slow read.
- * @param zkw
- * @param region
- * @param expectedState
- * @return true if region exists and is in expected state
- * @throws DeserializationException
- */
- static boolean verifyRegionState(ZooKeeperWatcher zkw, HRegionInfo region, EventType expectedState)
- throws KeeperException, DeserializationException {
- String encoded = region.getEncodedName();
-
- String node = ZKAssign.getNodeName(zkw, encoded);
- zkw.sync(node);
-
- // Read existing data of the node
- byte [] existingBytes = null;
- try {
- existingBytes = ZKUtil.getDataAndWatch(zkw, node);
- } catch (KeeperException.NoNodeException nne) {
- return false;
- } catch (KeeperException e) {
- throw e;
- }
- if (existingBytes == null) return false;
- RegionTransition rt = RegionTransition.parseFrom(existingBytes);
- return rt.getEventType().equals(expectedState);
- }
-}