Package io.debezium.connector.mysql
Class MySqlDatabaseSchema
java.lang.Object
io.debezium.relational.RelationalDatabaseSchema
io.debezium.relational.HistorizedRelationalDatabaseSchema
io.debezium.connector.mysql.MySqlDatabaseSchema
- All Implemented Interfaces:
DatabaseSchema<TableId>
,HistorizedDatabaseSchema<TableId>
,AutoCloseable
Component that records the schema history for databases hosted by a MySQL database server. The schema information includes
the
table definitions
and the Kafka Connect Schema
s for each table, where the
Schema
excludes any columns that have been specified
in the
configuration.- Author:
- Randall Hauch
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.debezium.schema.HistorizedDatabaseSchema
HistorizedDatabaseSchema.SchemaChangeEventConsumer
-
Field Summary
Modifier and TypeFieldDescriptionprivate final MySqlConnectorConfig
private final DdlChanges
private final DdlParser
private final RelationalTableFilters
private static final org.slf4j.Logger
private boolean
Fields inherited from class io.debezium.relational.HistorizedRelationalDatabaseSchema
schemaHistory
Fields inherited from interface io.debezium.schema.DatabaseSchema
NO_CAPTURED_DATA_COLLECTIONS_WARNING
-
Constructor Summary
ConstructorDescriptionMySqlDatabaseSchema
(MySqlConnectorConfig connectorConfig, MySqlValueConverters valueConverter, io.debezium.spi.topic.TopicNamingStrategy<TableId> topicNamingStrategy, SchemaNameAdjuster schemaNameAdjuster, boolean tableIdCaseInsensitive) Create a schema component given the suppliedMySQL connector configuration
. -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
acceptableDatabase
(String databaseName) protected void
appendCreateTableStatement
(StringBuilder sb, Table table) protected void
appendDropTableStatement
(StringBuilder sb, TableId tableId) void
applySchemaChange
(SchemaChangeEvent schemaChange) boolean
assignTableNumber
(long tableNumber, TableId id) Assign the given table number to the table with the specifiedtable ID
.String[]
Get all table names for all databases that are monitored whose events are captured by Debeziumvoid
Clear all of the table mappings.private void
emitChangeEvent
(MySqlPartition partition, MySqlOffsetContext offset, List<SchemaChangeEvent> schemaChangeEvents, String sanitizedDbName, DdlParserListener.Event event, TableId tableId, SchemaChangeEvent.SchemaChangeEventType type, boolean snapshot) protected DdlParser
getExcludeTableId
(long tableNumber) Return the excluded table id associated with MySQL-specific table number.getTableId
(long tableNumber) Return the table id associated with MySQL-specific table number.private TableId
boolean
Return true if the database schema history entity existsvoid
boolean
isGlobalSetVariableStatement
(String ddl, String databaseName) boolean
private List<SchemaChangeEvent>
parseDdl
(MySqlPartition partition, String ddlStatements, String databaseName, MySqlOffsetContext offset, Instant sourceTime, boolean snapshot) parseSnapshotDdl
(MySqlPartition partition, String ddlStatements, String databaseName, MySqlOffsetContext offset, Instant sourceTime) parseStreamingDdl
(MySqlPartition partition, String ddlStatements, String databaseName, MySqlOffsetContext offset, Instant sourceTime) protected void
Discard any currently-cached schemas and rebuild them using the filters.void
setSystemVariables
(Map<String, String> variables) Set the system variables on the DDL parser.boolean
boolean
Get the system variables as known by the DDL parser.Methods inherited from class io.debezium.relational.HistorizedRelationalDatabaseSchema
close, ddlFilter, isHistorized, record, recover, skipUnparseableDdlStatements, tableInformationComplete
Methods inherited from class io.debezium.relational.RelationalDatabaseSchema
assureNonEmptySchema, buildAndRegisterSchema, clearSchemas, getTableFilter, refresh, refreshSchema, removeSchema, schemaFor, tableFor, tableIds, tables
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.debezium.schema.DatabaseSchema
assureNonEmptySchema, schemaFor
Methods inherited from interface io.debezium.schema.HistorizedDatabaseSchema
recover
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
ignoredQueryStatements
-
ddlParser
-
filters
-
ddlChanges
-
tableIdsByTableNumber
-
excludeTableIdsByTableNumber
-
storageInitializationExecuted
private boolean storageInitializationExecuted -
connectorConfig
-
-
Constructor Details
-
MySqlDatabaseSchema
public MySqlDatabaseSchema(MySqlConnectorConfig connectorConfig, MySqlValueConverters valueConverter, io.debezium.spi.topic.TopicNamingStrategy<TableId> topicNamingStrategy, SchemaNameAdjuster schemaNameAdjuster, boolean tableIdCaseInsensitive) Create a schema component given the suppliedMySQL connector configuration
. The DDL statements passed to the schema are parsed and a logical model of the database schema is created.
-
-
Method Details
-
capturedTablesAsStringArray
Get all table names for all databases that are monitored whose events are captured by Debezium- Returns:
- the array with the table names
-
setSystemVariables
Set the system variables on the DDL parser.- Parameters:
variables
- the system variables; may not be null but may be empty
-
systemVariables
Get the system variables as known by the DDL parser.- Returns:
- the system variables; never null
-
appendDropTableStatement
-
appendCreateTableStatement
-
refreshSchemas
protected void refreshSchemas()Discard any currently-cached schemas and rebuild them using the filters. -
isGlobalSetVariableStatement
-
applySchemaChange
-
parseSnapshotDdl
public List<SchemaChangeEvent> parseSnapshotDdl(MySqlPartition partition, String ddlStatements, String databaseName, MySqlOffsetContext offset, Instant sourceTime) -
parseStreamingDdl
public List<SchemaChangeEvent> parseStreamingDdl(MySqlPartition partition, String ddlStatements, String databaseName, MySqlOffsetContext offset, Instant sourceTime) -
parseDdl
private List<SchemaChangeEvent> parseDdl(MySqlPartition partition, String ddlStatements, String databaseName, MySqlOffsetContext offset, Instant sourceTime, boolean snapshot) -
emitChangeEvent
private void emitChangeEvent(MySqlPartition partition, MySqlOffsetContext offset, List<SchemaChangeEvent> schemaChangeEvents, String sanitizedDbName, DdlParserListener.Event event, TableId tableId, SchemaChangeEvent.SchemaChangeEventType type, boolean snapshot) -
acceptableDatabase
-
getTableId
-
getDdlParser
- Specified by:
getDdlParser
in classHistorizedRelationalDatabaseSchema
-
historyExists
public boolean historyExists()Return true if the database schema history entity exists -
storeOnlyCapturedTables
public boolean storeOnlyCapturedTables()- Specified by:
storeOnlyCapturedTables
in interfaceHistorizedDatabaseSchema<TableId>
- Overrides:
storeOnlyCapturedTables
in classHistorizedRelationalDatabaseSchema
-
assignTableNumber
Assign the given table number to the table with the specifiedtable ID
.- Parameters:
tableNumber
- the table number found in binlog eventsid
- the identifier for the corresponding table- Returns:
true
if the assignment was successful, orfalse
if the table is currently excluded in the connector's configuration
-
getTableId
Return the table id associated with MySQL-specific table number.- Parameters:
tableNumber
-- Returns:
- the table id or null if not known
-
getExcludeTableId
Return the excluded table id associated with MySQL-specific table number.- Parameters:
tableNumber
-- Returns:
- the table id or null if not known
-
clearTableMappings
public void clearTableMappings()Clear all of the table mappings. This should be done when the logs are rotated, since in that a different table numbering scheme will be used by all subsequent TABLE_MAP binlog events. -
initializeStorage
public void initializeStorage()- Specified by:
initializeStorage
in interfaceHistorizedDatabaseSchema<TableId>
- Overrides:
initializeStorage
in classHistorizedRelationalDatabaseSchema
-
isStorageInitializationExecuted
public boolean isStorageInitializationExecuted() -
skipSchemaChangeEvent
-