HBASE-19114 Split out o.a.h.h.zookeeper from hbase-server and hbase-client

- Moved DrainingServerTracker and RegionServerTracker to 
hbase-server:o.a.h.h.master.
- Moved SplitOrMergeTracker to oahh.master (because it depends on a PB)
- Moving hbase-client:oahh.zookeeper.*  to hbase-zookeeper module.  After 
HBASE-19200, hbase-client doesn't need them anymore (except 3 classes).
- Renamed some classes to use a consistent naming for classes - ZK instead of 
mix of ZK, Zk , ZooKeeper. Couldn't rename following public classes: 
MiniZooKeeperCluster, ZooKeeperConnectionException. Left RecoverableZooKeeper 
for lack of better name. (suggestions?)
- Sadly, can't move tests out because they depend on HBaseTestingUtility (which 
defeats part of the purpose - trimming down hbase-server tests. We need to 
promote more use of mocks in our tests)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/330b0d05
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/330b0d05
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/330b0d05

Branch: refs/heads/master
Commit: 330b0d05b99981b4bdc92c81b22ebb5be5ece155
Parents: ca74ec7
Author: Apekshit Sharma <a...@apache.org>
Authored: Mon Nov 13 11:42:33 2017 -0800
Committer: Apekshit Sharma <a...@apache.org>
Committed: Fri Nov 17 13:20:18 2017 -0800

----------------------------------------------------------------------
 bin/hbase                                       |   14 +-
 bin/hbase.cmd                                   |   10 +-
 conf/log4j.properties                           |    2 +-
 .../src/main/resources/log4j.properties         |    2 +-
 .../src/main/resources/log4j.properties         |    2 +-
 hbase-assembly/pom.xml                          |    4 +
 .../src/main/assembly/hadoop-two-compat.xml     |    1 +
 .../hadoop/hbase/zookeeper/EmptyWatcher.java    |   34 -
 .../hadoop/hbase/zookeeper/HQuorumPeer.java     |  165 --
 .../hadoop/hbase/zookeeper/InstancePending.java |   80 -
 .../hbase/zookeeper/MasterAddressTracker.java   |  281 ---
 .../hbase/zookeeper/MetaTableLocator.java       |  629 ------
 .../hbase/zookeeper/MetricsZooKeeper.java       |  110 -
 .../hadoop/hbase/zookeeper/PendingWatcher.java  |   53 -
 .../hbase/zookeeper/RecoverableZooKeeper.java   |  814 -------
 .../hadoop/hbase/zookeeper/ZKClusterId.java     |   99 -
 .../hadoop/hbase/zookeeper/ZKLeaderManager.java |  183 --
 .../apache/hadoop/hbase/zookeeper/ZKUtil.java   | 2072 ------------------
 .../hadoop/hbase/zookeeper/ZkAclReset.java      |  116 -
 .../hbase/zookeeper/ZooKeeperListener.java      |   86 -
 .../zookeeper/ZooKeeperMetricsListener.java     |   91 -
 .../hbase/zookeeper/ZooKeeperNodeTracker.java   |  251 ---
 .../hbase/zookeeper/ZooKeeperWatcher.java       |  638 ------
 .../hbase/zookeeper/TestInstancePending.java    |   49 -
 .../hbase/zookeeper/TestMetricsZooKeeper.java   |   77 -
 .../hadoop/hbase/zookeeper/TestZKUtil.java      |  113 -
 .../hbase/zookeeper/TestZooKeeperWatcher.java   |   57 -
 .../hbase/IntegrationTestMetaReplicas.java      |    6 +-
 .../test/IntegrationTestZKAndFSPermissions.java |    8 +-
 .../apache/hadoop/hbase/mapreduce/Import.java   |    6 +-
 .../replication/VerifyReplication.java          |    6 +-
 hbase-replication/pom.xml                       |    4 +
 .../hbase/replication/ReplicationFactory.java   |   12 +-
 .../replication/ReplicationPeerZKImpl.java      |   14 +-
 .../replication/ReplicationPeersZKImpl.java     |    6 +-
 .../replication/ReplicationQueuesArguments.java |   10 +-
 .../ReplicationQueuesClientArguments.java       |    4 +-
 .../ReplicationQueuesClientZKImpl.java          |   12 +-
 .../replication/ReplicationQueuesZKImpl.java    |   10 +-
 .../replication/ReplicationStateZKBase.java     |   16 +-
 .../replication/ReplicationTrackerZKImpl.java   |   14 +-
 .../TableBasedReplicationQueuesImpl.java        |    5 +-
 .../hbase/rsgroup/RSGroupInfoManagerImpl.java   |    4 +-
 .../rsgroup/VerifyingRSGroupAdminClient.java    |    6 +-
 hbase-server/pom.xml                            |    4 +
 .../java/org/apache/hadoop/hbase/Server.java    |    4 +-
 .../apache/hadoop/hbase/ZKNamespaceManager.java |    8 +-
 .../org/apache/hadoop/hbase/ZNodeClearer.java   |   16 +-
 .../backup/example/HFileArchiveManager.java     |   10 +-
 .../example/TableHFileArchiveTracker.java       |   14 +-
 .../backup/example/ZKTableArchiveClient.java    |    4 +-
 .../ZKSplitLogManagerCoordination.java          |    8 +-
 .../coordination/ZkCoordinatedStateManager.java |    6 +-
 .../ZkSplitLogWorkerCoordination.java           |   14 +-
 .../hbase/master/ActiveMasterManager.java       |   14 +-
 .../hbase/master/DrainingServerTracker.java     |  135 ++
 .../org/apache/hadoop/hbase/master/HMaster.java |    8 +-
 .../hbase/master/MasterMetaBootstrap.java       |    4 +-
 .../hbase/master/MetricsMasterWrapperImpl.java  |    8 +-
 .../hbase/master/RegionServerTracker.java       |  164 ++
 .../hadoop/hbase/master/ServerManager.java      |    7 +-
 .../hbase/master/SplitOrMergeTracker.java       |  153 ++
 .../cleaner/ReplicationZKNodeCleaner.java       |    8 +-
 .../master/replication/ReplicationManager.java  |    6 +-
 .../hbase/procedure/ZKProcedureCoordinator.java |    6 +-
 .../hbase/procedure/ZKProcedureMemberRpcs.java  |    6 +-
 .../hadoop/hbase/procedure/ZKProcedureUtil.java |   10 +-
 .../RegionServerFlushTableProcedureManager.java |    5 +-
 .../hbase/regionserver/HRegionServer.java       |   12 +-
 .../MetricsRegionServerWrapperImpl.java         |    4 +-
 .../snapshot/RegionServerSnapshotManager.java   |    5 +-
 .../replication/HBaseReplicationEndpoint.java   |   14 +-
 .../master/ReplicationHFileCleaner.java         |   11 +-
 .../master/ReplicationLogCleaner.java           |    8 +-
 .../replication/master/TableCFsUpdater.java     |    6 +-
 .../regionserver/DumpReplicationQueues.java     |    8 +-
 .../regionserver/ReplicationSyncUp.java         |   12 +-
 .../hbase/security/access/AccessController.java |    4 +-
 .../hbase/security/access/TableAuthManager.java |    8 +-
 .../security/access/ZKPermissionWatcher.java    |   11 +-
 .../token/AuthenticationTokenSecretManager.java |   14 +-
 .../hadoop/hbase/security/token/TokenUtil.java  |    4 +-
 .../hbase/security/token/ZKSecretWatcher.java   |   12 +-
 .../DefaultVisibilityLabelServiceImpl.java      |    4 +-
 .../visibility/VisibilityLabelsCache.java       |    8 +-
 .../visibility/ZKVisibilityLabelWatcher.java    |   14 +-
 .../org/apache/hadoop/hbase/util/HBaseFsck.java |    8 +-
 .../apache/hadoop/hbase/util/RegionMover.java   |    4 +-
 .../hadoop/hbase/util/ZKDataMigrator.java       |   10 +-
 .../hbase/util/hbck/ReplicationChecker.java     |    6 +-
 .../hbase/zookeeper/ClusterStatusTracker.java   |   99 -
 .../hbase/zookeeper/DeletionListener.java       |  101 -
 .../hbase/zookeeper/DrainingServerTracker.java  |  134 --
 .../hbase/zookeeper/LoadBalancerTracker.java    |   94 -
 .../zookeeper/MasterMaintenanceModeTracker.java |   81 -
 .../hbase/zookeeper/MiniZooKeeperCluster.java   |  472 ----
 .../zookeeper/RegionNormalizerTracker.java      |   94 -
 .../hbase/zookeeper/RegionServerTracker.java    |  162 --
 .../hbase/zookeeper/SplitOrMergeTracker.java    |  149 --
 .../hadoop/hbase/zookeeper/ZKServerTool.java    |   65 -
 .../hadoop/hbase/zookeeper/ZKSplitLog.java      |  124 --
 .../hbase/zookeeper/ZooKeeperMainServer.java    |  126 --
 .../main/resources/hbase-webapps/master/zk.jsp  |    4 +-
 .../hadoop/hbase/HBaseTestingUtility.java       |   22 +-
 .../hadoop/hbase/MockRegionServerServices.java  |   11 +-
 .../hbase/TestMetaTableAccessorNoCluster.java   |    4 +-
 .../hadoop/hbase/TestMetaTableLocator.java      |    6 +-
 .../org/apache/hadoop/hbase/TestZooKeeper.java  |   18 +-
 .../TestZooKeeperTableArchiveClient.java        |    4 +-
 .../hbase/client/TestMetaWithReplicas.java      |   10 +-
 .../replication/TestReplicationAdmin.java       |    8 +-
 ...TestMasterCoprocessorExceptionWithAbort.java |   10 +-
 ...estMasterCoprocessorExceptionWithRemove.java |   10 +-
 .../hbase/master/MockNoopMasterServices.java    |    4 +-
 .../hadoop/hbase/master/MockRegionServer.java   |    9 +-
 .../hbase/master/TestActiveMasterManager.java   |   26 +-
 .../hbase/master/TestAssignmentListener.java    |    6 +-
 .../hbase/master/TestClockSkewDetection.java    |    6 -
 .../master/TestDistributedLogSplitting.java     |   22 +-
 .../hbase/master/TestHMasterRPCException.java   |    4 +-
 .../hbase/master/TestMasterNoCluster.java       |    4 +-
 .../hbase/master/TestMasterStatusServlet.java   |    4 +-
 .../hbase/master/TestSplitLogManager.java       |   12 +-
 .../hbase/master/TestTableStateManager.java     |    8 +-
 .../hbase/master/cleaner/TestHFileCleaner.java  |    6 +-
 .../master/cleaner/TestHFileLinkCleaner.java    |    6 +-
 .../hbase/master/cleaner/TestLogsCleaner.java   |   10 +-
 .../cleaner/TestReplicationHFileCleaner.java    |   10 +-
 .../cleaner/TestReplicationZKNodeCleaner.java   |    6 +-
 .../procedure/SimpleRSProcedureManager.java     |    4 +-
 .../hadoop/hbase/procedure/TestZKProcedure.java |   14 +-
 .../procedure/TestZKProcedureControllers.java   |   28 +-
 .../TestCompactionInDeadRegionServer.java       |    5 +-
 .../regionserver/TestHeapMemoryManager.java     |    4 +-
 .../regionserver/TestMasterAddressTracker.java  |   10 +-
 .../hbase/regionserver/TestRSStatusServlet.java |    4 +-
 .../regionserver/TestRegionServerHostname.java  |    6 +-
 .../regionserver/TestRegionServerNoMaster.java  |    4 +-
 .../hbase/regionserver/TestSplitLogWorker.java  |   12 +-
 .../hbase/regionserver/TestWALLockup.java       |    4 +-
 .../replication/TestMasterReplication.java      |    6 +-
 .../replication/TestMultiSlaveReplication.java  |   19 +-
 .../replication/TestPerTableCFReplication.java  |    8 +-
 .../hbase/replication/TestReplicationBase.java  |   12 +-
 .../TestReplicationStateHBaseImpl.java          |    6 +-
 .../replication/TestReplicationStateZKImpl.java |    8 +-
 .../replication/TestReplicationTableBase.java   |    4 +-
 .../TestReplicationTrackerZKImpl.java           |   14 +-
 .../replication/TestSerialReplication.java      |    6 +-
 .../replication/master/TestTableCFsUpdater.java |    6 +-
 .../regionserver/TestGlobalThrottler.java       |    6 +-
 .../TestReplicationSourceManager.java           |    8 +-
 .../security/access/TestAccessController2.java  |    4 +-
 .../security/access/TestTablePermissions.java   |    6 +-
 .../access/TestZKPermissionWatcher.java         |    6 +-
 .../security/token/TestTokenAuthentication.java |    8 +-
 .../security/token/TestZKSecretWatcher.java     |   26 +-
 .../token/TestZKSecretWatcherRefreshKeys.java   |   16 +-
 ...sibilityLabelReplicationWithExpAsString.java |    6 +-
 .../TestVisibilityLabelsReplication.java        |   10 +-
 .../apache/hadoop/hbase/util/MockServer.java    |   10 +-
 .../hadoop/hbase/util/TestHBaseFsckOneRS.java   |    4 +-
 .../zookeeper/TestRecoverableZooKeeper.java     |    2 +-
 .../hbase/zookeeper/TestZKLeaderManager.java    |   14 +-
 .../hbase/zookeeper/TestZKMainServer.java       |  118 +
 .../hadoop/hbase/zookeeper/TestZKMulti.java     |    4 +-
 .../hbase/zookeeper/TestZKNodeTracker.java      |  351 +++
 .../hbase/zookeeper/TestZooKeeperACL.java       |   12 +-
 .../zookeeper/TestZooKeeperMainServer.java      |  118 -
 .../zookeeper/TestZooKeeperNodeTracker.java     |  351 ---
 hbase-shell/src/main/ruby/hbase/admin.rb        |    2 +-
 hbase-zookeeper/pom.xml                         |  412 ++++
 .../hbase/zookeeper/ClusterStatusTracker.java   |   99 +
 .../hbase/zookeeper/DeletionListener.java       |  101 +
 .../hadoop/hbase/zookeeper/EmptyWatcher.java    |   34 +
 .../hadoop/hbase/zookeeper/HQuorumPeer.java     |  165 ++
 .../hadoop/hbase/zookeeper/InstancePending.java |   80 +
 .../hbase/zookeeper/LoadBalancerTracker.java    |   94 +
 .../hbase/zookeeper/MasterAddressTracker.java   |  281 +++
 .../zookeeper/MasterMaintenanceModeTracker.java |   81 +
 .../hbase/zookeeper/MetaTableLocator.java       |  629 ++++++
 .../hbase/zookeeper/MiniZooKeeperCluster.java   |  472 ++++
 .../hadoop/hbase/zookeeper/PendingWatcher.java  |   53 +
 .../hbase/zookeeper/RecoverableZooKeeper.java   |  810 +++++++
 .../zookeeper/RegionNormalizerTracker.java      |   94 +
 .../hadoop/hbase/zookeeper/ZKAclReset.java      |  116 +
 .../hadoop/hbase/zookeeper/ZKClusterId.java     |   99 +
 .../hadoop/hbase/zookeeper/ZKLeaderManager.java |  183 ++
 .../hadoop/hbase/zookeeper/ZKListener.java      |   85 +
 .../hadoop/hbase/zookeeper/ZKMainServer.java    |  126 ++
 .../hadoop/hbase/zookeeper/ZKMetrics.java       |  108 +
 .../hbase/zookeeper/ZKMetricsListener.java      |   91 +
 .../hadoop/hbase/zookeeper/ZKNodeTracker.java   |  251 +++
 .../hadoop/hbase/zookeeper/ZKServerTool.java    |   65 +
 .../hadoop/hbase/zookeeper/ZKSplitLog.java      |  122 ++
 .../apache/hadoop/hbase/zookeeper/ZKUtil.java   | 2072 ++++++++++++++++++
 .../hadoop/hbase/zookeeper/ZKWatcher.java       |  634 ++++++
 .../hbase/zookeeper/TestInstancePending.java    |   49 +
 .../hadoop/hbase/zookeeper/TestZKMetrics.java   |   80 +
 .../hadoop/hbase/zookeeper/TestZKUtil.java      |  113 +
 .../hadoop/hbase/zookeeper/TestZKWatcher.java   |   57 +
 pom.xml                                         |    6 +
 202 files changed, 9129 insertions(+), 8735 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/bin/hbase
----------------------------------------------------------------------
diff --git a/bin/hbase b/bin/hbase
index 998bdbe..d98e7bc 100755
--- a/bin/hbase
+++ b/bin/hbase
@@ -17,7 +17,7 @@
 # * See the License for the specific language governing permissions and
 # * limitations under the License.
 # */
-# 
+#
 # The hbase command script.  Based on the hadoop command script putting
 # in hbase classes, libs and configurations ahead of hadoop's.
 #
@@ -91,10 +91,10 @@ if [ $# = 0 ]; then
   echo "  hfile           Store file analyzer"
   echo "  zkcli           Run the ZooKeeper shell"
   echo "  master          Run an HBase HMaster node"
-  echo "  regionserver    Run an HBase HRegionServer node" 
+  echo "  regionserver    Run an HBase HRegionServer node"
   echo "  zookeeper       Run a ZooKeeper server"
-  echo "  rest            Run an HBase REST server" 
-  echo "  thrift          Run the HBase Thrift server" 
+  echo "  rest            Run an HBase REST server"
+  echo "  thrift          Run the HBase Thrift server"
   echo "  thrift2         Run the HBase Thrift2 server"
   echo "  clean           Run the HBase clean up script"
   echo "  classpath       Dump hbase CLASSPATH"
@@ -274,7 +274,7 @@ fi
 if $cygwin; then
   JAVA_LIBRARY_PATH=`cygpath -p "$JAVA_LIBRARY_PATH"`
 fi
- 
+
 # restore ordinary behaviour
 unset IFS
 
@@ -362,7 +362,7 @@ elif [ "$COMMAND" = "wal" ] ; then
 elif [ "$COMMAND" = "hfile" ] ; then
   CLASS='org.apache.hadoop.hbase.io.hfile.HFilePrettyPrinter'
 elif [ "$COMMAND" = "zkcli" ] ; then
-  CLASS="org.apache.hadoop.hbase.zookeeper.ZooKeeperMainServer"
+  CLASS="org.apache.hadoop.hbase.zookeeper.ZKMainServer"
 elif [ "$COMMAND" = "backup" ] ; then
   CLASS='org.apache.hadoop.hbase.backup.BackupDriver'
 elif [ "$COMMAND" = "restore" ] ; then
@@ -422,7 +422,7 @@ elif [ "$COMMAND" = "zookeeper" ] ; then
   fi
 elif [ "$COMMAND" = "clean" ] ; then
   case $1 in
-    --cleanZk|--cleanHdfs|--cleanAll) 
+    --cleanZk|--cleanHdfs|--cleanAll)
       matches="yes" ;;
     *) ;;
   esac

http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/bin/hbase.cmd
----------------------------------------------------------------------
diff --git a/bin/hbase.cmd b/bin/hbase.cmd
index 070cb61..8e4a59f 100644
--- a/bin/hbase.cmd
+++ b/bin/hbase.cmd
@@ -16,7 +16,7 @@
 @rem * See the License for the specific language governing permissions and
 @rem * limitations under the License.
 @rem */
-@rem 
+@rem
 @rem The hbase command script.  Based on the hadoop command script putting
 @rem in hbase classes, libs and configurations ahead of hadoop's.
 @rem
@@ -197,7 +197,7 @@ if exist "%HBASE_HOME%\build\native" (
 rem This loop would set %hbase-command-arguments%
 set _hbasearguments=
 :MakeCmdArgsLoop
-  if [%1]==[] goto :EndLoop 
+  if [%1]==[] goto :EndLoop
 
   if not defined _hbasearguments (
     set _hbasearguments=%1
@@ -205,8 +205,8 @@ set _hbasearguments=
     set _hbasearguments=!_hbasearguments! %1
   )
   shift
-goto :MakeCmdArgsLoop 
-:EndLoop 
+goto :MakeCmdArgsLoop
+:EndLoop
 
 set hbase-command-arguments=%_hbasearguments%
 
@@ -424,7 +424,7 @@ goto :eof
   goto :eof
 
 :zkcli
-  set CLASS=org.apache.hadoop.hbase.zookeeper.ZooKeeperMainServer
+  set CLASS=org.apache.hadoop.hbase.zookeeper.ZKMainServer
   goto :eof
 
 :mapredcp

http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/conf/log4j.properties
----------------------------------------------------------------------
diff --git a/conf/log4j.properties b/conf/log4j.properties
index 15545ff..6367dbe 100644
--- a/conf/log4j.properties
+++ b/conf/log4j.properties
@@ -98,7 +98,7 @@ log4j.logger.org.apache.hadoop.hbase=INFO
 log4j.logger.org.apache.hadoop.hbase.META=INFO
 # Make these two classes INFO-level. Make them DEBUG to see more zk debug.
 log4j.logger.org.apache.hadoop.hbase.zookeeper.ZKUtil=INFO
-log4j.logger.org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher=INFO
+log4j.logger.org.apache.hadoop.hbase.zookeeper.ZKWatcher=INFO
 #log4j.logger.org.apache.hadoop.dfs=DEBUG
 # Set this class to log INFO only otherwise its OTT
 # Enable this to get detailed connection error/retry logging.

http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-archetypes/hbase-client-project/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git 
a/hbase-archetypes/hbase-client-project/src/main/resources/log4j.properties 
b/hbase-archetypes/hbase-client-project/src/main/resources/log4j.properties
index 11f2b75..0b01e57 100644
--- a/hbase-archetypes/hbase-client-project/src/main/resources/log4j.properties
+++ b/hbase-archetypes/hbase-client-project/src/main/resources/log4j.properties
@@ -95,7 +95,7 @@ log4j.logger.org.apache.zookeeper=INFO
 log4j.logger.org.apache.hadoop.hbase=INFO
 # Make these two classes INFO-level. Make them DEBUG to see more zk debug.
 log4j.logger.org.apache.hadoop.hbase.zookeeper.ZKUtil=INFO
-log4j.logger.org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher=INFO
+log4j.logger.org.apache.hadoop.hbase.zookeeper.ZKWatcher=INFO
 #log4j.logger.org.apache.hadoop.dfs=DEBUG
 # Set this class to log INFO only otherwise its OTT
 # Enable this to get detailed connection error/retry logging.

http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-archetypes/hbase-shaded-client-project/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git 
a/hbase-archetypes/hbase-shaded-client-project/src/main/resources/log4j.properties
 
b/hbase-archetypes/hbase-shaded-client-project/src/main/resources/log4j.properties
index 11f2b75..0b01e57 100644
--- 
a/hbase-archetypes/hbase-shaded-client-project/src/main/resources/log4j.properties
+++ 
b/hbase-archetypes/hbase-shaded-client-project/src/main/resources/log4j.properties
@@ -95,7 +95,7 @@ log4j.logger.org.apache.zookeeper=INFO
 log4j.logger.org.apache.hadoop.hbase=INFO
 # Make these two classes INFO-level. Make them DEBUG to see more zk debug.
 log4j.logger.org.apache.hadoop.hbase.zookeeper.ZKUtil=INFO
-log4j.logger.org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher=INFO
+log4j.logger.org.apache.hadoop.hbase.zookeeper.ZKWatcher=INFO
 #log4j.logger.org.apache.hadoop.dfs=DEBUG
 # Set this class to log INFO only otherwise its OTT
 # Enable this to get detailed connection error/retry logging.

http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-assembly/pom.xml
----------------------------------------------------------------------
diff --git a/hbase-assembly/pom.xml b/hbase-assembly/pom.xml
index 71e90f3..75cba4d 100644
--- a/hbase-assembly/pom.xml
+++ b/hbase-assembly/pom.xml
@@ -303,6 +303,10 @@
       <groupId>org.apache.hbase</groupId>
       <artifactId>hbase-examples</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.hbase</groupId>
+      <artifactId>hbase-zookeeper</artifactId>
+    </dependency>
   </dependencies>
   <profiles>
     <profile>

http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-assembly/src/main/assembly/hadoop-two-compat.xml
----------------------------------------------------------------------
diff --git a/hbase-assembly/src/main/assembly/hadoop-two-compat.xml 
b/hbase-assembly/src/main/assembly/hadoop-two-compat.xml
index 03951bd..2aa3e57 100644
--- a/hbase-assembly/src/main/assembly/hadoop-two-compat.xml
+++ b/hbase-assembly/src/main/assembly/hadoop-two-compat.xml
@@ -59,6 +59,7 @@
         <include>org.apache.hbase:hbase-spark-it</include>
         <include>org.apache.hbase:hbase-testing-util</include>
         <include>org.apache.hbase:hbase-thrift</include>
+        <include>org.apache.hbase:hbase-zookeeper</include>
       </includes>
       <!-- Binaries for the dependencies also go in the hbase-jars directory 
-->
       <binaries>

http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/EmptyWatcher.java
----------------------------------------------------------------------
diff --git 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/EmptyWatcher.java
 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/EmptyWatcher.java
deleted file mode 100644
index 191943a..0000000
--- 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/EmptyWatcher.java
+++ /dev/null
@@ -1,34 +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 org.apache.yetus.audience.InterfaceAudience;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
-
-/**
- * An empty ZooKeeper watcher
- */
-@InterfaceAudience.Private
-public class EmptyWatcher implements Watcher {
-  // Used in this package but also by tests so needs to be public
-  public static final EmptyWatcher instance = new EmptyWatcher();
-  private EmptyWatcher() {}
-
-  public void process(WatchedEvent event) {}
-}

http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java
----------------------------------------------------------------------
diff --git 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java
deleted file mode 100644
index 5f3904a..0000000
--- 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java
+++ /dev/null
@@ -1,165 +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 static org.apache.hadoop.hbase.HConstants.DEFAULT_ZK_SESSION_TIMEOUT;
-import static org.apache.hadoop.hbase.HConstants.ZK_SESSION_TIMEOUT;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Map.Entry;
-import java.util.Properties;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.apache.hadoop.hbase.HBaseInterfaceAudience;
-import org.apache.hadoop.hbase.HConstants;
-import org.apache.yetus.audience.InterfaceAudience;
-import org.apache.yetus.audience.InterfaceStability;
-import org.apache.hadoop.hbase.util.DNS;
-import org.apache.hadoop.hbase.util.Strings;
-import org.apache.hadoop.util.StringUtils;
-import org.apache.zookeeper.server.ServerConfig;
-import org.apache.zookeeper.server.ZooKeeperServerMain;
-import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
-import org.apache.zookeeper.server.quorum.QuorumPeerMain;
-
-/**
- * HBase's version of ZooKeeper's QuorumPeer. When HBase is set to manage
- * ZooKeeper, this class is used to start up QuorumPeer instances. By doing
- * things in here rather than directly calling to ZooKeeper, we have more
- * control over the process. This class uses {@link ZKConfig} to get settings
- * from the hbase-site.xml file.
- */
-@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS)
-@InterfaceStability.Evolving
-public class HQuorumPeer {
-
-  /**
-   * Parse ZooKeeper configuration from HBase XML config and run a QuorumPeer.
-   * @param args String[] of command line arguments. Not used.
-   */
-  public static void main(String[] args) {
-    Configuration conf = HBaseConfiguration.create();
-    try {
-      Properties zkProperties = ZKConfig.makeZKProps(conf);
-      writeMyID(zkProperties);
-      QuorumPeerConfig zkConfig = new QuorumPeerConfig();
-      zkConfig.parseProperties(zkProperties);
-
-      // login the zookeeper server principal (if using security)
-      ZKUtil.loginServer(conf, HConstants.ZK_SERVER_KEYTAB_FILE,
-        HConstants.ZK_SERVER_KERBEROS_PRINCIPAL,
-        zkConfig.getClientPortAddress().getHostName());
-
-      runZKServer(zkConfig);
-    } catch (Exception e) {
-      e.printStackTrace();
-      System.exit(-1);
-    }
-  }
-
-  private static void runZKServer(QuorumPeerConfig zkConfig) throws 
UnknownHostException, IOException {
-    if (zkConfig.isDistributed()) {
-      QuorumPeerMain qp = new QuorumPeerMain();
-      qp.runFromConfig(zkConfig);
-    } else {
-      ZooKeeperServerMain zk = new ZooKeeperServerMain();
-      ServerConfig serverConfig = new ServerConfig();
-      serverConfig.readFrom(zkConfig);
-      zk.runFromConfig(serverConfig);
-    }
-  }
-
-  private static boolean addressIsLocalHost(String address) {
-    return address.equals("localhost") || address.equals("127.0.0.1");
-  }
-
-  static void writeMyID(Properties properties) throws IOException {
-    long myId = -1;
-
-    Configuration conf = HBaseConfiguration.create();
-    String myAddress = Strings.domainNamePointerToHostName(DNS.getDefaultHost(
-        conf.get("hbase.zookeeper.dns.interface","default"),
-        conf.get("hbase.zookeeper.dns.nameserver","default")));
-
-    List<String> ips = new ArrayList<>();
-
-    // Add what could be the best (configured) match
-    ips.add(myAddress.contains(".") ?
-        myAddress :
-        StringUtils.simpleHostname(myAddress));
-
-    // For all nics get all hostnames and IPs
-    Enumeration<?> nics = NetworkInterface.getNetworkInterfaces();
-    while(nics.hasMoreElements()) {
-      Enumeration<?> rawAdrs =
-          ((NetworkInterface)nics.nextElement()).getInetAddresses();
-      while(rawAdrs.hasMoreElements()) {
-        InetAddress inet = (InetAddress) rawAdrs.nextElement();
-        ips.add(StringUtils.simpleHostname(inet.getHostName()));
-        ips.add(inet.getHostAddress());
-      }
-    }
-
-    for (Entry<Object, Object> entry : properties.entrySet()) {
-      String key = entry.getKey().toString().trim();
-      String value = entry.getValue().toString().trim();
-      if (key.startsWith("server.")) {
-        int dot = key.indexOf('.');
-        long id = Long.parseLong(key.substring(dot + 1));
-        String[] parts = value.split(":");
-        String address = parts[0];
-        if (addressIsLocalHost(address) || ips.contains(address)) {
-          myId = id;
-          break;
-        }
-      }
-    }
-
-    // Set the max session timeout from the provided client-side timeout
-    properties.setProperty("maxSessionTimeout",
-      conf.get(ZK_SESSION_TIMEOUT, 
Integer.toString(DEFAULT_ZK_SESSION_TIMEOUT)));
-
-    if (myId == -1) {
-      throw new IOException("Could not find my address: " + myAddress +
-                            " in list of ZooKeeper quorum servers");
-    }
-
-    String dataDirStr = properties.get("dataDir").toString().trim();
-    File dataDir = new File(dataDirStr);
-    if (!dataDir.isDirectory()) {
-      if (!dataDir.mkdirs()) {
-        throw new IOException("Unable to create data dir " + dataDir);
-      }
-    }
-
-    File myIdFile = new File(dataDir, "myid");
-    PrintWriter w = new PrintWriter(myIdFile);
-    w.println(myId);
-    w.close();
-  }
-}

http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/InstancePending.java
----------------------------------------------------------------------
diff --git 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/InstancePending.java
 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/InstancePending.java
deleted file mode 100644
index e63bfc5..0000000
--- 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/InstancePending.java
+++ /dev/null
@@ -1,80 +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.concurrent.CountDownLatch;
-
-/**
- * Placeholder of an instance which will be accessed by other threads
- * but is not yet created. Thread safe.
- */
-class InstancePending<T> {
-  // Based on a subtle part of the Java Language Specification,
-  // in order to avoid a slight overhead of synchronization for each access.
-
-  private final CountDownLatch pendingLatch = new CountDownLatch(1);
-
-  /** Piggybacking on {@code pendingLatch}. */
-  private InstanceHolder<T> instanceHolder;
-
-  private static class InstanceHolder<T> {
-    // The JLS ensures the visibility of a final field and its contents
-    // unless they are exposed to another thread while the construction.
-    final T instance;
-
-    InstanceHolder(T instance) {
-      this.instance = instance;
-    }
-  }
-
-  /**
-   * Returns the instance given by the method {@link #prepare}.
-   * This is an uninterruptible blocking method
-   * and the interruption flag will be set just before returning if any.
-   */
-  T get() {
-    InstanceHolder<T> instanceHolder;
-    boolean interrupted = false;
-
-    while ((instanceHolder = this.instanceHolder) == null) {
-      try {
-        pendingLatch.await();
-      } catch (InterruptedException e) {
-        interrupted = true;
-      }
-    }
-
-    if (interrupted) {
-      Thread.currentThread().interrupt();
-    }
-    return instanceHolder.instance;
-  }
-
-  /**
-   * Associates the given instance for the method {@link #get}.
-   * This method should be called once, and {@code instance} should be 
non-null.
-   * This method is expected to call as soon as possible
-   * because the method {@code get} is uninterruptibly blocked until this 
method is called.
-   */
-  void prepare(T instance) {
-    assert instance != null;
-    instanceHolder = new InstanceHolder<>(instance);
-    pendingLatch.countDown();
-  }
-}

http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MasterAddressTracker.java
----------------------------------------------------------------------
diff --git 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MasterAddressTracker.java
 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MasterAddressTracker.java
deleted file mode 100644
index fba637f..0000000
--- 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MasterAddressTracker.java
+++ /dev/null
@@ -1,281 +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.io.IOException;
-import java.io.InterruptedIOException;
-
-import org.apache.hadoop.hbase.Abortable;
-import org.apache.hadoop.hbase.HConstants;
-import org.apache.hadoop.hbase.ServerName;
-import org.apache.yetus.audience.InterfaceAudience;
-import org.apache.hadoop.hbase.exceptions.DeserializationException;
-import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
-import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos;
-import org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.data.Stat;
-import 
org.apache.hadoop.hbase.shaded.com.google.protobuf.InvalidProtocolBufferException;
-
-/**
- * Manages the location of the current active Master for the RegionServer.
- * <p>
- * Listens for ZooKeeper events related to the master address. The node
- * <code>/master</code> will contain the address of the current master.
- * This listener is interested in
- * <code>NodeDeleted</code> and <code>NodeCreated</code> events on
- * <code>/master</code>.
- * <p>
- * Utilizes {@link ZooKeeperNodeTracker} for zk interactions.
- * <p>
- * You can get the current master via {@link #getMasterAddress()} or via
- * {@link #getMasterAddress(ZooKeeperWatcher)} if you do not have a running
- * instance of this Tracker in your context.
- * <p>
- * This class also includes utility for interacting with the master znode, for
- * writing and reading the znode content.
- */
-@InterfaceAudience.Private
-public class MasterAddressTracker extends ZooKeeperNodeTracker {
-  /**
-   * Construct a master address listener with the specified
-   * <code>zookeeper</code> reference.
-   * <p>
-   * This constructor does not trigger any actions, you must call methods
-   * explicitly.  Normally you will just want to execute {@link #start()} to
-   * begin tracking of the master address.
-   *
-   * @param watcher zk reference and watcher
-   * @param abortable abortable in case of fatal error
-   */
-  public MasterAddressTracker(ZooKeeperWatcher watcher, Abortable abortable) {
-    super(watcher, watcher.znodePaths.masterAddressZNode, abortable);
-  }
-
-  /**
-   * Get the address of the current master if one is available.  Returns null
-   * if no current master.
-   * @return Server name or null if timed out.
-   */
-  public ServerName getMasterAddress() {
-    return getMasterAddress(false);
-  }
-
-  /**
-   * Get the info port of the current master of one is available.
-   * Return 0 if no current master or zookeeper is unavailable
-   * @return info port or 0 if timed out
-   */
-  public int getMasterInfoPort() {
-    try {
-      final ZooKeeperProtos.Master master = parse(this.getData(false));
-      if (master == null) {
-        return 0;
-      }
-      return master.getInfoPort();
-    } catch (DeserializationException e) {
-      LOG.warn("Failed parse master zk node data", e);
-      return 0;
-    }
-  }
-  /**
-   * Get the info port of the backup master if it is available.
-   * Return 0 if no backup master or zookeeper is unavailable
-   * @param sn server name of backup master
-   * @return info port or 0 if timed out or exceptions
-   */
-  public int getBackupMasterInfoPort(final ServerName sn) {
-    String backupZNode = 
ZNodePaths.joinZNode(watcher.znodePaths.backupMasterAddressesZNode,
-      sn.toString());
-    try {
-      byte[] data = ZKUtil.getData(watcher, backupZNode);
-      final ZooKeeperProtos.Master backup = parse(data);
-      if (backup == null) {
-        return 0;
-      }
-      return backup.getInfoPort();
-    } catch (Exception e) {
-      LOG.warn("Failed to get backup master: " + sn + "'s info port.", e);
-      return 0;
-    }
-  }
-
-  /**
-   * Get the address of the current master if one is available.  Returns null
-   * if no current master. If refresh is set, try to load the data from ZK 
again,
-   * otherwise, cached data will be used.
-   *
-   * @param refresh whether to refresh the data by calling ZK directly.
-   * @return Server name or null if timed out.
-   */
-  public ServerName getMasterAddress(final boolean refresh) {
-    try {
-      return ProtobufUtil.parseServerNameFrom(super.getData(refresh));
-    } catch (DeserializationException e) {
-      LOG.warn("Failed parse", e);
-      return null;
-    }
-  }
-
-  /**
-   * Get master address.
-   * Use this instead of {@link #getMasterAddress()} if you do not have an
-   * instance of this tracker in your context.
-   * @param zkw ZooKeeperWatcher to use
-   * @return ServerName stored in the the master address znode or null if no
-   * znode present.
-   * @throws KeeperException 
-   * @throws IOException 
-   */
-  public static ServerName getMasterAddress(final ZooKeeperWatcher zkw)
-  throws KeeperException, IOException {
-    byte [] data;
-    try {
-      data = ZKUtil.getData(zkw, zkw.znodePaths.masterAddressZNode);
-    } catch (InterruptedException e) {
-      throw new InterruptedIOException();
-    }
-    // TODO javadoc claims we return null in this case. :/
-    if (data == null){
-      throw new IOException("Can't get master address from ZooKeeper; znode 
data == null");
-    }
-    try {
-      return ProtobufUtil.parseServerNameFrom(data);
-    } catch (DeserializationException e) {
-      KeeperException ke = new KeeperException.DataInconsistencyException();
-      ke.initCause(e);
-      throw ke;
-    }
-  }
-
-  /**
-   * Get master info port.
-   * Use this instead of {@link #getMasterInfoPort()} if you do not have an
-   * instance of this tracker in your context.
-   * @param zkw ZooKeeperWatcher to use
-   * @return master info port in the the master address znode or null if no
-   * znode present.
-   * // TODO can't return null for 'int' return type. non-static verison 
returns 0
-   * @throws KeeperException
-   * @throws IOException
-   */
-  public static int getMasterInfoPort(final ZooKeeperWatcher zkw) throws 
KeeperException,
-      IOException {
-    byte[] data;
-    try {
-      data = ZKUtil.getData(zkw, zkw.znodePaths.masterAddressZNode);
-    } catch (InterruptedException e) {
-      throw new InterruptedIOException();
-    }
-    // TODO javadoc claims we return null in this case. :/
-    if (data == null) {
-      throw new IOException("Can't get master address from ZooKeeper; znode 
data == null");
-    }
-    try {
-      return parse(data).getInfoPort();
-    } catch (DeserializationException e) {
-      KeeperException ke = new KeeperException.DataInconsistencyException();
-      ke.initCause(e);
-      throw ke;
-    }
-  }
-
-  /**
-   * Set master address into the <code>master</code> znode or into the backup
-   * subdirectory of backup masters; switch off the passed in 
<code>znode</code>
-   * path.
-   * @param zkw The ZooKeeperWatcher to use.
-   * @param znode Where to create the znode; could be at the top level or it
-   * could be under backup masters
-   * @param master ServerName of the current master must not be null.
-   * @return true if node created, false if not; a watch is set in both cases
-   * @throws KeeperException
-   */
-  public static boolean setMasterAddress(final ZooKeeperWatcher zkw,
-      final String znode, final ServerName master, int infoPort)
-  throws KeeperException {
-    return ZKUtil.createEphemeralNodeAndWatch(zkw, znode, toByteArray(master, 
infoPort));
-  }
-
-  /**
-   * Check if there is a master available.
-   * @return true if there is a master set, false if not.
-   */
-  public boolean hasMaster() {
-    return super.getData(false) != null;
-  }
-
-  /**
-   * @param sn must not be null
-   * @return Content of the master znode as a serialized pb with the pb
-   * magic as prefix.
-   */
-  static byte[] toByteArray(final ServerName sn, int infoPort) {
-    ZooKeeperProtos.Master.Builder mbuilder = 
ZooKeeperProtos.Master.newBuilder();
-    HBaseProtos.ServerName.Builder snbuilder = 
HBaseProtos.ServerName.newBuilder();
-    snbuilder.setHostName(sn.getHostname());
-    snbuilder.setPort(sn.getPort());
-    snbuilder.setStartCode(sn.getStartcode());
-    mbuilder.setMaster(snbuilder.build());
-    mbuilder.setRpcVersion(HConstants.RPC_CURRENT_VERSION);
-    mbuilder.setInfoPort(infoPort);
-    return ProtobufUtil.prependPBMagic(mbuilder.build().toByteArray());
-  }
-
-  /**
-   * @param data zookeeper data. may be null
-   * @return pb object of master, null if no active master
-   * @throws DeserializationException
-   */
-  public static ZooKeeperProtos.Master parse(byte[] data) throws 
DeserializationException {
-    if (data == null) {
-      return null;
-    }
-    int prefixLen = ProtobufUtil.lengthOfPBMagic();
-    try {
-      return ZooKeeperProtos.Master.PARSER.parseFrom(data, prefixLen, 
data.length - prefixLen);
-    } catch (InvalidProtocolBufferException e) {
-      throw new DeserializationException(e);
-    }
-  }
-  /**
-   * delete the master znode if its content is same as the parameter
-   * @param zkw must not be null
-   * @param content must not be null
-   */
-  public static boolean deleteIfEquals(ZooKeeperWatcher zkw, final String 
content) {
-    if (content == null){
-      throw new IllegalArgumentException("Content must not be null");
-    }
-
-    try {
-      Stat stat = new Stat();
-      byte[] data = ZKUtil.getDataNoWatch(zkw, 
zkw.znodePaths.masterAddressZNode, stat);
-      ServerName sn = ProtobufUtil.parseServerNameFrom(data);
-      if (sn != null && content.equals(sn.toString())) {
-        return (ZKUtil.deleteNode(zkw, zkw.znodePaths.masterAddressZNode, 
stat.getVersion()));
-      }
-    } catch (KeeperException e) {
-      LOG.warn("Can't get or delete the master znode", e);
-    } catch (DeserializationException e) {
-      LOG.warn("Can't get or delete the master znode", e);
-    }
-
-    return false;
-  }
-}

http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java
----------------------------------------------------------------------
diff --git 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java
 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java
deleted file mode 100644
index cddde2f..0000000
--- 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java
+++ /dev/null
@@ -1,629 +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.io.EOFException;
-import java.io.IOException;
-import java.net.ConnectException;
-import java.net.NoRouteToHostException;
-import java.net.SocketException;
-import java.net.SocketTimeoutException;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HConstants;
-import org.apache.hadoop.hbase.NotAllMetaRegionsOnlineException;
-import org.apache.hadoop.hbase.ServerName;
-import org.apache.hadoop.hbase.client.ClusterConnection;
-import org.apache.hadoop.hbase.client.RegionInfo;
-import org.apache.hadoop.hbase.client.RegionInfoBuilder;
-import org.apache.hadoop.hbase.client.RegionReplicaUtil;
-import org.apache.hadoop.hbase.client.RetriesExhaustedException;
-import org.apache.hadoop.hbase.exceptions.DeserializationException;
-import org.apache.hadoop.hbase.ipc.FailedServerException;
-import org.apache.hadoop.hbase.ipc.HBaseRpcController;
-import org.apache.hadoop.hbase.ipc.ServerNotRunningYetException;
-import org.apache.hadoop.hbase.master.RegionState;
-import org.apache.hadoop.hbase.regionserver.RegionServerStoppedException;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.Pair;
-import org.apache.hadoop.ipc.RemoteException;
-import org.apache.yetus.audience.InterfaceAudience;
-import org.apache.zookeeper.KeeperException;
-
-import 
org.apache.hadoop.hbase.shaded.com.google.protobuf.InvalidProtocolBufferException;
-import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
-import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos;
-import 
org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService;
-import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos;
-import org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos;
-import 
org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos.MetaRegionServer;
-
-/**
- * Utility class to perform operation (get/wait for/verify/set/delete) on 
znode in ZooKeeper
- * which keeps hbase:meta region server location.
- *
- * Stateless class with a bunch of static methods. Doesn't manage resources 
passed in
- * (e.g. Connection, ZooKeeperWatcher etc).
- *
- * Meta region location is set by <code>RegionServerServices</code>.
- * This class doesn't use ZK watchers, rather accesses ZK directly.
- *
- * This class it stateless. The only reason it's not made a non-instantiable 
util class
- * with a collection of static methods is that it'd be rather hard to mock 
properly in tests.
- *
- * TODO: rewrite using RPC calls to master to find out about hbase:meta.
- */
-@InterfaceAudience.Private
-public class MetaTableLocator {
-  private static final Log LOG = LogFactory.getLog(MetaTableLocator.class);
-
-  // only needed to allow non-timeout infinite waits to stop when cluster 
shuts down
-  private volatile boolean stopped = false;
-
-  /**
-   * Checks if the meta region location is available.
-   * @return true if meta region location is available, false if not
-   */
-  public boolean isLocationAvailable(ZooKeeperWatcher zkw) {
-    return getMetaRegionLocation(zkw) != null;
-  }
-
-  /**
-   * @param zkw ZooKeeper watcher to be used
-   * @return meta table regions and their locations.
-   */
-  public List<Pair<RegionInfo, ServerName>> 
getMetaRegionsAndLocations(ZooKeeperWatcher zkw) {
-    return getMetaRegionsAndLocations(zkw, RegionInfo.DEFAULT_REPLICA_ID);
-  }
-
-  /**
-   *
-   * @param zkw
-   * @param replicaId
-   * @return meta table regions and their locations.
-   */
-  public List<Pair<RegionInfo, ServerName>> 
getMetaRegionsAndLocations(ZooKeeperWatcher zkw,
-      int replicaId) {
-    ServerName serverName = getMetaRegionLocation(zkw, replicaId);
-    List<Pair<RegionInfo, ServerName>> list = new ArrayList<>(1);
-    list.add(new Pair<>(RegionReplicaUtil.getRegionInfoForReplica(
-        RegionInfoBuilder.FIRST_META_REGIONINFO, replicaId), serverName));
-    return list;
-  }
-
-  /**
-   * @param zkw ZooKeeper watcher to be used
-   * @return List of meta regions
-   */
-  public List<RegionInfo> getMetaRegions(ZooKeeperWatcher zkw) {
-    return getMetaRegions(zkw, RegionInfo.DEFAULT_REPLICA_ID);
-  }
-
-  /**
-   *
-   * @param zkw
-   * @param replicaId
-   * @return List of meta regions
-   */
-  public List<RegionInfo> getMetaRegions(ZooKeeperWatcher zkw, int replicaId) {
-    List<Pair<RegionInfo, ServerName>> result;
-    result = getMetaRegionsAndLocations(zkw, replicaId);
-    return getListOfRegionInfos(result);
-  }
-
-  private List<RegionInfo> getListOfRegionInfos(
-      final List<Pair<RegionInfo, ServerName>> pairs) {
-    if (pairs == null || pairs.isEmpty()) return Collections.EMPTY_LIST;
-    List<RegionInfo> result = new ArrayList<>(pairs.size());
-    for (Pair<RegionInfo, ServerName> pair: pairs) {
-      result.add(pair.getFirst());
-    }
-    return result;
-  }
-
-  /**
-   * Gets the meta region location, if available.  Does not block.
-   * @param zkw zookeeper connection to use
-   * @return server name or null if we failed to get the data.
-   */
-  public ServerName getMetaRegionLocation(final ZooKeeperWatcher zkw) {
-    try {
-      RegionState state = getMetaRegionState(zkw);
-      return state.isOpened() ? state.getServerName() : null;
-    } catch (KeeperException ke) {
-      return null;
-    }
-  }
-
-  /**
-   * Gets the meta region location, if available.  Does not block.
-   * @param zkw
-   * @param replicaId
-   * @return server name
-   */
-  public ServerName getMetaRegionLocation(final ZooKeeperWatcher zkw, int 
replicaId) {
-    try {
-      RegionState state = getMetaRegionState(zkw, replicaId);
-      return state.isOpened() ? state.getServerName() : null;
-    } catch (KeeperException ke) {
-      return null;
-    }
-  }
-
-  /**
-   * Gets the meta region location, if available, and waits for up to the
-   * specified timeout if not immediately available.
-   * Given the zookeeper notification could be delayed, we will try to
-   * get the latest data.
-   * @param zkw
-   * @param timeout maximum time to wait, in millis
-   * @return server name for server hosting meta region formatted as per
-   * {@link ServerName}, or null if none available
-   * @throws InterruptedException if interrupted while waiting
-   * @throws NotAllMetaRegionsOnlineException
-   */
-  public ServerName waitMetaRegionLocation(ZooKeeperWatcher zkw, long timeout)
-  throws InterruptedException, NotAllMetaRegionsOnlineException {
-    return waitMetaRegionLocation(zkw, RegionInfo.DEFAULT_REPLICA_ID, timeout);
-  }
-
-  /**
-   * Gets the meta region location, if available, and waits for up to the
-   * specified timeout if not immediately available.
-   * Given the zookeeper notification could be delayed, we will try to
-   * get the latest data.
-   * @param zkw
-   * @param replicaId
-   * @param timeout maximum time to wait, in millis
-   * @return server name for server hosting meta region formatted as per
-   * {@link ServerName}, or null if none available
-   * @throws InterruptedException
-   * @throws NotAllMetaRegionsOnlineException
-   */
-  public ServerName waitMetaRegionLocation(ZooKeeperWatcher zkw, int 
replicaId, long timeout)
-  throws InterruptedException, NotAllMetaRegionsOnlineException {
-    try {
-      if (ZKUtil.checkExists(zkw, zkw.znodePaths.baseZNode) == -1) {
-        String errorMsg = "Check the value configured in 
'zookeeper.znode.parent'. "
-            + "There could be a mismatch with the one configured in the 
master.";
-        LOG.error(errorMsg);
-        throw new IllegalArgumentException(errorMsg);
-      }
-    } catch (KeeperException e) {
-      throw new IllegalStateException("KeeperException while trying to check 
baseZNode:", e);
-    }
-    ServerName sn = blockUntilAvailable(zkw, replicaId, timeout);
-
-    if (sn == null) {
-      throw new NotAllMetaRegionsOnlineException("Timed out; " + timeout + 
"ms");
-    }
-
-    return sn;
-  }
-
-  /**
-   * Waits indefinitely for availability of <code>hbase:meta</code>.  Used 
during
-   * cluster startup.  Does not verify meta, just that something has been
-   * set up in zk.
-   * @see 
#waitMetaRegionLocation(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher, 
long)
-   * @throws InterruptedException if interrupted while waiting
-   */
-  public void waitMetaRegionLocation(ZooKeeperWatcher zkw) throws 
InterruptedException {
-    long startTime = System.currentTimeMillis();
-    while (!stopped) {
-      try {
-        if (waitMetaRegionLocation(zkw, 100) != null) break;
-        long sleepTime = System.currentTimeMillis() - startTime;
-        // +1 in case sleepTime=0
-        if ((sleepTime + 1) % 10000 == 0) {
-          LOG.warn("Have been waiting for meta to be assigned for " + 
sleepTime + "ms");
-        }
-      } catch (NotAllMetaRegionsOnlineException e) {
-        if (LOG.isTraceEnabled()) {
-          LOG.trace("hbase:meta still not available, sleeping and retrying." +
-            " Reason: " + e.getMessage());
-        }
-      }
-    }
-  }
-
-  /**
-   * Verify <code>hbase:meta</code> is deployed and accessible.
-   * @param hConnection
-   * @param zkw
-   * @param timeout How long to wait on zk for meta address (passed through to
-   * the internal call to {@link #getMetaServerConnection}.
-   * @return True if the <code>hbase:meta</code> location is healthy.
-   * @throws java.io.IOException
-   * @throws InterruptedException
-   */
-  public boolean verifyMetaRegionLocation(ClusterConnection hConnection,
-      ZooKeeperWatcher zkw, final long timeout)
-  throws InterruptedException, IOException {
-    return verifyMetaRegionLocation(hConnection, zkw, timeout, 
RegionInfo.DEFAULT_REPLICA_ID);
-  }
-
-  /**
-   * Verify <code>hbase:meta</code> is deployed and accessible.
-   * @param connection
-   * @param zkw
-   * @param timeout How long to wait on zk for meta address (passed through to
-   * @param replicaId
-   * @return True if the <code>hbase:meta</code> location is healthy.
-   * @throws InterruptedException
-   * @throws IOException
-   */
-  public boolean verifyMetaRegionLocation(ClusterConnection connection,
-      ZooKeeperWatcher zkw, final long timeout, int replicaId)
-  throws InterruptedException, IOException {
-    AdminProtos.AdminService.BlockingInterface service = null;
-    try {
-      service = getMetaServerConnection(connection, zkw, timeout, replicaId);
-    } catch (NotAllMetaRegionsOnlineException e) {
-      // Pass
-    } catch (ServerNotRunningYetException e) {
-      // Pass -- remote server is not up so can't be carrying root
-    } catch (UnknownHostException e) {
-      // Pass -- server name doesn't resolve so it can't be assigned anything.
-    } catch (RegionServerStoppedException e) {
-      // Pass -- server name sends us to a server that is dying or already 
dead.
-    }
-    return (service != null) && verifyRegionLocation(connection, service,
-            getMetaRegionLocation(zkw, replicaId), 
RegionReplicaUtil.getRegionInfoForReplica(
-                RegionInfoBuilder.FIRST_META_REGIONINFO, 
replicaId).getRegionName());
-  }
-
-  /**
-   * Verify we can connect to <code>hostingServer</code> and that its carrying
-   * <code>regionName</code>.
-   * @param hostingServer Interface to the server hosting 
<code>regionName</code>
-   * @param address The servername that goes with the <code>metaServer</code>
-   * Interface.  Used logging.
-   * @param regionName The regionname we are interested in.
-   * @return True if we were able to verify the region located at other side of
-   * the Interface.
-   * @throws IOException
-   */
-  // TODO: We should be able to get the ServerName from the AdminProtocol
-  // rather than have to pass it in.  Its made awkward by the fact that the
-  // HRI is likely a proxy against remote server so the getServerName needs
-  // to be fixed to go to a local method or to a cache before we can do this.
-  private boolean verifyRegionLocation(final ClusterConnection connection,
-      AdminService.BlockingInterface hostingServer, final ServerName address,
-      final byte [] regionName)
-  throws IOException {
-    if (hostingServer == null) {
-      LOG.info("Passed hostingServer is null");
-      return false;
-    }
-    Throwable t;
-    HBaseRpcController controller = 
connection.getRpcControllerFactory().newController();
-    try {
-      // Try and get regioninfo from the hosting server.
-      return ProtobufUtil.getRegionInfo(controller, hostingServer, regionName) 
!= null;
-    } catch (ConnectException e) {
-      t = e;
-    } catch (RetriesExhaustedException e) {
-      t = e;
-    } catch (RemoteException e) {
-      IOException ioe = e.unwrapRemoteException();
-      t = ioe;
-    } catch (IOException e) {
-      Throwable cause = e.getCause();
-      if (cause != null && cause instanceof EOFException) {
-        t = cause;
-      } else if (cause != null && cause.getMessage() != null
-          && cause.getMessage().contains("Connection reset")) {
-        t = cause;
-      } else {
-        t = e;
-      }
-    }
-    LOG.info("Failed verification of " + Bytes.toStringBinary(regionName) +
-      " at address=" + address + ", exception=" + t.getMessage());
-    return false;
-  }
-
-  /**
-   * Gets a connection to the server hosting meta, as reported by ZooKeeper,
-   * waiting up to the specified timeout for availability.
-   * <p>WARNING: Does not retry.  Use an {@link 
org.apache.hadoop.hbase.client.HTable} instead.
-   * @param connection
-   * @param zkw
-   * @param timeout How long to wait on meta location
-   * @param replicaId
-   * @return connection to server hosting meta
-   * @throws InterruptedException
-   * @throws NotAllMetaRegionsOnlineException if timed out waiting
-   * @throws IOException
-   */
-  private AdminService.BlockingInterface 
getMetaServerConnection(ClusterConnection connection,
-      ZooKeeperWatcher zkw, long timeout, int replicaId)
-  throws InterruptedException, NotAllMetaRegionsOnlineException, IOException {
-    return getCachedConnection(connection, waitMetaRegionLocation(zkw, 
replicaId, timeout));
-  }
-
-  /**
-   * @param sn ServerName to get a connection against.
-   * @return The AdminProtocol we got when we connected to <code>sn</code>
-   * May have come from cache, may not be good, may have been setup by this
-   * invocation, or may be null.
-   * @throws IOException
-   */
-  private static AdminService.BlockingInterface 
getCachedConnection(ClusterConnection connection,
-    ServerName sn)
-  throws IOException {
-    if (sn == null) {
-      return null;
-    }
-    AdminService.BlockingInterface service = null;
-    try {
-      service = connection.getAdmin(sn);
-    } catch (RetriesExhaustedException e) {
-      if (e.getCause() != null && e.getCause() instanceof ConnectException) {
-        // Catch this; presume it means the cached connection has gone bad.
-      } else {
-        throw e;
-      }
-    } catch (SocketTimeoutException e) {
-      LOG.debug("Timed out connecting to " + sn);
-    } catch (NoRouteToHostException e) {
-      LOG.debug("Connecting to " + sn, e);
-    } catch (SocketException e) {
-      LOG.debug("Exception connecting to " + sn);
-    } catch (UnknownHostException e) {
-      LOG.debug("Unknown host exception connecting to  " + sn);
-    } catch (FailedServerException e) {
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Server " + sn + " is in failed server list.");
-      }
-    } catch (IOException ioe) {
-      Throwable cause = ioe.getCause();
-      if (ioe instanceof ConnectException) {
-        // Catch. Connect refused.
-      } else if (cause != null && cause instanceof EOFException) {
-        // Catch. Other end disconnected us.
-      } else if (cause != null && cause.getMessage() != null &&
-        cause.getMessage().toLowerCase(Locale.ROOT).contains("connection 
reset")) {
-        // Catch. Connection reset.
-      } else {
-        throw ioe;
-      }
-
-    }
-    return service;
-  }
-
-  /**
-   * Sets the location of <code>hbase:meta</code> in ZooKeeper to the
-   * specified server address.
-   * @param zookeeper zookeeper reference
-   * @param serverName The server hosting <code>hbase:meta</code>
-   * @param state The region transition state
-   * @throws KeeperException unexpected zookeeper exception
-   */
-  public static void setMetaLocation(ZooKeeperWatcher zookeeper,
-      ServerName serverName, RegionState.State state) throws KeeperException {
-    setMetaLocation(zookeeper, serverName, RegionInfo.DEFAULT_REPLICA_ID, 
state);
-  }
-
-  /**
-   * Sets the location of <code>hbase:meta</code> in ZooKeeper to the
-   * specified server address.
-   * @param zookeeper
-   * @param serverName
-   * @param replicaId
-   * @param state
-   * @throws KeeperException
-   */
-  public static void setMetaLocation(ZooKeeperWatcher zookeeper,
-      ServerName serverName, int replicaId, RegionState.State state) throws 
KeeperException {
-    if (serverName == null) {
-      LOG.warn("Tried to set null ServerName in hbase:meta; skipping -- 
ServerName required");
-      return;
-    }
-    LOG.info("Setting hbase:meta (replicaId=" + replicaId + ") location in 
ZooKeeper as " +
-      serverName);
-    // Make the MetaRegionServer pb and then get its bytes and save this as
-    // the znode content.
-    MetaRegionServer pbrsr = MetaRegionServer.newBuilder()
-      .setServer(ProtobufUtil.toServerName(serverName))
-      .setRpcVersion(HConstants.RPC_CURRENT_VERSION)
-      .setState(state.convert()).build();
-    byte[] data = ProtobufUtil.prependPBMagic(pbrsr.toByteArray());
-    try {
-      ZKUtil.setData(zookeeper,
-          zookeeper.znodePaths.getZNodeForReplica(replicaId), data);
-    } catch(KeeperException.NoNodeException nne) {
-      if (replicaId == RegionInfo.DEFAULT_REPLICA_ID) {
-        LOG.debug("META region location doesn't exist, create it");
-      } else {
-        LOG.debug("META region location doesn't exist for replicaId=" + 
replicaId +
-            ", create it");
-      }
-      ZKUtil.createAndWatch(zookeeper, 
zookeeper.znodePaths.getZNodeForReplica(replicaId), data);
-    }
-  }
-
-  /**
-   * Load the meta region state from the meta server ZNode.
-   */
-  public static RegionState getMetaRegionState(ZooKeeperWatcher zkw) throws 
KeeperException {
-    return getMetaRegionState(zkw, RegionInfo.DEFAULT_REPLICA_ID);
-  }
-
-  /**
-   * Load the meta region state from the meta server ZNode.
-   * @param zkw
-   * @param replicaId
-   * @return regionstate
-   * @throws KeeperException
-   */
-  public static RegionState getMetaRegionState(ZooKeeperWatcher zkw, int 
replicaId)
-      throws KeeperException {
-    RegionState.State state = RegionState.State.OPEN;
-    ServerName serverName = null;
-    try {
-      byte[] data = ZKUtil.getData(zkw, 
zkw.znodePaths.getZNodeForReplica(replicaId));
-      if (data != null && data.length > 0 && 
ProtobufUtil.isPBMagicPrefix(data)) {
-        try {
-          int prefixLen = ProtobufUtil.lengthOfPBMagic();
-          ZooKeeperProtos.MetaRegionServer rl =
-            ZooKeeperProtos.MetaRegionServer.PARSER.parseFrom
-              (data, prefixLen, data.length - prefixLen);
-          if (rl.hasState()) {
-            state = RegionState.State.convert(rl.getState());
-          }
-          HBaseProtos.ServerName sn = rl.getServer();
-          serverName = ServerName.valueOf(
-            sn.getHostName(), sn.getPort(), sn.getStartCode());
-        } catch (InvalidProtocolBufferException e) {
-          throw new DeserializationException("Unable to parse meta region 
location");
-        }
-      } else {
-        // old style of meta region location?
-        serverName = ProtobufUtil.parseServerNameFrom(data);
-      }
-    } catch (DeserializationException e) {
-      throw ZKUtil.convert(e);
-    } catch (InterruptedException e) {
-      Thread.currentThread().interrupt();
-    }
-    if (serverName == null) {
-      state = RegionState.State.OFFLINE;
-    }
-    return new RegionState(
-        
RegionReplicaUtil.getRegionInfoForReplica(RegionInfoBuilder.FIRST_META_REGIONINFO,
 replicaId),
-      state, serverName);
-  }
-
-  /**
-   * Deletes the location of <code>hbase:meta</code> in ZooKeeper.
-   * @param zookeeper zookeeper reference
-   * @throws KeeperException unexpected zookeeper exception
-   */
-  public void deleteMetaLocation(ZooKeeperWatcher zookeeper)
-  throws KeeperException {
-    deleteMetaLocation(zookeeper, RegionInfo.DEFAULT_REPLICA_ID);
-  }
-
-  public void deleteMetaLocation(ZooKeeperWatcher zookeeper, int replicaId)
-  throws KeeperException {
-    if (replicaId == RegionInfo.DEFAULT_REPLICA_ID) {
-      LOG.info("Deleting hbase:meta region location in ZooKeeper");
-    } else {
-      LOG.info("Deleting hbase:meta for " + replicaId + " region location in 
ZooKeeper");
-    }
-    try {
-      // Just delete the node.  Don't need any watches.
-      ZKUtil.deleteNode(zookeeper, 
zookeeper.znodePaths.getZNodeForReplica(replicaId));
-    } catch(KeeperException.NoNodeException nne) {
-      // Has already been deleted
-    }
-  }
-  /**
-   * Wait until the primary meta region is available. Get the secondary
-   * locations as well but don't block for those.
-   * @param zkw
-   * @param timeout
-   * @param conf
-   * @return ServerName or null if we timed out.
-   * @throws InterruptedException
-   */
-  public List<ServerName> blockUntilAvailable(final ZooKeeperWatcher zkw,
-      final long timeout, Configuration conf)
-          throws InterruptedException {
-    int numReplicasConfigured = 1;
-
-    List<ServerName> servers = new ArrayList<>();
-    // Make the blocking call first so that we do the wait to know
-    // the znodes are all in place or timeout.
-    ServerName server = blockUntilAvailable(zkw, timeout);
-    if (server == null) return null;
-    servers.add(server);
-
-    try {
-      List<String> metaReplicaNodes = zkw.getMetaReplicaNodes();
-      numReplicasConfigured = metaReplicaNodes.size();
-    } catch (KeeperException e) {
-      LOG.warn("Got ZK exception " + e);
-    }
-    for (int replicaId = 1; replicaId < numReplicasConfigured; replicaId++) {
-      // return all replica locations for the meta
-      servers.add(getMetaRegionLocation(zkw, replicaId));
-    }
-    return servers;
-  }
-
-  /**
-   * Wait until the meta region is available and is not in transition.
-   * @param zkw zookeeper connection to use
-   * @param timeout maximum time to wait, in millis
-   * @return ServerName or null if we timed out.
-   * @throws InterruptedException
-   */
-  public ServerName blockUntilAvailable(final ZooKeeperWatcher zkw,
-      final long timeout)
-  throws InterruptedException {
-    return blockUntilAvailable(zkw, RegionInfo.DEFAULT_REPLICA_ID, timeout);
-  }
-
-  /**
-   * Wait until the meta region is available and is not in transition.
-   * @param zkw
-   * @param replicaId
-   * @param timeout
-   * @return ServerName or null if we timed out.
-   * @throws InterruptedException
-   */
-  public ServerName blockUntilAvailable(final ZooKeeperWatcher zkw, int 
replicaId,
-      final long timeout)
-  throws InterruptedException {
-    if (timeout < 0) throw new IllegalArgumentException();
-    if (zkw == null) throw new IllegalArgumentException();
-    long startTime = System.currentTimeMillis();
-    ServerName sn = null;
-    while (true) {
-      sn = getMetaRegionLocation(zkw, replicaId);
-      if (sn != null || (System.currentTimeMillis() - startTime)
-          > timeout - HConstants.SOCKET_RETRY_WAIT_MS) {
-        break;
-      }
-      Thread.sleep(HConstants.SOCKET_RETRY_WAIT_MS);
-    }
-    return sn;
-  }
-
-  /**
-   * Stop working.
-   * Interrupts any ongoing waits.
-   */
-  public void stop() {
-    if (!stopped) {
-      LOG.debug("Stopping MetaTableLocator");
-      stopped = true;
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MetricsZooKeeper.java
----------------------------------------------------------------------
diff --git 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MetricsZooKeeper.java
 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MetricsZooKeeper.java
deleted file mode 100644
index 5632031..0000000
--- 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MetricsZooKeeper.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.zookeeper;
-
-import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
-import org.apache.yetus.audience.InterfaceAudience;
-
-import 
org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting;
-import org.apache.hadoop.hbase.regionserver.wal.MetricsWALSource;
-import org.apache.hadoop.hbase.regionserver.wal.MetricsWALSourceImpl;
-
-/**
- * Class used to push numbers about ZooKeeper into the metrics subsystem. This 
will take a
- * single function call and turn it into multiple manipulations of the hadoop 
metrics system.
- */
-@InterfaceAudience.Private
-public class MetricsZooKeeper implements ZooKeeperMetricsListener {
-  private final MetricsZooKeeperSource source;
-
-  public MetricsZooKeeper() {
-    
this(CompatibilitySingletonFactory.getInstance(MetricsZooKeeperSource.class));
-  }
-
-  @VisibleForTesting
-  public MetricsZooKeeper(MetricsZooKeeperSource s) {
-    this.source = s;
-  }
-
-  @Override
-  public void registerAuthFailedException() {
-    source.incrementAuthFailedCount();
-  }
-
-  @Override
-  public void registerConnectionLossException() {
-    source.incrementConnectionLossCount();
-  }
-
-  @Override
-  public void registerDataInconsistencyException() {
-    source.incrementDataInconsistencyCount();
-  }
-
-  @Override
-  public void registerInvalidACLException() {
-    source.incrementInvalidACLCount();
-  }
-
-  @Override
-  public void registerNoAuthException() {
-    source.incrementNoAuthCount();
-  }
-
-  @Override
-  public void registerOperationTimeoutException() {
-    source.incrementOperationTimeoutCount();
-  }
-
-  @Override
-  public void registerRuntimeInconsistencyException() {
-    source.incrementRuntimeInconsistencyCount();
-  }
-
-  @Override
-  public void registerSessionExpiredException() {
-    source.incrementSessionExpiredCount();
-  }
-
-  @Override
-  public void registerSystemErrorException() {
-    source.incrementSystemErrorCount();
-  }
-
-  @Override
-  public void registerFailedZKCall() {
-    source.incrementTotalFailedZKCalls();
-  }
-
-  @Override
-  public void registerReadOperationLatency(long latency) {
-    source.recordReadOperationLatency(latency);
-  }
-
-  @Override
-  public void registerWriteOperationLatency(long latency) {
-    source.recordWriteOperationLatency(latency);
-  }
-
-  @Override
-  public void registerSyncOperationLatency(long latency) {
-    source.recordSyncOperationLatency(latency);
-  }
-}

http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/PendingWatcher.java
----------------------------------------------------------------------
diff --git 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/PendingWatcher.java
 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/PendingWatcher.java
deleted file mode 100644
index da7d176..0000000
--- 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/PendingWatcher.java
+++ /dev/null
@@ -1,53 +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 org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
-
-/**
- * Placeholder of a watcher which might be triggered before the instance is 
not yet created.
- * <p>
- * {@code ZooKeeper} starts its event thread within its constructor (and that 
is an anti-pattern),
- * and the watcher passed to the constructor might be called back by the event 
thread
- * before you get the instance of {@code ZooKeeper} from the constructor.
- * If your watcher calls methods of {@code ZooKeeper},
- * pass this placeholder to the constructor of the {@code ZooKeeper},
- * create your watcher using the instance of {@code ZooKeeper},
- * and then call the method {@code PendingWatcher.prepare}.
- */
-class PendingWatcher implements Watcher {
-  private final InstancePending<Watcher> pending = new InstancePending<>();
-
-  @Override
-  public void process(WatchedEvent event) {
-    pending.get().process(event);
-  }
-
-  /**
-   * Associates the substantial watcher of processing events.
-   * This method should be called once, and {@code watcher} should be non-null.
-   * This method is expected to call as soon as possible
-   * because the event processing, being invoked by the ZooKeeper event thread,
-   * is uninterruptibly blocked until this method is called.
-   */
-  void prepare(Watcher watcher) {
-    pending.prepare(watcher);
-  }
-}

Reply via email to