Class AbstractConnectorConnection

java.lang.Object
io.debezium.jdbc.JdbcConnection
io.debezium.connector.mysql.strategy.AbstractConnectorConnection
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
MariaDbConnection, MySqlConnection

public abstract class AbstractConnectorConnection extends JdbcConnection
An abstract common implementation of JdbcConnection for MySQL and MariaDB.
Author:
Jiri Pechanec, Randall Hauch, Chris Cranford
  • Field Details

  • Constructor Details

    • AbstractConnectorConnection

      public AbstractConnectorConnection(ConnectionConfiguration configuration, MySqlFieldReader fieldReader)
      Creates a new connection using the supplied configuration.
      Parameters:
      configuration - the connection configuration instance, may not be null
      fieldReader - the configured snapshot fetch size
  • Method Details

    • getColumnValue

      public Object getColumnValue(ResultSet rs, int columnIndex, Column column, Table table) throws SQLException
      Overrides:
      getColumnValue in class JdbcConnection
      Throws:
      SQLException
    • quotedTableIdString

      public String quotedTableIdString(TableId tableId)
      Overrides:
      quotedTableIdString in class JdbcConnection
    • getQualifiedTableName

      public String getQualifiedTableName(TableId tableId)
      Overrides:
      getQualifiedTableName in class JdbcConnection
    • connectionString

      public String connectionString()
    • connectionConfig

      public ConnectionConfiguration connectionConfig()
    • userHasPrivileges

      public boolean userHasPrivileges(String grantName)
      Determine whether the current user has the named privilege. If the user has the "ALL" privilege, this method will always return true.
      Parameters:
      grantName - the name of the database privilege; may not be null
      Returns:
      true if the user has the named privilege; false otherwise
    • earliestBinlogFilename

      public String earliestBinlogFilename()
      Determine the earliest binlog filename that is still available in the server.
      Returns:
      the name of the earliest binlog filename, or null if there are none
    • availableBinlogFiles

      public List<String> availableBinlogFiles()
      Query the database server and get the list of binlog files that are currently available.
      Returns:
      list of binlog files
    • getEstimatedTableSize

      public OptionalLong getEstimatedTableSize(TableId tableId)
      Get the estimated table size, aka number of rows.
      Parameters:
      tableId - the table identifier; should never be null
      Returns:
      an optional long-value that may be empty if no data is available or an exception occurred
    • readCharsetSystemVariables

      public Map<String,String> readCharsetSystemVariables()
      Read the charset-related system variables.
      Returns:
      the system variables that are related to server character sets; never null
    • setStatementFor

      public String setStatementFor(Map<String,String> variables)
      Executes a SET statement, setting each variable with it's specified value.
      Parameters:
      variables - key/value variable names as keys and the value(s) to be set
      Returns:
      the constructed SET database statement; never null
    • isBinlogRowImageFull

      public boolean isBinlogRowImageFull()
      Determines whether the binlog format used by the database server is binlog_row_image='FULL'.
      Returns:
      true if the binlog_row_image is set to FULL, false otherwise
    • isBinlogFormatRow

      public boolean isBinlogFormatRow()
      Determine whether the database server has the row-level binlog enabled.
      Returns:
      true if the server's binlog_format is set to ROW, false otherwise
    • readDatabaseCollations

      public Map<String,AbstractConnectorConnection.DatabaseLocales> readDatabaseCollations()
      Read the database server's default character sets for existing databases.
      Returns:
      the map of database names and their default character sets; never null
    • isTableIdCaseSensitive

      public boolean isTableIdCaseSensitive()
      Return whether the table identifiers are case-sensitive.
      Returns:
      true if the table identifiers are case-sensitive, false otherwise
    • isBinlogPositionAvailable

      public boolean isBinlogPositionAvailable(MySqlConnectorConfig config, String gtid, String binlogFileName)
      Determine whether the binlog position as set in the offset details is available on the server.
      Parameters:
      config - the connector configuration; should not be null
      gtid - the GTID from the connector offsets; may be null
      binlogFileName - the binlog file name from the connector offsets; may be null
      Returns:
      true if the binlog position is available, false otherwise
    • isGtidModeEnabled

      public abstract boolean isGtidModeEnabled()
      Determine whether the server has enabled GTID support.
      Returns:
      false if the server has not enabled GTIDs, true otherwise
    • knownGtidSet

      public abstract GtidSet knownGtidSet()
      Returns the most recent executed GTID set or position.
      Returns:
      the string representation of the most recent executed GTID set or position; never null but will be empty if the server does not support or has not processed any GTID
    • subtractGtidSet

      public abstract GtidSet subtractGtidSet(GtidSet set1, GtidSet set2)
      Determines the difference between two GTID sets.
      Parameters:
      set1 - the first set; should never be null
      set2 - the second set; should never be null
      Returns:
      the subtraction of the two sets in a new GtidSet instance; never null
    • purgedGtidSet

      public abstract GtidSet purgedGtidSet()
      Get the purged GTID values from the server.
      Returns:
      A GTID set; may be empty of GTID support is not enabled or if none have been purged
    • isMariaDb

      public abstract boolean isMariaDb()
    • filterGtidSet

      public abstract GtidSet filterGtidSet(Predicate<String> gtidSourceFilter, String offsetGtids, GtidSet availableServerGtidSet, GtidSet purgedServerGtidSet)
      Apply the include/exclude GTID source filters to the current GTID set and merge them onto the currently available GTID set from a MySQL server. The merging behavior of this method might seem a bit strange at first. It's required in order for Debezium to consume a MySQL binlog that has multi-source replication enabled, if a failover has to occur. In such a case, the server that Debezium is failed over to might have a different set of sources, but still include the sources required for Debezium to continue to function. MySQL does not allow downstream replicas to connect if the GTID set does not contain GTIDs for all channels that the server is replicating from, even if the server does have the data needed by the client. To get around this, we can have Debezium merge its GTID set with whatever is on the server, so that MySQL will allow it to connect. See DBZ-143 for details. This method does not mutate any state in the context.
      Parameters:
      gtidSourceFilter - the source filter
      offsetGtids - the gtids from the offsets
      availableServerGtidSet - the GTID set currently available in the MySQL server
      purgedServerGtidSet - the GTID set already purged by the MySQL server
      Returns:
      A GTID set meant for consuming from a MySQL binlog; may return null if the SourceInfo has no GTIDs and therefore none were filtered
    • readSystemVariables

      protected Map<String,String> readSystemVariables()
      Read the system variables.
      Returns:
      all the system variables; never null
    • getSessionVariableForSslVersion

      protected String getSessionVariableForSslVersion()
      Read the SSL version session variable.
      Returns:
      the session variable value related to the session SSL version
    • createGtidSet

      protected abstract GtidSet createGtidSet(String gtids)
    • querySystemVariables

      private Map<String,String> querySystemVariables(String statement)