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,8 @@ 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.ConsensusProviderFactory; +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,6 +392,8 @@ protected final RSRpcServices rpcServices; + protected ConsensusProvider consensus; + /** * Starts a HRegionServer at the default location * @@ -682,6 +686,10 @@ if (catalogTracker == null) { catalogTracker = createCatalogTracker(); catalogTracker.start(); + + consensus = ConsensusProviderFactory.getConsensusProvider(conf); + consensus.initialize(this); + consensus.start(); } } @@ -2126,6 +2134,10 @@ @Override public ZooKeeperWatcher getZooKeeper() { return zooKeeper; + } + + public ConsensusProvider getConsensus() { + return consensus; } @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-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/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/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/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,53 @@ +/** + * 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; + +/** + * Interface for consensus providers used by HBase + * for 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(); +}