Giter Site home page Giter Site logo

Comments (7)

rusuly avatar rusuly commented on May 16, 2024 2

Ok, just read the docs, looks like replicate-do-db and replicate-do-table parameters must be passed from the library.
But currently the lib doesn't support it. I will try and see if I can easily add support for filtering

from mysqlcdc.

rusuly avatar rusuly commented on May 16, 2024 1

I think it's a bad idea to change binlog_do_db parameter as it affects what is written in the server binlog

from mysqlcdc.

rusuly avatar rusuly commented on May 16, 2024 1

It looks like replicate-do-db and replicate-do-table parameters are used by the internal implementation of MySQL replica server when it replicates binary stream from the master.
So the only way to filter results(as I see it) is to filter events manually based on the DatabaseName and TableName from the TableMapEvent. I wouldn't recommend changing binlog_do_db because it will affect master-slave replication(the database slave will receive filtered events)

from mysqlcdc.

rusuly avatar rusuly commented on May 16, 2024

Hi,
The library doesn't filter results.
You need to configure filtering in the master server config file.
The documentation says that there is replicate-do-table parameter although I've never configured filtering.
In my project I switched to PostgreSQL which has logical replication and allows you to select the tables that you want to replicate

from mysqlcdc.

weirdyang avatar weirdyang commented on May 16, 2024

Thank you!

Just to clarify:
From the documentation, the table map event is triggered automatically, so I will just need to catch that and map then filter based on the table Id or table name. Is that the correct flow?

from mysqlcdc.

rusuly avatar rusuly commented on May 16, 2024

Yes, in my docs I wrote this:

A typical transaction has the following structure.

  1. GtidEvent if gtid mode is enabled.
  2. One or many TableMapEvent events.
    • One or many WriteRowsEvent events.
    • One or many UpdateRowsEvent events.
    • One or many DeleteRowsEvent events.
  3. XidEvent indicating commit of the transaction.

So you will receive TableMapEvent event first and then one or many change events associated with it.
You can then skip the events. Just wait for another TableMapEvent.

You can write something like this:

var filterDatabaseName = "MyDatabase";
var filterTableName = "MyTable";
var ignoredTables = new HashSet<long>();

if (binlogEvent is TableMapEvent tableMap)
{
    if(tableMap.DatabaseName != filterDatabaseName || tableMap.TableName != filterTableName)
    {
        ignoredTables.Add(tableMap.TableId);
    }
}
else if (binlogEvent is WriteRowsEvent writeRows)
{
    if(!ignoredTables.Contains(writeRows.TableId))
    {
        await HandleWriteRowsEvent(writeRows);
    }
}
else if (binlogEvent is UpdateRowsEvent updateRows)
{
    if(!ignoredTables.Contains(updateRows.TableId))
    {
        await HandleUpdateRowsEvent(updateRows);
    }
}
else if (binlogEvent is DeleteRowsEvent deleteRows)
{
    if(!ignoredTables.Contains(deleteRows.TableId))
    {
        await HandleDeleteRowsEvent(deleteRows);
    }
}

In PostgreSQL the filtering is done easier. You just create a slot on the master server and tell it to send your code only the changes you want while the database replication continues to work properly from a different event stream.

from mysqlcdc.

weirdyang avatar weirdyang commented on May 16, 2024

from mysqlcdc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.