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
This commit is contained in:
parent
d5db1fb545
commit
ece91da0d2
|
@ -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();
|
||||
}
|
|
@ -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<? extends ConsensusProvider> consensusKlass =
|
||||
conf.getClass(HConstants.HBASE_CONSENSUS_PROVIDER_CLASS, ZkConsensusProvider.class,
|
||||
ConsensusProvider.class);
|
||||
return ReflectionUtils.newInstance(consensusKlass, conf);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue