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.Collection;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Set;
25
26 import org.apache.hadoop.hbase.classification.InterfaceAudience;
27 import org.apache.hadoop.conf.Configuration;
28 import org.apache.hadoop.hbase.TableName;
29 import org.apache.hadoop.hbase.util.Pair;
30
31 /**
32 * This provides an interface for maintaining a set of peer clusters. These peers are remote slave
33 * clusters that data is replicated to. A peer cluster can be in three different states:
34 *
35 * 1. Not-Registered - There is no notion of the peer cluster.
36 * 2. Registered - The peer has an id and is being tracked but there is no connection.
37 * 3. Connected - There is an active connection to the remote peer.
38 *
39 * In the registered or connected state, a peer cluster can either be enabled or disabled.
40 */
41 @InterfaceAudience.Private
42 public interface ReplicationPeers {
43
44 /**
45 * Initialize the ReplicationPeers interface.
46 */
47 void init() throws ReplicationException;
48
49 /**
50 * Add a new remote slave cluster for replication.
51 * @param peerId a short that identifies the cluster
52 * @param peerConfig configuration for the replication slave cluster
53 */
54 void addPeer(String peerId, ReplicationPeerConfig peerConfig)
55 throws ReplicationException;
56
57 /**
58 * Removes a remote slave cluster and stops the replication to it.
59 * @param peerId a short that identifies the cluster
60 */
61 void removePeer(String peerId) throws ReplicationException;
62
63 boolean peerAdded(String peerId) throws ReplicationException;
64
65 void peerRemoved(String peerId);
66
67 /**
68 * Restart the replication to the specified remote slave cluster.
69 * @param peerId a short that identifies the cluster
70 */
71 void enablePeer(String peerId) throws ReplicationException;
72
73 /**
74 * Stop the replication to the specified remote slave cluster.
75 * @param peerId a short that identifies the cluster
76 */
77 void disablePeer(String peerId) throws ReplicationException;
78
79 /**
80 * Get the table and column-family list of the peer from ZK.
81 * @param peerId a short that identifies the cluster
82 */
83 public Map<TableName, List<String>> getPeerTableCFsConfig(String peerId)
84 throws ReplicationException;
85
86 /**
87 * Set the table and column-family list 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,
92 Map<TableName, ? extends Collection<String>> tableCFs) throws ReplicationException;
93
94 /**
95 * Get the table and column-family-list map of the peer.
96 * @param peerId a short that identifies the cluster
97 * @return the table and column-family list which will be replicated for this peer
98 */
99 public Map<TableName, List<String>> getTableCFs(String peerId);
100
101 /**
102 * Returns the ReplicationPeer
103 * @param peerId id for the peer
104 * @return ReplicationPeer object
105 */
106 ReplicationPeer getPeer(String peerId);
107
108 /**
109 * Returns the set of peerIds defined
110 * @return a Set of Strings for peerIds
111 */
112 public Set<String> getPeerIds();
113
114 /**
115 * Get the replication status for the specified connected remote slave cluster.
116 * The value might be read from cache, so it is recommended to
117 * use {@link #getStatusOfPeerFromBackingStore(String)}
118 * if reading the state after enabling or disabling it.
119 * @param peerId a short that identifies the cluster
120 * @return true if replication is enabled, false otherwise.
121 */
122 boolean getStatusOfPeer(String peerId);
123
124 /**
125 * Get the replication status for the specified remote slave cluster, which doesn't
126 * have to be connected. The state is read directly from the backing store.
127 * @param peerId a short that identifies the cluster
128 * @return true if replication is enabled, false otherwise.
129 * @throws ReplicationException thrown if there's an error contacting the store
130 */
131 boolean getStatusOfPeerFromBackingStore(String peerId) throws ReplicationException;
132
133 /**
134 * List the cluster replication configs of all remote slave clusters (whether they are
135 * enabled/disabled or connected/disconnected).
136 * @return A map of peer ids to peer cluster keys
137 */
138 Map<String, ReplicationPeerConfig> getAllPeerConfigs();
139
140 /**
141 * List the peer ids of all remote slave clusters (whether they are enabled/disabled or
142 * connected/disconnected).
143 * @return A list of peer ids
144 */
145 List<String> getAllPeerIds();
146
147 /**
148 * Returns the configured ReplicationPeerConfig for this peerId
149 * @param peerId a short name that identifies the cluster
150 * @return ReplicationPeerConfig for the peer
151 */
152 ReplicationPeerConfig getReplicationPeerConfig(String peerId) throws ReplicationException;
153
154 /**
155 * Returns the configuration needed to talk to the remote slave cluster.
156 * @param peerId a short that identifies the cluster
157 * @return the configuration for the peer cluster, null if it was unable to get the configuration
158 */
159 Pair<ReplicationPeerConfig, Configuration> getPeerConf(String peerId) throws ReplicationException;
160
161 /**
162 * Updates replication peer configuration and/or peer data
163 * @param id a short that identifies the cluster
164 * @param peerConfig configuration for the replication slave cluster
165 * @throws ReplicationException
166 */
167 void updatePeerConfig(String id, ReplicationPeerConfig peerConfig) throws ReplicationException;
168 }