HBASE-11611 Clean up ZK-based region assignment
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/17dff681 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/17dff681 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/17dff681 Branch: refs/heads/master Commit: 17dff6818e80305ea55da0519cbcf44de644992e Parents: e17a3ca Author: Jimmy Xiang <[email protected]> Authored: Tue Jul 29 16:15:42 2014 -0700 Committer: Jimmy Xiang <[email protected]> Committed: Wed Aug 6 16:22:08 2014 -0700 ---------------------------------------------------------------------- .../apache/hadoop/hbase/RegionTransition.java | 139 -- .../apache/hadoop/hbase/client/HBaseAdmin.java | 4 +- .../apache/hadoop/hbase/master/RegionState.java | 36 +- .../hadoop/hbase/protobuf/ProtobufUtil.java | 18 +- .../hadoop/hbase/protobuf/RequestConverter.java | 47 +- .../apache/hadoop/hbase/zookeeper/ZKAssign.java | 1057 ----------- .../apache/hadoop/hbase/zookeeper/ZKUtil.java | 9 +- .../hbase/zookeeper/ZooKeeperWatcher.java | 16 +- .../protobuf/generated/ZooKeeperProtos.java | 1177 +----------- .../src/main/protobuf/ZooKeeper.proto | 15 - .../BaseCoordinatedStateManager.java | 20 - .../coordination/CloseRegionCoordination.java | 69 - .../coordination/OpenRegionCoordination.java | 129 -- .../coordination/RegionMergeCoordination.java | 106 -- .../SplitTransactionCoordination.java | 101 - .../ZKSplitTransactionCoordination.java | 314 ---- .../coordination/ZkCloseRegionCoordination.java | 197 -- .../coordination/ZkCoordinatedStateManager.java | 32 - .../coordination/ZkOpenRegionCoordination.java | 414 ----- .../coordination/ZkRegionMergeCoordination.java | 326 ---- .../hadoop/hbase/master/AssignCallable.java | 2 +- .../hadoop/hbase/master/AssignmentManager.java | 1759 ++---------------- .../org/apache/hadoop/hbase/master/HMaster.java | 45 +- .../hadoop/hbase/master/MasterRpcServices.java | 4 +- .../hadoop/hbase/master/OfflineCallback.java | 114 -- .../hadoop/hbase/master/RegionStateStore.java | 27 +- .../hadoop/hbase/master/RegionStates.java | 39 +- .../hadoop/hbase/master/ServerManager.java | 30 +- .../master/handler/ClosedRegionHandler.java | 108 -- .../master/handler/OpenedRegionHandler.java | 103 - .../master/handler/ServerShutdownHandler.java | 31 +- .../hadoop/hbase/migration/UpgradeTo96.java | 259 --- .../hbase/regionserver/HRegionServer.java | 56 +- .../hbase/regionserver/RSRpcServices.java | 23 +- .../regionserver/RegionMergeTransaction.java | 133 +- .../hbase/regionserver/SplitTransaction.java | 125 +- .../regionserver/handler/CloseMetaHandler.java | 9 +- .../handler/CloseRegionHandler.java | 56 +- .../regionserver/handler/OpenMetaHandler.java | 7 +- .../regionserver/handler/OpenRegionHandler.java | 105 +- .../apache/hadoop/hbase/util/ConfigUtil.java | 33 - .../hadoop/hbase/util/HBaseFsckRepair.java | 3 +- .../src/test/data/TestNamespaceUpgrade.tgz | Bin 10449 -> 0 bytes .../hadoop/hbase/HBaseTestingUtility.java | 38 +- .../apache/hadoop/hbase/TestDrainingServer.java | 305 --- .../org/apache/hadoop/hbase/TestIOFencing.java | 2 +- .../hadoop/hbase/TestMetaTableAccessor.java | 3 +- .../org/apache/hadoop/hbase/TestZooKeeper.java | 10 +- .../hadoop/hbase/client/TestReplicasClient.java | 43 +- .../client/TestScannersFromClientSide.java | 37 +- .../hbase/io/encoding/TestChangingEncoding.java | 3 +- .../org/apache/hadoop/hbase/master/Mocking.java | 110 -- .../hbase/master/TestAssignmentManager.java | 1475 --------------- .../master/TestAssignmentManagerOnCluster.java | 43 +- .../master/TestDistributedLogSplitting.java | 8 +- .../apache/hadoop/hbase/master/TestMaster.java | 31 +- .../hadoop/hbase/master/TestMasterFailover.java | 1014 +--------- .../hbase/master/TestMasterNoCluster.java | 10 +- .../TestMasterRestartAfterDisablingTable.java | 15 +- .../hbase/master/TestOpenedRegionHandler.java | 227 --- .../hadoop/hbase/master/TestRestartCluster.java | 47 +- .../hadoop/hbase/master/TestRollingRestart.java | 25 +- .../master/TestZKBasedOpenCloseRegion.java | 302 --- .../hbase/master/TestZKLessAMOnCluster.java | 42 - .../hbase/migration/TestNamespaceUpgrade.java | 354 ---- .../hadoop/hbase/migration/TestUpgradeTo96.java | 270 --- .../TestEndToEndSplitTransaction.java | 26 +- .../TestRegionMergeTransactionOnCluster.java | 16 +- .../hbase/regionserver/TestRegionReplicas.java | 23 +- .../regionserver/TestRegionServerNoMaster.java | 205 +- .../TestSplitTransactionOnCluster.java | 408 +--- .../regionserver/TestZKLessMergeOnCluster.java | 45 - .../regionserver/TestZKLessSplitOnCluster.java | 45 - .../handler/TestCloseRegionHandler.java | 255 --- .../handler/TestOpenRegionHandler.java | 360 ---- .../util/hbck/TestOfflineMetaRebuildBase.java | 9 +- .../util/hbck/TestOfflineMetaRebuildHole.java | 7 +- .../hbck/TestOfflineMetaRebuildOverlap.java | 7 +- 78 files changed, 518 insertions(+), 12599 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-client/src/main/java/org/apache/hadoop/hbase/RegionTransition.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/RegionTransition.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/RegionTransition.java deleted file mode 100644 index 7e7f5c1..0000000 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/RegionTransition.java +++ /dev/null @@ -1,139 +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.hadoop.hbase.util.ByteStringer; -import com.google.protobuf.InvalidProtocolBufferException; - -import org.apache.hadoop.classification.InterfaceAudience; -import org.apache.hadoop.hbase.exceptions.DeserializationException; -import org.apache.hadoop.hbase.executor.EventType; -import org.apache.hadoop.hbase.protobuf.ProtobufUtil; -import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; -import org.apache.hadoop.hbase.util.Bytes; - -/** - * Current state of a region in transition. Holds state of a region as it moves through the - * steps that take it from offline to open, etc. Used by regionserver, master, and zk packages. - * Encapsulates protobuf serialization/deserialization so we don't leak generated pb outside this - * class. Create an instance using createRegionTransition(EventType, byte[], ServerName). - * <p>Immutable - */ [email protected] -public class RegionTransition { - private final ZooKeeperProtos.RegionTransition rt; - - /** - * Shutdown constructor - */ - private RegionTransition() { - this(null); - } - - private RegionTransition(final ZooKeeperProtos.RegionTransition rt) { - this.rt = rt; - } - - public EventType getEventType() { - return EventType.get(this.rt.getEventTypeCode()); - } - - public ServerName getServerName() { - return ProtobufUtil.toServerName(this.rt.getServerName()); - } - - public long getCreateTime() { - return this.rt.getCreateTime(); - } - - /** - * @return Full region name - */ - public byte [] getRegionName() { - return this.rt.getRegionName().toByteArray(); - } - - public byte [] getPayload() { - return this.rt.getPayload().toByteArray(); - } - - @Override - public String toString() { - byte [] payload = getPayload(); - return "region=" + Bytes.toStringBinary(getRegionName()) + ", state=" + getEventType() + - ", servername=" + getServerName() + ", createTime=" + this.getCreateTime() + - ", payload.length=" + (payload == null? 0: payload.length); - } - - /** - * @param type - * @param regionName - * @param sn - * @return a serialized pb {@link RegionTransition} - */ - public static RegionTransition createRegionTransition(final EventType type, - final byte [] regionName, final ServerName sn) { - return createRegionTransition(type, regionName, sn, null); - } - - /** - * @param type - * @param regionName - * @param sn - * @param payload May be null - * @return a serialized pb {@link RegionTransition} - */ - public static RegionTransition createRegionTransition(final EventType type, - final byte [] regionName, final ServerName sn, final byte [] payload) { - org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.ServerName pbsn = - org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.ServerName.newBuilder(). - setHostName(sn.getHostname()).setPort(sn.getPort()).setStartCode(sn.getStartcode()).build(); - ZooKeeperProtos.RegionTransition.Builder builder = ZooKeeperProtos.RegionTransition.newBuilder(). - setEventTypeCode(type.getCode()).setRegionName(ByteStringer.wrap(regionName)). - setServerName(pbsn); - builder.setCreateTime(System.currentTimeMillis()); - if (payload != null) builder.setPayload(ByteStringer.wrap(payload)); - return new RegionTransition(builder.build()); - } - - /** - * @param data Serialized date to parse. - * @return A RegionTransition instance made of the passed <code>data</code> - * @throws DeserializationException - * @see #toByteArray() - */ - public static RegionTransition parseFrom(final byte [] data) throws DeserializationException { - ProtobufUtil.expectPBMagicPrefix(data); - try { - int prefixLen = ProtobufUtil.lengthOfPBMagic(); - ZooKeeperProtos.RegionTransition rt = ZooKeeperProtos.RegionTransition.newBuilder(). - mergeFrom(data, prefixLen, data.length - prefixLen).build(); - return new RegionTransition(rt); - } catch (InvalidProtocolBufferException e) { - throw new DeserializationException(e); - } - } - - /** - * @return This instance serialized into a byte array - * @see #parseFrom(byte[]) - */ - public byte [] toByteArray() { - return ProtobufUtil.prependPBMagic(this.rt.toByteArray()); - } -} http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java index 10e4d04..fe8fb31 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java @@ -1427,7 +1427,7 @@ public class HBaseAdmin implements Admin { AdminService.BlockingInterface admin = this.connection.getAdmin(sn); // Close the region without updating zk state. CloseRegionRequest request = - RequestConverter.buildCloseRegionRequest(sn, encodedRegionName, false); + RequestConverter.buildCloseRegionRequest(sn, encodedRegionName); try { CloseRegionResponse response = admin.closeRegion(null, request); boolean isRegionClosed = response.getClosed(); @@ -1452,7 +1452,7 @@ public class HBaseAdmin implements Admin { throws IOException { AdminService.BlockingInterface admin = this.connection.getAdmin(sn); // Close the region without updating zk state. - ProtobufUtil.closeRegion(admin, sn, hri.getRegionName(), false); + ProtobufUtil.closeRegion(admin, sn, hri.getRegionName()); } /** http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-client/src/main/java/org/apache/hadoop/hbase/master/RegionState.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/master/RegionState.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/master/RegionState.java index 3289ac1..3830f93 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/master/RegionState.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/master/RegionState.java @@ -18,7 +18,6 @@ package org.apache.hadoop.hbase.master; import java.util.Date; -import java.util.concurrent.atomic.AtomicLong; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; @@ -28,8 +27,7 @@ import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos; /** * State of a Region while undergoing transitions. - * Region state cannot be modified except the stamp field. - * So it is almost immutable. + * This class is immutable. */ @InterfaceAudience.Private public class RegionState { @@ -58,16 +56,10 @@ public class RegionState { // master doesn't know it's already created } - // Many threads can update the state at the stamp at the same time - private final AtomicLong stamp; - private HRegionInfo hri; - - private volatile ServerName serverName; - private volatile State state; - - public RegionState() { - this.stamp = new AtomicLong(System.currentTimeMillis()); - } + private final long stamp; + private final HRegionInfo hri; + private final ServerName serverName; + private final State state; public RegionState(HRegionInfo region, State state) { this(region, state, System.currentTimeMillis(), null); @@ -82,20 +74,16 @@ public class RegionState { State state, long stamp, ServerName serverName) { this.hri = region; this.state = state; - this.stamp = new AtomicLong(stamp); + this.stamp = stamp; this.serverName = serverName; } - public void updateTimestampToNow() { - setTimestamp(System.currentTimeMillis()); - } - public State getState() { return state; } public long getStamp() { - return stamp.get(); + return stamp; } public HRegionInfo getRegion() { @@ -248,12 +236,10 @@ public class RegionState { * A slower (but more easy-to-read) stringification */ public String toDescriptiveString() { - long lstamp = stamp.get(); - long relTime = System.currentTimeMillis() - lstamp; - + long relTime = System.currentTimeMillis() - stamp; return hri.getRegionNameAsString() + " state=" + state - + ", ts=" + new Date(lstamp) + " (" + (relTime/1000) + "s ago)" + + ", ts=" + new Date(stamp) + " (" + (relTime/1000) + "s ago)" + ", server=" + serverName; } @@ -380,10 +366,6 @@ public class RegionState { return new RegionState(HRegionInfo.convert(proto.getRegionInfo()),state,proto.getStamp(),null); } - protected void setTimestamp(final long timestamp) { - stamp.set(timestamp); - } - /** * Check if two states are the same, except timestamp */ http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java index eea3b72..4033fb5 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java @@ -1142,6 +1142,7 @@ public final class ProtobufUtil { return toMutation(type, mutation, builder, HConstants.NO_NONCE); } + @SuppressWarnings("deprecation") public static MutationProto toMutation(final MutationType type, final Mutation mutation, MutationProto.Builder builder, long nonce) throws IOException { @@ -1616,13 +1617,12 @@ public final class ProtobufUtil { * * @param admin * @param regionName - * @param transitionInZK * @throws IOException */ public static void closeRegion(final AdminService.BlockingInterface admin, - final ServerName server, final byte[] regionName, final boolean transitionInZK) throws IOException { + final ServerName server, final byte[] regionName) throws IOException { CloseRegionRequest closeRegionRequest = - RequestConverter.buildCloseRegionRequest(server, regionName, transitionInZK); + RequestConverter.buildCloseRegionRequest(server, regionName); try { admin.closeRegion(null, closeRegionRequest); } catch (ServiceException se) { @@ -1636,18 +1636,15 @@ public final class ProtobufUtil { * * @param admin * @param regionName - * @param versionOfClosingNode * @return true if the region is closed * @throws IOException */ public static boolean closeRegion(final AdminService.BlockingInterface admin, - final ServerName server, - final byte[] regionName, - final int versionOfClosingNode, final ServerName destinationServer, - final boolean transitionInZK) throws IOException { + final ServerName server, final byte[] regionName, + final ServerName destinationServer) throws IOException { CloseRegionRequest closeRegionRequest = RequestConverter.buildCloseRegionRequest(server, - regionName, versionOfClosingNode, destinationServer, transitionInZK); + regionName, destinationServer); try { CloseRegionResponse response = admin.closeRegion(null, closeRegionRequest); return ResponseConverter.isClosed(response); @@ -1666,7 +1663,7 @@ public final class ProtobufUtil { public static void openRegion(final AdminService.BlockingInterface admin, ServerName server, final HRegionInfo region) throws IOException { OpenRegionRequest request = - RequestConverter.buildOpenRegionRequest(server, region, -1, null, null); + RequestConverter.buildOpenRegionRequest(server, region, null, null); try { admin.openRegion(null, request); } catch (ServiceException se) { @@ -2488,6 +2485,7 @@ public final class ProtobufUtil { } } + @SuppressWarnings("deprecation") public static CompactionDescriptor toCompactionDescriptor(HRegionInfo info, byte[] family, List<Path> inputPaths, List<Path> outputPaths, Path storeDir) { // compaction descriptor contains relative paths. http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/RequestConverter.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/RequestConverter.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/RequestConverter.java index e7d0934..d6bcb29 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/RequestConverter.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/RequestConverter.java @@ -22,7 +22,6 @@ import java.util.List; import org.apache.hadoop.hbase.util.ByteStringer; -import org.apache.commons.configuration.Configuration; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.hbase.CellScannable; import org.apache.hadoop.hbase.DoNotRetryIOException; @@ -104,7 +103,6 @@ import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.UnassignRegionReq import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.GetLastFlushedSequenceIdRequest; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Pair; -import org.apache.hadoop.hbase.util.Triple; import com.google.protobuf.ByteString; @@ -708,14 +706,12 @@ public final class RequestConverter { * @return a protocol buffer OpenRegionRequest */ public static OpenRegionRequest - buildOpenRegionRequest(final List<Triple<HRegionInfo, Integer, + buildOpenRegionRequest(final List<Pair<HRegionInfo, List<ServerName>>> regionOpenInfos, Boolean openForReplay) { OpenRegionRequest.Builder builder = OpenRegionRequest.newBuilder(); - for (Triple<HRegionInfo, Integer, List<ServerName>> regionOpenInfo: regionOpenInfos) { - Integer second = regionOpenInfo.getSecond(); - int versionOfOfflineNode = second == null ? -1 : second.intValue(); - builder.addOpenInfo(buildRegionOpenInfo(regionOpenInfo.getFirst(), versionOfOfflineNode, - regionOpenInfo.getThird(), openForReplay)); + for (Pair<HRegionInfo, List<ServerName>> regionOpenInfo: regionOpenInfos) { + builder.addOpenInfo(buildRegionOpenInfo(regionOpenInfo.getFirst(), + regionOpenInfo.getSecond(), openForReplay)); } return builder.build(); } @@ -725,16 +721,15 @@ public final class RequestConverter { * * @param server the serverName for the RPC * @param region the region to open - * @param versionOfOfflineNode that needs to be present in the offline node * @param favoredNodes * @param openForReplay * @return a protocol buffer OpenRegionRequest */ public static OpenRegionRequest buildOpenRegionRequest(ServerName server, - final HRegionInfo region, final int versionOfOfflineNode, List<ServerName> favoredNodes, + final HRegionInfo region, List<ServerName> favoredNodes, Boolean openForReplay) { OpenRegionRequest.Builder builder = OpenRegionRequest.newBuilder(); - builder.addOpenInfo(buildRegionOpenInfo(region, versionOfOfflineNode, favoredNodes, + builder.addOpenInfo(buildRegionOpenInfo(region, favoredNodes, openForReplay)); if (server != null) { builder.setServerStartCode(server.getStartcode()); @@ -765,33 +760,21 @@ public final class RequestConverter { * Create a CloseRegionRequest for a given region name * * @param regionName the name of the region to close - * @param transitionInZK indicator if to transition in ZK * @return a CloseRegionRequest */ public static CloseRegionRequest buildCloseRegionRequest(ServerName server, - final byte[] regionName, final boolean transitionInZK) { - CloseRegionRequest.Builder builder = CloseRegionRequest.newBuilder(); - RegionSpecifier region = buildRegionSpecifier( - RegionSpecifierType.REGION_NAME, regionName); - builder.setRegion(region); - builder.setTransitionInZK(transitionInZK); - if (server != null) { - builder.setServerStartCode(server.getStartcode()); - } - return builder.build(); + final byte[] regionName) { + return buildCloseRegionRequest(server, regionName, null); } public static CloseRegionRequest buildCloseRegionRequest(ServerName server, - final byte[] regionName, final int versionOfClosingNode, - ServerName destinationServer, final boolean transitionInZK) { + final byte[] regionName, ServerName destinationServer) { CloseRegionRequest.Builder builder = CloseRegionRequest.newBuilder(); RegionSpecifier region = buildRegionSpecifier( RegionSpecifierType.REGION_NAME, regionName); builder.setRegion(region); - builder.setVersionOfClosingNode(versionOfClosingNode); - builder.setTransitionInZK(transitionInZK); if (destinationServer != null){ - builder.setDestinationServer(ProtobufUtil.toServerName( destinationServer) ); + builder.setDestinationServer(ProtobufUtil.toServerName(destinationServer)); } if (server != null) { builder.setServerStartCode(server.getStartcode()); @@ -803,18 +786,15 @@ public final class RequestConverter { * Create a CloseRegionRequest for a given encoded region name * * @param encodedRegionName the name of the region to close - * @param transitionInZK indicator if to transition in ZK * @return a CloseRegionRequest */ public static CloseRegionRequest - buildCloseRegionRequest(ServerName server, final String encodedRegionName, - final boolean transitionInZK) { + buildCloseRegionRequest(ServerName server, final String encodedRegionName) { CloseRegionRequest.Builder builder = CloseRegionRequest.newBuilder(); RegionSpecifier region = buildRegionSpecifier( RegionSpecifierType.ENCODED_REGION_NAME, Bytes.toBytes(encodedRegionName)); builder.setRegion(region); - builder.setTransitionInZK(transitionInZK); if (server != null) { builder.setServerStartCode(server.getStartcode()); } @@ -1498,13 +1478,10 @@ public final class RequestConverter { * Create a RegionOpenInfo based on given region info and version of offline node */ private static RegionOpenInfo buildRegionOpenInfo( - final HRegionInfo region, final int versionOfOfflineNode, + final HRegionInfo region, final List<ServerName> favoredNodes, Boolean openForReplay) { RegionOpenInfo.Builder builder = RegionOpenInfo.newBuilder(); builder.setRegion(HRegionInfo.convert(region)); - if (versionOfOfflineNode >= 0) { - builder.setVersionOfOfflineNode(versionOfOfflineNode); - } if (favoredNodes != null) { for (ServerName server : favoredNodes) { builder.addFavoredNodes(ProtobufUtil.toServerName(server)); http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAssign.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAssign.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAssign.java deleted file mode 100644 index d85496c..0000000 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAssign.java +++ /dev/null @@ -1,1057 +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.zookeeper; - -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.classification.InterfaceAudience; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.HRegionInfo; -import org.apache.hadoop.hbase.RegionTransition; -import org.apache.hadoop.hbase.ServerName; -import org.apache.hadoop.hbase.exceptions.DeserializationException; -import org.apache.hadoop.hbase.executor.EventType; -import org.apache.zookeeper.AsyncCallback; -import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.KeeperException.Code; -import org.apache.zookeeper.KeeperException.NoNodeException; -import org.apache.zookeeper.KeeperException.NodeExistsException; -import org.apache.zookeeper.data.Stat; - -// We should not be importing this Type here, nor a RegionTransition, etc. This class should be -// about zk and bytes only. - -/** - * Utility class for doing region assignment in ZooKeeper. This class extends - * stuff done in {@link ZKUtil} to cover specific assignment operations. - * <p> - * Contains only static methods and constants. - * <p> - * Used by both the Master and RegionServer. - * <p> - * All valid transitions outlined below: - * <p> - * <b>MASTER</b> - * <ol> - * <li> - * Master creates an unassigned node as OFFLINE. - * - Cluster startup and table enabling. - * </li> - * <li> - * Master forces an existing unassigned node to OFFLINE. - * - RegionServer failure. - * - Allows transitions from all states to OFFLINE. - * </li> - * <li> - * Master deletes an unassigned node that was in a OPENED state. - * - Normal region transitions. Besides cluster startup, no other deletions - * of unassigned nodes is allowed. - * </li> - * <li> - * Master deletes all unassigned nodes regardless of state. - * - Cluster startup before any assignment happens. - * </li> - * </ol> - * <p> - * <b>REGIONSERVER</b> - * <ol> - * <li> - * RegionServer creates an unassigned node as CLOSING. - * - All region closes will do this in response to a CLOSE RPC from Master. - * - A node can never be transitioned to CLOSING, only created. - * </li> - * <li> - * RegionServer transitions an unassigned node from CLOSING to CLOSED. - * - Normal region closes. CAS operation. - * </li> - * <li> - * RegionServer transitions an unassigned node from OFFLINE to OPENING. - * - All region opens will do this in response to an OPEN RPC from the Master. - * - Normal region opens. CAS operation. - * </li> - * <li> - * RegionServer transitions an unassigned node from OPENING to OPENED. - * - Normal region opens. CAS operation. - * </li> - * </ol> - */ [email protected] -public class ZKAssign { - private static final Log LOG = LogFactory.getLog(ZKAssign.class); - - /** - * Gets the full path node name for the unassigned node for the specified - * region. - * @param zkw zk reference - * @param regionName region name - * @return full path node name - */ - public static String getNodeName(ZooKeeperWatcher zkw, String regionName) { - return ZKUtil.joinZNode(zkw.assignmentZNode, regionName); - } - - /** - * Gets the region name from the full path node name of an unassigned node. - * @param path full zk path - * @return region name - */ - public static String getRegionName(ZooKeeperWatcher zkw, String path) { - return path.substring(zkw.assignmentZNode.length()+1); - } - - // Master methods - - /** - * Creates a new unassigned node in the OFFLINE state for the specified region. - * - * <p>Does not transition nodes from other states. If a node already exists - * for this region, a {@link NodeExistsException} will be thrown. - * - * <p>Sets a watcher on the unassigned region node if the method is successful. - * - * <p>This method should only be used during cluster startup and the enabling - * of a table. - * - * @param zkw zk reference - * @param region region to be created as offline - * @param serverName server transition will happen on - * @throws KeeperException if unexpected zookeeper exception - * @throws KeeperException.NodeExistsException if node already exists - */ - public static void createNodeOffline(ZooKeeperWatcher zkw, HRegionInfo region, - ServerName serverName) - throws KeeperException, KeeperException.NodeExistsException { - createNodeOffline(zkw, region, serverName, EventType.M_ZK_REGION_OFFLINE); - } - - public static void createNodeOffline(ZooKeeperWatcher zkw, HRegionInfo region, - ServerName serverName, final EventType event) - throws KeeperException, KeeperException.NodeExistsException { - LOG.debug(zkw.prefix("Creating unassigned node " + - region.getEncodedName() + " in OFFLINE state")); - RegionTransition rt = - RegionTransition.createRegionTransition(event, region.getRegionName(), serverName); - String node = getNodeName(zkw, region.getEncodedName()); - ZKUtil.createAndWatch(zkw, node, rt.toByteArray()); - } - - /** - * Creates an unassigned node in the OFFLINE state for the specified region. - * <p> - * Runs asynchronously. Depends on no pre-existing znode. - * - * <p>Sets a watcher on the unassigned region node. - * - * @param zkw zk reference - * @param region region to be created as offline - * @param serverName server transition will happen on - * @param cb - * @param ctx - * @throws KeeperException if unexpected zookeeper exception - * @throws KeeperException.NodeExistsException if node already exists - */ - public static void asyncCreateNodeOffline(ZooKeeperWatcher zkw, - HRegionInfo region, ServerName serverName, - final AsyncCallback.StringCallback cb, final Object ctx) - throws KeeperException { - LOG.debug(zkw.prefix("Async create of unassigned node " + - region.getEncodedName() + " with OFFLINE state")); - RegionTransition rt = - RegionTransition.createRegionTransition( - EventType.M_ZK_REGION_OFFLINE, region.getRegionName(), serverName); - String node = getNodeName(zkw, region.getEncodedName()); - ZKUtil.asyncCreate(zkw, node, rt.toByteArray(), cb, ctx); - } - - /** - * Creates or force updates an unassigned node to the OFFLINE state for the - * specified region. - * <p> - * Attempts to create the node but if it exists will force it to transition to - * and OFFLINE state. - * - * <p>Sets a watcher on the unassigned region node if the method is - * successful. - * - * <p>This method should be used when assigning a region. - * - * @param zkw zk reference - * @param region region to be created as offline - * @param serverName server transition will happen on - * @return the version of the znode created in OFFLINE state, -1 if - * unsuccessful. - * @throws KeeperException if unexpected zookeeper exception - * @throws KeeperException.NodeExistsException if node already exists - */ - public static int createOrForceNodeOffline(ZooKeeperWatcher zkw, - HRegionInfo region, ServerName serverName) throws KeeperException { - LOG.debug(zkw.prefix("Creating (or updating) unassigned node " + - region.getEncodedName() + " with OFFLINE state")); - RegionTransition rt = RegionTransition.createRegionTransition(EventType.M_ZK_REGION_OFFLINE, - region.getRegionName(), serverName, HConstants.EMPTY_BYTE_ARRAY); - byte [] data = rt.toByteArray(); - String node = getNodeName(zkw, region.getEncodedName()); - zkw.sync(node); - int version = ZKUtil.checkExists(zkw, node); - if (version == -1) { - return ZKUtil.createAndWatch(zkw, node, data); - } else { - boolean setData = false; - try { - setData = ZKUtil.setData(zkw, node, data, version); - // Setdata throws KeeperException which aborts the Master. So we are - // catching it here. - // If just before setting the znode to OFFLINE if the RS has made any - // change to the - // znode state then we need to return -1. - } catch (KeeperException kpe) { - LOG.info("Version mismatch while setting the node to OFFLINE state."); - return -1; - } - if (!setData) { - return -1; - } else { - // We successfully forced to OFFLINE, reset watch and handle if - // the state changed in between our set and the watch - byte [] bytes = ZKAssign.getData(zkw, region.getEncodedName()); - rt = getRegionTransition(bytes); - if (rt.getEventType() != EventType.M_ZK_REGION_OFFLINE) { - // state changed, need to process - return -1; - } - } - } - return version + 1; - } - - /** - * Deletes an existing unassigned node that is in the OPENED state for the - * specified region. - * - * <p>If a node does not already exist for this region, a - * {@link NoNodeException} will be thrown. - * - * <p>No watcher is set whether this succeeds or not. - * - * <p>Returns false if the node was not in the proper state but did exist. - * - * <p>This method is used during normal region transitions when a region - * finishes successfully opening. This is the Master acknowledging completion - * of the specified regions transition. - * - * @param zkw zk reference - * @param encodedRegionName opened region to be deleted from zk - * @param sn the expected region transition target server name - * @throws KeeperException if unexpected zookeeper exception - * @throws KeeperException.NoNodeException if node does not exist - */ - public static boolean deleteOpenedNode(ZooKeeperWatcher zkw, - String encodedRegionName, ServerName sn) - throws KeeperException, KeeperException.NoNodeException { - return deleteNode(zkw, encodedRegionName, - EventType.RS_ZK_REGION_OPENED, sn); - } - - /** - * Deletes an existing unassigned node that is in the OFFLINE state for the - * specified region. - * - * <p>If a node does not already exist for this region, a - * {@link NoNodeException} will be thrown. - * - * <p>No watcher is set whether this succeeds or not. - * - * <p>Returns false if the node was not in the proper state but did exist. - * - * <p>This method is used during master failover when the regions on an RS - * that has died are all set to OFFLINE before being processed. - * - * @param zkw zk reference - * @param encodedRegionName closed region to be deleted from zk - * @param sn the expected region transition target server name - * @throws KeeperException if unexpected zookeeper exception - * @throws KeeperException.NoNodeException if node does not exist - */ - public static boolean deleteOfflineNode(ZooKeeperWatcher zkw, - String encodedRegionName, ServerName sn) - throws KeeperException, KeeperException.NoNodeException { - return deleteNode(zkw, encodedRegionName, - EventType.M_ZK_REGION_OFFLINE, sn); - } - - /** - * Deletes an existing unassigned node that is in the CLOSED state for the - * specified region. - * - * <p>If a node does not already exist for this region, a - * {@link NoNodeException} will be thrown. - * - * <p>No watcher is set whether this succeeds or not. - * - * <p>Returns false if the node was not in the proper state but did exist. - * - * <p>This method is used during table disables when a region finishes - * successfully closing. This is the Master acknowledging completion - * of the specified regions transition to being closed. - * - * @param zkw zk reference - * @param encodedRegionName closed region to be deleted from zk - * @param sn the expected region transition target server name - * @throws KeeperException if unexpected zookeeper exception - * @throws KeeperException.NoNodeException if node does not exist - */ - public static boolean deleteClosedNode(ZooKeeperWatcher zkw, - String encodedRegionName, ServerName sn) - throws KeeperException, KeeperException.NoNodeException { - return deleteNode(zkw, encodedRegionName, - EventType.RS_ZK_REGION_CLOSED, sn); - } - - /** - * Deletes an existing unassigned node that is in the CLOSING state for the - * specified region. - * - * <p>If a node does not already exist for this region, a - * {@link NoNodeException} will be thrown. - * - * <p>No watcher is set whether this succeeds or not. - * - * <p>Returns false if the node was not in the proper state but did exist. - * - * <p>This method is used during table disables when a region finishes - * successfully closing. This is the Master acknowledging completion - * of the specified regions transition to being closed. - * - * @param zkw zk reference - * @param region closing region to be deleted from zk - * @param sn the expected region transition target server name - * @throws KeeperException if unexpected zookeeper exception - * @throws KeeperException.NoNodeException if node does not exist - */ - public static boolean deleteClosingNode(ZooKeeperWatcher zkw, - HRegionInfo region, ServerName sn) - throws KeeperException, KeeperException.NoNodeException { - String encodedRegionName = region.getEncodedName(); - return deleteNode(zkw, encodedRegionName, - EventType.M_ZK_REGION_CLOSING, sn); - } - - /** - * Deletes an existing unassigned node that is in the specified state for the - * specified region. - * - * <p>If a node does not already exist for this region, a - * {@link NoNodeException} will be thrown. - * - * <p>No watcher is set whether this succeeds or not. - * - * <p>Returns false if the node was not in the proper state but did exist. - * - * <p>This method is used when a region finishes opening/closing. - * The Master acknowledges completion - * of the specified regions transition to being closed/opened. - * - * @param zkw zk reference - * @param encodedRegionName region to be deleted from zk - * @param expectedState state region must be in for delete to complete - * @param sn the expected region transition target server name - * @throws KeeperException if unexpected zookeeper exception - * @throws KeeperException.NoNodeException if node does not exist - */ - public static boolean deleteNode(ZooKeeperWatcher zkw, String encodedRegionName, - EventType expectedState, ServerName sn) - throws KeeperException, KeeperException.NoNodeException { - return deleteNode(zkw, encodedRegionName, expectedState, sn, -1); - } - - /** - * Deletes an existing unassigned node that is in the specified state for the - * specified region. - * - * <p>If a node does not already exist for this region, a - * {@link NoNodeException} will be thrown. - * - * <p>No watcher is set whether this succeeds or not. - * - * <p>Returns false if the node was not in the proper state but did exist. - * - * <p>This method is used when a region finishes opening/closing. - * The Master acknowledges completion - * of the specified regions transition to being closed/opened. - * - * @param zkw zk reference - * @param encodedRegionName region to be deleted from zk - * @param expectedState state region must be in for delete to complete - * @param expectedVersion of the znode that is to be deleted. - * If expectedVersion need not be compared while deleting the znode - * pass -1 - * @throws KeeperException if unexpected zookeeper exception - * @throws KeeperException.NoNodeException if node does not exist - */ - public static boolean deleteNode(ZooKeeperWatcher zkw, String encodedRegionName, - EventType expectedState, int expectedVersion) - throws KeeperException, KeeperException.NoNodeException { - return deleteNode(zkw, encodedRegionName, expectedState, null, expectedVersion); - } - - /** - * Deletes an existing unassigned node that is in the specified state for the - * specified region. - * - * <p>If a node does not already exist for this region, a - * {@link NoNodeException} will be thrown. - * - * <p>No watcher is set whether this succeeds or not. - * - * <p>Returns false if the node was not in the proper state but did exist. - * - * <p>This method is used when a region finishes opening/closing. - * The Master acknowledges completion - * of the specified regions transition to being closed/opened. - * - * @param zkw zk reference - * @param encodedRegionName region to be deleted from zk - * @param expectedState state region must be in for delete to complete - * @param serverName the expected region transition target server name - * @param expectedVersion of the znode that is to be deleted. - * If expectedVersion need not be compared while deleting the znode - * pass -1 - * @throws KeeperException if unexpected zookeeper exception - * @throws KeeperException.NoNodeException if node does not exist - */ - public static boolean deleteNode(ZooKeeperWatcher zkw, String encodedRegionName, - EventType expectedState, ServerName serverName, int expectedVersion) - throws KeeperException, KeeperException.NoNodeException { - if (LOG.isTraceEnabled()) { - LOG.trace(zkw.prefix("Deleting existing unassigned " + - "node " + encodedRegionName + " in expected state " + expectedState)); - } - String node = getNodeName(zkw, encodedRegionName); - zkw.sync(node); - Stat stat = new Stat(); - byte [] bytes = ZKUtil.getDataNoWatch(zkw, node, stat); - if (bytes == null) { - // If it came back null, node does not exist. - throw KeeperException.create(Code.NONODE); - } - RegionTransition rt = getRegionTransition(bytes); - EventType et = rt.getEventType(); - if (!et.equals(expectedState)) { - LOG.warn(zkw.prefix("Attempting to delete unassigned node " + encodedRegionName + " in " + - expectedState + " state but node is in " + et + " state")); - return false; - } - // Verify the server transition happens on is not changed - if (serverName != null && !rt.getServerName().equals(serverName)) { - LOG.warn(zkw.prefix("Attempting to delete unassigned node " + encodedRegionName - + " with target " + serverName + " but node has " + rt.getServerName())); - return false; - } - if (expectedVersion != -1 - && stat.getVersion() != expectedVersion) { - LOG.warn("The node " + encodedRegionName + " we are trying to delete is not" + - " the expected one. Got a version mismatch"); - return false; - } - if(!ZKUtil.deleteNode(zkw, node, stat.getVersion())) { - LOG.warn(zkw.prefix("Attempting to delete " + - "unassigned node " + encodedRegionName + " in " + expectedState + - " state but after verifying state, we got a version mismatch")); - return false; - } - LOG.debug(zkw.prefix("Deleted unassigned node " + - encodedRegionName + " in expected state " + expectedState)); - return true; - } - - /** - * Deletes all unassigned nodes regardless of their state. - * - * <p>No watchers are set. - * - * <p>This method is used by the Master during cluster startup to clear out - * any existing state from other cluster runs. - * - * @param zkw zk reference - * @throws KeeperException if unexpected zookeeper exception - */ - public static void deleteAllNodes(ZooKeeperWatcher zkw) - throws KeeperException { - LOG.debug(zkw.prefix("Deleting any existing unassigned nodes")); - ZKUtil.deleteChildrenRecursively(zkw, zkw.assignmentZNode); - } - - /** - * Creates a new unassigned node in the CLOSING state for the specified - * region. - * - * <p>Does not transition nodes from any states. If a node already exists - * for this region, a {@link NodeExistsException} will be thrown. - * - * <p>If creation is successful, returns the version number of the CLOSING - * node created. - * - * <p>Set a watch. - * - * <p>This method should only be used by a Master when initiating a - * close of a region before sending a close request to the region server. - * - * @param zkw zk reference - * @param region region to be created as closing - * @param serverName server transition will happen on - * @return version of node after transition, -1 if unsuccessful transition - * @throws KeeperException if unexpected zookeeper exception - * @throws KeeperException.NodeExistsException if node already exists - */ - public static int createNodeClosing(ZooKeeperWatcher zkw, HRegionInfo region, - ServerName serverName) - throws KeeperException, KeeperException.NodeExistsException { - LOG.debug(zkw.prefix("Creating unassigned node " + - region.getEncodedName() + " in a CLOSING state")); - RegionTransition rt = RegionTransition.createRegionTransition(EventType.M_ZK_REGION_CLOSING, - region.getRegionName(), serverName, HConstants.EMPTY_BYTE_ARRAY); - String node = getNodeName(zkw, region.getEncodedName()); - return ZKUtil.createAndWatch(zkw, node, rt.toByteArray()); - } - - // RegionServer methods - - /** - * Transitions an existing unassigned node for the specified region which is - * currently in the CLOSING state to be in the CLOSED state. - * - * <p>Does not transition nodes from other states. If for some reason the - * node could not be transitioned, the method returns -1. If the transition - * is successful, the version of the node after transition is returned. - * - * <p>This method can fail and return false for three different reasons: - * <ul><li>Unassigned node for this region does not exist</li> - * <li>Unassigned node for this region is not in CLOSING state</li> - * <li>After verifying CLOSING state, update fails because of wrong version - * (someone else already transitioned the node)</li> - * </ul> - * - * <p>Does not set any watches. - * - * <p>This method should only be used by a RegionServer when initiating a - * close of a region after receiving a CLOSE RPC from the Master. - * - * @param zkw zk reference - * @param region region to be transitioned to closed - * @param serverName server transition happens on - * @return version of node after transition, -1 if unsuccessful transition - * @throws KeeperException if unexpected zookeeper exception - */ - public static int transitionNodeClosed(ZooKeeperWatcher zkw, - HRegionInfo region, ServerName serverName, int expectedVersion) - throws KeeperException { - return transitionNode(zkw, region, serverName, - EventType.M_ZK_REGION_CLOSING, - EventType.RS_ZK_REGION_CLOSED, expectedVersion); - } - - /** - * Transitions an existing unassigned node for the specified region which is - * currently in the OFFLINE state to be in the OPENING state. - * - * <p>Does not transition nodes from other states. If for some reason the - * node could not be transitioned, the method returns -1. If the transition - * is successful, the version of the node written as OPENING is returned. - * - * <p>This method can fail and return -1 for three different reasons: - * <ul><li>Unassigned node for this region does not exist</li> - * <li>Unassigned node for this region is not in OFFLINE state</li> - * <li>After verifying OFFLINE state, update fails because of wrong version - * (someone else already transitioned the node)</li> - * </ul> - * - * <p>Does not set any watches. - * - * <p>This method should only be used by a RegionServer when initiating an - * open of a region after receiving an OPEN RPC from the Master. - * - * @param zkw zk reference - * @param region region to be transitioned to opening - * @param serverName server transition happens on - * @return version of node after transition, -1 if unsuccessful transition - * @throws KeeperException if unexpected zookeeper exception - */ - public static int transitionNodeOpening(ZooKeeperWatcher zkw, - HRegionInfo region, ServerName serverName) - throws KeeperException { - return transitionNodeOpening(zkw, region, serverName, - EventType.M_ZK_REGION_OFFLINE); - } - - public static int transitionNodeOpening(ZooKeeperWatcher zkw, - HRegionInfo region, ServerName serverName, final EventType beginState) - throws KeeperException { - return transitionNode(zkw, region, serverName, beginState, - EventType.RS_ZK_REGION_OPENING, -1); - } - - /** - * Confirm an existing unassigned node for the specified region which is - * currently in the OPENING state to be still in the OPENING state on - * the specified server. - * - * <p>If for some reason the check fails, the method returns -1. Otherwise, - * the version of the node (same as the expected version) is returned. - * - * <p>This method can fail and return -1 for three different reasons: - * <ul><li>Unassigned node for this region does not exist</li> - * <li>Unassigned node for this region is not in OPENING state</li> - * <li>After verifying OPENING state, the server name or the version of the - * doesn't match)</li> - * </ul> - * - * <p>Does not set any watches. - * - * <p>This method should only be used by a RegionServer when initiating an - * open of a region after receiving an OPEN RPC from the Master. - * - * @param zkw zk reference - * @param region region to be transitioned to opening - * @param serverName server transition happens on - * @return version of node after transition, -1 if unsuccessful transition - * @throws KeeperException if unexpected zookeeper exception - */ - public static int confirmNodeOpening(ZooKeeperWatcher zkw, - HRegionInfo region, ServerName serverName, int expectedVersion) - throws KeeperException { - - String encoded = region.getEncodedName(); - if(LOG.isDebugEnabled()) { - LOG.debug(zkw.prefix("Attempting to retransition opening state of node " + - HRegionInfo.prettyPrint(encoded))); - } - - String node = getNodeName(zkw, encoded); - zkw.sync(node); - - // Read existing data of the node - Stat stat = new Stat(); - byte [] existingBytes = ZKUtil.getDataNoWatch(zkw, node, stat); - if (existingBytes == null) { - // Node no longer exists. Return -1. It means unsuccessful transition. - return -1; - } - RegionTransition rt = getRegionTransition(existingBytes); - - // Verify it is the expected version - if (expectedVersion != -1 && stat.getVersion() != expectedVersion) { - LOG.warn(zkw.prefix("Attempt to retransition the opening state of the " + - "unassigned node for " + encoded + " failed, " + - "the node existed but was version " + stat.getVersion() + - " not the expected version " + expectedVersion)); - return -1; - } - - // Verify it is in expected state - EventType et = rt.getEventType(); - if (!et.equals(EventType.RS_ZK_REGION_OPENING)) { - String existingServer = (rt.getServerName() == null) - ? "<unknown>" : rt.getServerName().toString(); - LOG.warn(zkw.prefix("Attempt to retransition the opening state of the unassigned node for " - + encoded + " failed, the node existed but was in the state " + et + - " set by the server " + existingServer)); - return -1; - } - - return expectedVersion; - } - - /** - * Transitions an existing unassigned node for the specified region which is - * currently in the OPENING state to be in the OPENED state. - * - * <p>Does not transition nodes from other states. If for some reason the - * node could not be transitioned, the method returns -1. If the transition - * is successful, the version of the node after transition is returned. - * - * <p>This method can fail and return false for three different reasons: - * <ul><li>Unassigned node for this region does not exist</li> - * <li>Unassigned node for this region is not in OPENING state</li> - * <li>After verifying OPENING state, update fails because of wrong version - * (this should never actually happen since an RS only does this transition - * following a transition to OPENING. if two RS are conflicting, one would - * fail the original transition to OPENING and not this transition)</li> - * </ul> - * - * <p>Does not set any watches. - * - * <p>This method should only be used by a RegionServer when completing the - * open of a region. - * - * @param zkw zk reference - * @param region region to be transitioned to opened - * @param serverName server transition happens on - * @return version of node after transition, -1 if unsuccessful transition - * @throws KeeperException if unexpected zookeeper exception - */ - public static int transitionNodeOpened(ZooKeeperWatcher zkw, - HRegionInfo region, ServerName serverName, int expectedVersion) - throws KeeperException { - return transitionNode(zkw, region, serverName, - EventType.RS_ZK_REGION_OPENING, - EventType.RS_ZK_REGION_OPENED, expectedVersion); - } - - /** - * - * @param zkw zk reference - * @param region region to be closed - * @param expectedVersion expected version of the znode - * @return true if the znode exists, has the right version and the right state. False otherwise. - * @throws KeeperException - */ - public static boolean checkClosingState(ZooKeeperWatcher zkw, HRegionInfo region, - int expectedVersion) throws KeeperException { - - final String encoded = getNodeName(zkw, region.getEncodedName()); - zkw.sync(encoded); - - // Read existing data of the node - Stat stat = new Stat(); - byte[] existingBytes = ZKUtil.getDataNoWatch(zkw, encoded, stat); - - if (existingBytes == null) { - LOG.warn(zkw.prefix("Attempt to check the " + - "closing node for " + encoded + - ". The node does not exist")); - return false; - } - - if (expectedVersion != -1 && stat.getVersion() != expectedVersion) { - LOG.warn(zkw.prefix("Attempt to check the " + - "closing node for " + encoded + - ". The node existed but was version " + stat.getVersion() + - " not the expected version " + expectedVersion)); - return false; - } - - RegionTransition rt = getRegionTransition(existingBytes); - - if (!EventType.M_ZK_REGION_CLOSING.equals(rt.getEventType())) { - LOG.warn(zkw.prefix("Attempt to check the " + - "closing node for " + encoded + - ". The node existed but was in an unexpected state: " + rt.getEventType())); - return false; - } - - return true; - } - - /** - * Method that actually performs unassigned node transitions. - * - * <p>Attempts to transition the unassigned node for the specified region - * from the expected state to the state in the specified transition data. - * - * <p>Method first reads existing data and verifies it is in the expected - * state. If the node does not exist or the node is not in the expected - * state, the method returns -1. If the transition is successful, the - * version number of the node following the transition is returned. - * - * <p>If the read state is what is expected, it attempts to write the new - * state and data into the node. When doing this, it includes the expected - * version (determined when the existing state was verified) to ensure that - * only one transition is successful. If there is a version mismatch, the - * method returns -1. - * - * <p>If the write is successful, no watch is set and the method returns true. - * - * @param zkw zk reference - * @param region region to be transitioned to opened - * @param serverName server transition happens on - * @param endState state to transition node to if all checks pass - * @param beginState state the node must currently be in to do transition - * @param expectedVersion expected version of data before modification, or -1 - * @return version of node after transition, -1 if unsuccessful transition - * @throws KeeperException if unexpected zookeeper exception - */ - public static int transitionNode(ZooKeeperWatcher zkw, HRegionInfo region, - ServerName serverName, EventType beginState, EventType endState, - int expectedVersion) - throws KeeperException { - return transitionNode(zkw, region, serverName, beginState, endState, expectedVersion, null); - } - - - public static int transitionNode(ZooKeeperWatcher zkw, HRegionInfo region, - ServerName serverName, EventType beginState, EventType endState, - int expectedVersion, final byte [] payload) - throws KeeperException { - String encoded = region.getEncodedName(); - if(LOG.isDebugEnabled()) { - LOG.debug(zkw.prefix("Transitioning " + HRegionInfo.prettyPrint(encoded) + - " from " + beginState.toString() + " to " + endState.toString())); - } - - String node = getNodeName(zkw, encoded); - zkw.sync(node); - - // Read existing data of the node - Stat stat = new Stat(); - byte [] existingBytes = ZKUtil.getDataNoWatch(zkw, node, stat); - if (existingBytes == null) { - // Node no longer exists. Return -1. It means unsuccessful transition. - return -1; - } - - // Verify it is the expected version - if (expectedVersion != -1 && stat.getVersion() != expectedVersion) { - LOG.warn(zkw.prefix("Attempt to transition the " + - "unassigned node for " + encoded + - " from " + beginState + " to " + endState + " failed, " + - "the node existed but was version " + stat.getVersion() + - " not the expected version " + expectedVersion)); - return -1; - } - - if (beginState.equals(EventType.M_ZK_REGION_OFFLINE) - && endState.equals(EventType.RS_ZK_REGION_OPENING) - && expectedVersion == -1 && stat.getVersion() != 0) { - // the below check ensures that double assignment doesnot happen. - // When the node is created for the first time then the expected version - // that is passed will be -1 and the version in znode will be 0. - // In all other cases the version in znode will be > 0. - LOG.warn(zkw.prefix("Attempt to transition the " + "unassigned node for " - + encoded + " from " + beginState + " to " + endState + " failed, " - + "the node existed but was version " + stat.getVersion() - + " not the expected version " + expectedVersion)); - return -1; - } - - RegionTransition rt = getRegionTransition(existingBytes); - - // Verify the server transition happens on is not changed - if (!rt.getServerName().equals(serverName)) { - LOG.warn(zkw.prefix("Attempt to transition the " + - "unassigned node for " + encoded + - " from " + beginState + " to " + endState + " failed, " + - "the server that tried to transition was " + serverName + - " not the expected " + rt.getServerName())); - return -1; - } - - // Verify it is in expected state - EventType et = rt.getEventType(); - if (!et.equals(beginState)) { - String existingServer = (rt.getServerName() == null) - ? "<unknown>" : rt.getServerName().toString(); - LOG.warn(zkw.prefix("Attempt to transition the unassigned node for " + encoded - + " from " + beginState + " to " + endState + " failed, the node existed but" - + " was in the state " + et + " set by the server " + existingServer)); - return -1; - } - - // Write new data, ensuring data has not changed since we last read it - try { - rt = RegionTransition.createRegionTransition( - endState, region.getRegionName(), serverName, payload); - if(!ZKUtil.setData(zkw, node, rt.toByteArray(), stat.getVersion())) { - LOG.warn(zkw.prefix("Attempt to transition the " + - "unassigned node for " + encoded + - " from " + beginState + " to " + endState + " failed, " + - "the node existed and was in the expected state but then when " + - "setting data we got a version mismatch")); - return -1; - } - if(LOG.isDebugEnabled()) { - LOG.debug(zkw.prefix("Transitioned node " + encoded + - " from " + beginState + " to " + endState)); - } - return stat.getVersion() + 1; - } catch (KeeperException.NoNodeException nne) { - LOG.warn(zkw.prefix("Attempt to transition the " + - "unassigned node for " + encoded + - " from " + beginState + " to " + endState + " failed, " + - "the node existed and was in the expected state but then when " + - "setting data it no longer existed")); - return -1; - } - } - - private static RegionTransition getRegionTransition(final byte [] bytes) throws KeeperException { - try { - return RegionTransition.parseFrom(bytes); - } catch (DeserializationException e) { - // Convert to a zk exception for now. Otherwise have to change API - throw ZKUtil.convert(e); - } - } - - /** - * Gets the current data in the unassigned node for the specified region name - * or fully-qualified path. - * - * <p>Returns null if the region does not currently have a node. - * - * <p>Sets a watch on the node if the node exists. - * - * @param zkw zk reference - * @param pathOrRegionName fully-specified path or region name - * @return znode content - * @throws KeeperException if unexpected zookeeper exception - */ - public static byte [] getData(ZooKeeperWatcher zkw, - String pathOrRegionName) - throws KeeperException { - String node = getPath(zkw, pathOrRegionName); - return ZKUtil.getDataAndWatch(zkw, node); - } - - /** - * Gets the current data in the unassigned node for the specified region name - * or fully-qualified path. - * - * <p>Returns null if the region does not currently have a node. - * - * <p>Sets a watch on the node if the node exists. - * - * @param zkw zk reference - * @param pathOrRegionName fully-specified path or region name - * @param stat object to populate the version. - * @return znode content - * @throws KeeperException if unexpected zookeeper exception - */ - public static byte [] getDataAndWatch(ZooKeeperWatcher zkw, - String pathOrRegionName, Stat stat) - throws KeeperException { - String node = getPath(zkw, pathOrRegionName); - return ZKUtil.getDataAndWatch(zkw, node, stat); - } - - /** - * Gets the current data in the unassigned node for the specified region name - * or fully-qualified path. - * - * <p>Returns null if the region does not currently have a node. - * - * <p>Does not set a watch. - * - * @param zkw zk reference - * @param pathOrRegionName fully-specified path or region name - * @param stat object to store node info into on getData call - * @return znode content - * @throws KeeperException if unexpected zookeeper exception - */ - public static byte [] getDataNoWatch(ZooKeeperWatcher zkw, - String pathOrRegionName, Stat stat) - throws KeeperException { - String node = getPath(zkw, pathOrRegionName); - return ZKUtil.getDataNoWatch(zkw, node, stat); - } - - /** - * @param zkw - * @param pathOrRegionName - * @return Path to znode - */ - public static String getPath(final ZooKeeperWatcher zkw, final String pathOrRegionName) { - return pathOrRegionName.startsWith("/")? pathOrRegionName : getNodeName(zkw, pathOrRegionName); - } - - /** - * Get the version of the specified znode - * @param zkw zk reference - * @param region region's info - * @return the version of the znode, -1 if it doesn't exist - * @throws KeeperException - */ - public static int getVersion(ZooKeeperWatcher zkw, HRegionInfo region) - throws KeeperException { - String znode = getNodeName(zkw, region.getEncodedName()); - return ZKUtil.checkExists(zkw, znode); - } - - /** - * Delete the assignment node regardless of its current state. - * <p> - * Fail silent even if the node does not exist at all. - * @param watcher - * @param regionInfo - * @throws KeeperException - */ - public static void deleteNodeFailSilent(ZooKeeperWatcher watcher, - HRegionInfo regionInfo) - throws KeeperException { - String node = getNodeName(watcher, regionInfo.getEncodedName()); - ZKUtil.deleteNodeFailSilent(watcher, node); - } - - /** - * Blocks until there are no node in regions in transition. - * <p> - * Used in testing only. - * @param zkw zk reference - * @throws KeeperException - * @throws InterruptedException - */ - public static void blockUntilNoRIT(ZooKeeperWatcher zkw) - throws KeeperException, InterruptedException { - while (ZKUtil.nodeHasChildren(zkw, zkw.assignmentZNode)) { - List<String> znodes = - ZKUtil.listChildrenAndWatchForNewChildren(zkw, zkw.assignmentZNode); - if (znodes != null && !znodes.isEmpty()) { - LOG.debug("Waiting on RIT: " + znodes); - } - Thread.sleep(100); - } - } - - /** - * Blocks until there is at least one node in regions in transition. - * <p> - * Used in testing only. - * @param zkw zk reference - * @throws KeeperException - * @throws InterruptedException - */ - public static void blockUntilRIT(ZooKeeperWatcher zkw) - throws KeeperException, InterruptedException { - while (!ZKUtil.nodeHasChildren(zkw, zkw.assignmentZNode)) { - List<String> znodes = - ZKUtil.listChildrenAndWatchForNewChildren(zkw, zkw.assignmentZNode); - if (znodes == null || znodes.isEmpty()) { - LOG.debug("No RIT in ZK"); - } - Thread.sleep(100); - } - } - - /** - * Presume bytes are serialized unassigned data structure - * @param znodeBytes - * @return String of the deserialized znode bytes. - */ - static String toString(final byte[] znodeBytes) { - // This method should not exist. Used by ZKUtil stringifying RegionTransition. Have the - // method in here so RegionTransition does not leak into ZKUtil. - try { - RegionTransition rt = RegionTransition.parseFrom(znodeBytes); - return rt.toString(); - } catch (DeserializationException e) { - return ""; - } - } -} http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java index 7836d11..b13667f 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java @@ -263,10 +263,6 @@ public class ZKUtil { private final String keytabFile; private final String principal; - public JaasConfiguration(String loginContextName, String principal) { - this(loginContextName, principal, null, true); - } - public JaasConfiguration(String loginContextName, String principal, String keytabFile) { this(loginContextName, principal, keytabFile, keytabFile == null || keytabFile.length() == 0); } @@ -951,7 +947,7 @@ public class ZKUtil { conf.get("hbase.zookeeper.client.keytab.file") != null); } - private static ArrayList<ACL> createACL(ZooKeeperWatcher zkw, String node) { + private static List<ACL> createACL(ZooKeeperWatcher zkw, String node) { if (isSecureZooKeeper(zkw.getConfiguration())) { // Certain znodes are accessed directly by the client, // so they must be readable by non-authenticated clients @@ -961,7 +957,6 @@ public class ZKUtil { (node.equals(zkw.clusterIdZNode) == true) || (node.equals(zkw.rsZNode) == true) || (node.equals(zkw.backupMasterAddressesZNode) == true) || - (node.startsWith(zkw.assignmentZNode) == true) || (node.startsWith(zkw.tableZNode) == true)) { return ZooKeeperWatcher.CREATOR_ALL_AND_WORLD_READABLE; } @@ -1779,8 +1774,6 @@ public class ZKUtil { " byte(s) of data from znode " + znode + (watcherSet? " and set watcher; ": "; data=") + (data == null? "null": data.length == 0? "empty": ( - znode.startsWith(zkw.assignmentZNode)? - ZKAssign.toString(data): // We should not be doing this reaching into another class znode.startsWith(zkw.metaServerZNode)? getServerNameOrEmptyString(data): znode.startsWith(zkw.backupMasterAddressesZNode)? http://git-wip-us.apache.org/repos/asf/hbase/blob/17dff681/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java index c16d6d3..c8afac3 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java @@ -21,6 +21,7 @@ package org.apache.hadoop.hbase.zookeeper; import java.io.Closeable; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; @@ -92,8 +93,6 @@ public class ZooKeeperWatcher implements Watcher, Abortable, Closeable { public String backupMasterAddressesZNode; // znode containing the current cluster state public String clusterStateZNode; - // znode used for region transitioning and assignment - public String assignmentZNode; // znode used for table disabling/enabling public String tableZNode; // znode containing the unique cluster ID @@ -111,11 +110,9 @@ public class ZooKeeperWatcher implements Watcher, Abortable, Closeable { // Certain ZooKeeper nodes need to be world-readable - public static final ArrayList<ACL> CREATOR_ALL_AND_WORLD_READABLE = - new ArrayList<ACL>() { { - add(new ACL(ZooDefs.Perms.READ,ZooDefs.Ids.ANYONE_ID_UNSAFE)); - add(new ACL(ZooDefs.Perms.ALL,ZooDefs.Ids.AUTH_IDS)); - }}; + public static final List<ACL> CREATOR_ALL_AND_WORLD_READABLE = + Arrays.asList(new ACL(ZooDefs.Perms.READ,ZooDefs.Ids.ANYONE_ID_UNSAFE), + new ACL(ZooDefs.Perms.ALL,ZooDefs.Ids.AUTH_IDS)); private final Configuration conf; @@ -171,9 +168,6 @@ public class ZooKeeperWatcher implements Watcher, Abortable, Closeable { try { // Create all the necessary "directories" of znodes ZKUtil.createWithParents(this, baseZNode); - if (conf.getBoolean("hbase.assignment.usezk", false)) { - ZKUtil.createAndFailSilent(this, assignmentZNode); - } ZKUtil.createAndFailSilent(this, rsZNode); ZKUtil.createAndFailSilent(this, drainingZNode); ZKUtil.createAndFailSilent(this, tableZNode); @@ -220,8 +214,6 @@ public class ZooKeeperWatcher implements Watcher, Abortable, Closeable { conf.get("zookeeper.znode.backup.masters", "backup-masters")); clusterStateZNode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.state", "running")); - assignmentZNode = ZKUtil.joinZNode(baseZNode, - conf.get("zookeeper.znode.unassigned", "region-in-transition")); tableZNode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.tableEnableDisable", "table")); clusterIdZNode = ZKUtil.joinZNode(baseZNode,
