Index: hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (revision ) @@ -75,6 +75,7 @@ import org.apache.hadoop.hbase.client.ConnectionUtils; import org.apache.hadoop.hbase.client.HConnection; import org.apache.hadoop.hbase.client.HConnectionManager; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; import org.apache.hadoop.hbase.exceptions.RegionMovedException; import org.apache.hadoop.hbase.exceptions.RegionOpeningException; @@ -390,14 +391,17 @@ protected final RSRpcServices rpcServices; + protected ConsensusProvider consensusProvider; + /** * Starts a HRegionServer at the default location * * @param conf + * @param consensusProvider implementation of ConsensusProvider to be used * @throws IOException * @throws InterruptedException */ - public HRegionServer(Configuration conf) + public HRegionServer(Configuration conf, ConsensusProvider consensusProvider) throws IOException, InterruptedException { this.fsOk = true; this.conf = conf; @@ -469,6 +473,10 @@ zooKeeper = new ZooKeeperWatcher(conf, getProcessName() + ":" + rpcServices.isa.getPort(), this, canCreateBaseZNode()); + this.consensusProvider = consensusProvider; + this.consensusProvider.initialize(this); + this.consensusProvider.start(); + tableLockManager = TableLockManager.createTableLockManager( conf, zooKeeper, serverName); @@ -2126,6 +2134,10 @@ @Override public ZooKeeperWatcher getZooKeeper() { return zooKeeper; + } + + public ConsensusProvider getConsensusProvider() { + return consensusProvider; } @Override Index: hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java (revision ) @@ -971,6 +971,9 @@ /** Configuration key for setting replication codec class name */ 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"; + private HConstants() { // Can't be instantiated with this ctor. } Index: hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java (revision ) @@ -65,6 +65,7 @@ import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Scan; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver; import org.apache.hadoop.hbase.coprocessor.ObserverContext; import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; @@ -1301,9 +1302,10 @@ public static class MockMasterWithoutCatalogJanitor extends HMaster { - public MockMasterWithoutCatalogJanitor(Configuration conf) throws IOException, KeeperException, + public MockMasterWithoutCatalogJanitor(Configuration conf, ConsensusProvider cp) + throws IOException, KeeperException, InterruptedException { - super(conf); + super(conf, cp); } @Override Index: hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ConsensusProviderFactory.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ConsensusProviderFactory.java (revision ) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ConsensusProviderFactory.java (revision ) @@ -0,0 +1,43 @@ +/** + * 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.conf.Configuration; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.util.ReflectionUtils; + +/** + * Creates instance of {@link org.apache.hadoop.hbase.consensus.ConsensusProvider} + * based on configuration. + */ +@InterfaceAudience.Private +public class ConsensusProviderFactory { + + /** + * Creates consensus provider from the given configuration. + * @param conf Configuration + * @return A {@link org.apache.hadoop.hbase.consensus.ConsensusProvider} + */ + public static ConsensusProvider getConsensusProvider(Configuration conf) { + Class consensusKlass = + conf.getClass(HConstants.HBASE_CONSENSUS_PROVIDER_CLASS, ZkConsensusProvider.class, + ConsensusProvider.class); + return ReflectionUtils.newInstance(consensusKlass, conf); + } +} Index: hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java (revision ) @@ -30,6 +30,8 @@ import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.client.HBaseAdmin; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; +import org.apache.hadoop.hbase.consensus.ConsensusProviderFactory; import org.apache.hadoop.hbase.regionserver.HRegionServer; import org.apache.hadoop.hbase.security.User; import org.apache.hadoop.hbase.util.Bytes; @@ -73,6 +75,7 @@ private final Class masterClass; private final Class regionServerClass; + ConsensusProvider consensusProvider; /** * Constructor. * @param conf @@ -139,6 +142,8 @@ final Class regionServerClass) throws IOException { this.conf = conf; + consensusProvider = ConsensusProviderFactory.getConsensusProvider(conf); + // Always have masters and regionservers come up on port '0' so we don't // clash over default ports. conf.set(HConstants.MASTER_PORT, "0"); @@ -173,7 +178,7 @@ // its HConnection instance rather than share (see HBASE_INSTANCES down in // the guts of HConnectionManager. JVMClusterUtil.RegionServerThread rst = - JVMClusterUtil.createRegionServerThread(config, + JVMClusterUtil.createRegionServerThread(config, consensusProvider, this.regionServerClass, index); this.regionThreads.add(rst); return rst; @@ -199,7 +204,7 @@ // Create each master with its own Configuration instance so each has // its HConnection instance rather than share (see HBASE_INSTANCES down in // the guts of HConnectionManager. - JVMClusterUtil.MasterThread mt = JVMClusterUtil.createMasterThread(c, + JVMClusterUtil.MasterThread mt = JVMClusterUtil.createMasterThread(c, consensusProvider, (Class) conf.getClass(HConstants.MASTER_IMPL, this.masterClass), index); this.masterThreads.add(mt); return mt; Index: hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransaction.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransaction.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransaction.java (revision ) @@ -42,6 +42,8 @@ import org.apache.hadoop.hbase.client.Durability; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Scan; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; +import org.apache.hadoop.hbase.consensus.ConsensusProviderFactory; import org.apache.hadoop.hbase.regionserver.wal.HLog; import org.apache.hadoop.hbase.regionserver.wal.HLogFactory; import org.apache.hadoop.hbase.util.Bytes; @@ -218,7 +220,9 @@ // Run the execute. Look at what it returns. TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, 0); - Server mockServer = new HRegionServer(TEST_UTIL.getConfiguration()); + ConsensusProvider cp = ConsensusProviderFactory.getConsensusProvider( + TEST_UTIL.getConfiguration()); + Server mockServer = new HRegionServer(TEST_UTIL.getConfiguration(), cp); HRegion mergedRegion = mt.execute(mockServer, null); // Do some assertions about execution. assertTrue(this.fs.exists(mt.getMergesDir())); @@ -265,7 +269,9 @@ // Run the execute. Look at what it returns. boolean expectedException = false; TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, 0); - Server mockServer = new HRegionServer(TEST_UTIL.getConfiguration()); + ConsensusProvider cp = ConsensusProviderFactory.getConsensusProvider( + TEST_UTIL.getConfiguration()); + Server mockServer = new HRegionServer(TEST_UTIL.getConfiguration(), cp); try { mt.execute(mockServer, null); } catch (MockedFailedMergedRegionCreation e) { @@ -324,7 +330,9 @@ // Run the execute. Look at what it returns. boolean expectedException = false; TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, 0); - Server mockServer = new HRegionServer(TEST_UTIL.getConfiguration()); + ConsensusProvider cp = ConsensusProviderFactory.getConsensusProvider( + TEST_UTIL.getConfiguration()); + Server mockServer = new HRegionServer(TEST_UTIL.getConfiguration(), cp); try { mt.execute(mockServer, null); } catch (MockedFailedMergedRegionOpen e) { Index: hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java (revision ) @@ -27,6 +27,7 @@ import org.apache.hadoop.hbase.MediumTests; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; import org.apache.hadoop.hbase.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos; import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos; @@ -49,9 +50,9 @@ private static HBaseTestingUtility TEST_UTIL; public static class MyMaster extends HMaster { - public MyMaster(Configuration conf) throws IOException, + public MyMaster(Configuration conf, ConsensusProvider cp) throws IOException, KeeperException, InterruptedException { - super(conf); + super(conf, cp); } @Override Index: hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientScannerRPCTimeout.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientScannerRPCTimeout.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientScannerRPCTimeout.java (revision ) @@ -30,6 +30,7 @@ import org.apache.hadoop.hbase.MediumTests; import org.apache.hadoop.hbase.MiniHBaseCluster.MiniHBaseClusterRegionServer; import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; import org.apache.hadoop.hbase.ipc.RpcClient; import org.apache.hadoop.hbase.ipc.RpcServer; import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ScanRequest; @@ -129,9 +130,9 @@ } private static class RegionServerWithScanTimeout extends MiniHBaseClusterRegionServer { - public RegionServerWithScanTimeout(Configuration conf) + public RegionServerWithScanTimeout(Configuration conf, ConsensusProvider cp) throws IOException, InterruptedException { - super(conf); + super(conf, cp); } protected RSRpcServices createRpcServices() throws IOException { \ No newline at end of file Index: hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerOnCluster.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerOnCluster.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerOnCluster.java (revision ) @@ -48,6 +48,7 @@ import org.apache.hadoop.hbase.catalog.MetaEditor; import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.client.HTable; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver; import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; import org.apache.hadoop.hbase.coprocessor.ObserverContext; @@ -837,9 +838,10 @@ public static class MyMaster extends HMaster { AtomicBoolean enabled = new AtomicBoolean(true); - public MyMaster(Configuration conf) throws IOException, KeeperException, + public MyMaster(Configuration conf, ConsensusProvider cp) + throws IOException, KeeperException, InterruptedException { - super(conf); + super(conf, cp); } @Override Index: hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/OOMERegionServer.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/OOMERegionServer.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/OOMERegionServer.java (revision ) @@ -25,6 +25,7 @@ import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Durability; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; import org.apache.hadoop.hbase.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.protobuf.RequestConverter; import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutateRequest; @@ -41,8 +42,9 @@ public class OOMERegionServer extends HRegionServer { private List retainer = new ArrayList(); - public OOMERegionServer(HBaseConfiguration conf) throws IOException, InterruptedException { - super(conf); + public OOMERegionServer(HBaseConfiguration conf, ConsensusProvider cp) + throws IOException, InterruptedException { + super(conf, cp); } public void put(byte [] regionName, Put put) Index: hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ConsensusProvider.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ConsensusProvider.java (revision ) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ConsensusProvider.java (revision ) @@ -0,0 +1,58 @@ +/** + * 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; + +/** + * Implementations of this interface will keep and return to clients + * implementations of classes providing API to execute + * coordinated operations. + * + * 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(); +} Index: hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSKilledWhenInitializing.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSKilledWhenInitializing.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSKilledWhenInitializing.java (revision ) @@ -32,6 +32,7 @@ import org.apache.hadoop.hbase.LocalHBaseCluster; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameStringPair; import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionServerStartupResponse; @@ -103,8 +104,9 @@ public static class MockedRegionServer extends MiniHBaseCluster.MiniHBaseClusterRegionServer { - public MockedRegionServer(Configuration conf) throws IOException, InterruptedException { - super(conf); + public MockedRegionServer(Configuration conf, ConsensusProvider cp) + throws IOException, InterruptedException { + super(conf, cp); } @Override Index: hbase-server/src/test/java/org/apache/hadoop/hbase/TestLocalHBaseCluster.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/TestLocalHBaseCluster.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/TestLocalHBaseCluster.java (revision ) @@ -22,6 +22,7 @@ import java.io.IOException; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; import org.apache.hadoop.hbase.master.HMaster; import org.apache.zookeeper.KeeperException; @@ -64,9 +65,10 @@ * running in local mode. */ public static class MyHMaster extends HMaster { - public MyHMaster(Configuration conf) throws IOException, KeeperException, + public MyHMaster(Configuration conf, ConsensusProvider cp) + throws IOException, KeeperException, InterruptedException { - super(conf); + super(conf, cp); } public int echo(int val) { @@ -79,9 +81,9 @@ */ public static class MyHRegionServer extends MiniHBaseCluster.MiniHBaseClusterRegionServer { - public MyHRegionServer(Configuration conf) throws IOException, + public MyHRegionServer(Configuration conf, ConsensusProvider cp) throws IOException, InterruptedException { - super(conf); + super(conf, cp); } public int echo(int val) { Index: hbase-common/src/main/resources/hbase-default.xml IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-common/src/main/resources/hbase-default.xml (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-common/src/main/resources/hbase-default.xml (revision ) @@ -1160,4 +1160,9 @@ procedure. After implementing your own MasterProcedureManager, just put it in HBase's classpath and add the fully qualified class name here. + + hbase.consensus.provider.class + org.apache.hadoop.hbase.consensus.ZkConsensusProvider + Fully qualified name of class implementing consensus. + Index: hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ZkConsensusProvider.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ZkConsensusProvider.java (revision ) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ZkConsensusProvider.java (revision ) @@ -0,0 +1,50 @@ +/** + * 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 ConsensusProvider}. + */ +@InterfaceAudience.Private +public class ZkConsensusProvider implements ConsensusProvider { + private Server server; + private ZooKeeperWatcher watcher; + + @Override + public void initialize(Server server) { + this.server = server; + this.watcher = server.getZooKeeper(); + } + + @Override + public void start() { + } + + @Override + public void stop() { + } + + @Override + public Server getServer() { + return server; + } +} Index: hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterNoCluster.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterNoCluster.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterNoCluster.java (revision ) @@ -46,6 +46,8 @@ import org.apache.hadoop.hbase.client.HConnection; import org.apache.hadoop.hbase.client.HConnectionTestingUtility; import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; +import org.apache.hadoop.hbase.consensus.ConsensusProviderFactory; import org.apache.hadoop.hbase.monitoring.MonitoredTask; import org.apache.hadoop.hbase.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.RegionServerReportRequest; @@ -123,7 +125,9 @@ @Test (timeout=30000) public void testStopDuringStart() throws IOException, KeeperException, InterruptedException { - HMaster master = new HMaster(TESTUTIL.getConfiguration()); + ConsensusProvider cp = ConsensusProviderFactory.getConsensusProvider( + TESTUTIL.getConfiguration()); + HMaster master = new HMaster(TESTUTIL.getConfiguration(), cp); master.start(); // Immediately have it stop. We used hang in assigning meta. master.stopMaster(); @@ -173,7 +177,9 @@ // and get notification on transitions. We need to fake out any rpcs the // master does opening/closing regions. Also need to fake out the address // of the 'remote' mocked up regionservers. - HMaster master = new HMaster(conf) { + ConsensusProvider cp = ConsensusProviderFactory.getConsensusProvider( + TESTUTIL.getConfiguration()); + HMaster master = new HMaster(conf, cp) { InetAddress getRemoteInetAddress(final int port, final long serverStartCode) throws UnknownHostException { // Return different address dependent on port passed. @@ -254,7 +260,9 @@ final ServerName deadServer = ServerName.valueOf("test.sample", 1, 100); final MockRegionServer rs0 = new MockRegionServer(conf, newServer); - HMaster master = new HMaster(conf) { + ConsensusProvider cp = ConsensusProviderFactory.getConsensusProvider( + TESTUTIL.getConfiguration()); + HMaster master = new HMaster(conf, cp) { @Override void assignMeta(MonitoredTask status, Set previouslyFailedMeatRSs) { } Index: hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java (revision ) @@ -50,6 +50,8 @@ import org.apache.hadoop.hbase.client.HConnection; import org.apache.hadoop.hbase.client.HConnectionTestingUtility; import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; +import org.apache.hadoop.hbase.consensus.ConsensusProviderFactory; import org.apache.hadoop.hbase.exceptions.DeserializationException; import org.apache.hadoop.hbase.executor.EventType; import org.apache.hadoop.hbase.executor.ExecutorService; @@ -886,7 +888,9 @@ Mockito.when(this.serverManager.createDestinationServersList()).thenReturn(destServers); // To avoid cast exception in DisableTableHandler process. HTU.getConfiguration().setInt(HConstants.MASTER_PORT, 0); - Server server = new HMaster(HTU.getConfiguration()); + + ConsensusProvider cp = ConsensusProviderFactory.getConsensusProvider(HTU.getConfiguration()); + Server server = new HMaster(HTU.getConfiguration(), cp); AssignmentManagerWithExtrasForTesting am = setUpMockedAssignmentManager(server, this.serverManager); AtomicBoolean gate = new AtomicBoolean(false); @@ -928,7 +932,8 @@ Mockito.when(this.serverManager.createDestinationServersList()).thenReturn(destServers); Mockito.when(this.serverManager.isServerOnline(SERVERNAME_A)).thenReturn(true); HTU.getConfiguration().setInt(HConstants.MASTER_PORT, 0); - Server server = new HMaster(HTU.getConfiguration()); + ConsensusProvider cp = ConsensusProviderFactory.getConsensusProvider(HTU.getConfiguration()); + Server server = new HMaster(HTU.getConfiguration(), cp); Whitebox.setInternalState(server, "serverManager", this.serverManager); AssignmentManagerWithExtrasForTesting am = setUpMockedAssignmentManager(server, this.serverManager); @@ -965,7 +970,8 @@ Mockito.when(this.serverManager.createDestinationServersList()).thenReturn(destServers); Mockito.when(this.serverManager.isServerOnline(SERVERNAME_A)).thenReturn(true); HTU.getConfiguration().setInt(HConstants.MASTER_PORT, 0); - Server server = new HMaster(HTU.getConfiguration()); + ConsensusProvider cp = ConsensusProviderFactory.getConsensusProvider(HTU.getConfiguration()); + Server server = new HMaster(HTU.getConfiguration(), cp); Whitebox.setInternalState(server, "serverManager", this.serverManager); AssignmentManagerWithExtrasForTesting am = setUpMockedAssignmentManager(server, this.serverManager); Index: hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java (revision ) @@ -26,6 +26,8 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.*; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; +import org.apache.hadoop.hbase.consensus.ConsensusProviderFactory; import org.apache.hadoop.hbase.ipc.RpcClient; import org.apache.hadoop.hbase.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.protobuf.generated.MasterProtos; @@ -46,7 +48,8 @@ TEST_UTIL.startMiniZKCluster(); Configuration conf = TEST_UTIL.getConfiguration(); conf.set(HConstants.MASTER_PORT, "0"); - HMaster hm = new HMaster(conf); + ConsensusProvider cp = ConsensusProviderFactory.getConsensusProvider(conf); + HMaster hm = new HMaster(conf, cp); ServerName sm = hm.getServerName(); RpcClient rpcClient = new RpcClient(conf, HConstants.CLUSTER_ID_DEFAULT); try { \ No newline at end of file Index: hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java (revision ) @@ -30,6 +30,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hbase.client.HConnectionManager; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.AdminService; import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ClientService; @@ -110,9 +111,9 @@ private User user = null; public static boolean TEST_SKIP_CLOSE = false; - public MiniHBaseClusterRegionServer(Configuration conf) + public MiniHBaseClusterRegionServer(Configuration conf, ConsensusProvider cp) throws IOException, InterruptedException { - super(conf); + super(conf, cp); this.user = User.getCurrent(); } Index: hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java (revision ) @@ -36,6 +36,7 @@ import org.apache.hadoop.hbase.LocalHBaseCluster; import org.apache.hadoop.hbase.ZooKeeperConnectionException; import org.apache.hadoop.hbase.client.HBaseAdmin; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; import org.apache.hadoop.hbase.regionserver.HRegionServer; import org.apache.hadoop.hbase.util.JVMClusterUtil; import org.apache.hadoop.hbase.util.ServerCommandLine; @@ -255,9 +256,9 @@ public static class LocalHMaster extends HMaster { private MiniZooKeeperCluster zkcluster = null; - public LocalHMaster(Configuration conf) + public LocalHMaster(Configuration conf, ConsensusProvider consensusProvider) throws IOException, KeeperException, InterruptedException { - super(conf); + super(conf, consensusProvider); } @Override Index: hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestClusterId.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestClusterId.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestClusterId.java (revision ) @@ -30,6 +30,8 @@ import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MediumTests; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; +import org.apache.hadoop.hbase.consensus.ConsensusProviderFactory; import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.hbase.util.JVMClusterUtil; @@ -70,9 +72,10 @@ TEST_UTIL.startMiniDFSCluster(1); Configuration conf = new Configuration(TEST_UTIL.getConfiguration()); + ConsensusProvider cp = ConsensusProviderFactory.getConsensusProvider(conf); //start region server, needs to be separate //so we get an unset clusterId - rst = JVMClusterUtil.createRegionServerThread(conf, + rst = JVMClusterUtil.createRegionServerThread(conf,cp, HRegionServer.class, 0); rst.start(); //Make sure RS is in blocking state Index: hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (revision ) @@ -68,6 +68,7 @@ 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.consensus.ConsensusProvider; import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; import org.apache.hadoop.hbase.exceptions.DeserializationException; import org.apache.hadoop.hbase.executor.ExecutorType; @@ -254,9 +255,9 @@ * @throws KeeperException * @throws IOException */ - public HMaster(final Configuration conf) + public HMaster(final Configuration conf, ConsensusProvider consensusProvider) throws IOException, KeeperException, InterruptedException { - super(conf); + super(conf, consensusProvider); this.rsFatals = new MemoryBoundedLogMessageBuffer( conf.getLong("hbase.master.buffer.for.rs.fatals", 1*1024*1024)); Index: hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java (revision 1cf2c530779316f1cd3cd41f9d3834365e02e423) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java (revision ) @@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.consensus.ConsensusProvider; import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.regionserver.HRegionServer; import org.apache.hadoop.util.ReflectionUtils; @@ -73,20 +74,23 @@ * Creates a {@link RegionServerThread}. * Call 'start' on the returned thread to make it run. * @param c Configuration to use. + * @param cp consensus provider to use * @param hrsc Class to create. * @param index Used distinguishing the object returned. * @throws IOException * @return Region server added. */ public static JVMClusterUtil.RegionServerThread createRegionServerThread( - final Configuration c, final Class hrsc, + final Configuration c, ConsensusProvider cp, final Class hrsc, final int index) throws IOException { HRegionServer server; try { - Constructor ctor = hrsc.getConstructor(Configuration.class); + + Constructor ctor = hrsc.getConstructor(Configuration.class, + ConsensusProvider.class); ctor.setAccessible(true); - server = ctor.newInstance(c); + server = ctor.newInstance(c, cp); } catch (InvocationTargetException ite) { Throwable target = ite.getTargetException(); throw new RuntimeException("Failed construction of RegionServer: " + @@ -122,18 +126,20 @@ * Creates a {@link MasterThread}. * Call 'start' on the returned thread to make it run. * @param c Configuration to use. + * @param cp consensus provider to use * @param hmc Class to create. * @param index Used distinguishing the object returned. * @throws IOException * @return Master added. */ public static JVMClusterUtil.MasterThread createMasterThread( - final Configuration c, final Class hmc, + final Configuration c, ConsensusProvider cp, final Class hmc, final int index) throws IOException { HMaster server; try { - server = hmc.getConstructor(Configuration.class).newInstance(c); + server = hmc.getConstructor(Configuration.class, ConsensusProvider.class). + newInstance(c, cp); } catch (InvocationTargetException ite) { Throwable target = ite.getTargetException(); throw new RuntimeException("Failed construction of Master: " +