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  
25  import org.apache.hadoop.hbase.classification.InterfaceAudience;
26  import org.apache.hadoop.conf.Configuration;
27  import org.apache.hadoop.hbase.TableName;
28  import org.apache.hadoop.hbase.util.Pair;
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    /**
49     * Add a new remote slave cluster for replication.
50     * @param peerId a short that identifies the cluster
51     * @param peerConfig configuration for the replication slave cluster
52     * @param tableCFs the table and column-family list which will be replicated for this peer or null
53     * for all table and column families
54     */
55    void addPeer(String peerId, ReplicationPeerConfig peerConfig, String tableCFs)
56        throws ReplicationException;
57  
58    /**
59     * Removes a remote slave cluster and stops the replication to it.
60     * @param peerId a short that identifies the cluster
61     */
62    void removePeer(String peerId) throws ReplicationException;
63  
64    boolean peerAdded(String peerId) throws ReplicationException;
65  
66    void peerRemoved(String peerId);
67  
68    /**
69     * Restart the replication to the specified remote slave cluster.
70     * @param peerId a short that identifies the cluster
71     */
72    void enablePeer(String peerId) throws ReplicationException;
73  
74    /**
75     * Stop the replication to the specified remote slave cluster.
76     * @param peerId a short that identifies the cluster
77     */
78    void disablePeer(String peerId) throws ReplicationException;
79  
80    /**
81     * Get the table and column-family list string of the peer from ZK.
82     * @param peerId a short that identifies the cluster
83     */
84    public String getPeerTableCFsConfig(String peerId) throws ReplicationException;
85  
86    /**
87     * Set the table and column-family list string of the peer to ZK.
88     * @param peerId a short that identifies the cluster
89     * @param tableCFs the table and column-family list which will be replicated for this peer
90     */
91    public void setPeerTableCFsConfig(String peerId, String tableCFs) throws ReplicationException;
92  
93    /**
94     * Get the table and column-family-list map of the peer.
95     * @param peerId a short that identifies the cluster
96     * @return the table and column-family list which will be replicated for this peer
97     */
98    public Map<TableName, List<String>> getTableCFs(String peerId);
99  
100   /**
101    * Returns the ReplicationPeer
102    * @param peerId id for the peer
103    * @return ReplicationPeer object
104    */
105   ReplicationPeer getPeer(String peerId);
106 
107   /**
108    * Returns the set of peerIds defined
109    * @return a Set of Strings for peerIds
110    */
111   public Set<String> getPeerIds();
112 
113   /**
114    * Get the replication status for the specified connected remote slave cluster.
115    * The value might be read from cache, so it is recommended to
116    * use {@link #getStatusOfPeerFromBackingStore(String)}
117    * if reading the state after enabling or disabling it.
118    * @param peerId a short that identifies the cluster
119    * @return true if replication is enabled, false otherwise.
120    */
121   boolean getStatusOfPeer(String peerId);
122 
123   /**
124    * Get the replication status for the specified remote slave cluster, which doesn't
125    * have to be connected. The state is read directly from the backing store.
126    * @param peerId a short that identifies the cluster
127    * @return true if replication is enabled, false otherwise.
128    * @throws IOException Throws if there's an error contacting the store
129    */
130   boolean getStatusOfPeerFromBackingStore(String peerId) throws ReplicationException;
131 
132   /**
133    * List the cluster replication configs of all remote slave clusters (whether they are
134    * enabled/disabled or connected/disconnected).
135    * @return A map of peer ids to peer cluster keys
136    */
137   Map<String, ReplicationPeerConfig> getAllPeerConfigs();
138 
139   /**
140    * List the peer ids of all remote slave clusters (whether they are enabled/disabled or
141    * connected/disconnected).
142    * @return A list of peer ids
143    */
144   List<String> getAllPeerIds();
145 
146   /**
147    * Returns the configured ReplicationPeerConfig for this peerId
148    * @param peerId a short name that identifies the cluster
149    * @return ReplicationPeerConfig for the peer
150    */
151   ReplicationPeerConfig getReplicationPeerConfig(String peerId) throws ReplicationException;
152 
153   /**
154    * Returns the configuration needed to talk to the remote slave cluster.
155    * @param peerId a short that identifies the cluster
156    * @return the configuration for the peer cluster, null if it was unable to get the configuration
157    */
158   Pair<ReplicationPeerConfig, Configuration> getPeerConf(String peerId) throws ReplicationException;
159 }