virajjasani commented on a change in pull request #951: URL: https://github.com/apache/phoenix/pull/951#discussion_r515785773
########## File path: phoenix-core/src/it/java/org/apache/phoenix/replication/SystemCatalogWALEntryFilterIT.java ########## @@ -134,11 +135,16 @@ public void testSystemCatalogWALEntryFilter() throws Exception { //verify that the tenant view WAL.Entry passes the filter and the non-tenant view does not SystemCatalogWALEntryFilter filter = new SystemCatalogWALEntryFilter(); - Assert.assertNull(filter.filter(nonTenantEntry)); - WAL.Entry filteredTenantEntry = filter.filter(tenantEntry); + // Chain the system catalog WAL entry filter to ChainWALEntryFilter + ChainWALEntryFilter chainWALEntryFilter = new ChainWALEntryFilter(filter); + // Asserting the WALEdit for non tenant has cells before getting filtered + Assert.assertTrue(nonTenantEntry.getEdit().size() > 0); + // All the cells will get removed by the filter since they do not belong to tenant + Assert.assertTrue("Non tenant edits for system catalog got ", chainWALEntryFilter.filter(nonTenantEntry).getEdit().isEmpty()); + WAL.Entry filteredTenantEntry = chainWALEntryFilter.filter(tenantEntry); Assert.assertNotNull("Tenant view was filtered when it shouldn't be!", filteredTenantEntry); Assert.assertEquals(tenantEntry.getEdit().size(), - filter.filter(tenantEntry).getEdit().size()); + chainWALEntryFilter.filter(tenantEntry).getEdit().size()); Review comment: nit: this could be `filteredTenantEntry.getEdit().size())` ? ########## File path: phoenix-core/src/main/java/org/apache/phoenix/replication/SystemCatalogWALEntryFilter.java ########## @@ -35,30 +36,30 @@ * be copied. This WALEntryFilter will only allow tenant-owned rows in SYSTEM.CATALOG to * be replicated. Data from all other tables is automatically passed. */ -public class SystemCatalogWALEntryFilter implements WALEntryFilter { +public class SystemCatalogWALEntryFilter implements WALEntryFilter, WALCellFilter { + // This is an optimization to just skip the cell filter if we do not care about + // cell filter for certain WALEdits. + private boolean skipCellFilter; @Override public WAL.Entry filter(WAL.Entry entry) { - + // We use the WALCellFilter to filter the cells from entry, WALEntryFilter + // should not block anything //if the WAL.Entry's table isn't System.Catalog or System.Child_Link, it auto-passes this filter - //TODO: when Phoenix drops support for pre-1.3 versions of HBase, redo as a WALCellFilter if (!SchemaUtil.isMetaTable(entry.getKey().getTableName().getName())){ - return entry; + skipCellFilter = true; + } else { + skipCellFilter = false; } + return entry; + } - List<Cell> cells = entry.getEdit().getCells(); - List<Cell> cellsToRemove = Lists.newArrayList(); - for (Cell cell : cells) { - if (!isTenantRowCell(cell)){ - cellsToRemove.add(cell); - } - } - cells.removeAll(cellsToRemove); - if (cells.size() > 0) { - return entry; - } else { - return null; + @Override + public Cell filterCell(WAL.Entry entry, Cell cell) { + if (skipCellFilter) { + return cell; } + return isTenantRowCell(cell) ? cell : null; } private boolean isTenantRowCell(Cell cell) { Review comment: Not related to this changes, but wondering if we need to construct ImmutableBytesWritable object. Can this method impl be reduced to: ``` return cell.getRowArray()[cell.getRowOffset()] != QueryConstants.SEPARATOR_BYTE; ``` ########## File path: phoenix-core/src/main/java/org/apache/phoenix/replication/SystemCatalogWALEntryFilter.java ########## @@ -21,6 +21,7 @@ import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; +import org.apache.hadoop.hbase.replication.WALCellFilter; import org.apache.hadoop.hbase.replication.WALEntryFilter; import org.apache.hadoop.hbase.wal.WAL; import org.apache.phoenix.query.QueryConstants; Review comment: nit: we can get rid of `List` and `Lists` imports ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org