Package io.debezium.connector.binlog
Class BinlogDatabaseSchema<P extends BinlogPartition,O extends BinlogOffsetContext<?>,V extends ValueConverterProvider,D extends DefaultValueConverter>
java.lang.Object
io.debezium.relational.RelationalDatabaseSchema
io.debezium.relational.HistorizedRelationalDatabaseSchema
io.debezium.connector.binlog.BinlogDatabaseSchema<P,O,V,D>
- All Implemented Interfaces:
DatabaseSchema<TableId>,HistorizedDatabaseSchema<TableId>,AutoCloseable
public abstract class BinlogDatabaseSchema<P extends BinlogPartition,O extends BinlogOffsetContext<?>,V extends ValueConverterProvider,D extends DefaultValueConverter>
extends HistorizedRelationalDatabaseSchema
Abstract implementation that records schema history for binlog-based databases.
The schema information includes the
Tables and the Kafka Connect
RelationalDatabaseSchema.schemaFor(TableId) for each table, where the Schema excludes
any columns that have been specified in the RelationalDatabaseConnectorConfig.COLUMN_EXCLUDE_LIST configuration.- Author:
- Chris Cranford
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.debezium.schema.HistorizedDatabaseSchema
HistorizedDatabaseSchema.SchemaChangeEventConsumer -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BinlogConnectorConfigprivate final DdlChangesprivate final DdlParserprivate final RelationalTableFiltersprivate static final org.slf4j.LoggerFields inherited from class io.debezium.relational.HistorizedRelationalDatabaseSchema
schemaHistory, storageInitializationExecutedFields inherited from interface io.debezium.schema.DatabaseSchema
NO_CAPTURED_DATA_COLLECTIONS_WARNING -
Constructor Summary
ConstructorsConstructorDescriptionBinlogDatabaseSchema(BinlogConnectorConfig connectorConfig, V valueConverter, D defaultValueConverter, io.debezium.spi.topic.TopicNamingStrategy<TableId> topicNamingStrategy, SchemaNameAdjuster schemaNameAdjuster, boolean tableIdCaseInsensitive) Creates a binlog-connector based relational schema based on the supplied configuration. -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanacceptableDatabase(String databaseName) voidapplySchemaChange(SchemaChangeEvent schemaChange) booleanassignTableNumber(long tableNumber, TableId id) Assign the given table number to the table with the specifiedTableId.String[]Get all table names for all databases that are captured.voidClear all table mappings.protected abstract DdlParsercreateDdlParser(BinlogConnectorConfig connectorConfig, V valueConverter) Creates the connector-specific DDL parser instance.private voidemitChangeEvent(P partition, O offset, List<SchemaChangeEvent> schemaChangeEvents, String sanitizedDbName, DdlParserListener.Event event, TableId tableId, SchemaChangeEvent.SchemaChangeEventType type, boolean snapshot) protected DdlParsergetExcludeTableId(long tableNumber) Return the excluded table id associated with connector-specific table number.private TablegetTable(TableId tableId, SchemaChangeEvent.SchemaChangeEventType type) getTableId(long tableNumber) Return the table id associated with connector-specific table number.private TableIdprotected voidhandleDatabaseEvent(O offset, String databaseName, Instant changeTime) Update offsets based on a database-specific event.protected voidUpdate offsets based on a table-specific event.booleanisGlobalSetVariableStatement(String ddl, String databaseName) Checks whether the provided DDL is a global set variable statement.private List<SchemaChangeEvent>parseDdl(P partition, String ddlStatements, String databaseName, O offset, Instant sourceTime, boolean snapshot) parseSnapshotDdl(P partition, String ddlStatements, String databaseName, O offset, Instant sourceTime) Parse DDL from the connector's snapshot phase.parseStreamingDdl(P partition, String ddlStatements, String databaseName, O offset, Instant sourceTime) Parse DDL from the connector's streaming phase.protected voidDiscards any currently-cached schemas and rebuild using filtersvoidsetSystemVariables(SystemVariables.Scope scope, Map<String, String> variables) Sets system variables with use by the DDL parser.booleanGet all system variables known to the DDL parser.Methods inherited from class io.debezium.relational.HistorizedRelationalDatabaseSchema
close, ddlFilter, historyExists, initializeStorage, isHistorized, isStorageInitializationExecuted, record, recover, skipUnparseableDdlStatements, storeOnlyCapturedDatabases, storeOnlyCapturedTables, tableInformationCompleteMethods inherited from class io.debezium.relational.RelationalDatabaseSchema
assureNonEmptySchema, buildAndRegisterSchema, clearSchemas, getTableFilter, refresh, refreshSchema, removeSchema, schemaFor, tableFor, tableIds, tablesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.debezium.schema.DatabaseSchema
assureNonEmptySchema, schemaForMethods inherited from interface io.debezium.schema.HistorizedDatabaseSchema
recover
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
ignoredQueryStatements
-
ddlParser
-
filters
-
ddlChanges
-
tableIdsByTableNumber
-
excludeTableIdsByTableNumber
-
connectorConfig
-
-
Constructor Details
-
BinlogDatabaseSchema
public BinlogDatabaseSchema(BinlogConnectorConfig connectorConfig, V valueConverter, D defaultValueConverter, io.debezium.spi.topic.TopicNamingStrategy<TableId> topicNamingStrategy, SchemaNameAdjuster schemaNameAdjuster, boolean tableIdCaseInsensitive) Creates a binlog-connector based relational schema based on the supplied configuration. The DDL statements passed to the schema are parsed and a logical model is maintained of the database.- Parameters:
connectorConfig- the connector configuration, should not be nullvalueConverter- the connector-specific value converter, should not be nulldefaultValueConverter- the connector-specific default value converter, should not be nulltopicNamingStrategy- the topic naming strategy to be used, should not be nullschemaNameAdjuster- the schema name adjuster, should not be nulltableIdCaseInsensitive- whether table identifiers are case-insensitive
-
-
Method Details
-
getDdlParser
- Specified by:
getDdlParserin classHistorizedRelationalDatabaseSchema
-
skipSchemaChangeEvent
- Overrides:
skipSchemaChangeEventin classHistorizedRelationalDatabaseSchema
-
applySchemaChange
-
capturedTablesAsStringArray
Get all table names for all databases that are captured.- Returns:
- array of table names
-
setSystemVariables
Sets system variables with use by the DDL parser.- Parameters:
scope- the variable scopevariables- system variables; may not be null but can be empty
-
systemVariables
Get all system variables known to the DDL parser.- Returns:
- the system variables; never null
-
isGlobalSetVariableStatement
Checks whether the provided DDL is a global set variable statement.- Parameters:
ddl- the DDL to check; may be null or emptydatabaseName- the database name; may be null or empty- Returns:
- true if the statement is a global set variable statement; false otherwise
-
assignTableNumber
Assign the given table number to the table with the specifiedTableId.- Parameters:
tableNumber- the table number found in binlog eventsid- the identifier for the corresponding table- Returns:
- true if the assignment was successful, false if the table is excluded via configuration
-
getTableId
Return the table id associated with connector-specific table number.- Parameters:
tableNumber- the table number from binlog- Returns:
- the table id or null if not known
-
getExcludeTableId
Return the excluded table id associated with connector-specific table number.- Parameters:
tableNumber- the table number from binlog- Returns:
- the table id or null if not known
-
clearTableMappings
public void clearTableMappings()Clear all table mappings. This should be done when the logs are rotated, since in that a different table, numbering scheme will be used by all subsequentTABLE_MAPbinlog events. -
parseSnapshotDdl
public List<SchemaChangeEvent> parseSnapshotDdl(P partition, String ddlStatements, String databaseName, O offset, Instant sourceTime) Parse DDL from the connector's snapshot phase.- Parameters:
partition- the partition; should not be nullddlStatements- the DDL statement to be parseddatabaseName- the database nameoffset- the connector offsets; should not be nullsourceTime- time the DDL happened, should not be null- Returns:
- list of parsed schema changes
-
parseStreamingDdl
public List<SchemaChangeEvent> parseStreamingDdl(P partition, String ddlStatements, String databaseName, O offset, Instant sourceTime) Parse DDL from the connector's streaming phase.- Parameters:
partition- the partition; should not be nullddlStatements- the DDL statement to be parseddatabaseName- the database nameoffset- the connector offsets; should not be nullsourceTime- time the DDL happened, should not be null- Returns:
- list of parsed schema changes
-
createDdlParser
protected abstract DdlParser createDdlParser(BinlogConnectorConfig connectorConfig, V valueConverter) Creates the connector-specific DDL parser instance.- Parameters:
connectorConfig- the binlog connector configuration, never nullvalueConverter- the value converter, never null- Returns:
- the connector's DDL parser instance, never null
-
handleTableEvent
protected void handleTableEvent(O offset, String databaseName, Set<TableId> tableIds, Instant changeTime) Update offsets based on a table-specific event.- Parameters:
offset- the offsets to be mutated; should not be nulldatabaseName- the database nametableIds- set of table identifierschangeTime- the time the event happened
-
handleDatabaseEvent
Update offsets based on a database-specific event.- Parameters:
offset- the offsets to be mutated; should not be nulldatabaseName- the database namechangeTime- the time the event happened
-
refreshSchemas
protected void refreshSchemas()Discards any currently-cached schemas and rebuild using filters -
parseDdl
-
emitChangeEvent
private void emitChangeEvent(P partition, O offset, List<SchemaChangeEvent> schemaChangeEvents, String sanitizedDbName, DdlParserListener.Event event, TableId tableId, SchemaChangeEvent.SchemaChangeEventType type, boolean snapshot) -
getTable
-
acceptableDatabase
-
getTableId
-