1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.replication;
20
21 import java.util.NavigableMap;
22
23 import org.apache.hadoop.hbase.Cell;
24 import org.apache.hadoop.hbase.CellUtil;
25 import org.apache.hadoop.hbase.HConstants;
26 import org.apache.hadoop.hbase.classification.InterfaceAudience;
27 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
28 import org.apache.hadoop.hbase.wal.WAL.Entry;
29
30 import com.google.common.base.Predicate;
31
32
33
34
35 @InterfaceAudience.Private
36 public class ScopeWALEntryFilter implements WALEntryFilter, WALCellFilter {
37
38 BulkLoadCellFilter bulkLoadFilter = new BulkLoadCellFilter();
39
40 @Override
41 public Entry filter(Entry entry) {
42 NavigableMap<byte[], Integer> scopes = entry.getKey().getScopes();
43 if (scopes == null || scopes.isEmpty()) {
44 return null;
45 }
46 return entry;
47 }
48
49 @Override
50 public Cell filterCell(Entry entry, Cell cell) {
51 final NavigableMap<byte[], Integer> scopes = entry.getKey().getScopes();
52
53
54 byte[] fam = CellUtil.cloneFamily(cell);
55 if (CellUtil.matchingColumn(cell, WALEdit.METAFAMILY, WALEdit.BULK_LOAD)) {
56 cell = bulkLoadFilter.filterCell(cell, new Predicate<byte[]>() {
57 @Override
58 public boolean apply(byte[] fam) {
59 return !scopes.containsKey(fam) || scopes.get(fam) == HConstants.REPLICATION_SCOPE_LOCAL;
60 }
61 });
62 } else {
63 if (!scopes.containsKey(fam) || scopes.get(fam) == HConstants.REPLICATION_SCOPE_LOCAL) {
64 return null;
65 }
66 }
67 return cell;
68 }
69 }