protected void rewindBinaryLogClient(BinlogPosition position) { try { if (isRunning()) { logger.debug("Rewinding binlog to position {}", position); client.disconnect(); client.setBinlogFilename(position.getFilename()); client.setBinlogPosition(position.getPosition()); client.connect(); } } catch (IOException e) { logger.error("Unexpected error when re-connecting to the MySQL binary log reader", e); } }
private void checkConnection() throws Exception { if (!binaryLogClient.isConnected()) { BinlogPosition binlogPosition = replicator.getNextBinlogPosition(); if (binlogPosition != null) { binaryLogClient.setBinlogFilename(binlogPosition.getBinlogFilename()); binaryLogClient.setBinlogPosition(binlogPosition.getPosition()); } binaryLogClient.connect(3000); } }
binlogClient.setBinlogPosition(currentBinlogPosition);
private void ensureReplicatorThread() throws Exception { checkCommErrors(); if ( !client.isConnected() && !stopOnEOF ) { if (this.gtidPositioning) { // When using gtid positioning, reconnecting should take us to the top // of the gtid event. We throw away any binlog position we have // (other than GTID) and bail out of getTransactionRows() LOGGER.warn("replicator stopped at position: {} -- restarting", client.getGtidSet()); client.setBinlogFilename(""); client.setBinlogPosition(4L); client.connect(5000); throw new ClientReconnectedException(); } else { // standard binlog positioning is a lot easier; we can really reconnect anywhere // we like, so we don't have to bail out of the middle of an event. LOGGER.warn("replicator stopped at position: {} -- restarting", client.getBinlogFilename() + ":" + client.getBinlogPosition()); client.connect(5000); } } }
client.setBinlogPosition(source.binlogPosition()); gtidSet = new com.github.shyiko.mysql.binlog.GtidSet(""); client.setBinlogPosition(source.binlogPosition());
/** * Test case that is normally commented out since it is only useful to print out the DDL statements recorded by * the binlog during a MySQL server initialization and startup. * * @throws Exception if there are problems */ @Ignore @Test public void shouldCaptureQueryEventData() throws Exception { // Testing.Print.enable(); startClient(client -> { client.setBinlogFilename("mysql-bin.000001"); client.setBinlogPosition(4); }); counters.consumeAll(5, TimeUnit.SECONDS); List<QueryEventData> allQueryEvents = recordedEventData(QueryEventData.class, -1); allQueryEvents.forEach(event -> { String sql = event.getSql(); if (sql.equalsIgnoreCase("BEGIN") || sql.equalsIgnoreCase("COMMIT")) return; System.out.println(event.getSql()); }); }
public void start() throws Exception { initDataSource(); binlogPositionManager = new BinlogPositionManager(config, dataSource); binlogPositionManager.initBeginPosition(); schema = new Schema(dataSource); schema.load(); eventListener = new EventListener(queue); binaryLogClient = new BinaryLogClient(config.mysqlAddr, config.mysqlPort, config.mysqlUsername, config.mysqlPassword); binaryLogClient.setBlocking(true); binaryLogClient.setServerId(1001); EventDeserializer eventDeserializer = new EventDeserializer(); eventDeserializer.setCompatibilityMode(EventDeserializer.CompatibilityMode.DATE_AND_TIME_AS_LONG, EventDeserializer.CompatibilityMode.CHAR_AND_BINARY_AS_BYTE_ARRAY); binaryLogClient.setEventDeserializer(eventDeserializer); binaryLogClient.registerEventListener(eventListener); binaryLogClient.setBinlogFilename(binlogPositionManager.getBinlogFilename()); binaryLogClient.setBinlogPosition(binlogPositionManager.getPosition()); binaryLogClient.connect(3000); LOGGER.info("Started."); doProcess(); }
LOGGER.info("Setting initial binlog pos to: " + startBinlog.getFile() + ":" + startBinlog.getOffset()); this.client.setBinlogFilename(startBinlog.getFile()); this.client.setBinlogPosition(startBinlog.getOffset()); this.gtidPositioning = false;
binlogClient.setBinlogPosition(currentBinlogPosition);
this.client.setBinlogPosition(checkpoint.getBinlog().getPosition());
logger.debug("Starting with {}", bfo); client.setBinlogFilename(bfo.getBinlogFilename()); client.setBinlogPosition(bfo.getOffset());
/** * Test case that is normally commented out since it is only useful to print out the DDL statements recorded by * the binlog during a MySQL server initialization and startup. * * @throws Exception if there are problems */ @Ignore @Test public void shouldCaptureQueryEventData() throws Exception { // Testing.Print.enable(); startClient(client -> { client.setBinlogFilename("mysql-bin.000001"); client.setBinlogPosition(4); }); counters.consumeAll(5, TimeUnit.SECONDS); List<QueryEventData> allQueryEvents = recordedEventData(QueryEventData.class, -1); allQueryEvents.forEach(event -> { String sql = event.getSql(); if (sql.equalsIgnoreCase("BEGIN") || sql.equalsIgnoreCase("COMMIT")) return; System.out.println(event.getSql()); }); }
logger.debug("Starting with {}", bfo); client.setBinlogFilename(bfo.getBinlogFilename()); client.setBinlogPosition(bfo.getOffset());