View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.replication;
20  
21  import java.io.IOException;
22  import java.util.List;
23  import java.util.UUID;
24  
25  import org.apache.hadoop.hbase.Abortable;
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.hbase.HBaseInterfaceAudience;
30  import org.apache.hadoop.hbase.TableDescriptors;
31  import org.apache.hadoop.hbase.wal.WAL.Entry;
32  import org.apache.hadoop.hbase.replication.regionserver.MetricsSource;
33  
34  import com.google.common.util.concurrent.Service;
35  
36  /**
37   * ReplicationEndpoint is a plugin which implements replication
38   * to other HBase clusters, or other systems. ReplicationEndpoint implementation
39   * can be specified at the peer creation time by specifying it
40   * in the {@link ReplicationPeerConfig}. A ReplicationEndpoint is run in a thread
41   * in each region server in the same process.
42   * <p>
43   * ReplicationEndpoint is closely tied to ReplicationSource in a producer-consumer
44   * relation. ReplicationSource is an HBase-private class which tails the logs and manages
45   * the queue of logs plus management and persistence of all the state for replication.
46   * ReplicationEndpoint on the other hand is responsible for doing the actual shipping
47   * and persisting of the WAL entries in the other cluster.
48   */
49  @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.REPLICATION)
50  public interface ReplicationEndpoint extends Service {
51  
52    @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.REPLICATION)
53    class Context {
54      private final Configuration conf;
55      private final FileSystem fs;
56      private final TableDescriptors tableDescriptors;
57      private final ReplicationPeerConfig peerConfig;
58      private final ReplicationPeer replicationPeer;
59      private final String peerId;
60      private final UUID clusterId;
61      private final MetricsSource metrics;
62      private final Abortable abortable;
63  
64      @InterfaceAudience.Private
65      public Context(
66          final Configuration conf,
67          final FileSystem fs,
68          final ReplicationPeerConfig peerConfig,
69          final String peerId,
70          final UUID clusterId,
71          final ReplicationPeer replicationPeer,
72          final MetricsSource metrics,
73          final TableDescriptors tableDescriptors,
74          final Abortable abortable) {
75        this.peerConfig = peerConfig;
76        this.conf = conf;
77        this.fs = fs;
78        this.clusterId = clusterId;
79        this.peerId = peerId;
80        this.replicationPeer = replicationPeer;
81        this.metrics = metrics;
82        this.tableDescriptors = tableDescriptors;
83        this.abortable = abortable;
84      }
85      public Configuration getConfiguration() {
86        return conf;
87      }
88      public FileSystem getFilesystem() {
89        return fs;
90      }
91      public UUID getClusterId() {
92        return clusterId;
93      }
94      public String getPeerId() {
95        return peerId;
96      }
97      public ReplicationPeerConfig getPeerConfig() {
98        return peerConfig;
99      }
100     public ReplicationPeer getReplicationPeer() {
101       return replicationPeer;
102     }
103     public MetricsSource getMetrics() {
104       return metrics;
105     }
106     public TableDescriptors getTableDescriptors() {
107       return tableDescriptors;
108     }
109     public Abortable getAbortable() { return abortable; }
110   }
111 
112   /**
113    * Initialize the replication endpoint with the given context.
114    * @param context replication context
115    * @throws IOException
116    */
117   void init(Context context) throws IOException;
118 
119   /** Whether or not, the replication endpoint can replicate to it's source cluster with the same
120    * UUID */
121   boolean canReplicateToSameCluster();
122 
123   /**
124    * Returns a UUID of the provided peer id. Every HBase cluster instance has a persisted
125    * associated UUID. If the replication is not performed to an actual HBase cluster (but
126    * some other system), the UUID returned has to uniquely identify the connected target system.
127    * @return a UUID or null if the peer cluster does not exist or is not connected.
128    */
129   UUID getPeerUUID();
130 
131   /**
132    * Returns a WALEntryFilter to use for filtering out WALEntries from the log. Replication
133    * infrastructure will call this filter before sending the edits to shipEdits().
134    * @return a {@link WALEntryFilter} or null.
135    */
136   WALEntryFilter getWALEntryfilter();
137 
138   /**
139    * A context for {@link ReplicationEndpoint#replicate(ReplicateContext)} method.
140    */
141   @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.REPLICATION)
142   static class ReplicateContext {
143     List<Entry> entries;
144     int size;
145     String walGroupId;
146     @InterfaceAudience.Private
147     public ReplicateContext() {
148     }
149 
150     public ReplicateContext setEntries(List<Entry> entries) {
151       this.entries = entries;
152       return this;
153     }
154     public ReplicateContext setSize(int size) {
155       this.size = size;
156       return this;
157     }
158     public ReplicateContext setWalGroupId(String walGroupId) {
159       this.walGroupId = walGroupId;
160       return this;
161     }
162     public List<Entry> getEntries() {
163       return entries;
164     }
165     public int getSize() {
166       return size;
167     }
168     public String getWalGroupId(){
169       return walGroupId;
170     }
171   }
172 
173   /**
174    * Replicate the given set of entries (in the context) to the other cluster.
175    * Can block until all the given entries are replicated. Upon this method is returned,
176    * all entries that were passed in the context are assumed to be persisted in the
177    * target cluster.
178    * @param replicateContext a context where WAL entries and other
179    * parameters can be obtained.
180    */
181   boolean replicate(ReplicateContext replicateContext);
182 
183 }