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.ArrayList;
22 import java.util.List;
23 import java.util.Map;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hadoop.hbase.KeyValue;
27 import org.apache.hadoop.hbase.regionserver.wal.HLog.Entry;
28 import org.apache.hadoop.hbase.util.Bytes;
29
30 public class TableCfWALEntryFilter implements WALEntryFilter {
31
32 private static final Log LOG = LogFactory.getLog(TableCfWALEntryFilter.class);
33 private final ReplicationPeer peer;
34
35 public TableCfWALEntryFilter(ReplicationPeer peer) {
36 this.peer = peer;
37 }
38
39 @Override
40 public Entry filter(Entry entry) {
41 String tabName = entry.getKey().getTablename().getNameAsString();
42 ArrayList<KeyValue> kvs = entry.getEdit().getKeyValues();
43 Map<String, List<String>> tableCFs = null;
44
45 try {
46 tableCFs = this.peer.getTableCFs();
47 } catch (IllegalArgumentException e) {
48 LOG.error("should not happen: can't get tableCFs for peer " + peer.getId() +
49 ", degenerate as if it's not configured by keeping tableCFs==null");
50 }
51 int size = kvs.size();
52
53
54
55 if (tableCFs != null && !tableCFs.containsKey(tabName)) {
56 return null;
57 } else {
58 List<String> cfs = (tableCFs == null) ? null : tableCFs.get(tabName);
59 for (int i = size - 1; i >= 0; i--) {
60 KeyValue kv = kvs.get(i);
61
62
63 if ((cfs != null && !cfs.contains(Bytes.toString(kv.getFamily())))) {
64 kvs.remove(i);
65 }
66 }
67 }
68 if (kvs.size() < size/2) {
69 kvs.trimToSize();
70 }
71 return entry;
72 }
73
74 }