Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1k
PHOENIX-5895: Leverage WALCellFilter in the SystemCatalogWALEntryFilter to replicate system catalog table#951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -17,16 +17,13 @@ | ||
| */ | ||
| package org.apache.phoenix.replication; | ||
| import java.util.List; | ||
| 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; | ||
| import org.apache.phoenix.util.SchemaUtil; | ||
| import org.apache.phoenix.thirdparty.com.google.common.collect.Lists; | ||
| /** | ||
| * Standard replication of the SYSTEM.CATALOG table can be dangerous because schemas | ||
| @@ -35,36 +32,40 @@ | ||
| * 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) { | ||
| //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 | ||
| // 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 | ||
| 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(final WAL.Entry entry, final Cell cell) { | ||
| if (skipCellFilter) { | ||
| return cell; | ||
| } | ||
| return isTenantRowCell(cell) ? cell : null; | ||
| } | ||
| private boolean isTenantRowCell(Cell cell) { | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to this changes, but wondering if we need to construct ImmutableBytesWritable object. Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @virajjasani - yes, I believe that will work. ImmutableBytesWritable.get() just returns the underlying byte array ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it should be same, I will change that publicbyte [] get() {
if (this.bytes == null) {
thrownewIllegalStateException("Uninitialiized. Null constructor " +
"called w/o accompaying readFields invocation");
}
returnthis.bytes;
} | ||
| ImmutableBytesWritable key = | ||
| new ImmutableBytesWritable(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()); | ||
| //rows in system.catalog that aren't tenant-owned will have a leading separator byte | ||
| return key.get()[key.getOffset()] != QueryConstants.SEPARATOR_BYTE; | ||
| // rows in system.catalog that aren't tenant-owned | ||
| // will have a leading separator byte | ||
| return cell.getRowArray()[cell.getRowOffset()] | ||
| != QueryConstants.SEPARATOR_BYTE; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can get rid of
ListandListsimports