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.SortedMap;
23 import java.util.SortedSet;
24
25 import org.apache.hadoop.fs.Path;
26 import org.apache.hadoop.hbase.classification.InterfaceAudience;
27 import org.apache.hadoop.hbase.util.Pair;
28
29 /**
30 * This provides an interface for maintaining a region server's replication queues. These queues
31 * keep track of the WALs and HFile references (if hbase.replication.bulkload.enabled is enabled)
32 * that still need to be replicated to remote clusters.
33 */
34 @InterfaceAudience.Private
35 public interface ReplicationQueues {
36
37 /**
38 * Initialize the region server replication queue interface.
39 * @param serverName The server name of the region server that owns the replication queues this
40 * interface manages.
41 */
42 void init(String serverName) throws ReplicationException;
43
44 /**
45 * Remove a replication queue.
46 * @param queueId a String that identifies the queue.
47 */
48 void removeQueue(String queueId);
49
50 /**
51 * Add a new WAL file to the given queue. If the queue does not exist it is created.
52 * @param queueId a String that identifies the queue.
53 * @param filename name of the WAL
54 */
55 void addLog(String queueId, String filename) throws ReplicationException;
56
57 /**
58 * Remove an WAL file from the given queue.
59 * @param queueId a String that identifies the queue.
60 * @param filename name of the WAL
61 */
62 void removeLog(String queueId, String filename) throws ReplicationSourceWithoutPeerException;
63
64 /**
65 * Set the current position for a specific WAL in a given queue.
66 * @param queueId a String that identifies the queue
67 * @param filename name of the WAL
68 * @param position the current position in the file
69 */
70 void setLogPosition(String queueId, String filename, long position);
71
72 /**
73 * Get the current position for a specific WAL in a given queue.
74 * @param queueId a String that identifies the queue
75 * @param filename name of the WAL
76 * @return the current position in the file
77 */
78 long getLogPosition(String queueId, String filename) throws ReplicationException;
79
80 /**
81 * Remove all replication queues for this region server.
82 */
83 void removeAllQueues();
84
85 /**
86 * Get a list of all WALs in the given queue.
87 * @param queueId a String that identifies the queue
88 * @return a list of WALs, null if this region server is dead and has no outstanding queues
89 */
90 List<String> getLogsInQueue(String queueId);
91
92 /**
93 * Get a list of all queues for this region server.
94 * @return a list of queueIds, null if this region server is dead and has no outstanding queues
95 */
96 List<String> getAllQueues();
97
98 /**
99 * Checks if the provided znode is the same as this region server's
100 * @param regionserver the id of the region server
101 * @return if this is this rs's znode
102 */
103 boolean isThisOurRegionServer(String regionserver);
104
105 /**
106 * Get queueIds from a dead region server, whose queues has not been claimed by other region
107 * servers.
108 * @return empty if the queue exists but no children, null if the queue does not exist.
109 */
110 List<String> getUnClaimedQueueIds(String regionserver);
111
112 /**
113 * Take ownership for the queue identified by queueId and belongs to a dead region server.
114 * @param regionserver the id of the dead region server
115 * @param queueId the id of the queue
116 * @return the new PeerId and A SortedSet of WALs in its queue, and null if no unclaimed queue.
117 */
118 Pair<String, SortedSet<String>> claimQueue(String regionserver, String queueId);
119
120 /**
121 * Remove the znode of region server if the queue is empty.
122 * @param regionserver
123 */
124 void removeReplicatorIfQueueIsEmpty(String regionserver);
125 /**
126 * Get a list of all region servers that have outstanding replication queues. These servers could
127 * be alive, dead or from a previous run of the cluster.
128 * @return a list of server names
129 * @throws ReplicationException
130 */
131 List<String> getListOfReplicators() throws ReplicationException;
132
133 /**
134 * Checks if the provided znode is the same as this region server's
135 * @param znode to check
136 * @return if this is this rs's znode
137 */
138 boolean isThisOurZnode(String znode);
139
140 /**
141 * Add a peer to hfile reference queue if peer does not exist.
142 * @param peerId peer cluster id to be added
143 * @throws ReplicationException if fails to add a peer id to hfile reference queue
144 */
145 void addPeerToHFileRefs(String peerId) throws ReplicationException;
146
147 /**
148 * Remove a peer from hfile reference queue.
149 * @param peerId peer cluster id to be removed
150 */
151 void removePeerFromHFileRefs(String peerId);
152
153 /**
154 * Add new hfile references to the queue.
155 * @param peerId peer cluster id to which the hfiles need to be replicated
156 * @param pairs list of pairs of { HFile location in staging dir, HFile path in region dir which
157 * will be added in the queue }
158 * @throws ReplicationException if fails to add a hfile reference
159 */
160 void addHFileRefs(String peerId, List<Pair<Path, Path>> pairs) throws ReplicationException;
161
162 /**
163 * Remove hfile references from the queue.
164 * @param peerId peer cluster id from which this hfile references needs to be removed
165 * @param files list of hfile references to be removed
166 */
167 void removeHFileRefs(String peerId, List<String> files);
168 }