Filtering only a single database schema can be useful when you want to
extract a single schema for external processing, or for sharding
information across multiple replication targets. The
dbselector
filter deletes all
statement and row changes, except those for the selected table. To
configure, the db
parameter to
the filter configuration specifies the schema to be replicated.
Pre-configured filter name |
dbselector
| ||
JavaScript Filter File |
tungsten-replicator/support/filters-javascript/dbselector.js
| ||
Property prefix |
replicator.filter.dbselector
| ||
Stage compatibility |
binlog-to-q ,
q-to-thl ,
q-to-dbms
| ||
tpm Option compatibility |
--svc-extractor-filters ,
--svc-applier-filters
| ||
Data compatibility | Any event | ||
Parameters | |||
Parameter | Type | Default | Description |
db
|
string
| (none) | Database to be selected |
Within the filter, statement changes look for the schema in the
StatementData
object and remove it from the array:
if (d instanceof com.continuent.tungsten.replicator.dbms.StatementData) { if(d.getDefaultSchema().compareTo(db)!=0) { data.remove(i); i--; } }
Because entries are being removed from the list of statements, the iterator used to process each item must be explicitly decremented by 1 to reset the counter back to the new position.
Similarly, when looking at row changes in the
RowChangeData
:
else if(d instanceof com.continuent.tungsten.replicator.dbms.RowChangeData) { rowChanges = data.get(i).getRowChanges(); for(j=0;j<rowChanges.size();j++) { oneRowChange = rowChanges.get(j); if(oneRowChange.getSchemaName().compareTo(db)!=0) { rowChanges.remove(j); j--; } } }