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.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);
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     * Take ownership for the set of queues belonging to a dead region server.
100    * @param regionserver the id of the dead region server
101    * @return A SortedMap of the queues that have been claimed, including a SortedSet of WALs in
102    *         each queue. Returns an empty map if no queues were failed-over.
103    */
104   SortedMap<String, SortedSet<String>> claimQueues(String regionserver);
105 
106   /**
107    * Get a list of all region servers that have outstanding replication queues. These servers could
108    * be alive, dead or from a previous run of the cluster.
109    * @return a list of server names
110    */
111   List<String> getListOfReplicators();
112 
113   /**
114    * Checks if the provided znode is the same as this region server's
115    * @param znode to check
116    * @return if this is this rs's znode
117    */
118   boolean isThisOurZnode(String znode);
119 
120   /**
121    * Add a peer to hfile reference queue if peer does not exist.
122    * @param peerId peer cluster id to be added
123    * @throws ReplicationException if fails to add a peer id to hfile reference queue
124    */
125   void addPeerToHFileRefs(String peerId) throws ReplicationException;
126 
127   /**
128    * Add new hfile references to the queue.
129    * @param peerId peer cluster id to which the hfiles need to be replicated
130    * @param pairs list of pairs of { HFile location in staging dir, HFile path in region dir which
131    *          will be added in the queue }
132    * @throws ReplicationException if fails to add a hfile reference
133    */
134   void addHFileRefs(String peerId, List<Pair<Path, Path>> pairs) throws ReplicationException;
135 
136   /**
137    * Remove hfile references from the queue.
138    * @param peerId peer cluster id from which this hfile references needs to be removed
139    * @param files list of hfile references to be removed
140    */
141   void removeHFileRefs(String peerId, List<String> files);
142 }