public void startReplicator() throws Exception { this.client.connect(5000); replicatorStarted = true; }
@Override public void run() { try { setConnectTimeout(timeout); connect(); } catch (IOException e) { exceptionReference.set(e); countDownLatch.countDown(); // making sure we don't end up waiting whole "timeout" } } };
connect(connectTimeout); } catch (Exception ce) { if (logger.isLoggable(Level.WARNING)) {
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 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); } } }
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); } }
connectTimeout = Long.MAX_VALUE; binlogClient.connect(connectTimeout); transitUri = "mysql://" + connectedHost.getHostString() + ":" + connectedHost.getPort();
try { logger.debug("Attempting to establish binlog reader connection with timeout of {} ms", timeoutInMilliseconds); client.connect(context.timeoutInMilliseconds()); } catch (TimeoutException e) {
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(); }
protected void startClient(Consumer<BinaryLogClient> preConnect) throws IOException, TimeoutException, SQLException { // Connect the bin log client ... counters = new EventQueue(DEFAULT_TIMEOUT, this::logConsumedEvent, this::logIgnoredEvent); client = new BinaryLogClient(config.getHostname(), config.getPort(), "replicator", "replpass"); client.setServerId(client.getServerId() - 1); // avoid clashes between BinaryLogClient instances client.setKeepAlive(false); client.setSSLMode(SSLMode.DISABLED); client.registerEventListener(counters); client.registerEventListener(this::recordEvent); client.registerLifecycleListener(new TraceLifecycleListener()); EventDeserializer eventDeserializer = new EventDeserializer(); eventDeserializer.setEventDataDeserializer(EventType.STOP, new StopEventDataDeserializer()); client.setEventDeserializer(eventDeserializer); if (preConnect != null) preConnect.accept(client); client.connect(DEFAULT_TIMEOUT); // does not block // Set up the table as one transaction and wait to see the events ... conn.execute("DROP TABLE IF EXISTS person", "CREATE TABLE person (" + " name VARCHAR(255) primary key," + " age INTEGER NULL DEFAULT 10," + " createdAt DATETIME NULL DEFAULT CURRENT_TIMESTAMP," + " updatedAt DATETIME NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP" + ")"); counters.consume(2, EventType.QUERY); counters.reset(); }
@Override public void run() { try { client.connect(); } catch (IOException error) { LOGGER.warn("Can't connect to MySQL as a slave!", error); } } };
@Override public void run() { try { client.connect(); } catch (IOException error) { LOGGER.warn("Can't connect to MySQL as a slave!", error); } } };
private void connectWithRetriesOnFail() { for (int i = 1;; i++) { try { logger.info("trying to connect to mysql binlog for schema {}", sourceDatabase.getEventuateDatabaseSchema()); client.connect(connectionTimeoutInMilliseconds); logger.info("connection to mysql binlog succeed"); break; } catch (TimeoutException | IOException e) { logger.error("connection to mysql binlog failed"); if (i == maxAttemptsForBinlogConnection) { logger.error("connection attempts exceeded"); throw new RuntimeException(e); } try { Thread.sleep(connectionTimeoutInMilliseconds); } catch (InterruptedException ex) { throw new RuntimeException(ex); } } } }
connectTimeout = Long.MAX_VALUE; binlogClient.connect(connectTimeout); transitUri = "mysql://" + connectedHost.getHostString() + ":" + connectedHost.getPort();
this.client.connect();
for (int i=1; i<5; i++) { try { client.connect(10 * 1000); break; } catch (Exception e) {
protected void startClient(Consumer<BinaryLogClient> preConnect) throws IOException, TimeoutException, SQLException { // Connect the bin log client ... counters = new EventQueue(DEFAULT_TIMEOUT, this::logConsumedEvent, this::logIgnoredEvent); client = new BinaryLogClient(config.getHostname(), config.getPort(), "replicator", "replpass"); client.setServerId(client.getServerId() - 1); // avoid clashes between BinaryLogClient instances client.setKeepAlive(false); client.setSSLMode(SSLMode.DISABLED); client.registerEventListener(counters); client.registerEventListener(this::recordEvent); client.registerLifecycleListener(new TraceLifecycleListener()); EventDeserializer eventDeserializer = new EventDeserializer(); eventDeserializer.setEventDataDeserializer(EventType.STOP, new StopEventDataDeserializer()); client.setEventDeserializer(eventDeserializer); if (preConnect != null) preConnect.accept(client); client.connect(DEFAULT_TIMEOUT); // does not block // Set up the table as one transaction and wait to see the events ... conn.execute("DROP TABLE IF EXISTS person", "CREATE TABLE person (" + " name VARCHAR(255) primary key," + " age INTEGER NULL DEFAULT 10," + " createdAt DATETIME NULL DEFAULT CURRENT_TIMESTAMP," + " updatedAt DATETIME NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP" + ")"); counters.consume(2, EventType.QUERY); counters.reset(); }