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