Class AbstractConnectorConnection
java.lang.Object
io.debezium.jdbc.JdbcConnection
io.debezium.connector.mysql.strategy.AbstractConnectorConnection
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
MariaDbConnection
,MySqlConnection
An abstract common implementation of
JdbcConnection
for MySQL and MariaDB.- Author:
- Jiri Pechanec, Randall Hauch, Chris Cranford
-
Nested Class Summary
Nested classes/interfaces inherited from class io.debezium.jdbc.JdbcConnection
JdbcConnection.BlockingMultiResultSetConsumer, JdbcConnection.BlockingResultSetConsumer, JdbcConnection.CallPreparer, JdbcConnection.ConnectionFactory, JdbcConnection.MultiResultSetConsumer, JdbcConnection.Operations, JdbcConnection.ParameterResultSetConsumer, JdbcConnection.ResultSetConsumer, JdbcConnection.ResultSetExtractor<T extends Object>, JdbcConnection.ResultSetMapper<T extends Object>, JdbcConnection.StatementFactory, JdbcConnection.StatementPreparer
-
Field Summary
Modifier and TypeFieldDescriptionprivate final ConnectionConfiguration
private final MySqlFieldReader
private static final org.slf4j.Logger
private static final String
private static final String
private static final String
private static final String
-
Constructor Summary
ConstructorDescriptionAbstractConnectorConnection
(ConnectionConfiguration configuration, MySqlFieldReader fieldReader) Creates a new connection using the supplied configuration. -
Method Summary
Modifier and TypeMethodDescriptionQuery the database server and get the list of binlog files that are currently available.protected abstract GtidSet
createGtidSet
(String gtids) Determine the earliest binlog filename that is still available in the server.abstract GtidSet
filterGtidSet
(Predicate<String> gtidSourceFilter, String offsetGtids, GtidSet availableServerGtidSet, GtidSet purgedServerGtidSet) Apply the include/exclude GTID source filters to the currentGTID set
and merge them onto the currently available GTID set from a MySQL server.getColumnValue
(ResultSet rs, int columnIndex, Column column, Table table) getEstimatedTableSize
(TableId tableId) Get the estimated table size, aka number of rows.getQualifiedTableName
(TableId tableId) protected String
Read the SSL version session variable.boolean
Determine whether the database server has the row-level binlog enabled.boolean
isBinlogPositionAvailable
(MySqlConnectorConfig config, String gtid, String binlogFileName) Determine whether the binlog position as set in the offset details is available on the server.boolean
Determines whether the binlog format used by the database server isbinlog_row_image='FULL'
.abstract boolean
Determine whether the server has enabled GTID support.abstract boolean
boolean
Return whether the table identifiers are case-sensitive.abstract GtidSet
Returns the most recent executed GTID set or position.abstract GtidSet
Get the purged GTID values from the server.querySystemVariables
(String statement) quotedTableIdString
(TableId tableId) Read the charset-related system variables.Read the database server's default character sets for existing databases.Read the system variables.setStatementFor
(Map<String, String> variables) Executes aSET
statement, setting each variable with it's specified value.abstract GtidSet
subtractGtidSet
(GtidSet set1, GtidSet set2) Determines the difference between two GTID sets.boolean
userHasPrivileges
(String grantName) Determine whether the current user has the named privilege.Methods inherited from class io.debezium.jdbc.JdbcConnection
buildReselectColumnQuery, buildSelectWithRowLimits, call, close, commit, config, connect, connection, connection, connectionString, createTableId, database, escapeEscapeSequence, execute, execute, executeWithoutCommitting, getAttributeDetails, getColumnsDetails, getCurrentTimestamp, isConnected, isNullable, isTableType, isTableUniqueIndexIncluded, isValid, loadKeyStore, overrideColumn, parseSqlStatementString, patternBasedFactory, patternBasedFactory, prepareQuery, prepareQuery, prepareQuery, prepareQuery, prepareQuery, prepareQueryAndMap, prepareQueryWithBlockingConsumer, prepareUpdate, print, print, query, query, queryAndMap, queryAndMap, querySingleValue, queryWithBlockingConsumer, quotedColumnIdString, readAllCatalogNames, readAllSchemaNames, readAllTableNames, readPrimaryKeyNames, readPrimaryKeyOrUniqueIndexNames, readSchema, readTableColumn, readTableNames, readTablePreparedStatement, readTableStatement, readTableUniqueIndices, reselectColumns, resolveCatalogName, resolveJdbcType, resolveNativeType, rollback, rowToArray, setAutoCommit, setQueryColumnValue, singleResultMapper, supportedTableTypes, tableTypes, username
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
SQL_SHOW_SYSTEM_VARIABLES
- See Also:
-
SQL_SHOW_SYSTEM_VARIABLES_CHARACTER_SET
- See Also:
-
SQL_SHOW_SESSION_VARIABLE_SSL_VERSION
- See Also:
-
QUOTED_CHARACTER
- See Also:
-
connectionConfig
-
fieldReader
-
-
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 nullfieldReader
- the configured snapshot fetch size
-
-
Method Details
-
getColumnValue
public Object getColumnValue(ResultSet rs, int columnIndex, Column column, Table table) throws SQLException - Overrides:
getColumnValue
in classJdbcConnection
- Throws:
SQLException
-
quotedTableIdString
- Overrides:
quotedTableIdString
in classJdbcConnection
-
getQualifiedTableName
- Overrides:
getQualifiedTableName
in classJdbcConnection
-
connectionString
-
connectionConfig
-
userHasPrivileges
Determine whether the current user has the named privilege. If the user has the "ALL" privilege, this method will always returntrue
.- Parameters:
grantName
- the name of the database privilege; may not be null- Returns:
true
if the user has the named privilege;false
otherwise
-
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
Query the database server and get the list of binlog files that are currently available.- Returns:
- list of binlog files
-
getEstimatedTableSize
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
Read the charset-related system variables.- Returns:
- the system variables that are related to server character sets; never null
-
setStatementFor
Executes aSET
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 isbinlog_row_image='FULL'
.- Returns:
true
if thebinlog_row_image
is set toFULL
,false
otherwise
-
isBinlogFormatRow
public boolean isBinlogFormatRow()Determine whether the database server has the row-level binlog enabled.- Returns:
true
if the server'sbinlog_format
is set toROW
,false
otherwise
-
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 nullgtid
- the GTID from the connector offsets; may be nullbinlogFileName
- 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
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
Determines the difference between two GTID sets.- Parameters:
set1
- the first set; should never be nullset2
- the second set; should never be null- Returns:
- the subtraction of the two sets in a new GtidSet instance; never null
-
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 currentGTID 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 filteroffsetGtids
- the gtids from the offsetsavailableServerGtidSet
- the GTID set currently available in the MySQL serverpurgedServerGtidSet
- 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
Read the system variables.- Returns:
- all the system variables; never null
-
getSessionVariableForSslVersion
Read the SSL version session variable.- Returns:
- the session variable value related to the session SSL version
-
createGtidSet
-
querySystemVariables
-