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.util.List;
22  import java.util.Map;
23  import java.util.Set;
24  import java.util.UUID;
25  
26  import org.apache.hadoop.classification.InterfaceAudience;
27  import org.apache.hadoop.conf.Configuration;
28  import org.apache.hadoop.hbase.ServerName;
29  
30  /**
31   * This provides an interface for maintaining a set of peer clusters. These peers are remote slave
32   * clusters that data is replicated to. A peer cluster can be in three different states:
33   *
34   * 1. Not-Registered - There is no notion of the peer cluster.
35   * 2. Registered - The peer has an id and is being tracked but there is no connection.
36   * 3. Connected - There is an active connection to the remote peer.
37   *
38   * In the registered or connected state, a peer cluster can either be enabled or disabled.
39   */
40  @InterfaceAudience.Private
41  public interface ReplicationPeers {
42  
43    /**
44     * Initialize the ReplicationPeers interface.
45     */
46    void init() throws ReplicationException;
47    /**
48     * Add a new remote slave cluster for replication.
49     * @param peerId a short that identifies the cluster
50     * @param clusterKey the concatenation of the slave cluster's:
51     *          hbase.zookeeper.quorum:hbase.zookeeper.property.clientPort:zookeeper.znode.parent
52     */
53    void addPeer(String peerId, String clusterKey) throws ReplicationException;
54  
55    /**
56     * Add a new remote slave cluster for replication.
57     * @param peerId a short that identifies the cluster
58     * @param clusterKey the concatenation of the slave cluster's:
59     *          hbase.zookeeper.quorum:hbase.zookeeper.property.clientPort:zookeeper.znode.parent
60     * @param tableCFs the table and column-family list which will be replicated for this peer
61     */
62    void addPeer(String peerId, String clusterKey, String tableCFs) throws ReplicationException;
63  
64    /**
65     * Removes a remote slave cluster and stops the replication to it.
66     * @param peerId a short that identifies the cluster
67     */
68    void removePeer(String peerId) throws ReplicationException;
69  
70    /**
71     * Restart the replication to the specified remote slave cluster.
72     * @param peerId a short that identifies the cluster
73     */
74    void enablePeer(String peerId) throws ReplicationException;
75  
76    /**
77     * Stop the replication to the specified remote slave cluster.
78     * @param peerId a short that identifies the cluster
79     */
80    void disablePeer(String peerId) throws ReplicationException;
81  
82    /**
83     * Get the table and column-family list string of the peer from ZK.
84     * @param peerId a short that identifies the cluster
85     */
86    public String getPeerTableCFsConfig(String peerId) throws ReplicationException;
87  
88    /**
89     * Set the table and column-family list string of the peer to ZK.
90     * @param peerId a short that identifies the cluster
91     * @param tableCFs the table and column-family list which will be replicated for this peer
92     */
93    public void setPeerTableCFsConfig(String peerId, String tableCFs) throws ReplicationException;
94  
95    /**
96     * Get the table and column-family-list map of the peer.
97     * @param peerId a short that identifies the cluster
98     * @return the table and column-family list which will be replicated for this peer
99     */
100   public Map<String, List<String>> getTableCFs(String peerId);
101 
102   /**
103    * Get the replication status for the specified connected remote slave cluster.
104    * The value might be read from cache, so it is recommended to
105    * use {@link #getStatusOfPeerFromBackingStore(String)}
106    * if reading the state after enabling or disabling it.
107    * @param peerId a short that identifies the cluster
108    * @return true if replication is enabled, false otherwise.
109    */
110   boolean getStatusOfConnectedPeer(String peerId);
111 
112   /**
113    * Get the replication status for the specified remote slave cluster, which doesn't
114    * have to be connected. The state is read directly from the backing store.
115    * @param peerId a short that identifies the cluster
116    * @return true if replication is enabled, false otherwise.
117    * @throws IOException Throws if there's an error contacting the store
118    */
119   boolean getStatusOfPeerFromBackingStore(String peerId) throws ReplicationException;
120 
121   /**
122    * Get a set of all connected remote slave clusters.
123    * @return set of peer ids
124    */
125   Set<String> getConnectedPeers();
126 
127   /**
128    * List the cluster keys of all remote slave clusters (whether they are enabled/disabled or
129    * connected/disconnected).
130    * @return A map of peer ids to peer cluster keys
131    */
132   Map<String, String> getAllPeerClusterKeys();
133 
134   /**
135    * List the peer ids of all remote slave clusters (whether they are enabled/disabled or
136    * connected/disconnected).
137    * @return A list of peer ids
138    */
139   List<String> getAllPeerIds();
140 
141   /**
142    * Attempt to connect to a new remote slave cluster.
143    * @param peerId a short that identifies the cluster
144    * @return true if a new connection was made, false if no new connection was made.
145    */
146   boolean connectToPeer(String peerId) throws ReplicationException;
147 
148   /**
149    * Disconnect from a remote slave cluster.
150    * @param peerId a short that identifies the cluster
151    */
152   void disconnectFromPeer(String peerId);
153 
154   /**
155    * Returns all region servers from given connected remote slave cluster.
156    * @param peerId a short that identifies the cluster
157    * @return addresses of all region servers in the peer cluster. Returns an empty list if the peer
158    *         cluster is unavailable or there are no region servers in the cluster.
159    */
160   List<ServerName> getRegionServersOfConnectedPeer(String peerId);
161 
162   /**
163    * Get the timestamp of the last change in composition of a given peer cluster.
164    * @param peerId identifier of the peer cluster for which the timestamp is requested
165    * @return the timestamp (in milliseconds) of the last change to the composition of
166    *         the peer cluster
167    */
168   long getTimestampOfLastChangeToPeer(String peerId);
169 
170   /**
171    * Returns the UUID of the provided peer id.
172    * @param peerId the peer's ID that will be converted into a UUID
173    * @return a UUID or null if the peer cluster does not exist or is not connected.
174    */
175   UUID getPeerUUID(String peerId);
176 
177   /**
178    * Returns the configuration needed to talk to the remote slave cluster.
179    * @param peerId a short that identifies the cluster
180    * @return the configuration for the peer cluster, null if it was unable to get the configuration
181    */
182   Configuration getPeerConf(String peerId) throws ReplicationException;
183 }