001/* 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019package org.apache.hadoop.hbase.replication.regionserver; 020 021import java.io.IOException; 022import java.util.List; 023import java.util.UUID; 024 025import org.apache.yetus.audience.InterfaceAudience; 026import org.apache.hadoop.conf.Configuration; 027import org.apache.hadoop.fs.FileSystem; 028import org.apache.hadoop.fs.Path; 029import org.apache.hadoop.hbase.Server; 030import org.apache.hadoop.hbase.ServerName; 031import org.apache.hadoop.hbase.TableName; 032import org.apache.hadoop.hbase.replication.ReplicationEndpoint; 033import org.apache.hadoop.hbase.replication.ReplicationException; 034import org.apache.hadoop.hbase.replication.ReplicationPeers; 035import org.apache.hadoop.hbase.replication.ReplicationQueues; 036import org.apache.hadoop.hbase.util.Pair; 037import org.apache.hadoop.hbase.wal.WAL.Entry; 038 039/** 040 * Interface that defines a replication source 041 */ 042@InterfaceAudience.Private 043public interface ReplicationSourceInterface { 044 045 /** 046 * Initializer for the source 047 * @param conf the configuration to use 048 * @param fs the file system to use 049 * @param manager the manager to use 050 * @param replicationQueues 051 * @param replicationPeers 052 * @param server the server for this region server 053 * @param peerClusterZnode 054 * @param clusterId 055 * @throws IOException 056 */ 057 void init(Configuration conf, FileSystem fs, ReplicationSourceManager manager, 058 ReplicationQueues replicationQueues, ReplicationPeers replicationPeers, Server server, 059 String peerClusterZnode, UUID clusterId, ReplicationEndpoint replicationEndpoint, 060 WALFileLengthProvider walFileLengthProvider, MetricsSource metrics) throws IOException; 061 062 /** 063 * Add a log to the list of logs to replicate 064 * @param log path to the log to replicate 065 */ 066 void enqueueLog(Path log); 067 068 /** 069 * Add hfile names to the queue to be replicated. 070 * @param tableName Name of the table these files belongs to 071 * @param family Name of the family these files belong to 072 * @param pairs list of pairs of { HFile location in staging dir, HFile path in region dir which 073 * will be added in the queue for replication} 074 * @throws ReplicationException If failed to add hfile references 075 */ 076 void addHFileRefs(TableName tableName, byte[] family, List<Pair<Path, Path>> pairs) 077 throws ReplicationException; 078 079 /** 080 * Start the replication 081 */ 082 void startup(); 083 084 /** 085 * End the replication 086 * @param reason why it's terminating 087 */ 088 void terminate(String reason); 089 090 /** 091 * End the replication 092 * @param reason why it's terminating 093 * @param cause the error that's causing it 094 */ 095 void terminate(String reason, Exception cause); 096 097 /** 098 * Get the current log that's replicated 099 * @return the current log 100 */ 101 Path getCurrentPath(); 102 103 /** 104 * Get the id that the source is replicating to 105 * 106 * @return peer cluster id 107 */ 108 String getPeerClusterZnode(); 109 110 /** 111 * Get the id that the source is replicating to. 112 * 113 * @return peer id 114 */ 115 String getPeerId(); 116 117 /** 118 * Get a string representation of the current statistics 119 * for this source 120 * @return printable stats 121 */ 122 String getStats(); 123 124 /** 125 * @return peer enabled or not 126 */ 127 boolean isPeerEnabled(); 128 129 /** 130 * @return active or not 131 */ 132 boolean isSourceActive(); 133 134 /** 135 * @return metrics of this replication source 136 */ 137 MetricsSource getSourceMetrics(); 138 139 /** 140 * @return the replication endpoint used by this replication source 141 */ 142 ReplicationEndpoint getReplicationEndpoint(); 143 144 /** 145 * @return the replication source manager 146 */ 147 ReplicationSourceManager getSourceManager(); 148 149 /** 150 * @return the wal file length provider 151 */ 152 WALFileLengthProvider getWALFileLengthProvider(); 153 154 /** 155 * Try to throttle when the peer config with a bandwidth 156 * @param batchSize entries size will be pushed 157 * @throws InterruptedException 158 */ 159 void tryThrottle(int batchSize) throws InterruptedException; 160 161 /** 162 * Call this after the shipper thread ship some entries to peer cluster. 163 * @param entries pushed 164 * @param batchSize entries size pushed 165 */ 166 void postShipEdits(List<Entry> entries, int batchSize); 167 168 /** 169 * The queue of WALs only belong to one region server. This will return the server name which all 170 * WALs belong to. 171 * @return the server name which all WALs belong to 172 */ 173 ServerName getServerWALsBelongTo(); 174}