Class SnapshotReader
- All Implemented Interfaces:
Reader
MySqlSchema.- Author:
- Randall Hauch
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class io.debezium.connector.mysql.legacy.AbstractReader
AbstractReader.AcceptAllPredicateNested classes/interfaces inherited from interface io.debezium.connector.mysql.legacy.Reader
Reader.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ExecutorServiceprivate final booleanprivate final SnapshotReaderMetricsprivate final MysqlFieldReaderprivate SnapshotReader.RecordRecorderprivate final MySqlConnectorConfig.SnapshotLockingModeprivate final booleanFields inherited from class io.debezium.connector.mysql.legacy.AbstractReader
changeEventQueueMetrics, connectionContext, context, logger -
Constructor Summary
ConstructorsConstructorDescriptionSnapshotReader(String name, MySqlTaskContext context) Create a snapshot reader.SnapshotReader(String name, MySqlTaskContext context, boolean useGlobalLock) Create a snapshot reader that can use global locking only optionally. -
Method Summary
Modifier and TypeMethodDescriptionprivate StatementcreateStatement(Connection connection) private StatementcreateStatementWithLargeResultSet(Connection connection) Create a JDBC statement that can be used for large result sets.protected voidThe reader has completed all processing and allenqueued recordshave beenconsumed, so this reader should clean up any resources that might remain.voidThe reader has been requested to de-initialize resources after stopping.protected voidThe reader has been requested to initialize resources prior to starting.protected voiddoStart(MySqlPartition partition) Start the snapshot and return immediately.protected voiddoStop(MySqlPartition partition) The reader has been requested to stop, so perform any work required to stop the reader's resources that were previouslystarted.protected voidenqueueSchemaChanges(String dbName, Set<TableId> tables, String ddlStatement) protected voidexecute(MySqlPartition partition) Perform the snapshot using the same logic as the "mysqldump" utility.Set this reader'sexecutionto produce anEnvelope.Operation.READevent for each row.private FiltersgetCreateTableFilters(Filters filters) Get the filters for table creation.private voidprivate voidprotected Stringprotected Stringprotected voidreadBinlogPosition(int step, SourceInfo source, JdbcConnection mysql, AtomicReference<String> sql) private voidreadTableSchema(AtomicReference<String> sql, JdbcConnection mysql, MySqlSchema schema, SourceInfo source, String dbName, TableId tableId) protected voidrecordRowAsInsert(RecordMakers.RecordsForTable recordMaker, Object[] row, Instant ts) protected voidrecordRowAsRead(RecordMakers.RecordsForTable recordMaker, Object[] row, Instant ts) protected org.apache.kafka.connect.source.SourceRecordreplaceOffsetAndSource(org.apache.kafka.connect.source.SourceRecord record) Utility method to replace the offset and the source in the given record with the latest.private booleanshouldRecordTableSchema(MySqlSchema schema, Filters filters, TableId id) Whether DDL for the given table should be recorded.Methods inherited from class io.debezium.connector.mysql.legacy.AbstractReader
cleanupResources, completeSuccessfully, destroy, enqueueRecord, failed, failed, initialize, isRunning, name, poll, pollComplete, start, state, stop, toString, uponCompletion, wrap
-
Field Details
-
includeData
private final boolean includeData -
recorder
-
metrics
-
executorService
-
useGlobalLock
private final boolean useGlobalLock -
mysqlFieldReader
-
snapshotLockingMode
-
-
Constructor Details
-
SnapshotReader
Create a snapshot reader.- Parameters:
name- the name of this reader; may not be nullcontext- the task context in which this reader is running; may not be null
-
SnapshotReader
SnapshotReader(String name, MySqlTaskContext context, boolean useGlobalLock) Create a snapshot reader that can use global locking only optionally. Used mostly for testing.- Parameters:
name- the name of this reader; may not be nullcontext- the task context in which this reader is running; may not be nulluseGlobalLock-falseto simulate cloud (Amazon RDS) restrictions
-
-
Method Details
-
generateReadEvents
Set this reader'sexecutionto produce anEnvelope.Operation.READevent for each row.- Returns:
- this object for method chaining; never null
-
doInitialize
protected void doInitialize()Description copied from class:AbstractReaderThe reader has been requested to initialize resources prior to starting. This should only be called once beforeAbstractReader.doStart(MySqlPartition).- Overrides:
doInitializein classAbstractReader
-
doDestroy
public void doDestroy()Description copied from class:AbstractReaderThe reader has been requested to de-initialize resources after stopping. This should only be called once afterAbstractReader.doStop(MySqlPartition).- Overrides:
doDestroyin classAbstractReader
-
doStart
Start the snapshot and return immediately. Once started, the records read from the database can be retrieved usingAbstractReader.poll()until that method returnsnull.- Specified by:
doStartin classAbstractReader
-
doStop
Description copied from class:AbstractReaderThe reader has been requested to stop, so perform any work required to stop the reader's resources that were previouslystarted.This method is always called when
Reader.stop()is called, and the first timeAbstractReader.isRunning()will returntruethe first time andfalsefor any subsequent calls.- Specified by:
doStopin classAbstractReader
-
doCleanup
protected void doCleanup()Description copied from class:AbstractReaderThe reader has completed all processing and allenqueued recordshave beenconsumed, so this reader should clean up any resources that might remain.- Specified by:
doCleanupin classAbstractReader
-
execute
Perform the snapshot using the same logic as the "mysqldump" utility. -
readTableSchema
private void readTableSchema(AtomicReference<String> sql, JdbcConnection mysql, MySqlSchema schema, SourceInfo source, String dbName, TableId tableId) throws SQLException - Throws:
SQLException
-
shouldRecordTableSchema
Whether DDL for the given table should be recorded. -
readBinlogPosition
protected void readBinlogPosition(int step, SourceInfo source, JdbcConnection mysql, AtomicReference<String> sql) throws SQLException - Throws:
SQLException
-
getCreateTableFilters
Get the filters for table creation. Depending on the configuration, this may not be the default filter set.- Parameters:
filters- the default filters of thisSnapshotReader- Returns:
Filtersthat represent all the tables that this snapshot reader should CREATE
-
quote
-
quote
-
createStatementWithLargeResultSet
Create a JDBC statement that can be used for large result sets.By default, the MySQL Connector/J driver retrieves all rows for ResultSets and stores them in memory. In most cases this is the most efficient way to operate and, due to the design of the MySQL network protocol, is easier to implement. However, when ResultSets that have a large number of rows or large values, the driver may not be able to allocate heap space in the JVM and may result in an
OutOfMemoryError. See DBZ-94 for details.This method handles such cases using the recommended technique for MySQL by creating the JDBC
Statementwithforward-onlycursor andread-only concurrencyflags, and with aminimum valuefetch size hint.- Parameters:
connection- the JDBC connection; may not be null- Returns:
- the statement; never null
- Throws:
SQLException- if there is a problem creating the statement
-
createStatement
- Throws:
SQLException
-
logServerInformation
-
logRolesForCurrentUser
-
replaceOffsetAndSource
protected org.apache.kafka.connect.source.SourceRecord replaceOffsetAndSource(org.apache.kafka.connect.source.SourceRecord record) Utility method to replace the offset and the source in the given record with the latest. This is used on the last record produced during the snapshot.- Parameters:
record- the record- Returns:
- the updated record
-
enqueueSchemaChanges
-
recordRowAsRead
protected void recordRowAsRead(RecordMakers.RecordsForTable recordMaker, Object[] row, Instant ts) throws InterruptedException - Throws:
InterruptedException
-
recordRowAsInsert
protected void recordRowAsInsert(RecordMakers.RecordsForTable recordMaker, Object[] row, Instant ts) throws InterruptedException - Throws:
InterruptedException
-