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.classification.InterfaceAudience;
26  import org.apache.hadoop.conf.Configuration;
27  import org.apache.hadoop.fs.FileSystem;
28  import org.apache.hadoop.hbase.HBaseInterfaceAudience;
29  import org.apache.hadoop.hbase.TableDescriptors;
30  import org.apache.hadoop.hbase.wal.WAL.Entry;
31  import org.apache.hadoop.hbase.replication.regionserver.MetricsSource;
32  
33  import com.google.common.util.concurrent.Service;
34  
35  /**
36   * ReplicationEndpoint is a plugin which implements replication
37   * to other HBase clusters, or other systems. ReplicationEndpoint implementation
38   * can be specified at the peer creation time by specifying it
39   * in the {@link ReplicationPeerConfig}. A ReplicationEndpoint is run in a thread
40   * in each region server in the same process.
41   * <p>
42   * ReplicationEndpoint is closely tied to ReplicationSource in a producer-consumer
43   * relation. ReplicationSource is an HBase-private class which tails the logs and manages
44   * the queue of logs plus management and persistence of all the state for replication.
45   * ReplicationEndpoint on the other hand is responsible for doing the actual shipping
46   * and persisting of the WAL entries in the other cluster.
47   */
48  @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.REPLICATION)
49  public interface ReplicationEndpoint extends Service, ReplicationPeerConfigListener {
50  
51    @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.REPLICATION)
52    class Context {
53      private final Configuration conf;
54      private final FileSystem fs;
55      private final TableDescriptors tableDescriptors;
56      private final ReplicationPeer replicationPeer;
57      private final String peerId;
58      private final UUID clusterId;
59      private final MetricsSource metrics;
60  
61      @InterfaceAudience.Private
62      public Context(
63          final Configuration conf,
64          final FileSystem fs,
65          final String peerId,
66          final UUID clusterId,
67          final ReplicationPeer replicationPeer,
68          final MetricsSource metrics,
69          final TableDescriptors tableDescriptors) {
70        this.conf = conf;
71        this.fs = fs;
72        this.clusterId = clusterId;
73        this.peerId = peerId;
74        this.replicationPeer = replicationPeer;
75        this.metrics = metrics;
76        this.tableDescriptors = tableDescriptors;
77      }
78      public Configuration getConfiguration() {
79        return conf;
80      }
81      public FileSystem getFilesystem() {
82        return fs;
83      }
84      public UUID getClusterId() {
85        return clusterId;
86      }
87      public String getPeerId() {
88        return peerId;
89      }
90      public ReplicationPeerConfig getPeerConfig() {
91        return replicationPeer.getPeerConfig();
92      }
93      public ReplicationPeer getReplicationPeer() {
94        return replicationPeer;
95      }
96      public MetricsSource getMetrics() {
97        return metrics;
98      }
99      public TableDescriptors getTableDescriptors() {
100       return tableDescriptors;
101     }
102   }
103 
104   /**
105    * Initialize the replication endpoint with the given context.
106    * @param context replication context
107    * @throws IOException
108    */
109   void init(Context context) throws IOException;
110 
111   /** Whether or not, the replication endpoint can replicate to it's source cluster with the same
112    * UUID */
113   boolean canReplicateToSameCluster();
114 
115   /**
116    * Returns a UUID of the provided peer id. Every HBase cluster instance has a persisted
117    * associated UUID. If the replication is not performed to an actual HBase cluster (but
118    * some other system), the UUID returned has to uniquely identify the connected target system.
119    * @return a UUID or null if the peer cluster does not exist or is not connected.
120    */
121   UUID getPeerUUID();
122 
123   /**
124    * Returns a WALEntryFilter to use for filtering out WALEntries from the log. Replication
125    * infrastructure will call this filter before sending the edits to shipEdits().
126    * @return a {@link WALEntryFilter} or null.
127    */
128   WALEntryFilter getWALEntryfilter();
129 
130   /**
131    * A context for {@link ReplicationEndpoint#replicate(ReplicateContext)} method.
132    */
133   @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.REPLICATION)
134   static class ReplicateContext {
135     List<Entry> entries;
136     int size;
137     String walGroupId;
138     @InterfaceAudience.Private
139     public ReplicateContext() {
140     }
141 
142     public ReplicateContext setEntries(List<Entry> entries) {
143       this.entries = entries;
144       return this;
145     }
146     public ReplicateContext setSize(int size) {
147       this.size = size;
148       return this;
149     }
150     public ReplicateContext setWalGroupId(String walGroupId) {
151       this.walGroupId = walGroupId;
152       return this;
153     }
154     public List<Entry> getEntries() {
155       return entries;
156     }
157     public int getSize() {
158       return size;
159     }
160     public String getWalGroupId(){
161       return walGroupId;
162     }
163   }
164 
165   /**
166    * Replicate the given set of entries (in the context) to the other cluster.
167    * Can block until all the given entries are replicated. Upon this method is returned,
168    * all entries that were passed in the context are assumed to be persisted in the
169    * target cluster.
170    * @param replicateContext a context where WAL entries and other
171    * parameters can be obtained.
172    */
173   boolean replicate(ReplicateContext replicateContext);
174 
175 }