Class ParallelSnapshotReader
- java.lang.Object
-
- io.debezium.connector.mysql.legacy.ParallelSnapshotReader
-
- All Implemented Interfaces:
Reader
public class ParallelSnapshotReader extends Object implements Reader
A reader that runs aChainedReader
consisting of aSnapshotReader
and aBinlogReader
for all tables newly added to the config in parallel with aBinlogReader
for all the tables previously in the config.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
ParallelSnapshotReader.ParallelHaltingPredicate
A Halting Predicate for the parallel snapshot reader.-
Nested classes/interfaces inherited from interface io.debezium.connector.mysql.legacy.Reader
Reader.State
-
-
Field Summary
Fields Modifier and Type Field Description private AtomicBoolean
completed
private static org.slf4j.Logger
LOGGER
private BinlogReader
newTablesBinlogReader
private ChainedReader
newTablesReader
private BinlogReader
oldTablesReader
private AtomicBoolean
running
private MySqlConnectorTask.ServerIdGenerator
serverIdGenerator
private AtomicReference<Runnable>
uponCompletion
-
Constructor Summary
Constructors Constructor Description ParallelSnapshotReader(Configuration config, MySqlTaskContext noSnapshotContext, Filters snapshotFilters, MySqlConnectorTask.ServerIdGenerator serverIdGenerator)
Create a ParallelSnapshotReader.ParallelSnapshotReader(BinlogReader oldTablesBinlogReader, SnapshotReader newTablesSnapshotReader, BinlogReader newTablesBinlogReader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
completeSuccessfully()
ReconcilingBinlogReader
createReconcilingBinlogReader(BinlogReader unifiedReader)
Create and return aReconcilingBinlogReader
for the two binlog readers contained in this ParallelSnapshotReader.void
initialize()
Perform any initialization of the reader before being started.String
name()
Get the name of this reader.List<org.apache.kafka.connect.source.SourceRecord>
poll()
Poll for the next batch of source records.void
start()
Start the reader and return immediately.Reader.State
state()
Get the current state of this reader.void
stop()
Stop the reader from running and transition to theReader.State.STOPPING
state until all remaining records areconsumed
, at which point its state transitions toReader.State.STOPPED
.void
uponCompletion(Runnable handler)
Set the function that should be called when this reader transitions from theReader.State.STOPPING
toReader.State.STOPPED
state, which is after all generated records have been consumed via thepoll
method.
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
oldTablesReader
private final BinlogReader oldTablesReader
-
newTablesBinlogReader
private final BinlogReader newTablesBinlogReader
-
newTablesReader
private final ChainedReader newTablesReader
-
running
private final AtomicBoolean running
-
completed
private final AtomicBoolean completed
-
uponCompletion
private final AtomicReference<Runnable> uponCompletion
-
serverIdGenerator
private final MySqlConnectorTask.ServerIdGenerator serverIdGenerator
-
-
Constructor Detail
-
ParallelSnapshotReader
public ParallelSnapshotReader(Configuration config, MySqlTaskContext noSnapshotContext, Filters snapshotFilters, MySqlConnectorTask.ServerIdGenerator serverIdGenerator)
Create a ParallelSnapshotReader.- Parameters:
config
- the current connector configuration.noSnapshotContext
- The context for those tables not undergoing a snapshot.snapshotFilters
-Filters
matching the tables that should be snapshotted.serverIdGenerator
- a generator for creating unconflicting serverIds.
-
ParallelSnapshotReader
ParallelSnapshotReader(BinlogReader oldTablesBinlogReader, SnapshotReader newTablesSnapshotReader, BinlogReader newTablesBinlogReader)
-
-
Method Detail
-
createReconcilingBinlogReader
public ReconcilingBinlogReader createReconcilingBinlogReader(BinlogReader unifiedReader)
Create and return aReconcilingBinlogReader
for the two binlog readers contained in this ParallelSnapshotReader.- Returns:
- a
ReconcilingBinlogReader
-
uponCompletion
public void uponCompletion(Runnable handler)
Description copied from interface:Reader
Set the function that should be called when this reader transitions from theReader.State.STOPPING
toReader.State.STOPPED
state, which is after all generated records have been consumed via thepoll
method.This method should only be called while the reader is in the
Reader.State.STOPPED
state.- Specified by:
uponCompletion
in interfaceReader
- Parameters:
handler
- the function; may not be null
-
initialize
public void initialize()
Description copied from interface:Reader
Perform any initialization of the reader before being started. This method should be called exactly once beforeReader.start()
is called, and it should block until all initialization is completed.- Specified by:
initialize
in interfaceReader
-
start
public void start()
Description copied from interface:Reader
Start the reader and return immediately. Once started, theSourceRecord
s generated by the reader can be obtained by periodically callingReader.poll()
until that method returnsnull
.This method does nothing if it is already running.
-
stop
public void stop()
Description copied from interface:Reader
Stop the reader from running and transition to theReader.State.STOPPING
state until all remaining records areconsumed
, at which point its state transitions toReader.State.STOPPED
.
-
state
public Reader.State state()
Description copied from interface:Reader
Get the current state of this reader.
-
poll
public List<org.apache.kafka.connect.source.SourceRecord> poll() throws InterruptedException
Description copied from interface:Reader
Poll for the next batch of source records. This method returnsnull
only when all records generated by this reader have been processed, following the natural or explicitstopping
of this reader. Note that this method may block if no additional records are available but the reader may produce more, thus callers should call this method continually until this method returnsnull
.- Specified by:
poll
in interfaceReader
- Returns:
- the list of source records that may or may not be empty; or
null
when there will be no more records because the reader has completelyReader.State.STOPPED
. - Throws:
InterruptedException
- if this thread is interrupted while waiting for more records
-
completeSuccessfully
private void completeSuccessfully()
-
-