Class MySqlDatabaseSchema

All Implemented Interfaces:
DatabaseSchema<TableId>, HistorizedDatabaseSchema<TableId>, AutoCloseable

@NotThreadSafe public class MySqlDatabaseSchema extends HistorizedRelationalDatabaseSchema
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 Schemas for each table, where the Schema excludes any columns that have been specified in the configuration.
Author:
Randall Hauch
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • ignoredQueryStatements

      private final Set<String> ignoredQueryStatements
    • ddlParser

      private final DdlParser ddlParser
    • filters

      private final RelationalTableFilters filters
    • ddlChanges

      private final DdlChanges ddlChanges
    • tableIdsByTableNumber

      private final Map<Long,TableId> tableIdsByTableNumber
    • excludeTableIdsByTableNumber

      private final Map<Long,TableId> excludeTableIdsByTableNumber
    • storageInitializationExecuted

      private boolean storageInitializationExecuted
    • connectorConfig

      private final MySqlConnectorConfig connectorConfig
  • Constructor Details

  • Method Details

    • capturedTablesAsStringArray

      public String[] 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

      public void setSystemVariables(Map<String,String> variables)
      Set the system variables on the DDL parser.
      Parameters:
      variables - the system variables; may not be null but may be empty
    • systemVariables

      public SystemVariables systemVariables()
      Get the system variables as known by the DDL parser.
      Returns:
      the system variables; never null
    • appendDropTableStatement

      protected void appendDropTableStatement(StringBuilder sb, TableId tableId)
    • appendCreateTableStatement

      protected void appendCreateTableStatement(StringBuilder sb, Table table)
    • refreshSchemas

      protected void refreshSchemas()
      Discard any currently-cached schemas and rebuild them using the filters.
    • isGlobalSetVariableStatement

      public boolean isGlobalSetVariableStatement(String ddl, String databaseName)
    • applySchemaChange

      public void applySchemaChange(SchemaChangeEvent schemaChange)
    • 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

      private boolean acceptableDatabase(String databaseName)
    • getTableId

      private TableId getTableId(DdlParserListener.Event event)
    • getDdlParser

      protected DdlParser getDdlParser()
      Specified by:
      getDdlParser in class HistorizedRelationalDatabaseSchema
    • historyExists

      public boolean historyExists()
      Return true if the database schema history entity exists
    • storeOnlyCapturedTables

      public boolean storeOnlyCapturedTables()
      Specified by:
      storeOnlyCapturedTables in interface HistorizedDatabaseSchema<TableId>
      Overrides:
      storeOnlyCapturedTables in class HistorizedRelationalDatabaseSchema
    • assignTableNumber

      public boolean assignTableNumber(long tableNumber, TableId id)
      Assign the given table number to the table with the specified table ID.
      Parameters:
      tableNumber - the table number found in binlog events
      id - the identifier for the corresponding table
      Returns:
      true if the assignment was successful, or false if the table is currently excluded in the connector's configuration
    • getTableId

      public TableId getTableId(long tableNumber)
      Return the table id associated with MySQL-specific table number.
      Parameters:
      tableNumber -
      Returns:
      the table id or null if not known
    • getExcludeTableId

      public TableId getExcludeTableId(long tableNumber)
      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 interface HistorizedDatabaseSchema<TableId>
      Overrides:
      initializeStorage in class HistorizedRelationalDatabaseSchema
    • isStorageInitializationExecuted

      public boolean isStorageInitializationExecuted()
    • skipSchemaChangeEvent

      public boolean skipSchemaChangeEvent(SchemaChangeEvent event)