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