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 org.apache.hadoop.hbase.Cell; 021import org.apache.hadoop.hbase.CellUtil; 022import org.apache.hadoop.hbase.ExtendedCell; 023import org.apache.hadoop.hbase.PrivateCellUtil; 024import org.apache.hadoop.hbase.TableName; 025import org.apache.hadoop.hbase.wal.WAL.Entry; 026import org.apache.hadoop.hbase.wal.WALEdit; 027import org.apache.yetus.audience.InterfaceAudience; 028 029/** 030 * Filter a WAL Entry by the peer config according to the table and family which it belongs to. 031 * @see ReplicationPeerConfig#needToReplicate(TableName, byte[]) 032 */ 033@InterfaceAudience.Private 034public class NamespaceTableCfWALEntryFilter implements WALEntryFilter, WALCellFilter { 035 036 private final ReplicationPeer peer; 037 private BulkLoadCellFilter bulkLoadFilter = new BulkLoadCellFilter(); 038 039 public NamespaceTableCfWALEntryFilter(ReplicationPeer peer) { 040 this.peer = peer; 041 } 042 043 @Override 044 public Entry filter(Entry entry) { 045 if (this.peer.getPeerConfig().needToReplicate(entry.getKey().getTableName())) { 046 return entry; 047 } else { 048 return null; 049 } 050 } 051 052 @Override 053 public Cell filterCell(final Entry entry, Cell cell) { 054 ExtendedCell extendedCell = PrivateCellUtil.ensureExtendedCell(cell); 055 ReplicationPeerConfig peerConfig = this.peer.getPeerConfig(); 056 TableName tableName = entry.getKey().getTableName(); 057 if (CellUtil.matchingColumn(cell, WALEdit.METAFAMILY, WALEdit.BULK_LOAD)) { 058 // If the cell is about BULKLOAD event, unpack and filter it by BulkLoadCellFilter. 059 return bulkLoadFilter.filterCell(extendedCell, 060 fam -> !peerConfig.needToReplicate(tableName, fam)); 061 } else { 062 return peerConfig.needToReplicate(tableName, CellUtil.cloneFamily(cell)) ? cell : null; 063 } 064 } 065}