Uploaded image for project: 'Debezium'
  1. Debezium
  2. DBZ-1338

Set heartbeat interval for the binlog reader

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Done
    • Icon: Critical Critical
    • 0.10.0.Beta3
    • 0.10.0.Beta1
    • mysql-connector
    • None

      Hi, I'm researching the way to monitor the connection between connectors and MySQL server.Debezium has provided the opition connect.keep.alive (default true) and connect.keep.alive.interval.ms(default 1 min) and the shyiko BinaryLogClient will use them to check the connection once per minute by sending ping command .The related code has been pasted below:

      In BinlogReader.java ,the client is configured below.

      client.setKeepAlive(context.config().getBoolean(MySqlConnectorConfig.KEEP_ALIVE));
      client.setKeepAliveInterval(context.config().getLong(MySqlConnectorConfig.KEEP_ALIVE_INTERVAL_MS));
      

      In BinarylogClient.java,the seperate thread will send ping command to MySQL by default.(because the heartbeatInterval is not configured)

      threadExecutor.submit(new Runnable() {
                      @Override
                      public void run() {
                          while (!threadExecutor.isShutdown()) {
                              try {
                                  Thread.sleep(keepAliveInterval);
                              } catch (InterruptedException e) {
                                  // expected in case of disconnect
                              }
                              if (threadExecutor.isShutdown()) {
                                  return;
                              }
                              boolean connectionLost = false;
                              if (heartbeatInterval > 0) {
                                  connectionLost = System.currentTimeMillis() - eventLastSeen > keepAliveInterval;
                              } else {
                                  try {
                                      channel.write(new PingCommand());
                                  } catch (IOException e) {
                                      connectionLost = true;
                                  }
                              }
                              if (connectionLost) {
                                  if (logger.isLoggable(Level.INFO)) {
                                      logger.info("Trying to restore lost connection to " + hostname + ":" + port);
                                  }
                                  try {
                                      terminateConnect();
                                      connect(connectTimeout);
                                  } catch (Exception ce) {
                                      if (logger.isLoggable(Level.WARNING)) {
                                          logger.warning("Failed to restore connection to " + hostname + ":" + port +
                                              ". Next attempt in " + keepAliveInterval + "ms");
                                      }
                                  }
                              }
                          }
                      }
                  });
      

      I wonder if debezium can provide property , e.g. mysqlHeartbeatInterval, to our users, and we can receive the heartbeat from MySQL server instead of sending ping command which is not a efficient way.In more detail, you can have a look at this issue : https://github.com/shyiko/mysql-binlog-connector-java/issues/118.

      We wait for your feed-back,many thanks!

              Unassigned Unassigned
              binli1988 Bin LI (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: