Giter VIP home page Giter VIP logo

Comments (8)

wushujames avatar wushujames commented on September 8, 2024

I did this in two parts:

  1. Attach a lifecycle listener that implements onConnect() and grabs the initial binlog filename from the client. This gets you the initial binlog filename.
  2. Handle the rotate event, which will tell you the filename of the next binlog.

from mysql-binlog-connector-java.

duc0 avatar duc0 commented on September 8, 2024

That sounds good, thanks!

from mysql-binlog-connector-java.

shyiko avatar shyiko commented on September 8, 2024

@ducaddepar @wushujames For the record, you can get it from BinaryLogClient::getBinlogFilename(). Its value changes with each incoming event.

from mysql-binlog-connector-java.

wushujames avatar wushujames commented on September 8, 2024

@shyiko Oh right, that's definitely the way to go if you have a reference to the BinaryLogClient. I had assumed @ducaddepar was asking about getting it within the context of an EventListener, where it's normally not exposed to you.

You bring up a good point tho. You could simply pass your BinaryLogClient to the EventListener, and grab the filename that way. That way, you don't need to handle ROTATE events.

from mysql-binlog-connector-java.

duc0 avatar duc0 commented on September 8, 2024

I was asking because it's unclear if BinaryLogClient getBinLogFileName() is thread-safe to access during onEvent(). But looks like it should be since the binary log client runs in one thread. Is that right?

from mysql-binlog-connector-java.

shyiko avatar shyiko commented on September 8, 2024

Both binlogFilename & binlogPosition are marked volatile ;)

from mysql-binlog-connector-java.

duc0 avatar duc0 commented on September 8, 2024

I think marking them volatile not necessarily make binlogFilename return the corresponding binlog file name of the event. If the client processes the binlog in two threads, while thread 1's onEvent() is invoked, thread 2 may modify binlogFilename, and so accessing binlogFilename in thread 1's onEvent() gives an inaccurate value.

from mysql-binlog-connector-java.

shyiko avatar shyiko commented on September 8, 2024

EventListeners are getting called in the same thread BinaryLogClient listens in, meaning you don't have to worry about thread safety unless you grab that piece of information from another thread (like through JMX). Because there is no point in setting a different binlogFilename other than before connect (in which case BinaryLogClient should not be running, thus no onEvent() can be called at this time) volatile does provide enough (visible reads) guarantee.

NOTE: BinaryLogClient either uses the same thread it was connected in or a separate one in case of connect(timeout). There are no other threads (except for a "keep alive" thread).

from mysql-binlog-connector-java.

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.