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.hbase.classification.InterfaceAudience;
26
27 /**
28 * This provides an interface for maintaining a region server's replication queues. These queues
29 * keep track of the WALs and HFile references (if hbase.replication.bulkload.enabled is enabled)
30 * that still need to be replicated to remote clusters.
31 */
32 @InterfaceAudience.Private
33 public interface ReplicationQueues {
34
35 /**
36 * Initialize the region server replication queue interface.
37 * @param serverName The server name of the region server that owns the replication queues this
38 * interface manages.
39 */
40 void init(String serverName) throws ReplicationException;
41
42 /**
43 * Remove a replication queue.
44 * @param queueId a String that identifies the queue.
45 */
46 void removeQueue(String queueId);
47
48 /**
49 * Add a new WAL file to the given queue. If the queue does not exist it is created.
50 * @param queueId a String that identifies the queue.
51 * @param filename name of the WAL
52 */
53 void addLog(String queueId, String filename) throws ReplicationException;
54
55 /**
56 * Remove an WAL file from the given queue.
57 * @param queueId a String that identifies the queue.
58 * @param filename name of the WAL
59 */
60 void removeLog(String queueId, String filename);
61
62 /**
63 * Set the current position for a specific WAL in a given queue.
64 * @param queueId a String that identifies the queue
65 * @param filename name of the WAL
66 * @param position the current position in the file
67 */
68 void setLogPosition(String queueId, String filename, long position);
69
70 /**
71 * Get the current position for a specific WAL in a given queue.
72 * @param queueId a String that identifies the queue
73 * @param filename name of the WAL
74 * @return the current position in the file
75 */
76 long getLogPosition(String queueId, String filename) throws ReplicationException;
77
78 /**
79 * Remove all replication queues for this region server.
80 */
81 void removeAllQueues();
82
83 /**
84 * Get a list of all WALs in the given queue.
85 * @param queueId a String that identifies the queue
86 * @return a list of WALs, null if this region server is dead and has no outstanding queues
87 */
88 List<String> getLogsInQueue(String queueId);
89
90 /**
91 * Get a list of all queues for this region server.
92 * @return a list of queueIds, null if this region server is dead and has no outstanding queues
93 */
94 List<String> getAllQueues();
95
96 /**
97 * Take ownership for the set of queues belonging to a dead region server.
98 * @param regionserver the id of the dead region server
99 * @return A SortedMap of the queues that have been claimed, including a SortedSet of WALs in
100 * each queue. Returns an empty map if no queues were failed-over.
101 */
102 SortedMap<String, SortedSet<String>> claimQueues(String regionserver);
103
104 /**
105 * Get a list of all region servers that have outstanding replication queues. These servers could
106 * be alive, dead or from a previous run of the cluster.
107 * @return a list of server names
108 */
109 List<String> getListOfReplicators();
110
111 /**
112 * Checks if the provided znode is the same as this region server's
113 * @param znode to check
114 * @return if this is this rs's znode
115 */
116 boolean isThisOurZnode(String znode);
117
118 /**
119 * Add a peer to hfile reference queue if peer does not exist.
120 * @param peerId peer cluster id to be added
121 * @throws ReplicationException if fails to add a peer id to hfile reference queue
122 */
123 void addPeerToHFileRefs(String peerId) throws ReplicationException;
124
125 /**
126 * Add new hfile references to the queue.
127 * @param peerId peer cluster id to which the hfiles need to be replicated
128 * @param files list of hfile references to be added
129 * @throws ReplicationException if fails to add a hfile reference
130 */
131 void addHFileRefs(String peerId, List<String> files) throws ReplicationException;
132
133 /**
134 * Remove hfile references from the queue.
135 * @param peerId peer cluster id from which this hfile references needs to be removed
136 * @param files list of hfile references to be removed
137 */
138 void removeHFileRefs(String peerId, List<String> files);
139 }