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 */
018package org.apache.hadoop.hbase.replication;
019
020import java.util.List;
021import java.util.Map;
022import java.util.Set;
023import org.apache.hadoop.hbase.TableName;
024import org.apache.yetus.audience.InterfaceAudience;
025
026/**
027 * For creating {@link ReplicationPeerConfig}.
028 */
029@InterfaceAudience.Public
030public interface ReplicationPeerConfigBuilder {
031
032  /**
033   * Set the clusterKey which is the concatenation of the slave cluster's:
034   * hbase.zookeeper.quorum:hbase.zookeeper.property.clientPort:zookeeper.znode.parent
035   */
036  ReplicationPeerConfigBuilder setClusterKey(String clusterKey);
037
038  /**
039   * Sets the ReplicationEndpoint plugin class for this peer.
040   * @param replicationEndpointImpl a class implementing ReplicationEndpoint
041   */
042  ReplicationPeerConfigBuilder setReplicationEndpointImpl(String replicationEndpointImpl);
043
044  /**
045   * Sets a "raw" configuration property for this replication peer. For experts only.
046   * @param key   Configuration property key
047   * @param value Configuration property value
048   * @return {@code this}
049   */
050  @InterfaceAudience.Private
051  ReplicationPeerConfigBuilder putConfiguration(String key, String value);
052
053  /**
054   * Removes a "raw" configuration property for this replication peer. For experts only.
055   * @param key Configuration property key to ve removed
056   * @return {@code this}
057   */
058  @InterfaceAudience.Private
059  ReplicationPeerConfigBuilder removeConfiguration(String key);
060
061  /**
062   * Adds all of the provided "raw" configuration entries to {@code this}.
063   * @param configuration A collection of raw configuration entries
064   * @return {@code this}
065   */
066  @InterfaceAudience.Private
067  default ReplicationPeerConfigBuilder putAllConfiguration(Map<String, String> configuration) {
068    configuration.forEach(this::putConfiguration);
069    return this;
070  }
071
072  /**
073   * Sets the serialized peer configuration data
074   * @return {@code this}
075   */
076  @InterfaceAudience.Private
077  ReplicationPeerConfigBuilder putPeerData(byte[] key, byte[] value);
078
079  /**
080   * Sets all of the provided serialized peer configuration data.
081   * @return {@code this}
082   */
083  @InterfaceAudience.Private
084  default ReplicationPeerConfigBuilder putAllPeerData(Map<byte[], byte[]> peerData) {
085    peerData.forEach(this::putPeerData);
086    return this;
087  }
088
089  /**
090   * Sets an explicit map of tables and column families in those tables that should be replicated to
091   * the given peer. Use {@link #setReplicateAllUserTables(boolean)} to replicate all tables to a
092   * peer.
093   * @param tableCFsMap A map from tableName to column family names. An empty collection can be
094   *                    passed to indicate replicating all column families.
095   * @return {@code this}
096   * @see #setReplicateAllUserTables(boolean)
097   */
098  ReplicationPeerConfigBuilder setTableCFsMap(Map<TableName, List<String>> tableCFsMap);
099
100  /**
101   * Sets a unique collection of HBase namespaces that should be replicated to this peer.
102   * @param namespaces A set of namespaces to be replicated to this peer.
103   * @return {@code this}
104   */
105  ReplicationPeerConfigBuilder setNamespaces(Set<String> namespaces);
106
107  /**
108   * Sets the speed, in bytes per second, for any one RegionServer to replicate data to the peer.
109   * @param bandwidth Bytes per second
110   * @return {@code this}.
111   */
112  ReplicationPeerConfigBuilder setBandwidth(long bandwidth);
113
114  /**
115   * Configures HBase to replicate all user tables (not system tables) to the peer. Default is
116   * {@code true}.
117   * @param replicateAllUserTables True if all user tables should be replicated, else false.
118   * @return {@code this}
119   */
120  ReplicationPeerConfigBuilder setReplicateAllUserTables(boolean replicateAllUserTables);
121
122  /**
123   * Sets the mapping of table name to column families which should not be replicated. This method
124   * sets state which is mutually exclusive to {@link #setTableCFsMap(Map)}. Invoking this method is
125   * only relevant when all user tables are being replicated.
126   * @param tableCFsMap A mapping of table names to column families which should not be replicated.
127   *                    An empty list of column families implies all families for the table.
128   * @return {@code this}.
129   */
130  ReplicationPeerConfigBuilder setExcludeTableCFsMap(Map<TableName, List<String>> tableCFsMap);
131
132  /**
133   * Sets the collection of namespaces which should not be replicated when all user tables are
134   * configured to be replicated. This method sets state which is mutually exclusive to
135   * {@link #setNamespaces(Set)}. Invoking this method is only relevant when all user tables are
136   * being replicated.
137   * @param namespaces A set of namespaces whose tables should not be replicated.
138   * @return {@code this}
139   */
140  ReplicationPeerConfigBuilder setExcludeNamespaces(Set<String> namespaces);
141
142  /**
143   * <p>
144   * Sets whether we should preserve order when replicating, i.e, serial replication.
145   * </p>
146   * <p>
147   * Default {@code false}.
148   * </p>
149   * @param serial {@code true} means preserve order, otherwise {@code false}.
150   * @return {@code this}
151   */
152  ReplicationPeerConfigBuilder setSerial(boolean serial);
153
154  /**
155   * Builds the configuration object from the current state of {@code this}.
156   * @return A {@link ReplicationPeerConfig} instance.
157   */
158  ReplicationPeerConfig build();
159}