You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2014/05/23 01:16:51 UTC

[4/4] git commit: HBASE-11108 Split ZKTable into interface and implementation (Mikhail Antononv)

HBASE-11108 Split ZKTable into interface and implementation (Mikhail Antononv)


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

Branch: refs/heads/master
Commit: ea0731d60f09859a3d35db011822e676bc9e2dda
Parents: c5d5a5d
Author: Michael Stack <st...@duboce.net>
Authored: Thu May 22 16:15:51 2014 -0700
Committer: Michael Stack <st...@duboce.net>
Committed: Thu May 22 16:15:51 2014 -0700

----------------------------------------------------------------------
 .../apache/hadoop/hbase/ConsensusProvider.java  |  58 ---
 .../java/org/apache/hadoop/hbase/Server.java    |   4 +-
 .../hadoop/hbase/client/ZooKeeperRegistry.java  |   6 +-
 .../apache/hadoop/hbase/zookeeper/ZKTable.java  | 406 -------------------
 .../hadoop/hbase/zookeeper/ZKTableReadOnly.java | 167 --------
 .../org/apache/hadoop/hbase/HConstants.java     |   3 +-
 .../src/main/resources/hbase-default.xml        |   6 +-
 .../hadoop/hbase/ConsensusProviderFactory.java  |  43 --
 .../apache/hadoop/hbase/LocalHBaseCluster.java  |  13 +-
 .../hbase/consensus/BaseConsensusProvider.java  |  49 ---
 .../hbase/consensus/ZkConsensusProvider.java    |  42 --
 .../hadoop/hbase/master/AssignmentManager.java  | 109 +++--
 .../org/apache/hadoop/hbase/master/HMaster.java |  26 +-
 .../hadoop/hbase/master/HMasterCommandLine.java |  13 +-
 .../master/handler/ClosedRegionHandler.java     |   5 +-
 .../master/handler/CreateTableHandler.java      |  22 +-
 .../master/handler/DeleteTableHandler.java      |  10 +-
 .../master/handler/DisableTableHandler.java     |  22 +-
 .../master/handler/EnableTableHandler.java      |  29 +-
 .../master/handler/OpenedRegionHandler.java     |   4 +-
 .../master/handler/ServerShutdownHandler.java   |  12 +-
 .../hbase/master/handler/TableEventHandler.java |  11 +-
 .../master/handler/TruncateTableHandler.java    |  17 +-
 .../hbase/master/snapshot/SnapshotManager.java  |  11 +-
 .../hbase/regionserver/HRegionServer.java       |  26 +-
 .../regionserver/HRegionServerCommandLine.java  |   6 +-
 .../hbase/regionserver/SplitLogWorker.java      |   5 +-
 .../hbase/regionserver/wal/HLogSplitter.java    |  28 +-
 .../regionserver/ReplicationSyncUp.java         |   6 +-
 .../org/apache/hadoop/hbase/util/HBaseFsck.java |   4 +-
 .../hadoop/hbase/util/JVMClusterUtil.java       |  10 +-
 .../apache/hadoop/hbase/MiniHBaseCluster.java   |   2 +-
 .../hadoop/hbase/MockRegionServerServices.java  |   2 +-
 .../apache/hadoop/hbase/TestDrainingServer.java |  15 +-
 .../hadoop/hbase/TestLocalHBaseCluster.java     |   4 +-
 .../apache/hadoop/hbase/client/TestAdmin.java   |  19 +-
 .../client/TestClientScannerRPCTimeout.java     |   4 +-
 .../hadoop/hbase/master/MockRegionServer.java   |   4 +-
 .../hbase/master/TestActiveMasterManager.java   |   4 +-
 .../hbase/master/TestAssignmentManager.java     | 115 ++++--
 .../master/TestAssignmentManagerOnCluster.java  |   9 +-
 .../hadoop/hbase/master/TestCatalogJanitor.java |   6 +-
 .../hbase/master/TestClockSkewDetection.java    |   4 +-
 .../hbase/master/TestHMasterRPCException.java   |   6 +-
 .../apache/hadoop/hbase/master/TestMaster.java  |   4 +-
 .../hadoop/hbase/master/TestMasterFailover.java |  18 +-
 .../hadoop/hbase/master/TestMasterMetrics.java  |   4 +-
 .../hbase/master/TestMasterNoCluster.java       |  13 +-
 .../TestMasterRestartAfterDisablingTable.java   |  10 +-
 .../hbase/master/TestOpenedRegionHandler.java   |   4 +-
 .../hbase/master/cleaner/TestHFileCleaner.java  |   4 +-
 .../master/cleaner/TestHFileLinkCleaner.java    |   4 +-
 .../hbase/master/cleaner/TestLogsCleaner.java   |   4 +-
 .../hbase/regionserver/OOMERegionServer.java    |   4 +-
 .../hbase/regionserver/TestClusterId.java       |   6 +-
 .../regionserver/TestHeapMemoryManager.java     |   4 +-
 .../hbase/regionserver/TestPriorityRpc.java     |   6 +-
 .../TestRSKilledWhenInitializing.java           |   4 +-
 .../TestRegionMergeTransaction.java             |  10 +-
 .../TestSplitTransactionOnCluster.java          |   4 +-
 .../hbase/regionserver/wal/TestHLogMethods.java |   2 +-
 .../hbase/regionserver/wal/TestHLogSplit.java   |   8 +-
 .../hbase/regionserver/wal/TestWALReplay.java   |   4 +-
 .../replication/TestReplicationStateZKImpl.java |   4 +-
 .../TestReplicationTrackerZKImpl.java           |   4 +-
 .../TestReplicationSourceManager.java           |   4 +-
 .../security/token/TestTokenAuthentication.java |   4 +-
 .../apache/hadoop/hbase/util/MockServer.java    |   4 +-
 .../hadoop/hbase/zookeeper/TestZKTable.java     | 110 -----
 69 files changed, 431 insertions(+), 1183 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-client/src/main/java/org/apache/hadoop/hbase/ConsensusProvider.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ConsensusProvider.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ConsensusProvider.java
deleted file mode 100644
index 09870d2..0000000
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ConsensusProvider.java
+++ /dev/null
@@ -1,58 +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.classification.InterfaceAudience;
-
-/**
- * Implementations of this interface will keep and return to clients 
- * implementations of classes providing API to execute
- * coordinated operations. This interface is client-sise, so it does NOT
- * include method to retrieve the particular consensus providers.
- *
- * For each coarse-grained area of operations there will be a separate
- * interface with implementation, providing API for relevant operations
- * requiring coordination.
- *
- * Property hbase.consensus.provider.class in hbase-site.xml controls
- * which provider to use.
- */
-@InterfaceAudience.Private
-public interface ConsensusProvider {
-
-  /**
-   * Initialize consensus service.
-   * @param server server instance to run within.
-   */
-  void initialize(Server server);
-
-  /**
-   * Starts consensus service.
-   */
-  void start();
-
-  /**
-   * Stop consensus provider.
-   */
-  void stop();
-
-  /**
-   * @return instance of Server consensus runs within
-   */
-  Server getServer();
-}

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-client/src/main/java/org/apache/hadoop/hbase/Server.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/Server.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/Server.java
index 9966962..c39d6ad 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/Server.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/Server.java
@@ -50,7 +50,7 @@ public interface Server extends Abortable, Stoppable {
   ServerName getServerName();
 
   /**
-   * Get ConsensusProvider instance for this server.
+   * Get CoordinatedStateManager instance for this server.
    */
-  ConsensusProvider getConsensusProvider();
+  CoordinatedStateManager getCoordinatedStateManager();
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZooKeeperRegistry.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZooKeeperRegistry.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZooKeeperRegistry.java
index d77bb11..529b7f6 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZooKeeperRegistry.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ZooKeeperRegistry.java
@@ -28,7 +28,7 @@ import org.apache.hadoop.hbase.HRegionLocation;
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.zookeeper.MetaRegionTracker;
 import org.apache.hadoop.hbase.zookeeper.ZKClusterId;
-import org.apache.hadoop.hbase.zookeeper.ZKTableReadOnly;
+import org.apache.hadoop.hbase.zookeeper.ZKTableStateClientSideReader;
 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
 import org.apache.zookeeper.KeeperException;
 
@@ -101,9 +101,9 @@ class ZooKeeperRegistry implements Registry {
     ZooKeeperKeepAliveConnection zkw = hci.getKeepAliveZooKeeperWatcher();
     try {
       if (enabled) {
-        return ZKTableReadOnly.isEnabledTable(zkw, tableName);
+        return ZKTableStateClientSideReader.isEnabledTable(zkw, tableName);
       }
-      return ZKTableReadOnly.isDisabledTable(zkw, tableName);
+      return ZKTableStateClientSideReader.isDisabledTable(zkw, tableName);
     } catch (KeeperException e) {
       throw new IOException("Enable/Disable failed", e);
     } catch (InterruptedException e) {

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKTable.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKTable.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKTable.java
deleted file mode 100644
index 36e6b89..0000000
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKTable.java
+++ /dev/null
@@ -1,406 +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.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.hbase.TableName;
-import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
-import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos;
-import org.apache.zookeeper.KeeperException;
-
-import java.io.InterruptedIOException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Helper class for table state tracking for use by AssignmentManager.
- * Reads, caches and sets state up in zookeeper.  If multiple read/write
- * clients, will make for confusion.  Read-only clients other than
- * AssignmentManager interested in learning table state can use the
- * read-only utility methods in {@link ZKTableReadOnly}.
- *
- * <p>To save on trips to the zookeeper ensemble, internally we cache table
- * state.
- */
-@InterfaceAudience.Private
-public class ZKTable {
-  // A znode will exist under the table directory if it is in any of the
-  // following states: {@link TableState#ENABLING} , {@link TableState#DISABLING},
-  // or {@link TableState#DISABLED}.  If {@link TableState#ENABLED}, there will
-  // be no entry for a table in zk.  Thats how it currently works.
-
-  private static final Log LOG = LogFactory.getLog(ZKTable.class);
-  private final ZooKeeperWatcher watcher;
-
-  /**
-   * Cache of what we found in zookeeper so we don't have to go to zk ensemble
-   * for every query.  Synchronize access rather than use concurrent Map because
-   * synchronization needs to span query of zk.
-   */
-  private final Map<TableName, ZooKeeperProtos.Table.State> cache =
-    new HashMap<TableName, ZooKeeperProtos.Table.State>();
-
-  // TODO: Make it so always a table znode. Put table schema here as well as table state.
-  // Have watcher on table znode so all are notified of state or schema change.
-
-  public ZKTable(final ZooKeeperWatcher zkw) throws KeeperException, InterruptedException {
-    super();
-    this.watcher = zkw;
-    populateTableStates();
-  }
-
-  /**
-   * Gets a list of all the tables set as disabled in zookeeper.
-   * @throws KeeperException
-   */
-  private void populateTableStates()
-      throws KeeperException, InterruptedException {
-    synchronized (this.cache) {
-      List<String> children = ZKUtil.listChildrenNoWatch(this.watcher, this.watcher.tableZNode);
-      if (children == null) return;
-      for (String child: children) {
-        TableName tableName = TableName.valueOf(child);
-        ZooKeeperProtos.Table.State state = ZKTableReadOnly.getTableState(this.watcher, tableName);
-        if (state != null) this.cache.put(tableName, state);
-      }
-    }
-  }
-
-  /**
-   * Sets the specified table as DISABLED in zookeeper.  Fails silently if the
-   * table is already disabled in zookeeper.  Sets no watches.
-   * @param tableName
-   * @throws KeeperException unexpected zookeeper exception
-   */
-  public void setDisabledTable(TableName tableName)
-  throws KeeperException {
-    synchronized (this.cache) {
-      if (!isDisablingOrDisabledTable(tableName)) {
-        LOG.warn("Moving table " + tableName + " state to disabled but was " +
-          "not first in disabling state: " + this.cache.get(tableName));
-      }
-      setTableState(tableName, ZooKeeperProtos.Table.State.DISABLED);
-    }
-  }
-
-  /**
-   * Sets the specified table as DISABLING in zookeeper.  Fails silently if the
-   * table is already disabled in zookeeper.  Sets no watches.
-   * @param tableName
-   * @throws KeeperException unexpected zookeeper exception
-   */
-  public void setDisablingTable(final TableName tableName)
-  throws KeeperException {
-    synchronized (this.cache) {
-      if (!isEnabledOrDisablingTable(tableName)) {
-        LOG.warn("Moving table " + tableName + " state to disabling but was " +
-          "not first in enabled state: " + this.cache.get(tableName));
-      }
-      setTableState(tableName, ZooKeeperProtos.Table.State.DISABLING);
-    }
-  }
-
-  /**
-   * Sets the specified table as ENABLING in zookeeper.  Fails silently if the
-   * table is already disabled in zookeeper.  Sets no watches.
-   * @param tableName
-   * @throws KeeperException unexpected zookeeper exception
-   */
-  public void setEnablingTable(final TableName tableName)
-  throws KeeperException {
-    synchronized (this.cache) {
-      if (!isDisabledOrEnablingTable(tableName)) {
-        LOG.warn("Moving table " + tableName + " state to enabling but was " +
-          "not first in disabled state: " + this.cache.get(tableName));
-      }
-      setTableState(tableName, ZooKeeperProtos.Table.State.ENABLING);
-    }
-  }
-
-  /**
-   * Sets the specified table as ENABLING in zookeeper atomically
-   * If the table is already in ENABLING state, no operation is performed
-   * @param tableName
-   * @return if the operation succeeds or not
-   * @throws KeeperException unexpected zookeeper exception
-   */
-  public boolean checkAndSetEnablingTable(final TableName tableName)
-    throws KeeperException {
-    synchronized (this.cache) {
-      if (isEnablingOrEnabledTable(tableName)) {
-        return false;
-      }
-      setTableState(tableName, ZooKeeperProtos.Table.State.ENABLING);
-      return true;
-    }
-  }
-
-  /**
-   * Sets the specified table as ENABLING in zookeeper atomically
-   * If the table isn't in DISABLED state, no operation is performed
-   * @param tableName
-   * @return if the operation succeeds or not
-   * @throws KeeperException unexpected zookeeper exception
-   */
-  public boolean checkDisabledAndSetEnablingTable(final TableName tableName)
-    throws KeeperException {
-    synchronized (this.cache) {
-      if (!isDisabledTable(tableName)) {
-        return false;
-      }
-      setTableState(tableName, ZooKeeperProtos.Table.State.ENABLING);
-      return true;
-    }
-  }
-
-  /**
-   * Sets the specified table as DISABLING in zookeeper atomically
-   * If the table isn't in ENABLED state, no operation is performed
-   * @param tableName
-   * @return if the operation succeeds or not
-   * @throws KeeperException unexpected zookeeper exception
-   */
-  public boolean checkEnabledAndSetDisablingTable(final TableName tableName)
-    throws KeeperException {
-    synchronized (this.cache) {
-      if (this.cache.get(tableName) != null && !isEnabledTable(tableName)) {
-        return false;
-      }
-      setTableState(tableName, ZooKeeperProtos.Table.State.DISABLING);
-      return true;
-    }
-  }
-
-  private void setTableState(final TableName tableName, final ZooKeeperProtos.Table.State state)
-  throws KeeperException {
-    String znode = ZKUtil.joinZNode(this.watcher.tableZNode, tableName.getNameAsString());
-    if (ZKUtil.checkExists(this.watcher, znode) == -1) {
-      ZKUtil.createAndFailSilent(this.watcher, znode);
-    }
-    synchronized (this.cache) {
-      ZooKeeperProtos.Table.Builder builder = ZooKeeperProtos.Table.newBuilder();
-      builder.setState(state);
-      byte [] data = ProtobufUtil.prependPBMagic(builder.build().toByteArray());
-      ZKUtil.setData(this.watcher, znode, data);
-      this.cache.put(tableName, state);
-    }
-  }
-
-  public boolean isDisabledTable(final TableName tableName) {
-    return isTableState(tableName, ZooKeeperProtos.Table.State.DISABLED);
-  }
-
-  public boolean isDisablingTable(final TableName tableName) {
-    return isTableState(tableName, ZooKeeperProtos.Table.State.DISABLING);
-  }
-
-  public boolean isEnablingTable(final TableName tableName) {
-    return isTableState(tableName, ZooKeeperProtos.Table.State.ENABLING);
-  }
-
-  public boolean isEnabledTable(TableName tableName) {
-    return isTableState(tableName, ZooKeeperProtos.Table.State.ENABLED);
-  }
-
-  public boolean isDisablingOrDisabledTable(final TableName tableName) {
-    synchronized (this.cache) {
-      return isDisablingTable(tableName) || isDisabledTable(tableName);
-    }
-  }
-
-  public boolean isEnablingOrEnabledTable(final TableName tableName) {
-    synchronized (this.cache) {
-      return isEnablingTable(tableName) || isEnabledTable(tableName);
-    }
-  }
-
-  public boolean isEnabledOrDisablingTable(final TableName tableName) {
-    synchronized (this.cache) {
-      return isEnabledTable(tableName) || isDisablingTable(tableName);
-    }
-  }
-
-  public boolean isDisabledOrEnablingTable(final TableName tableName) {
-    synchronized (this.cache) {
-      return isDisabledTable(tableName) || isEnablingTable(tableName);
-    }
-  }
-
-  private boolean isTableState(final TableName tableName, final ZooKeeperProtos.Table.State state) {
-    synchronized (this.cache) {
-      ZooKeeperProtos.Table.State currentState = this.cache.get(tableName);
-      return ZKTableReadOnly.isTableState(currentState, state);
-    }
-  }
-
-  /**
-   * Deletes the table in zookeeper.  Fails silently if the
-   * table is not currently disabled in zookeeper.  Sets no watches.
-   * @param tableName
-   * @throws KeeperException unexpected zookeeper exception
-   */
-  public void setDeletedTable(final TableName tableName)
-  throws KeeperException {
-    synchronized (this.cache) {
-      if (this.cache.remove(tableName) == null) {
-        LOG.warn("Moving table " + tableName + " state to deleted but was " +
-          "already deleted");
-      }
-      ZKUtil.deleteNodeFailSilent(this.watcher,
-        ZKUtil.joinZNode(this.watcher.tableZNode, tableName.getNameAsString()));
-    }
-  }
-  
-  /**
-   * Sets the ENABLED state in the cache and creates or force updates a node to
-   * ENABLED state for the specified table
-   * 
-   * @param tableName
-   * @throws KeeperException
-   */
-  public void setEnabledTable(final TableName tableName) throws KeeperException {
-    setTableState(tableName, ZooKeeperProtos.Table.State.ENABLED);
-  }
-
-  /**
-   * check if table is present .
-   * 
-   * @param tableName
-   * @return true if the table is present
-   */
-  public boolean isTablePresent(final TableName tableName) {
-    synchronized (this.cache) {
-      ZooKeeperProtos.Table.State state = this.cache.get(tableName);
-      return !(state == null);
-    }
-  }
-  
-  /**
-   * Gets a list of all the tables set as disabled in zookeeper.
-   * @return Set of disabled tables, empty Set if none
-   */
-  public Set<TableName> getDisabledTables() {
-    Set<TableName> disabledTables = new HashSet<TableName>();
-    synchronized (this.cache) {
-      Set<TableName> tables = this.cache.keySet();
-      for (TableName table: tables) {
-        if (isDisabledTable(table)) disabledTables.add(table);
-      }
-    }
-    return disabledTables;
-  }
-
-  /**
-   * Gets a list of all the tables set as disabled in zookeeper.
-   * @return Set of disabled tables, empty Set if none
-   * @throws KeeperException
-   */
-  public static Set<TableName> getDisabledTables(ZooKeeperWatcher zkw)
-      throws KeeperException, InterruptedIOException {
-    return getAllTables(zkw, ZooKeeperProtos.Table.State.DISABLED);
-  }
-
-  /**
-   * Gets a list of all the tables set as disabling in zookeeper.
-   * @return Set of disabling tables, empty Set if none
-   * @throws KeeperException
-   */
-  public static Set<TableName> getDisablingTables(ZooKeeperWatcher zkw)
-      throws KeeperException, InterruptedIOException {
-    return getAllTables(zkw, ZooKeeperProtos.Table.State.DISABLING);
-  }
-
-  /**
-   * Gets a list of all the tables set as enabling in zookeeper.
-   * @return Set of enabling tables, empty Set if none
-   * @throws KeeperException
-   */
-  public static Set<TableName> getEnablingTables(ZooKeeperWatcher zkw)
-      throws KeeperException, InterruptedIOException {
-    return getAllTables(zkw, ZooKeeperProtos.Table.State.ENABLING);
-  }
-
-  /**
-   * Gets a list of all the tables set as disabled in zookeeper.
-   * @return Set of disabled tables, empty Set if none
-   * @throws KeeperException
-   */
-  public static Set<TableName> getDisabledOrDisablingTables(ZooKeeperWatcher zkw)
-      throws KeeperException, InterruptedIOException {
-    return getAllTables(zkw, ZooKeeperProtos.Table.State.DISABLED,
-      ZooKeeperProtos.Table.State.DISABLING);
-  }
-  
-  /**
-   * If the table is found in ENABLING state the inmemory state is removed. This
-   * helps in cases where CreateTable is to be retried by the client incase of
-   * failures.  If deleteZNode is true - the znode is also deleted
-   * 
-   * @param tableName
-   * @param deleteZNode
-   * @throws KeeperException
-   */
-  public void removeEnablingTable(final TableName tableName, boolean deleteZNode)
-      throws KeeperException {
-    synchronized (this.cache) {
-      if (isEnablingTable(tableName)) {
-        this.cache.remove(tableName);
-        if (deleteZNode) {
-          ZKUtil.deleteNodeFailSilent(this.watcher,
-              ZKUtil.joinZNode(this.watcher.tableZNode, tableName.getNameAsString()));
-        }
-      }
-    }
-  }
-
-
-  /**
-   * Gets a list of all the tables of specified states in zookeeper.
-   * @return Set of tables of specified states, empty Set if none
-   * @throws KeeperException
-   */
-  static Set<TableName> getAllTables(final ZooKeeperWatcher zkw,
-      final ZooKeeperProtos.Table.State... states) throws KeeperException, InterruptedIOException {
-    Set<TableName> allTables = new HashSet<TableName>();
-    List<String> children =
-      ZKUtil.listChildrenNoWatch(zkw, zkw.tableZNode);
-    if(children == null) return allTables;
-    for (String child: children) {
-      TableName tableName = TableName.valueOf(child);
-      ZooKeeperProtos.Table.State state = null;
-      try {
-        state = ZKTableReadOnly.getTableState(zkw, tableName);
-      } catch (InterruptedException e) {
-        throw new InterruptedIOException();
-      }
-      for (ZooKeeperProtos.Table.State expectedState: states) {
-        if (state == expectedState) {
-          allTables.add(tableName);
-          break;
-        }
-      }
-    }
-    return allTables;
-  }
-}

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKTableReadOnly.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKTableReadOnly.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKTableReadOnly.java
deleted file mode 100644
index 236aa7f..0000000
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKTableReadOnly.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/**
- * Copyright The Apache Software Foundation
- *
- * 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 com.google.protobuf.InvalidProtocolBufferException;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.hbase.TableName;
-import org.apache.hadoop.hbase.exceptions.DeserializationException;
-import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
-import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos;
-import org.apache.zookeeper.KeeperException;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Non-instantiable class that provides helper functions for
- * clients other than AssignmentManager for reading the
- * state of a table in ZK.
- *
- * <p>Does not cache state like {@link ZKTable}, actually reads from ZK each call.
- */
-@InterfaceAudience.Private
-public class ZKTableReadOnly {
-
-  private ZKTableReadOnly() {}
-  
-  /**
-   * Go to zookeeper and see if state of table is {@code ZooKeeperProtos.Table.State#DISABLED}.
-   * This method does not use cache.
-   * This method is for clients other than AssignmentManager
-   * @param zkw
-   * @param tableName
-   * @return True if table is enabled.
-   * @throws KeeperException
-   */
-  public static boolean isDisabledTable(final ZooKeeperWatcher zkw,
-      final TableName tableName)
-      throws KeeperException, InterruptedException {
-    ZooKeeperProtos.Table.State state = getTableState(zkw, tableName);
-    return isTableState(ZooKeeperProtos.Table.State.DISABLED, state);
-  }
-
-  /**
-   * Go to zookeeper and see if state of table is {@code ZooKeeperProtos.Table.State#ENABLED}.
-   * This method does not use cache.
-   * This method is for clients other than AssignmentManager
-   * @param zkw
-   * @param tableName
-   * @return True if table is enabled.
-   * @throws KeeperException
-   */
-  public static boolean isEnabledTable(final ZooKeeperWatcher zkw,
-      final TableName tableName)
-      throws KeeperException, InterruptedException {
-    return getTableState(zkw, tableName) == ZooKeeperProtos.Table.State.ENABLED;
-  }
-
-  /**
-   * Go to zookeeper and see if state of table is {@code ZooKeeperProtos.Table.State#DISABLING}
-   * of {@code ZooKeeperProtos.Table.State#DISABLED}.
-   * This method does not use cache.
-   * This method is for clients other than AssignmentManager.
-   * @param zkw
-   * @param tableName
-   * @return True if table is enabled.
-   * @throws KeeperException
-   */
-  public static boolean isDisablingOrDisabledTable(final ZooKeeperWatcher zkw,
-      final TableName tableName)
-      throws KeeperException, InterruptedException {
-    ZooKeeperProtos.Table.State state = getTableState(zkw, tableName);
-    return isTableState(ZooKeeperProtos.Table.State.DISABLING, state) ||
-      isTableState(ZooKeeperProtos.Table.State.DISABLED, state);
-  }
-
-  /**
-   * Gets a list of all the tables set as disabled in zookeeper.
-   * @return Set of disabled tables, empty Set if none
-   * @throws KeeperException
-   */
-  public static Set<TableName> getDisabledTables(ZooKeeperWatcher zkw)
-      throws KeeperException, InterruptedException {
-    Set<TableName> disabledTables = new HashSet<TableName>();
-    List<String> children =
-      ZKUtil.listChildrenNoWatch(zkw, zkw.tableZNode);
-    for (String child: children) {
-      TableName tableName =
-          TableName.valueOf(child);
-      ZooKeeperProtos.Table.State state = getTableState(zkw, tableName);
-      if (state == ZooKeeperProtos.Table.State.DISABLED) disabledTables.add(tableName);
-    }
-    return disabledTables;
-  }
-
-  /**
-   * Gets a list of all the tables set as disabled in zookeeper.
-   * @return Set of disabled tables, empty Set if none
-   * @throws KeeperException
-   */
-  public static Set<TableName> getDisabledOrDisablingTables(ZooKeeperWatcher zkw)
-      throws KeeperException, InterruptedException {
-    Set<TableName> disabledTables = new HashSet<TableName>();
-    List<String> children =
-      ZKUtil.listChildrenNoWatch(zkw, zkw.tableZNode);
-    for (String child: children) {
-      TableName tableName =
-          TableName.valueOf(child);
-      ZooKeeperProtos.Table.State state = getTableState(zkw, tableName);
-      if (state == ZooKeeperProtos.Table.State.DISABLED ||
-          state == ZooKeeperProtos.Table.State.DISABLING)
-        disabledTables.add(tableName);
-    }
-    return disabledTables;
-  }
-
-  static boolean isTableState(final ZooKeeperProtos.Table.State expectedState,
-      final ZooKeeperProtos.Table.State currentState) {
-    return currentState != null && currentState.equals(expectedState);
-  }
-
-  /**
-   * @param zkw
-   * @param tableName
-   * @return Null or {@link ZooKeeperProtos.Table.State} found in znode.
-   * @throws KeeperException
-   */
-  static ZooKeeperProtos.Table.State getTableState(final ZooKeeperWatcher zkw,
-      final TableName tableName)
-      throws KeeperException, InterruptedException {
-    String znode = ZKUtil.joinZNode(zkw.tableZNode, tableName.getNameAsString());
-    byte [] data = ZKUtil.getData(zkw, znode);
-    if (data == null || data.length <= 0) return null;
-    try {
-      ProtobufUtil.expectPBMagicPrefix(data);
-      ZooKeeperProtos.Table.Builder builder = ZooKeeperProtos.Table.newBuilder();
-      int magicLen = ProtobufUtil.lengthOfPBMagic();
-      ZooKeeperProtos.Table t = builder.mergeFrom(data, magicLen, data.length - magicLen).build();
-      return t.getState();
-    } catch (InvalidProtocolBufferException e) {
-      KeeperException ke = new KeeperException.DataInconsistencyException();
-      ke.initCause(e);
-      throw ke;
-    } catch (DeserializationException e) {
-      throw ZKUtil.convert(e);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java
index 31aebcb..3bf1249 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java
@@ -989,7 +989,8 @@ public final class HConstants {
   public static final String REPLICATION_CODEC_CONF_KEY = "hbase.replication.rpc.codec";
 
   /** Config for pluggable consensus provider */
-  public static final String HBASE_CONSENSUS_PROVIDER_CLASS = "hbase.consensus.provider.class";
+  public static final String HBASE_COORDINATED_STATE_MANAGER_CLASS =
+    "hbase.coordinated.state.manager.class";
 
   private HConstants() {
     // Can't be instantiated with this ctor.

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-common/src/main/resources/hbase-default.xml
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/resources/hbase-default.xml b/hbase-common/src/main/resources/hbase-default.xml
index c61f347..46b6447 100644
--- a/hbase-common/src/main/resources/hbase-default.xml
+++ b/hbase-common/src/main/resources/hbase-default.xml
@@ -1180,8 +1180,8 @@ possible configurations would overwhelm and obscure the important.
     and add the fully qualified class name here.</description>
   </property>
   <property>
-    <name>hbase.consensus.provider.class</name>
-    <value>org.apache.hadoop.hbase.consensus.ZkConsensusProvider</value>
-    <description>Fully qualified name of class implementing consensus.</description>
+    <name>hbase.coordinated.state.manager.class</name>
+    <value>org.apache.hadoop.hbase.consensus.ZkCoordinatedStateManager</value>
+    <description>Fully qualified name of class implementing coordinated state manager.</description>
   </property>
 </configuration>

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-server/src/main/java/org/apache/hadoop/hbase/ConsensusProviderFactory.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ConsensusProviderFactory.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ConsensusProviderFactory.java
deleted file mode 100644
index 87cd9ff..0000000
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ConsensusProviderFactory.java
+++ /dev/null
@@ -1,43 +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.classification.InterfaceAudience;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.consensus.ZkConsensusProvider;
-import org.apache.hadoop.util.ReflectionUtils;
-
-/**
- * Creates instance of {@link ConsensusProvider}
- * based on configuration.
- */
-@InterfaceAudience.Private
-public class ConsensusProviderFactory {
-
-  /**
-   * Creates consensus provider from the given configuration.
-   * @param conf Configuration
-   * @return A {@link ConsensusProvider}
-   */
-  public static ConsensusProvider getConsensusProvider(Configuration conf) {
-    Class<? extends ConsensusProvider> consensusKlass =
-      conf.getClass(HConstants.HBASE_CONSENSUS_PROVIDER_CLASS, ZkConsensusProvider.class,
-        ConsensusProvider.class);
-    return ReflectionUtils.newInstance(consensusKlass, conf);
-  }
-}

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java
index 6962707..a30819d 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java
@@ -32,7 +32,6 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.regionserver.HRegionServer;
 import org.apache.hadoop.hbase.security.User;
-import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
 import org.apache.hadoop.hbase.util.Threads;
 
@@ -174,10 +173,10 @@ public class LocalHBaseCluster {
     // its HConnection instance rather than share (see HBASE_INSTANCES down in
     // the guts of HConnectionManager.
 
-    // Also, create separate ConsensusProvider instance per Server.
-    // This is special case when we have to have more than 1 ConsensusProvider
+    // Also, create separate CoordinatedStateManager instance per Server.
+    // This is special case when we have to have more than 1 CoordinatedStateManager
     // within 1 process.
-    ConsensusProvider cp = ConsensusProviderFactory.getConsensusProvider(conf);
+    CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
 
     JVMClusterUtil.RegionServerThread rst =
       JVMClusterUtil.createRegionServerThread(config, cp,
@@ -207,10 +206,10 @@ public class LocalHBaseCluster {
     // its HConnection instance rather than share (see HBASE_INSTANCES down in
     // the guts of HConnectionManager.
 
-    // Also, create separate ConsensusProvider instance per Server.
-    // This is special case when we have to have more than 1 ConsensusProvider
+    // Also, create separate CoordinatedStateManager instance per Server.
+    // This is special case when we have to have more than 1 CoordinatedStateManager
     // within 1 process.
-    ConsensusProvider cp = ConsensusProviderFactory.getConsensusProvider(conf);
+    CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
 
     JVMClusterUtil.MasterThread mt = JVMClusterUtil.createMasterThread(c, cp,
         (Class<? extends HMaster>) conf.getClass(HConstants.MASTER_IMPL, this.masterClass), index);

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/BaseConsensusProvider.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/BaseConsensusProvider.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/BaseConsensusProvider.java
deleted file mode 100644
index 03f5fca..0000000
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/BaseConsensusProvider.java
+++ /dev/null
@@ -1,49 +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.consensus;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.hbase.ConsensusProvider;
-import org.apache.hadoop.hbase.Server;
-
-/**
- * Base class for {@link org.apache.hadoop.hbase.ConsensusProvider} implementations.
- * Defines methods to retrieve consensus objects for relevant areas. ConsensusProvider
- * reference returned from Server interface has to be casted to this type to
- * access those methods.
- */
-@InterfaceAudience.Private
-public abstract class BaseConsensusProvider implements ConsensusProvider {
-
-  @Override
-  public void initialize(Server server) {
-  }
-
-  @Override
-  public void start() {
-  }
-
-  @Override
-  public void stop() {
-  }
-
-  @Override
-  public Server getServer() {
-    return null;
-  }
-}

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ZkConsensusProvider.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ZkConsensusProvider.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ZkConsensusProvider.java
deleted file mode 100644
index 56175ae..0000000
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ZkConsensusProvider.java
+++ /dev/null
@@ -1,42 +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.consensus;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.hbase.Server;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
-
-/**
- * ZooKeeper-based implementation of {@link org.apache.hadoop.hbase.ConsensusProvider}.
- */
-@InterfaceAudience.Private
-public class ZkConsensusProvider extends BaseConsensusProvider {
-  private Server server;
-  private ZooKeeperWatcher watcher;
-
-  @Override
-  public void initialize(Server server) {
-    this.server = server;
-    this.watcher = server.getZooKeeper();
-  }
-
-  @Override
-  public Server getServer() {
-    return server;
-  }
-}

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
index 9ae4371..ba9e103 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
@@ -43,6 +43,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.CoordinatedStateException;
 import org.apache.hadoop.hbase.HBaseIOException;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.HRegionInfo;
@@ -52,6 +53,7 @@ import org.apache.hadoop.hbase.Server;
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.TableNotFoundException;
+import org.apache.hadoop.hbase.TableStateManager;
 import org.apache.hadoop.hbase.catalog.CatalogTracker;
 import org.apache.hadoop.hbase.catalog.MetaReader;
 import org.apache.hadoop.hbase.client.Result;
@@ -69,6 +71,7 @@ import org.apache.hadoop.hbase.master.handler.ClosedRegionHandler;
 import org.apache.hadoop.hbase.master.handler.DisableTableHandler;
 import org.apache.hadoop.hbase.master.handler.EnableTableHandler;
 import org.apache.hadoop.hbase.master.handler.OpenedRegionHandler;
+import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos;
 import org.apache.hadoop.hbase.regionserver.RegionAlreadyInTransitionException;
 import org.apache.hadoop.hbase.regionserver.RegionMergeTransaction;
 import org.apache.hadoop.hbase.regionserver.RegionOpeningState;
@@ -82,7 +85,6 @@ import org.apache.hadoop.hbase.util.Threads;
 import org.apache.hadoop.hbase.util.Triple;
 import org.apache.hadoop.hbase.zookeeper.MetaRegionTracker;
 import org.apache.hadoop.hbase.zookeeper.ZKAssign;
-import org.apache.hadoop.hbase.zookeeper.ZKTable;
 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
 import org.apache.hadoop.hbase.zookeeper.ZooKeeperListener;
 import org.apache.hadoop.ipc.RemoteException;
@@ -161,7 +163,7 @@ public class AssignmentManager extends ZooKeeperListener {
   final NavigableMap<String, RegionPlan> regionPlans =
     new TreeMap<String, RegionPlan>();
 
-  private final ZKTable zkTable;
+  private final TableStateManager tableStateManager;
 
   private final ExecutorService executorService;
 
@@ -233,7 +235,8 @@ public class AssignmentManager extends ZooKeeperListener {
   public AssignmentManager(Server server, ServerManager serverManager,
       CatalogTracker catalogTracker, final LoadBalancer balancer,
       final ExecutorService service, MetricsMaster metricsMaster,
-      final TableLockManager tableLockManager) throws KeeperException, IOException {
+      final TableLockManager tableLockManager) throws KeeperException,
+        IOException, CoordinatedStateException {
     super(server.getZooKeeper());
     this.server = server;
     this.serverManager = serverManager;
@@ -247,7 +250,11 @@ public class AssignmentManager extends ZooKeeperListener {
            HConstants.HBASE_MASTER_LOADBALANCER_CLASS, Object.class).equals(
            FavoredNodeLoadBalancer.class);
     try {
-      this.zkTable = new ZKTable(this.watcher);
+      if (server.getCoordinatedStateManager() != null) {
+        this.tableStateManager = server.getCoordinatedStateManager().getTableStateManager();
+      } else {
+        this.tableStateManager = null;
+      }
     } catch (InterruptedException e) {
       throw new InterruptedIOException();
     }
@@ -277,12 +284,12 @@ public class AssignmentManager extends ZooKeeperListener {
   }
 
   /**
-   * @return Instance of ZKTable.
+   * @return Instance of ZKTableStateManager.
    */
-  public ZKTable getZKTable() {
+  public TableStateManager getTableStateManager() {
     // These are 'expensive' to make involving trip to zk ensemble so allow
     // sharing.
-    return this.zkTable;
+    return this.tableStateManager;
   }
 
   /**
@@ -387,9 +394,10 @@ public class AssignmentManager extends ZooKeeperListener {
    * @throws IOException
    * @throws KeeperException
    * @throws InterruptedException
+   * @throws CoordinatedStateException
    */
   void joinCluster() throws IOException,
-      KeeperException, InterruptedException {
+      KeeperException, InterruptedException, CoordinatedStateException {
     // Concurrency note: In the below the accesses on regionsInTransition are
     // outside of a synchronization block where usually all accesses to RIT are
     // synchronized.  The presumption is that in this case it is safe since this
@@ -400,8 +408,9 @@ public class AssignmentManager extends ZooKeeperListener {
 
     // Scan hbase:meta to build list of existing regions, servers, and assignment
     // Returns servers who have not checked in (assumed dead) and their regions
-    Map<ServerName, List<HRegionInfo>> deadServers = rebuildUserRegions();
+    Map<ServerName, List<HRegionInfo>> deadServers;
 
+    deadServers = rebuildUserRegions();
     // This method will assign all user regions if a clean server startup or
     // it will reconstruct master state and cleanup any leftovers from
     // previous master process.
@@ -424,7 +433,7 @@ public class AssignmentManager extends ZooKeeperListener {
    */
   void processDeadServersAndRegionsInTransition(
       final Map<ServerName, List<HRegionInfo>> deadServers)
-          throws KeeperException, IOException, InterruptedException {
+    throws KeeperException, IOException, InterruptedException, CoordinatedStateException {
     List<String> nodes = ZKUtil.listChildrenNoWatch(watcher,
       watcher.assignmentZNode);
 
@@ -1134,7 +1143,10 @@ public class AssignmentManager extends ZooKeeperListener {
             HRegionInfo regionInfo = rs.getRegion();
             String regionNameStr = regionInfo.getRegionNameAsString();
             LOG.debug("Znode " + regionNameStr + " deleted, state: " + rs);
-            boolean disabled = getZKTable().isDisablingOrDisabledTable(regionInfo.getTable());
+
+            boolean disabled = getTableStateManager().isTableState(regionInfo.getTable(),
+                ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING);
+
             ServerName serverName = rs.getServerName();
             if (serverManager.isServerOnline(serverName)) {
               if (rs.isOnServer(serverName)
@@ -1819,7 +1831,8 @@ public class AssignmentManager extends ZooKeeperListener {
             // assignRegion then we need to make the table ENABLED. Hence in such case the table
             // will not be in ENABLING or ENABLED state.
             TableName tableName = region.getTable();
-            if (!zkTable.isEnablingTable(tableName) && !zkTable.isEnabledTable(tableName)) {
+            if (!tableStateManager.isTableState(tableName,
+              ZooKeeperProtos.Table.State.ENABLED, ZooKeeperProtos.Table.State.ENABLING)) {
               LOG.debug("Setting table " + tableName + " to ENABLED state.");
               setEnabledTable(tableName);
             }
@@ -2001,11 +2014,11 @@ public class AssignmentManager extends ZooKeeperListener {
   }
 
   private boolean isDisabledorDisablingRegionInRIT(final HRegionInfo region) {
-    TableName tableName = region.getTable();
-    boolean disabled = this.zkTable.isDisabledTable(tableName);
-    if (disabled || this.zkTable.isDisablingTable(tableName)) {
-      LOG.info("Table " + tableName + (disabled ? " disabled;" : " disabling;") +
-        " skipping assign of " + region.getRegionNameAsString());
+    if (this.tableStateManager.isTableState(region.getTable(),
+        ZooKeeperProtos.Table.State.DISABLED,
+        ZooKeeperProtos.Table.State.DISABLING)) {
+      LOG.info("Table " + region.getTable() + " is disabled or disabling;"
+        + " skipping assign of " + region.getRegionNameAsString());
       offlineDisabledRegion(region);
       return true;
     }
@@ -2455,7 +2468,7 @@ public class AssignmentManager extends ZooKeeperListener {
    * @throws KeeperException
    */
   private void assignAllUserRegions()
-      throws IOException, InterruptedException, KeeperException {
+      throws IOException, InterruptedException, KeeperException, CoordinatedStateException {
     // Cleanup any existing ZK nodes and start watching
     ZKAssign.deleteAllNodes(watcher);
     ZKUtil.listChildrenAndWatchForNewChildren(this.watcher,
@@ -2465,8 +2478,11 @@ public class AssignmentManager extends ZooKeeperListener {
     // Skip assignment for regions of tables in DISABLING state because during clean cluster startup
     // no RS is alive and regions map also doesn't have any information about the regions.
     // See HBASE-6281.
-    Set<TableName> disabledOrDisablingOrEnabling = ZKTable.getDisabledOrDisablingTables(watcher);
-    disabledOrDisablingOrEnabling.addAll(ZKTable.getEnablingTables(watcher));
+    Set<TableName> disabledOrDisablingOrEnabling = tableStateManager.getTablesInStates(
+      ZooKeeperProtos.Table.State.DISABLED,
+      ZooKeeperProtos.Table.State.DISABLING,
+      ZooKeeperProtos.Table.State.ENABLING);
+
     // Scan hbase:meta for all user regions, skipping any disabled tables
     Map<HRegionInfo, ServerName> allRegions;
     SnapshotOfRegionAssignmentFromMeta snapshotOfRegionAssignment =
@@ -2488,7 +2504,8 @@ public class AssignmentManager extends ZooKeeperListener {
 
     for (HRegionInfo hri : allRegions.keySet()) {
       TableName tableName = hri.getTable();
-      if (!zkTable.isEnabledTable(tableName)) {
+      if (!tableStateManager.isTableState(tableName,
+          ZooKeeperProtos.Table.State.ENABLED)) {
         setEnabledTable(tableName);
       }
     }
@@ -2527,12 +2544,17 @@ public class AssignmentManager extends ZooKeeperListener {
    *         in META
    * @throws IOException
    */
-  Map<ServerName, List<HRegionInfo>> rebuildUserRegions() throws IOException, KeeperException {
-    Set<TableName> enablingTables = ZKTable.getEnablingTables(watcher);
-    Set<TableName> disabledOrEnablingTables = ZKTable.getDisabledTables(watcher);
-    disabledOrEnablingTables.addAll(enablingTables);
-    Set<TableName> disabledOrDisablingOrEnabling = ZKTable.getDisablingTables(watcher);
-    disabledOrDisablingOrEnabling.addAll(disabledOrEnablingTables);
+  Map<ServerName, List<HRegionInfo>> rebuildUserRegions() throws
+      IOException, KeeperException, CoordinatedStateException {
+    Set<TableName> enablingTables = tableStateManager.getTablesInStates(
+      ZooKeeperProtos.Table.State.ENABLING);
+    Set<TableName> disabledOrEnablingTables = tableStateManager.getTablesInStates(
+      ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.ENABLING);
+
+    Set<TableName> disabledOrDisablingOrEnabling = tableStateManager.getTablesInStates(
+      ZooKeeperProtos.Table.State.DISABLED,
+      ZooKeeperProtos.Table.State.DISABLING,
+      ZooKeeperProtos.Table.State.ENABLING);
 
     // Region assignment from META
     List<Result> results = MetaReader.fullScan(this.catalogTracker);
@@ -2584,7 +2606,8 @@ public class AssignmentManager extends ZooKeeperListener {
         // need to enable the table if not disabled or disabling or enabling
         // this will be used in rolling restarts
         if (!disabledOrDisablingOrEnabling.contains(tableName)
-            && !getZKTable().isEnabledTable(tableName)) {
+            && !getTableStateManager().isTableState(tableName,
+            ZooKeeperProtos.Table.State.ENABLED)) {
           setEnabledTable(tableName);
         }
       } else {
@@ -2598,7 +2621,8 @@ public class AssignmentManager extends ZooKeeperListener {
         // need to enable the table if not disabled or disabling or enabling
         // this will be used in rolling restarts
         if (!disabledOrDisablingOrEnabling.contains(tableName)
-            && !getZKTable().isEnabledTable(tableName)) {
+          && !getTableStateManager().isTableState(tableName,
+            ZooKeeperProtos.Table.State.ENABLED)) {
           setEnabledTable(tableName);
         }
       }
@@ -2615,8 +2639,9 @@ public class AssignmentManager extends ZooKeeperListener {
    * @throws IOException
    */
   private void recoverTableInDisablingState()
-      throws KeeperException, TableNotFoundException, IOException {
-    Set<TableName> disablingTables = ZKTable.getDisablingTables(watcher);
+      throws KeeperException, IOException, CoordinatedStateException {
+    Set<TableName> disablingTables =
+      tableStateManager.getTablesInStates(ZooKeeperProtos.Table.State.DISABLING);
     if (disablingTables.size() != 0) {
       for (TableName tableName : disablingTables) {
         // Recover by calling DisableTableHandler
@@ -2638,8 +2663,9 @@ public class AssignmentManager extends ZooKeeperListener {
    * @throws IOException
    */
   private void recoverTableInEnablingState()
-      throws KeeperException, TableNotFoundException, IOException {
-    Set<TableName> enablingTables = ZKTable.getEnablingTables(watcher);
+      throws KeeperException, IOException, CoordinatedStateException {
+    Set<TableName> enablingTables = tableStateManager.
+      getTablesInStates(ZooKeeperProtos.Table.State.ENABLING);
     if (enablingTables.size() != 0) {
       for (TableName tableName : enablingTables) {
         // Recover by calling EnableTableHandler
@@ -2876,7 +2902,8 @@ public class AssignmentManager extends ZooKeeperListener {
           } catch (KeeperException ke) {
             server.abort("Unexpected ZK exception deleting node " + hri, ke);
           }
-          if (zkTable.isDisablingOrDisabledTable(hri.getTable())) {
+          if (tableStateManager.isTableState(hri.getTable(),
+              ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING)) {
             regionStates.regionOffline(hri);
             it.remove();
             continue;
@@ -2897,7 +2924,8 @@ public class AssignmentManager extends ZooKeeperListener {
   public void balance(final RegionPlan plan) {
     HRegionInfo hri = plan.getRegionInfo();
     TableName tableName = hri.getTable();
-    if (zkTable.isDisablingOrDisabledTable(tableName)) {
+    if (tableStateManager.isTableState(tableName,
+      ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING)) {
       LOG.info("Ignored moving region of disabling/disabled table "
         + tableName);
       return;
@@ -2940,8 +2968,9 @@ public class AssignmentManager extends ZooKeeperListener {
 
   protected void setEnabledTable(TableName tableName) {
     try {
-      this.zkTable.setEnabledTable(tableName);
-    } catch (KeeperException e) {
+      this.tableStateManager.setTableState(tableName,
+        ZooKeeperProtos.Table.State.ENABLED);
+    } catch (CoordinatedStateException e) {
       // here we can abort as it is the start up flow
       String errorMsg = "Unable to ensure that the table " + tableName
           + " will be" + " enabled because of a ZooKeeper issue";
@@ -3113,7 +3142,8 @@ public class AssignmentManager extends ZooKeeperListener {
         + hri_b.getRegionNameAsString() + ", on " + sn);
 
       // User could disable the table before master knows the new region.
-      if (zkTable.isDisablingOrDisabledTable(p.getTable())) {
+      if (tableStateManager.isTableState(p.getTable(),
+          ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING)) {
         unassign(p);
       }
     }
@@ -3239,7 +3269,8 @@ public class AssignmentManager extends ZooKeeperListener {
         + hri_b.getRegionNameAsString() + ", on " + sn);
 
       // User could disable the table before master knows the new region.
-      if (zkTable.isDisablingOrDisabledTable(p.getTable())) {
+      if (tableStateManager.isTableState(p.getTable(),
+          ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING)) {
         unassign(hri_a);
         unassign(hri_b);
       }

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
index 01293f0..2233cfd 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
@@ -45,6 +45,7 @@ import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hbase.ClusterStatus;
+import org.apache.hadoop.hbase.CoordinatedStateException;
 import org.apache.hadoop.hbase.DoNotRetryIOException;
 import org.apache.hadoop.hbase.HBaseIOException;
 import org.apache.hadoop.hbase.HColumnDescriptor;
@@ -68,7 +69,7 @@ import org.apache.hadoop.hbase.client.MetaScanner;
 import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor;
 import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitorBase;
 import org.apache.hadoop.hbase.client.Result;
-import org.apache.hadoop.hbase.ConsensusProvider;
+import org.apache.hadoop.hbase.CoordinatedStateManager;
 import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
 import org.apache.hadoop.hbase.exceptions.DeserializationException;
 import org.apache.hadoop.hbase.executor.ExecutorType;
@@ -99,6 +100,7 @@ import org.apache.hadoop.hbase.monitoring.TaskMonitor;
 import org.apache.hadoop.hbase.procedure.MasterProcedureManagerHost;
 import org.apache.hadoop.hbase.procedure.flush.MasterFlushTableProcedureManager;
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionServerInfo;
+import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos;
 import org.apache.hadoop.hbase.regionserver.HRegionServer;
 import org.apache.hadoop.hbase.regionserver.RSRpcServices;
 import org.apache.hadoop.hbase.regionserver.RegionSplitPolicy;
@@ -257,9 +259,9 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
    * @throws KeeperException
    * @throws IOException
    */
-  public HMaster(final Configuration conf, ConsensusProvider consensusProvider)
+  public HMaster(final Configuration conf, CoordinatedStateManager csm)
       throws IOException, KeeperException, InterruptedException {
-    super(conf, consensusProvider);
+    super(conf, csm);
     this.rsFatals = new MemoryBoundedLogMessageBuffer(
       conf.getLong("hbase.master.buffer.for.rs.fatals", 1*1024*1024));
 
@@ -397,9 +399,11 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
    * Initialize all ZK based system trackers.
    * @throws IOException
    * @throws InterruptedException
+   * @throws KeeperException
+   * @throws CoordinatedStateException
    */
   void initializeZKBasedSystemTrackers() throws IOException,
-      InterruptedException, KeeperException {
+      InterruptedException, KeeperException, CoordinatedStateException {
     this.balancer = LoadBalancerFactory.getLoadBalancer(conf);
     this.loadBalancerTracker = new LoadBalancerTracker(zooKeeper, this);
     this.loadBalancerTracker.start();
@@ -453,9 +457,10 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
    * @throws IOException
    * @throws InterruptedException
    * @throws KeeperException
+   * @throws CoordinatedStateException
    */
   private void finishActiveMasterInitialization(MonitoredTask status)
-      throws IOException, InterruptedException, KeeperException {
+      throws IOException, InterruptedException, KeeperException, CoordinatedStateException {
 
     isActiveMaster = true;
 
@@ -765,7 +770,8 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
   }
 
   private void enableMeta(TableName metaTableName) {
-    if (!this.assignmentManager.getZKTable().isEnabledTable(metaTableName)) {
+    if (!this.assignmentManager.getTableStateManager().isTableState(metaTableName,
+        ZooKeeperProtos.Table.State.ENABLED)) {
       this.assignmentManager.setEnabledTable(metaTableName);
     }
   }
@@ -1477,8 +1483,8 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
     if (!MetaReader.tableExists(getCatalogTracker(), tableName)) {
       throw new TableNotFoundException(tableName);
     }
-    if (!getAssignmentManager().getZKTable().
-        isDisabledTable(tableName)) {
+    if (!getAssignmentManager().getTableStateManager().
+        isTableState(tableName, ZooKeeperProtos.Table.State.DISABLED)) {
       throw new TableNotDisabledException(tableName);
     }
   }
@@ -1770,10 +1776,10 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
    * @return HMaster instance.
    */
   public static HMaster constructMaster(Class<? extends HMaster> masterClass,
-      final Configuration conf, final ConsensusProvider cp)  {
+      final Configuration conf, final CoordinatedStateManager cp)  {
     try {
       Constructor<? extends HMaster> c =
-        masterClass.getConstructor(Configuration.class, ConsensusProvider.class);
+        masterClass.getConstructor(Configuration.class, CoordinatedStateManager.class);
       return c.newInstance(conf, cp);
     } catch (InvocationTargetException ite) {
       Throwable target = ite.getTargetException() != null?

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java
index c4cf6e5..6aef257 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java
@@ -30,14 +30,14 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.CoordinatedStateManager;
+import org.apache.hadoop.hbase.CoordinatedStateManagerFactory;
 import org.apache.hadoop.hbase.MasterNotRunningException;
 import org.apache.hadoop.hbase.ZNodeClearer;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.LocalHBaseCluster;
 import org.apache.hadoop.hbase.ZooKeeperConnectionException;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.ConsensusProvider;
-import org.apache.hadoop.hbase.ConsensusProviderFactory;
 import org.apache.hadoop.hbase.regionserver.HRegionServer;
 import org.apache.hadoop.hbase.util.JVMClusterUtil;
 import org.apache.hadoop.hbase.util.ServerCommandLine;
@@ -187,8 +187,9 @@ public class HMasterCommandLine extends ServerCommandLine {
         waitOnMasterThreads(cluster);
       } else {
         logProcessInfo(getConf());
-        ConsensusProvider cp = ConsensusProviderFactory.getConsensusProvider(conf);
-        HMaster master = HMaster.constructMaster(masterClass, conf, cp);
+        CoordinatedStateManager csm =
+          CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
+        HMaster master = HMaster.constructMaster(masterClass, conf, csm);
         if (master.isStopped()) {
           LOG.info("Won't bring the Master up as a shutdown is requested");
           return 1;
@@ -258,9 +259,9 @@ public class HMasterCommandLine extends ServerCommandLine {
   public static class LocalHMaster extends HMaster {
     private MiniZooKeeperCluster zkcluster = null;
 
-    public LocalHMaster(Configuration conf, ConsensusProvider consensusProvider)
+    public LocalHMaster(Configuration conf, CoordinatedStateManager csm)
     throws IOException, KeeperException, InterruptedException {
-      super(conf, consensusProvider);
+      super(conf, csm);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ClosedRegionHandler.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ClosedRegionHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ClosedRegionHandler.java
index 906cfd5..3bb5220 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ClosedRegionHandler.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/ClosedRegionHandler.java
@@ -27,6 +27,7 @@ import org.apache.hadoop.hbase.executor.EventHandler;
 import org.apache.hadoop.hbase.executor.EventType;
 import org.apache.hadoop.hbase.master.AssignmentManager;
 import org.apache.hadoop.hbase.master.RegionState;
+import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos;
 
 /**
  * Handles CLOSED region event on Master.
@@ -91,8 +92,8 @@ public class ClosedRegionHandler extends EventHandler implements TotesHRegionInf
   public void process() {
     LOG.debug("Handling CLOSED event for " + regionInfo.getEncodedName());
     // Check if this table is being disabled or not
-    if (this.assignmentManager.getZKTable().
-        isDisablingOrDisabledTable(this.regionInfo.getTable())) {
+    if (this.assignmentManager.getTableStateManager().isTableState(this.regionInfo.getTable(),
+        ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING)) {
       assignmentManager.offlineDisabledRegion(regionInfo);
       return;
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java
index 75cbde5..e723247 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java
@@ -28,6 +28,7 @@ import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.CoordinatedStateException;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HTableDescriptor;
@@ -46,10 +47,10 @@ import org.apache.hadoop.hbase.master.MasterFileSystem;
 import org.apache.hadoop.hbase.master.MasterServices;
 import org.apache.hadoop.hbase.master.TableLockManager;
 import org.apache.hadoop.hbase.master.TableLockManager.TableLock;
+import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos;
 import org.apache.hadoop.hbase.util.FSTableDescriptors;
 import org.apache.hadoop.hbase.util.FSUtils;
 import org.apache.hadoop.hbase.util.ModifyRegionUtils;
-import org.apache.zookeeper.KeeperException;
 
 /**
  * Handler to create a table.
@@ -130,10 +131,13 @@ public class CreateTableHandler extends EventHandler {
     // We could have cleared the hbase.rootdir and not zk.  How can we detect this case?
     // Having to clean zk AND hdfs is awkward.
     try {
-      if (!assignmentManager.getZKTable().checkAndSetEnablingTable(tableName)) {
+      if (!assignmentManager.getTableStateManager().setTableStateIfNotInStates(tableName,
+        ZooKeeperProtos.Table.State.ENABLING,
+        ZooKeeperProtos.Table.State.ENABLING,
+        ZooKeeperProtos.Table.State.ENABLED)) {
         throw new TableExistsException(tableName);
       }
-    } catch (KeeperException e) {
+    } catch (CoordinatedStateException e) {
       throw new IOException("Unable to ensure that the table will be" +
         " enabling because of a ZooKeeper issue", e);
     }
@@ -146,8 +150,9 @@ public class CreateTableHandler extends EventHandler {
     // again with the same Active master
     // It will block the creation saying TableAlreadyExists.
     try {
-      assignmentManager.getZKTable().removeEnablingTable(tableName, false);
-    } catch (KeeperException e) {
+      assignmentManager.getTableStateManager().checkAndRemoveTableState(tableName,
+        ZooKeeperProtos.Table.State.ENABLING, false);
+    } catch (CoordinatedStateException e) {
       // Keeper exception should not happen here
       LOG.error("Got a keeper exception while removing the ENABLING table znode "
           + tableName, e);
@@ -211,7 +216,7 @@ public class CreateTableHandler extends EventHandler {
    * - Update ZooKeeper with the enabled state
    */
   private void handleCreateTable(TableName tableName)
-      throws IOException, KeeperException {
+      throws IOException, CoordinatedStateException {
     Path tempdir = fileSystemManager.getTempDir();
     FileSystem fs = fileSystemManager.getFileSystem();
 
@@ -239,8 +244,9 @@ public class CreateTableHandler extends EventHandler {
 
     // 6. Set table enabled flag up in zk.
     try {
-      assignmentManager.getZKTable().setEnabledTable(tableName);
-    } catch (KeeperException e) {
+      assignmentManager.getTableStateManager().setTableState(tableName,
+        ZooKeeperProtos.Table.State.ENABLED);
+    } catch (CoordinatedStateException e) {
       throw new IOException("Unable to ensure that " + tableName + " will be" +
         " enabled because of a ZooKeeper issue", e);
     }

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java
index 99b98ac..2102d5f 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DeleteTableHandler.java
@@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.CoordinatedStateException;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HTableDescriptor;
@@ -42,7 +43,6 @@ import org.apache.hadoop.hbase.master.MasterFileSystem;
 import org.apache.hadoop.hbase.master.MasterServices;
 import org.apache.hadoop.hbase.master.RegionStates;
 import org.apache.hadoop.hbase.master.RegionState.State;
-import org.apache.zookeeper.KeeperException;
 
 @InterfaceAudience.Private
 public class DeleteTableHandler extends TableEventHandler {
@@ -62,7 +62,7 @@ public class DeleteTableHandler extends TableEventHandler {
   }
 
   protected void waitRegionInTransition(final List<HRegionInfo> regions)
-      throws IOException, KeeperException {
+      throws IOException, CoordinatedStateException {
     AssignmentManager am = this.masterServices.getAssignmentManager();
     RegionStates states = am.getRegionStates();
     long waitTime = server.getConfiguration().
@@ -93,7 +93,7 @@ public class DeleteTableHandler extends TableEventHandler {
 
   @Override
   protected void handleTableOperation(List<HRegionInfo> regions)
-      throws IOException, KeeperException {
+      throws IOException, CoordinatedStateException {
     MasterCoprocessorHost cpHost = ((HMaster) this.server).getMasterCoprocessorHost();
     if (cpHost != null) {
       cpHost.preDeleteTableHandler(this.tableName);
@@ -118,7 +118,7 @@ public class DeleteTableHandler extends TableEventHandler {
 
       // 5. If entry for this table in zk, and up in AssignmentManager, remove it.
       LOG.debug("Marking '" + tableName + "' as deleted.");
-      am.getZKTable().setDeletedTable(tableName);
+      am.getTableStateManager().setDeletedTable(tableName);
     }
 
     if (cpHost != null) {
@@ -130,7 +130,7 @@ public class DeleteTableHandler extends TableEventHandler {
    * Removes the table from .META. and archives the HDFS files.
    */
   protected void removeTableData(final List<HRegionInfo> regions)
-      throws IOException, KeeperException {
+      throws IOException, CoordinatedStateException {
     // 1. Remove regions from META
     LOG.debug("Deleting regions from META");
     MetaEditor.deleteRegions(this.server.getCatalogTracker(), regions);

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DisableTableHandler.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DisableTableHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DisableTableHandler.java
index 8ee2dc0..a83eb3f 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DisableTableHandler.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/DisableTableHandler.java
@@ -25,6 +25,7 @@ import java.util.concurrent.ExecutorService;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.hbase.CoordinatedStateException;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.Server;
@@ -43,7 +44,7 @@ import org.apache.hadoop.hbase.master.RegionStates;
 import org.apache.hadoop.hbase.master.TableLockManager;
 import org.apache.hadoop.hbase.master.RegionState.State;
 import org.apache.hadoop.hbase.master.TableLockManager.TableLock;
-import org.apache.zookeeper.KeeperException;
+import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos;
 import org.htrace.Trace;
 
 /**
@@ -94,14 +95,15 @@ public class DisableTableHandler extends EventHandler {
       //TODO: reevaluate this since we have table locks now
       if (!skipTableStateCheck) {
         try {
-          if (!this.assignmentManager.getZKTable().checkEnabledAndSetDisablingTable
-            (this.tableName)) {
+          if (!this.assignmentManager.getTableStateManager().setTableStateIfInStates(
+            this.tableName, ZooKeeperProtos.Table.State.DISABLING,
+            ZooKeeperProtos.Table.State.ENABLED)) {
             LOG.info("Table " + tableName + " isn't enabled; skipping disable");
             throw new TableNotEnabledException(this.tableName);
           }
-        } catch (KeeperException e) {
+        } catch (CoordinatedStateException e) {
           throw new IOException("Unable to ensure that the table will be" +
-            " disabling because of a ZooKeeper issue", e);
+            " disabling because of a coordination engine issue", e);
         }
       }
       success = true;
@@ -139,7 +141,7 @@ public class DisableTableHandler extends EventHandler {
       }
     } catch (IOException e) {
       LOG.error("Error trying to disable table " + this.tableName, e);
-    } catch (KeeperException e) {
+    } catch (CoordinatedStateException e) {
       LOG.error("Error trying to disable table " + this.tableName, e);
     } finally {
       releaseTableLock();
@@ -156,9 +158,10 @@ public class DisableTableHandler extends EventHandler {
     }
   }
 
-  private void handleDisableTable() throws IOException, KeeperException {
+  private void handleDisableTable() throws IOException, CoordinatedStateException {
     // Set table disabling flag up in zk.
-    this.assignmentManager.getZKTable().setDisablingTable(this.tableName);
+    this.assignmentManager.getTableStateManager().setTableState(this.tableName,
+      ZooKeeperProtos.Table.State.DISABLING);
     boolean done = false;
     while (true) {
       // Get list of online regions that are of this table.  Regions that are
@@ -186,7 +189,8 @@ public class DisableTableHandler extends EventHandler {
       }
     }
     // Flip the table to disabled if success.
-    if (done) this.assignmentManager.getZKTable().setDisabledTable(this.tableName);
+    if (done) this.assignmentManager.getTableStateManager().setTableState(this.tableName,
+      ZooKeeperProtos.Table.State.DISABLED);
     LOG.info("Disabled table is done=" + done);
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java
index 11a5606..6fb2302 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java
@@ -26,6 +26,7 @@ import java.util.Map;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.hbase.CoordinatedStateException;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.Server;
@@ -45,8 +46,8 @@ import org.apache.hadoop.hbase.master.RegionStates;
 import org.apache.hadoop.hbase.master.ServerManager;
 import org.apache.hadoop.hbase.master.TableLockManager;
 import org.apache.hadoop.hbase.master.TableLockManager.TableLock;
+import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos;
 import org.apache.hadoop.hbase.util.Pair;
-import org.apache.zookeeper.KeeperException;
 
 /**
  * Handler to run enable of a table.
@@ -88,9 +89,10 @@ public class EnableTableHandler extends EventHandler {
           throw new TableNotFoundException(tableName);
         } 
         try {
-          this.assignmentManager.getZKTable().removeEnablingTable(tableName, true);
+          this.assignmentManager.getTableStateManager().checkAndRemoveTableState(tableName,
+            ZooKeeperProtos.Table.State.ENABLING, true);
           throw new TableNotFoundException(tableName);
-        } catch (KeeperException e) {
+        } catch (CoordinatedStateException e) {
           // TODO : Use HBCK to clear such nodes
           LOG.warn("Failed to delete the ENABLING node for the table " + tableName
               + ".  The table will remain unusable. Run HBCK to manually fix the problem.");
@@ -103,14 +105,15 @@ public class EnableTableHandler extends EventHandler {
       // DISABLED or ENABLED.
       if (!skipTableStateCheck) {
         try {
-          if (!this.assignmentManager.getZKTable().checkDisabledAndSetEnablingTable
-            (this.tableName)) {
+          if (!this.assignmentManager.getTableStateManager().setTableStateIfInStates(
+              this.tableName, ZooKeeperProtos.Table.State.ENABLING,
+              ZooKeeperProtos.Table.State.DISABLED)) {
             LOG.info("Table " + tableName + " isn't disabled; skipping enable");
             throw new TableNotDisabledException(this.tableName);
           }
-        } catch (KeeperException e) {
+        } catch (CoordinatedStateException e) {
           throw new IOException("Unable to ensure that the table will be" +
-            " enabling because of a ZooKeeper issue", e);
+            " enabling because of a coordination engine issue", e);
         }
       }
       success = true;
@@ -147,7 +150,7 @@ public class EnableTableHandler extends EventHandler {
       }
     } catch (IOException e) {
       LOG.error("Error trying to enable the table " + this.tableName, e);
-    } catch (KeeperException e) {
+    } catch (CoordinatedStateException e) {
       LOG.error("Error trying to enable the table " + this.tableName, e);
     } catch (InterruptedException e) {
       LOG.error("Error trying to enable the table " + this.tableName, e);
@@ -166,12 +169,14 @@ public class EnableTableHandler extends EventHandler {
     }
   }
 
-  private void handleEnableTable() throws IOException, KeeperException, InterruptedException {
+  private void handleEnableTable() throws IOException, CoordinatedStateException,
+      InterruptedException {
     // I could check table is disabling and if so, not enable but require
     // that user first finish disabling but that might be obnoxious.
 
     // Set table enabling flag up in zk.
-    this.assignmentManager.getZKTable().setEnablingTable(this.tableName);
+    this.assignmentManager.getTableStateManager().setTableState(this.tableName,
+      ZooKeeperProtos.Table.State.ENABLING);
     boolean done = false;
     ServerManager serverManager = ((HMaster)this.server).getServerManager();
     // Get the regions of this table. We're done when all listed
@@ -206,8 +211,8 @@ public class EnableTableHandler extends EventHandler {
     }
     if (done) {
       // Flip the table to enabled.
-      this.assignmentManager.getZKTable().setEnabledTable(
-        this.tableName);
+      this.assignmentManager.getTableStateManager().setTableState(
+        this.tableName, ZooKeeperProtos.Table.State.ENABLED);
       LOG.info("Table '" + this.tableName
       + "' was successfully enabled. Status: done=" + done);
     } else {

http://git-wip-us.apache.org/repos/asf/hbase/blob/ea0731d6/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/OpenedRegionHandler.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/OpenedRegionHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/OpenedRegionHandler.java
index f711bd1..3457131 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/OpenedRegionHandler.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/OpenedRegionHandler.java
@@ -30,6 +30,7 @@ import org.apache.hadoop.hbase.executor.EventHandler;
 import org.apache.hadoop.hbase.executor.EventType;
 import org.apache.hadoop.hbase.master.AssignmentManager;
 import org.apache.hadoop.hbase.master.RegionState;
+import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos;
 import org.apache.hadoop.hbase.zookeeper.ZKAssign;
 import org.apache.zookeeper.KeeperException;
 
@@ -113,7 +114,8 @@ public class OpenedRegionHandler extends EventHandler implements TotesHRegionInf
         " because regions is NOT in RIT -- presuming this is because it SPLIT");
     }
     if (!openedNodeDeleted) {
-      if (this.assignmentManager.getZKTable().isDisablingOrDisabledTable(regionInfo.getTable())) {
+      if (this.assignmentManager.getTableStateManager().isTableState(regionInfo.getTable(),
+        ZooKeeperProtos.Table.State.DISABLED, ZooKeeperProtos.Table.State.DISABLING)) {
         debugLog(regionInfo, "Opened region "
             + regionInfo.getShortNameToLog() + " but "
             + "this table is disabled, triggering close of region");