001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019package org.apache.hadoop.hbase.replication; 020 021import java.util.List; 022import java.util.Map; 023import java.util.Set; 024 025import org.apache.hadoop.hbase.TableName; 026import org.apache.yetus.audience.InterfaceAudience; 027 028/** 029 * For creating {@link ReplicationPeerConfig}. 030 */ 031@InterfaceAudience.Public 032public interface ReplicationPeerConfigBuilder { 033 034 /** 035 * Set the clusterKey which is the concatenation of the slave cluster's: 036 * hbase.zookeeper.quorum:hbase.zookeeper.property.clientPort:zookeeper.znode.parent 037 */ 038 ReplicationPeerConfigBuilder setClusterKey(String clusterKey); 039 040 /** 041 * Sets the ReplicationEndpoint plugin class for this peer. 042 * @param replicationEndpointImpl a class implementing ReplicationEndpoint 043 */ 044 ReplicationPeerConfigBuilder setReplicationEndpointImpl(String replicationEndpointImpl); 045 046 /** 047 * Sets a "raw" configuration property for this replication peer. For experts only. 048 * @param key Configuration property key 049 * @param value Configuration property value 050 * @return {@code this} 051 */ 052 @InterfaceAudience.Private 053 ReplicationPeerConfigBuilder putConfiguration(String key, String value); 054 055 /** 056 * Removes a "raw" configuration property for this replication peer. For experts only. 057 * @param key Configuration property key to ve removed 058 * @return {@code this} 059 */ 060 @InterfaceAudience.Private 061 ReplicationPeerConfigBuilder removeConfiguration(String key); 062 063 064 /** 065 * Adds all of the provided "raw" configuration entries to {@code this}. 066 * @param configuration A collection of raw configuration entries 067 * @return {@code this} 068 */ 069 @InterfaceAudience.Private 070 default ReplicationPeerConfigBuilder putAllConfiguration(Map<String, String> configuration) { 071 configuration.forEach(this::putConfiguration); 072 return this; 073 } 074 075 /** 076 * Sets the serialized peer configuration data 077 * @return {@code this} 078 */ 079 @InterfaceAudience.Private 080 ReplicationPeerConfigBuilder putPeerData(byte[] key, byte[] value); 081 082 /** 083 * Sets all of the provided serialized peer configuration data. 084 * @return {@code this} 085 */ 086 @InterfaceAudience.Private 087 default ReplicationPeerConfigBuilder putAllPeerData(Map<byte[], byte[]> peerData) { 088 peerData.forEach(this::putPeerData); 089 return this; 090 } 091 092 /** 093 * Sets an explicit map of tables and column families in those tables that should be replicated 094 * to the given peer. Use {@link #setReplicateAllUserTables(boolean)} to replicate all tables 095 * to a peer. 096 * 097 * @param tableCFsMap A map from tableName to column family names. An empty collection can be 098 * passed to indicate replicating all column families. 099 * @return {@code this} 100 * @see #setReplicateAllUserTables(boolean) 101 */ 102 ReplicationPeerConfigBuilder 103 setTableCFsMap(Map<TableName, List<String>> tableCFsMap); 104 105 /** 106 * Sets a unique collection of HBase namespaces that should be replicated to this peer. 107 * @param namespaces A set of namespaces to be replicated to this peer. 108 * @return {@code this} 109 */ 110 ReplicationPeerConfigBuilder setNamespaces(Set<String> namespaces); 111 112 /** 113 * Sets the speed, in bytes per second, for any one RegionServer to replicate data to the peer. 114 * @param bandwidth Bytes per second 115 * @return {@code this}. 116 */ 117 ReplicationPeerConfigBuilder setBandwidth(long bandwidth); 118 119 /** 120 * Configures HBase to replicate all user tables (not system tables) to the peer. Default is 121 * {@code true}. 122 * @param replicateAllUserTables True if all user tables should be replicated, else false. 123 * @return {@code this} 124 */ 125 ReplicationPeerConfigBuilder setReplicateAllUserTables(boolean replicateAllUserTables); 126 127 /** 128 * Sets the mapping of table name to column families which should not be replicated. This 129 * method sets state which is mutually exclusive to {@link #setTableCFsMap(Map)}. Invoking this 130 * method is only relevant when all user tables are being replicated. 131 * 132 * @param tableCFsMap A mapping of table names to column families which should not be 133 * replicated. An empty list of column families implies all families for the table. 134 * @return {@code this}. 135 */ 136 ReplicationPeerConfigBuilder setExcludeTableCFsMap(Map<TableName, List<String>> tableCFsMap); 137 138 /** 139 * Sets the collection of namespaces which should not be replicated when all user tables are 140 * configured to be replicated. This method sets state which is mutually exclusive to 141 * {@link #setNamespaces(Set)}. Invoking this method is only relevant when all user tables are 142 * being replicated. 143 * 144 * @param namespaces A set of namespaces whose tables should not be replicated. 145 * @return {@code this} 146 */ 147 ReplicationPeerConfigBuilder setExcludeNamespaces(Set<String> namespaces); 148 149 /** 150 * <p> 151 * Sets whether we should preserve order when replicating, i.e, serial replication. 152 * </p> 153 * <p> 154 * Default {@code false}. 155 * </p> 156 * @param serial {@code true} means preserve order, otherwise {@code false}. 157 * @return {@code this} 158 */ 159 ReplicationPeerConfigBuilder setSerial(boolean serial); 160 161 /** 162 * Builds the configuration object from the current state of {@code this}. 163 * @return A {@link ReplicationPeerConfig} instance. 164 */ 165 ReplicationPeerConfig build(); 166}