View Javadoc

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.replication;
20  
21  import java.io.IOException;
22  import java.util.List;
23  import java.util.Map;
24  import java.util.Set;
25  import java.util.UUID;
26  
27  import org.apache.hadoop.classification.InterfaceAudience;
28  import org.apache.hadoop.conf.Configuration;
29  import org.apache.hadoop.hbase.ServerName;
30  import org.apache.zookeeper.KeeperException;
31  
32  /**
33   * This provides an interface for maintaining a set of peer clusters. These peers are remote slave
34   * clusters that data is replicated to. A peer cluster can be in three different states:
35   *
36   * 1. Not-Registered - There is no notion of the peer cluster.
37   * 2. Registered - The peer has an id and is being tracked but there is no connection.
38   * 3. Connected - There is an active connection to the remote peer.
39   *
40   * In the registered or connected state, a peer cluster can either be enabled or disabled.
41   */
42  @InterfaceAudience.Private
43  public interface ReplicationPeers {
44  
45    /**
46     * Initialize the ReplicationPeers interface.
47     * @throws KeeperException
48     */
49    void init() throws IOException, KeeperException;
50  
51    /**
52     * Add a new remote slave cluster for replication.
53     * @param peerId a short that identifies the cluster
54     * @param clusterKey the concatenation of the slave cluster's:
55     *          hbase.zookeeper.quorum:hbase.zookeeper.property.clientPort:zookeeper.znode.parent
56     */
57    void addPeer(String peerId, String clusterKey) throws IOException;
58  
59    /**
60     * Removes a remote slave cluster and stops the replication to it.
61     * @param peerId a short that identifies the cluster
62     */
63    void removePeer(String peerId) throws IOException;
64  
65    /**
66     * Restart the replication to the specified remote slave cluster.
67     * @param peerId a short that identifies the cluster
68     */
69    void enablePeer(String peerId) throws IOException;
70  
71    /**
72     * Stop the replication to the specified remote slave cluster.
73     * @param peerId a short that identifies the cluster
74     */
75    void disablePeer(String peerId) throws IOException;
76  
77    /**
78     * Get the replication status for the specified connected remote slave cluster.
79     * The value might be read from cache, so it is recommended to
80     * use {@link #getStatusOfPeerFromBackingStore(String)}
81     * if reading the state after enabling or disabling it.
82     * @param peerId a short that identifies the cluster
83     * @return true if replication is enabled, false otherwise.
84     */
85    boolean getStatusOfConnectedPeer(String peerId);
86  
87    /**
88     * Get the replication status for the specified remote slave cluster, which doesn't
89     * have to be connected. The state is read directly from the backing store.
90     * @param peerId a short that identifies the cluster
91     * @return true if replication is enabled, false otherwise.
92     * @throws IOException Throws if there's an error contacting the store
93     */
94    boolean getStatusOfPeerFromBackingStore(String peerId) throws IOException;
95  
96    /**
97     * Get a set of all connected remote slave clusters.
98     * @return set of peer ids
99     */
100   Set<String> getConnectedPeers();
101 
102   /**
103    * List the cluster keys of all remote slave clusters (whether they are enabled/disabled or
104    * connected/disconnected).
105    * @return A map of peer ids to peer cluster keys
106    */
107   Map<String, String> getAllPeerClusterKeys();
108 
109   /**
110    * List the peer ids of all remote slave clusters (whether they are enabled/disabled or
111    * connected/disconnected).
112    * @return A list of peer ids
113    */
114   List<String> getAllPeerIds();
115 
116   /**
117    * Attempt to connect to a new remote slave cluster.
118    * @param peerId a short that identifies the cluster
119    * @return true if a new connection was made, false if no new connection was made.
120    */
121   boolean connectToPeer(String peerId) throws IOException, KeeperException;
122 
123   /**
124    * Disconnect from a remote slave cluster.
125    * @param peerId a short that identifies the cluster
126    */
127   void disconnectFromPeer(String peerId);
128 
129   /**
130    * Returns all region servers from given connected remote slave cluster.
131    * @param peerId a short that identifies the cluster
132    * @return addresses of all region servers in the peer cluster. Returns an empty list if the peer
133    *         cluster is unavailable or there are no region servers in the cluster.
134    */
135   List<ServerName> getRegionServersOfConnectedPeer(String peerId);
136 
137   /**
138    * Get the timestamp of the last change in composition of a given peer cluster.
139    * @param peerId identifier of the peer cluster for which the timestamp is requested
140    * @return the timestamp (in milliseconds) of the last change to the composition of
141    *         the peer cluster
142    */
143   long getTimestampOfLastChangeToPeer(String peerId);
144 
145   /**
146    * Returns the UUID of the provided peer id.
147    * @param peerId the peer's ID that will be converted into a UUID
148    * @return a UUID or null if the peer cluster does not exist or is not connected.
149    */
150   UUID getPeerUUID(String peerId);
151 
152   /**
153    * Returns the configuration needed to talk to the remote slave cluster.
154    * @param peerId a short that identifies the cluster
155    * @return the configuration for the peer cluster, null if it was unable to get the configuration
156    */
157   Configuration getPeerConf(String peerId) throws KeeperException;
158 }