Skip to main content
Common Reference

dbselector.js Filter

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 namedbselector
JavaScript Filter Filetungsten-replicator/support/filters-javascript/dbselector.js
Property prefixreplicator.filter.dbselector
Stage compatibilitybinlog-to-q,q-to-thl,q-to-dbms
tpm Option compatibilitysvc-extractor-filters, svc-applier-filters
Data compatibilityAny event

Parameters

ParameterTypeDefaultDescription
dbstring(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--;
}
}
}