2929import org .apache .hadoop .hbase .util .Bytes ;
3030import org .apache .yetus .audience .InterfaceAudience ;
3131
32+ import org .apache .hbase .thirdparty .org .apache .commons .collections4 .CollectionUtils ;
33+
3234/**
3335 * A configuration for the replication peer cluster.
3436 */
@@ -366,6 +368,19 @@ public String toString() {
366368 * @return true if the table need replicate to the peer cluster
367369 */
368370 public boolean needToReplicate (TableName table ) {
371+ return needToReplicate (table , null );
372+ }
373+
374+ /**
375+ * Decide whether the passed family of the table need replicate to the peer cluster according to
376+ * this peer config.
377+ * @param table name of the table
378+ * @param family family name
379+ * @return true if (the family of) the table need replicate to the peer cluster.
380+ * If passed family is null, return true if any CFs of the table need replicate;
381+ * If passed family is not null, return true if the passed family need replicate.
382+ */
383+ public boolean needToReplicate (TableName table , byte [] family ) {
369384 String namespace = table .getNamespaceAsString ();
370385 if (replicateAllUserTables ) {
371386 // replicate all user tables, but filter by exclude namespaces and table-cfs config
@@ -377,9 +392,12 @@ public boolean needToReplicate(TableName table) {
377392 return true ;
378393 }
379394 Collection <String > cfs = excludeTableCFsMap .get (table );
380- // if cfs is null or empty then we can make sure that we do not need to replicate this table,
395+ // If cfs is null or empty then we can make sure that we do not need to replicate this table,
381396 // otherwise, we may still need to replicate the table but filter out some families.
382- return cfs != null && !cfs .isEmpty ();
397+ return cfs != null && !cfs .isEmpty ()
398+ // If exclude-table-cfs contains passed family then we make sure that we do not need to
399+ // replicate this family.
400+ && (family == null || !cfs .contains (Bytes .toString (family )));
383401 } else {
384402 // Not replicate all user tables, so filter by namespaces and table-cfs config
385403 if (namespaces == null && tableCFsMap == null ) {
@@ -390,7 +408,12 @@ public boolean needToReplicate(TableName table) {
390408 if (namespaces != null && namespaces .contains (namespace )) {
391409 return true ;
392410 }
393- return tableCFsMap != null && tableCFsMap .containsKey (table );
411+ // If table-cfs contains this table then we can make sure that we need replicate some CFs of
412+ // this table. Further we need all CFs if tableCFsMap.get(table) is null or empty.
413+ return tableCFsMap != null && tableCFsMap .containsKey (table )
414+ && (family == null || CollectionUtils .isEmpty (tableCFsMap .get (table ))
415+ // If table-cfs must contain passed family then we need to replicate this family.
416+ || tableCFsMap .get (table ).contains (Bytes .toString (family )));
394417 }
395418 }
396419}
0 commit comments