Skip to content

Commit

Permalink
HBASE-25590 Bulkload replication HFileRefs cannot be cleared in some …
Browse files Browse the repository at this point in the history
…cases where set exclude-namespace/exclude-table-cfs (#2969)

Signed-off-by: Wellington Chevreuil <[email protected]>
  • Loading branch information
ddupg authored and sunxin committed Feb 26, 2021
1 parent d724d05 commit 328ff8c
Show file tree
Hide file tree
Showing 6 changed files with 557 additions and 268 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.yetus.audience.InterfaceAudience;

import org.apache.hbase.thirdparty.org.apache.commons.collections4.CollectionUtils;

/**
* A configuration for the replication peer cluster.
*/
Expand Down Expand Up @@ -372,6 +374,19 @@ public String toString() {
* @return true if the table need replicate to the peer cluster
*/
public boolean needToReplicate(TableName table) {
return needToReplicate(table, null);
}

/**
* Decide whether the passed family of the table need replicate to the peer cluster according to
* this peer config.
* @param table name of the table
* @param family family name
* @return true if (the family of) the table need replicate to the peer cluster.
* If passed family is null, return true if any CFs of the table need replicate;
* If passed family is not null, return true if the passed family need replicate.
*/
public boolean needToReplicate(TableName table, byte[] family) {
String namespace = table.getNamespaceAsString();
if (replicateAllUserTables) {
// replicate all user tables, but filter by exclude namespaces and table-cfs config
Expand All @@ -383,9 +398,12 @@ public boolean needToReplicate(TableName table) {
return true;
}
Collection<String> cfs = excludeTableCFsMap.get(table);
// if cfs is null or empty then we can make sure that we do not need to replicate this table,
// If cfs is null or empty then we can make sure that we do not need to replicate this table,
// otherwise, we may still need to replicate the table but filter out some families.
return cfs != null && !cfs.isEmpty();
return cfs != null && !cfs.isEmpty()
// If exclude-table-cfs contains passed family then we make sure that we do not need to
// replicate this family.
&& (family == null || !cfs.contains(Bytes.toString(family)));
} else {
// Not replicate all user tables, so filter by namespaces and table-cfs config
if (namespaces == null && tableCFsMap == null) {
Expand All @@ -396,7 +414,12 @@ public boolean needToReplicate(TableName table) {
if (namespaces != null && namespaces.contains(namespace)) {
return true;
}
return tableCFsMap != null && tableCFsMap.containsKey(table);
// If table-cfs contains this table then we can make sure that we need replicate some CFs of
// this table. Further we need all CFs if tableCFsMap.get(table) is null or empty.
return tableCFsMap != null && tableCFsMap.containsKey(table)
&& (family == null || CollectionUtils.isEmpty(tableCFsMap.get(table))
// If table-cfs must contain passed family then we need to replicate this family.
|| tableCFsMap.get(table).contains(Bytes.toString(family)));
}
}
}
Loading

0 comments on commit 328ff8c

Please sign in to comment.