View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.coordination;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  import org.apache.hadoop.hbase.classification.InterfaceAudience;
23  import org.apache.hadoop.hbase.CoordinatedStateException;
24  import org.apache.hadoop.hbase.HBaseInterfaceAudience;
25  import org.apache.hadoop.hbase.Server;
26  import org.apache.hadoop.hbase.TableStateManager;
27  import org.apache.hadoop.hbase.zookeeper.ZKTableStateManager;
28  import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
29  import org.apache.zookeeper.KeeperException;
30  
31  /**
32   * ZooKeeper-based implementation of {@link org.apache.hadoop.hbase.CoordinatedStateManager}.
33   */
34  @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
35  public class ZkCoordinatedStateManager extends BaseCoordinatedStateManager {
36    private static final Log LOG = LogFactory.getLog(ZkCoordinatedStateManager.class);
37    protected Server server;
38    protected ZooKeeperWatcher watcher;
39    protected SplitTransactionCoordination splitTransactionCoordination;
40    protected CloseRegionCoordination closeRegionCoordination;
41    protected SplitLogWorkerCoordination splitLogWorkerCoordination;
42    protected SplitLogManagerCoordination splitLogManagerCoordination;
43    protected OpenRegionCoordination openRegionCoordination;
44    protected RegionMergeCoordination regionMergeCoordination;
45  
46    @Override
47    public void initialize(Server server) {
48      this.server = server;
49      this.watcher = server.getZooKeeper();
50      splitLogWorkerCoordination = new ZkSplitLogWorkerCoordination(this, watcher);
51      splitLogManagerCoordination = new ZKSplitLogManagerCoordination(this, watcher);
52      splitTransactionCoordination = new ZKSplitTransactionCoordination(this, watcher);
53      closeRegionCoordination = new ZkCloseRegionCoordination(this, watcher);
54      openRegionCoordination = new ZkOpenRegionCoordination(this, watcher);
55      regionMergeCoordination = new ZkRegionMergeCoordination(this, watcher);
56    }
57  
58    @Override
59    public Server getServer() {
60      return server;
61    }
62  
63    @Override
64    public TableStateManager getTableStateManager() throws InterruptedException,
65        CoordinatedStateException {
66      try {
67        return new ZKTableStateManager(server.getZooKeeper());
68      } catch (KeeperException e) {
69        throw new CoordinatedStateException(e);
70      }
71    }
72  
73    @Override
74    public SplitLogWorkerCoordination getSplitLogWorkerCoordination() {
75      return splitLogWorkerCoordination;
76      }
77    @Override
78    public SplitLogManagerCoordination getSplitLogManagerCoordination() {
79      return splitLogManagerCoordination;
80    }
81  
82    @Override
83    public SplitTransactionCoordination getSplitTransactionCoordination() {
84      return splitTransactionCoordination;
85    }
86  
87    @Override
88    public CloseRegionCoordination getCloseRegionCoordination() {
89      return closeRegionCoordination;
90    }
91  
92    @Override
93    public OpenRegionCoordination getOpenRegionCoordination() {
94      return openRegionCoordination;
95    }
96  
97    @Override
98    public RegionMergeCoordination getRegionMergeCoordination() {
99      return regionMergeCoordination;
100   }
101 }