public class SnapshotReader extends AbstractReader
MySqlSchema.| Modifier and Type | Class and Description |
|---|---|
protected static interface |
SnapshotReader.RecordRecorder |
Reader.State| Modifier and Type | Field and Description |
|---|---|
private boolean |
includeData |
private SnapshotReaderMetrics |
metrics |
private boolean |
minimalBlocking |
private SnapshotReader.RecordRecorder |
recorder |
private Thread |
thread |
context, logger| Constructor and Description |
|---|
SnapshotReader(String name,
MySqlTaskContext context)
Create a snapshot reader.
|
| Modifier and Type | Method and Description |
|---|---|
private Statement |
createStatement(Connection connection) |
private Statement |
createStatementWithLargeResultSet(Connection connection)
Create a JDBC statement that can be used for large result sets.
|
protected void |
doCleanup()
The reader has completed all processing and all
enqueued records have been
consumed, so this reader should clean up any resources that might remain. |
protected void |
doStart()
Start the snapshot and return immediately.
|
protected void |
doStop()
The reader has been requested to stop, so perform any work required to stop the reader's resources that were previously
started. |
protected void |
enqueueSchemaChanges(String dbName,
String ddlStatement) |
protected void |
execute()
Perform the snapshot using the same logic as the "mysqldump" utility.
|
SnapshotReader |
generateInsertEvents()
Set this reader's
execution to produce a Envelope.Operation.CREATE event for
each row. |
SnapshotReader |
generateReadEvents()
Set this reader's
execution to produce a Envelope.Operation.READ event for each
row. |
private void |
logRolesForCurrentUser(JdbcConnection mysql) |
private void |
logServerInformation(JdbcConnection mysql) |
protected String |
quote(String dbOrTableName) |
protected String |
quote(TableId id) |
protected void |
readBinlogPosition(int step,
SourceInfo source,
JdbcConnection mysql,
AtomicReference<String> sql) |
protected void |
recordRowAsInsert(RecordMakers.RecordsForTable recordMaker,
Object[] row,
long ts) |
protected void |
recordRowAsRead(RecordMakers.RecordsForTable recordMaker,
Object[] row,
long ts) |
protected org.apache.kafka.connect.source.SourceRecord |
replaceOffset(org.apache.kafka.connect.source.SourceRecord record)
Utility method to replace the offset in the given record with the latest.
|
SnapshotReader |
useMinimalBlocking(boolean minimalBlocking)
Set whether this reader's
execution should block other transactions as minimally as possible by
releasing the read lock as early as possible. |
cleanupResources, completeSuccessfully, enqueueRecord, failed, failed, isRunning, name, poll, pollComplete, start, state, stop, uponCompletion, wrapprivate boolean minimalBlocking
private final boolean includeData
private SnapshotReader.RecordRecorder recorder
private volatile Thread thread
private final SnapshotReaderMetrics metrics
public SnapshotReader(String name, MySqlTaskContext context)
name - the name of this reader; may not be nullcontext - the task context in which this reader is running; may not be nullpublic SnapshotReader useMinimalBlocking(boolean minimalBlocking)
execution should block other transactions as minimally as possible by
releasing the read lock as early as possible. Although the snapshot process should obtain a consistent snapshot even
when releasing the lock as early as possible, it may be desirable to explicitly hold onto the read lock until execution
completes. In such cases, holding onto the lock will prevent all updates to the database during the snapshot process.minimalBlocking - true if the lock is to be released as early as possible, or false if the lock
is to be held for the entire executionpublic SnapshotReader generateReadEvents()
execution to produce a Envelope.Operation.READ event for each
row.public SnapshotReader generateInsertEvents()
execution to produce a Envelope.Operation.CREATE event for
each row.protected void doStart()
AbstractReader.poll() until that method returns null.doStart in class AbstractReaderprotected void doStop()
AbstractReaderstarted.
This method is always called when AbstractReader.stop() is called, and the first time AbstractReader.isRunning() will return
true the first time and false for any subsequent calls.
doStop in class AbstractReaderprotected void doCleanup()
AbstractReaderenqueued records have been
consumed, so this reader should clean up any resources that might remain.doCleanup in class AbstractReaderprotected void execute()
protected void readBinlogPosition(int step,
SourceInfo source,
JdbcConnection mysql,
AtomicReference<String> sql)
throws SQLException
SQLExceptionprivate Statement createStatementWithLargeResultSet(Connection connection) throws SQLException
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 Statement with forward-only cursor
and read-only concurrency flags, and with a minimum value
fetch size hint.
connection - the JDBC connection; may not be nullSQLException - if there is a problem creating the statementprivate Statement createStatement(Connection connection) throws SQLException
SQLExceptionprivate void logServerInformation(JdbcConnection mysql)
private void logRolesForCurrentUser(JdbcConnection mysql)
protected org.apache.kafka.connect.source.SourceRecord replaceOffset(org.apache.kafka.connect.source.SourceRecord record)
record - the recordprotected void recordRowAsRead(RecordMakers.RecordsForTable recordMaker, Object[] row, long ts) throws InterruptedException
InterruptedExceptionprotected void recordRowAsInsert(RecordMakers.RecordsForTable recordMaker, Object[] row, long ts) throws InterruptedException
InterruptedExceptionCopyright © 2017 JBoss by Red Hat. All rights reserved.