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, ReplicationPeerConfigListener {
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 ReplicationPeer replicationPeer;
58      private final String peerId;
59      private final UUID clusterId;
60      private final MetricsSource metrics;
61      private final Abortable abortable;
62
63      @InterfaceAudience.Private
64      public Context(
65          final Configuration conf,
66          final FileSystem fs,
67          final String peerId,
68          final UUID clusterId,
69          final ReplicationPeer replicationPeer,
70          final MetricsSource metrics,
71          final TableDescriptors tableDescriptors,
72          final Abortable abortable) {
73        this.conf = conf;
74        this.fs = fs;
75        this.clusterId = clusterId;
76        this.peerId = peerId;
77        this.replicationPeer = replicationPeer;
78        this.metrics = metrics;
79        this.tableDescriptors = tableDescriptors;
80        this.abortable = abortable;
81      }
82      public Configuration getConfiguration() {
83        return conf;
84      }
85      public FileSystem getFilesystem() {
86        return fs;
87      }
88      public UUID getClusterId() {
89        return clusterId;
90      }
91      public String getPeerId() {
92        return peerId;
93      }
94      public ReplicationPeerConfig getPeerConfig() {
95        return replicationPeer.getPeerConfig();
96      }
97      public ReplicationPeer getReplicationPeer() {
98        return replicationPeer;
99      }
100     public MetricsSource getMetrics() {
101       return metrics;
102     }
103     public TableDescriptors getTableDescriptors() {
104       return tableDescriptors;
105     }
106     public Abortable getAbortable() { return abortable; }
107   }
108
109   /**
110    * Initialize the replication endpoint with the given context.
111    * @param context replication context
112    * @throws IOException
113    */
114   void init(Context context) throws IOException;
115
116   /** Whether or not, the replication endpoint can replicate to it's source cluster with the same
117    * UUID */
118   boolean canReplicateToSameCluster();
119
120   /**
121    * Returns a UUID of the provided peer id. Every HBase cluster instance has a persisted
122    * associated UUID. If the replication is not performed to an actual HBase cluster (but
123    * some other system), the UUID returned has to uniquely identify the connected target system.
124    * @return a UUID or null if the peer cluster does not exist or is not connected.
125    */
126   UUID getPeerUUID();
127
128   /**
129    * Returns a WALEntryFilter to use for filtering out WALEntries from the log. Replication
130    * infrastructure will call this filter before sending the edits to shipEdits().
131    * @return a {@link WALEntryFilter} or null.
132    */
133   WALEntryFilter getWALEntryfilter();
134
135   /**
136    * A context for {@link ReplicationEndpoint#replicate(ReplicateContext)} method.
137    */
138   @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.REPLICATION)
139   static class ReplicateContext {
140     List<Entry> entries;
141     int size;
142     String walGroupId;
143     @InterfaceAudience.Private
144     public ReplicateContext() {
145     }
146
147     public ReplicateContext setEntries(List<Entry> entries) {
148       this.entries = entries;
149       return this;
150     }
151     public ReplicateContext setSize(int size) {
152       this.size = size;
153       return this;
154     }
155     public ReplicateContext setWalGroupId(String walGroupId) {
156       this.walGroupId = walGroupId;
157       return this;
158     }
159     public List<Entry> getEntries() {
160       return entries;
161     }
162     public int getSize() {
163       return size;
164     }
165     public String getWalGroupId(){
166       return walGroupId;
167     }
168   }
169
170   /**
171    * Replicate the given set of entries (in the context) to the other cluster.
172    * Can block until all the given entries are replicated. Upon this method is returned,
173    * all entries that were passed in the context are assumed to be persisted in the
174    * target cluster.
175    * @param replicateContext a context where WAL entries and other
176    * parameters can be obtained.
177    */
178   boolean replicate(ReplicateContext replicateContext);
179
180 }