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