From ece91da0d2804b2225cd8c4f83c6242b2068d1aa Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Wed, 23 Apr 2014 22:58:51 +0000 Subject: [PATCH] HBASE-11025 Infrastructure for pluggable consensus service (Mikhail Antonov) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1589538 13f79535-47bb-0310-9956-ffa450edef68 --- .../hbase/consensus/ConsensusProvider.java | 58 +++++++++++++++++++ .../consensus/ConsensusProviderFactory.java | 43 ++++++++++++++ .../hbase/consensus/ZkConsensusProvider.java | 50 ++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ConsensusProvider.java create mode 100644 hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ConsensusProviderFactory.java create mode 100644 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/ConsensusProvider.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ConsensusProvider.java new file mode 100644 index 00000000000..bc9533735f3 --- /dev/null +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ConsensusProvider.java @@ -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(); +} diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ConsensusProviderFactory.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ConsensusProviderFactory.java new file mode 100644 index 00000000000..3429e04e436 --- /dev/null +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ConsensusProviderFactory.java @@ -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); + } +} 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 new file mode 100644 index 00000000000..09f6191cb66 --- /dev/null +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/consensus/ZkConsensusProvider.java @@ -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; + } +}