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.regionserver;
20  
21  import java.io.IOException;
22  import java.util.List;
23  import java.util.Map;
24  import java.util.UUID;
25  
26  import org.apache.hadoop.hbase.classification.InterfaceAudience;
27  import org.apache.hadoop.conf.Configuration;
28  import org.apache.hadoop.fs.FileSystem;
29  import org.apache.hadoop.fs.Path;
30  import org.apache.hadoop.hbase.Stoppable;
31  import org.apache.hadoop.hbase.TableName;
32  import org.apache.hadoop.hbase.replication.ReplicationEndpoint;
33  import org.apache.hadoop.hbase.replication.ReplicationException;
34  import org.apache.hadoop.hbase.replication.ReplicationPeers;
35  import org.apache.hadoop.hbase.replication.ReplicationQueues;
36  import org.apache.hadoop.hbase.util.Pair;
37  
38  /**
39   * Interface that defines a replication source
40   */
41  @InterfaceAudience.Private
42  public interface ReplicationSourceInterface {
43  
44    /**
45     * Initializer for the source
46     * @param conf the configuration to use
47     * @param fs the file system to use
48     * @param manager the manager to use
49     * @param replicationQueues
50     * @param replicationPeers
51     * @param stopper the stopper object for this region server
52     * @param peerClusterZnode
53     * @param clusterId
54     * @throws IOException
55     */
56    public void init(final Configuration conf, final FileSystem fs,
57        final ReplicationSourceManager manager, final ReplicationQueues replicationQueues,
58        final ReplicationPeers replicationPeers, final Stoppable stopper,
59        final String peerClusterZnode, final UUID clusterId, ReplicationEndpoint replicationEndpoint,
60        final MetricsSource metrics) throws IOException;
61  
62    /**
63     * Add a log to the list of logs to replicate
64     * @param log path to the log to replicate
65     */
66    void enqueueLog(Path log);
67  
68    /**
69     * Get the current log that's replicated
70     * @return the current log
71     */
72    Path getCurrentPath();
73  
74    /**
75     * Start the replication
76     */
77    void startup();
78  
79    /**
80     * End the replication
81     * @param reason why it's terminating
82     */
83    void terminate(String reason);
84  
85    /**
86     * End the replication
87     * @param reason why it's terminating
88     * @param cause the error that's causing it
89     */
90    void terminate(String reason, Exception cause);
91  
92    /**
93     * Get the id that the source is replicating to
94     *
95     * @return peer cluster id
96     */
97    String getPeerClusterZnode();
98  
99    /**
100    * Get the id that the source is replicating to.
101    *
102    * @return peer cluster id
103    */
104   String getPeerClusterId();
105 
106   /**
107    * Get a string representation of the current statistics
108    * for this source
109    * @return printable stats
110    */
111   String getStats();
112 
113   /**
114    * Add hfile names to the queue to be replicated.
115    * @param tableName Name of the table these files belongs to
116    * @param family Name of the family these files belong to
117    * @param pairs list of pairs of { HFile location in staging dir, HFile path in region dir which
118    *          will be added in the queue for replication}
119    * @throws ReplicationException If failed to add hfile references
120    */
121   void addHFileRefs(TableName tableName, byte[] family, List<Pair<Path, Path>> pairs)
122       throws ReplicationException;
123 
124   /**
125    * Get the associated metrics.
126    *
127    * @return The metrics for this source.
128    */
129   MetricsSource getSourceMetrics();
130 
131   /**
132    * get the stat of replication for each wal group.
133    * @return stat of replication
134    */
135   Map<String, ReplicationStatus> getWalGroupStatus();
136 }