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  
27  /**
28   * This provides an interface for maintaining a region server's replication queues. These queues
29   * keep track of the WALs that still need to be replicated to remote clusters.
30   */
31  @InterfaceAudience.Private
32  public interface ReplicationQueues {
33  
34    /**
35     * Initialize the region server replication queue interface.
36     * @param serverName The server name of the region server that owns the replication queues this
37     *          interface manages.
38     */
39    void init(String serverName) throws ReplicationException;
40  
41    /**
42     * Remove a replication queue.
43     * @param queueId a String that identifies the queue.
44     */
45    void removeQueue(String queueId);
46  
47    /**
48     * Add a new WAL file to the given queue. If the queue does not exist it is created.
49     * @param queueId a String that identifies the queue.
50     * @param filename name of the WAL
51     */
52    void addLog(String queueId, String filename) throws ReplicationException;
53  
54    /**
55     * Remove an WAL file from the given queue.
56     * @param queueId a String that identifies the queue.
57     * @param filename name of the WAL
58     */
59    void removeLog(String queueId, String filename);
60  
61    /**
62     * Set the current position for a specific WAL in a given queue.
63     * @param queueId a String that identifies the queue
64     * @param filename name of the WAL
65     * @param position the current position in the file
66     */
67    void setLogPosition(String queueId, String filename, long position);
68  
69    /**
70     * Get the current position for a specific WAL in a given queue.
71     * @param queueId a String that identifies the queue
72     * @param filename name of the WAL
73     * @return the current position in the file
74     */
75    long getLogPosition(String queueId, String filename) throws ReplicationException;
76  
77    /**
78     * Remove all replication queues for this region server.
79     */
80    void removeAllQueues();
81  
82    /**
83     * Get a list of all WALs in the given queue.
84     * @param queueId a String that identifies the queue
85     * @return a list of WALs, null if this region server is dead and has no outstanding queues
86     */
87    List<String> getLogsInQueue(String queueId);
88  
89    /**
90     * Get a list of all queues for this region server.
91     * @return a list of queueIds, null if this region server is dead and has no outstanding queues
92     */
93    List<String> getAllQueues();
94  
95    /**
96     * Take ownership for the set of queues belonging to a dead region server.
97     * @param regionserver the id of the dead region server
98     * @return A SortedMap of the queues that have been claimed, including a SortedSet of WALs in
99     *         each queue. Returns an empty map if no queues were failed-over.
100    */
101   SortedMap<String, SortedSet<String>> claimQueues(String regionserver);
102 
103   /**
104    * Get a list of all region servers that have outstanding replication queues. These servers could
105    * be alive, dead or from a previous run of the cluster.
106    * @return a list of server names
107    * @throws ReplicationException
108    */
109   List<String> getListOfReplicators() throws ReplicationException;
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 }