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 /** 49 * Add a new remote slave cluster for replication. 50 * @param peerId a short that identifies the cluster 51 * @param clusterKey the concatenation of the slave cluster's: 52 * hbase.zookeeper.quorum:hbase.zookeeper.property.clientPort:zookeeper.znode.parent 53 */ 54 void addPeer(String peerId, String clusterKey) throws ReplicationException; 55 56 /** 57 * Removes a remote slave cluster and stops the replication to it. 58 * @param peerId a short that identifies the cluster 59 */ 60 void removePeer(String peerId) throws ReplicationException; 61 62 /** 63 * Restart the replication to the specified remote slave cluster. 64 * @param peerId a short that identifies the cluster 65 */ 66 void enablePeer(String peerId) throws ReplicationException; 67 68 /** 69 * Stop the replication to the specified remote slave cluster. 70 * @param peerId a short that identifies the cluster 71 */ 72 void disablePeer(String peerId) throws ReplicationException; 73 74 /** 75 * Get the replication status for the specified connected remote slave cluster. 76 * The value might be read from cache, so it is recommended to 77 * use {@link #getStatusOfPeerFromBackingStore(String)} 78 * if reading the state after enabling or disabling it. 79 * @param peerId a short that identifies the cluster 80 * @return true if replication is enabled, false otherwise. 81 */ 82 boolean getStatusOfConnectedPeer(String peerId); 83 84 /** 85 * Get the replication status for the specified remote slave cluster, which doesn't 86 * have to be connected. The state is read directly from the backing store. 87 * @param peerId a short that identifies the cluster 88 * @return true if replication is enabled, false otherwise. 89 * @throws IOException Throws if there's an error contacting the store 90 */ 91 boolean getStatusOfPeerFromBackingStore(String peerId) throws ReplicationException; 92 93 /** 94 * Get a set of all connected remote slave clusters. 95 * @return set of peer ids 96 */ 97 Set<String> getConnectedPeers(); 98 99 /** 100 * List the cluster keys of all remote slave clusters (whether they are enabled/disabled or 101 * connected/disconnected). 102 * @return A map of peer ids to peer cluster keys 103 */ 104 Map<String, String> getAllPeerClusterKeys(); 105 106 /** 107 * List the peer ids of all remote slave clusters (whether they are enabled/disabled or 108 * connected/disconnected). 109 * @return A list of peer ids 110 */ 111 List<String> getAllPeerIds(); 112 113 /** 114 * Attempt to connect to a new remote slave cluster. 115 * @param peerId a short that identifies the cluster 116 * @return true if a new connection was made, false if no new connection was made. 117 */ 118 boolean connectToPeer(String peerId) throws ReplicationException; 119 120 /** 121 * Disconnect from a remote slave cluster. 122 * @param peerId a short that identifies the cluster 123 */ 124 void disconnectFromPeer(String peerId); 125 126 /** 127 * Returns all region servers from given connected remote slave cluster. 128 * @param peerId a short that identifies the cluster 129 * @return addresses of all region servers in the peer cluster. Returns an empty list if the peer 130 * cluster is unavailable or there are no region servers in the cluster. 131 */ 132 List<ServerName> getRegionServersOfConnectedPeer(String peerId); 133 134 /** 135 * Get the timestamp of the last change in composition of a given peer cluster. 136 * @param peerId identifier of the peer cluster for which the timestamp is requested 137 * @return the timestamp (in milliseconds) of the last change to the composition of 138 * the peer cluster 139 */ 140 long getTimestampOfLastChangeToPeer(String peerId); 141 142 /** 143 * Returns the UUID of the provided peer id. 144 * @param peerId the peer's ID that will be converted into a UUID 145 * @return a UUID or null if the peer cluster does not exist or is not connected. 146 */ 147 UUID getPeerUUID(String peerId); 148 149 /** 150 * Returns the configuration needed to talk to the remote slave cluster. 151 * @param peerId a short that identifies the cluster 152 * @return the configuration for the peer cluster, null if it was unable to get the configuration 153 */ 154 Configuration getPeerConf(String peerId) throws ReplicationException; 155 }