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 java.io.IOException;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.hadoop.hbase.classification.InterfaceAudience;
25  import org.apache.hadoop.hbase.CoordinatedStateException;
26  import org.apache.hadoop.hbase.HBaseInterfaceAudience;
27  import org.apache.hadoop.hbase.Server;
28  import org.apache.hadoop.hbase.TableStateManager;
29  import org.apache.hadoop.hbase.zookeeper.ZKTableStateManager;
30  import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
31  import org.apache.hadoop.hbase.procedure.ProcedureCoordinatorRpcs;
32  import org.apache.hadoop.hbase.procedure.ProcedureMemberRpcs;
33  import org.apache.hadoop.hbase.procedure.ZKProcedureCoordinatorRpcs;
34  import org.apache.hadoop.hbase.procedure.ZKProcedureMemberRpcs;
35  import org.apache.zookeeper.KeeperException;
36  
37  /**
38   * ZooKeeper-based implementation of {@link org.apache.hadoop.hbase.CoordinatedStateManager}.
39   */
40  @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
41  public class ZkCoordinatedStateManager extends BaseCoordinatedStateManager {
42    private static final Log LOG = LogFactory.getLog(ZkCoordinatedStateManager.class);
43    protected Server server;
44    protected ZooKeeperWatcher watcher;
45    protected SplitTransactionCoordination splitTransactionCoordination;
46    protected CloseRegionCoordination closeRegionCoordination;
47    protected SplitLogWorkerCoordination splitLogWorkerCoordination;
48    protected SplitLogManagerCoordination splitLogManagerCoordination;
49    protected OpenRegionCoordination openRegionCoordination;
50    protected RegionMergeCoordination regionMergeCoordination;
51  
52    @Override
53    public void initialize(Server server) {
54      this.server = server;
55      this.watcher = server.getZooKeeper();
56      splitLogWorkerCoordination = new ZkSplitLogWorkerCoordination(this, watcher);
57      splitLogManagerCoordination = new ZKSplitLogManagerCoordination(this, watcher);
58      splitTransactionCoordination = new ZKSplitTransactionCoordination(this, watcher);
59      closeRegionCoordination = new ZkCloseRegionCoordination(this, watcher);
60      openRegionCoordination = new ZkOpenRegionCoordination(this, watcher);
61      regionMergeCoordination = new ZkRegionMergeCoordination(this, watcher);
62    }
63  
64    @Override
65    public Server getServer() {
66      return server;
67    }
68  
69    @Override
70    public TableStateManager getTableStateManager() throws InterruptedException,
71        CoordinatedStateException {
72      try {
73        return new ZKTableStateManager(server.getZooKeeper());
74      } catch (KeeperException e) {
75        throw new CoordinatedStateException(e);
76      }
77    }
78  
79    @Override
80    public SplitLogWorkerCoordination getSplitLogWorkerCoordination() {
81      return splitLogWorkerCoordination;
82      }
83    @Override
84    public SplitLogManagerCoordination getSplitLogManagerCoordination() {
85      return splitLogManagerCoordination;
86    }
87  
88    @Override
89    public SplitTransactionCoordination getSplitTransactionCoordination() {
90      return splitTransactionCoordination;
91    }
92  
93    @Override
94    public CloseRegionCoordination getCloseRegionCoordination() {
95      return closeRegionCoordination;
96    }
97  
98    @Override
99    public OpenRegionCoordination getOpenRegionCoordination() {
100     return openRegionCoordination;
101   }
102 
103   @Override
104   public RegionMergeCoordination getRegionMergeCoordination() {
105     return regionMergeCoordination;
106   }
107 
108   @Override
109   public ProcedureCoordinatorRpcs getProcedureCoordinatorRpcs(String procType, String coordNode)
110       throws IOException {
111     return new ZKProcedureCoordinatorRpcs(watcher, procType, coordNode);
112   }
113 
114   @Override
115   public ProcedureMemberRpcs getProcedureMemberRpcs(String procType) throws IOException {
116     return new ZKProcedureMemberRpcs(watcher, procType);
117   }
118 }