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 aChainedReaderconsisting of aSnapshotReaderand aBinlogReaderfor all tables newly added to the config in parallel with aBinlogReaderfor all the tables previously in the config.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classParallelSnapshotReader.ParallelHaltingPredicateA 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 AtomicBooleancompletedprivate static org.slf4j.LoggerLOGGERprivate BinlogReadernewTablesBinlogReaderprivate ChainedReadernewTablesReaderprivate BinlogReaderoldTablesReaderprivate AtomicBooleanrunningprivate MySqlConnectorTask.ServerIdGeneratorserverIdGeneratorprivate 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 voidcompleteSuccessfully()ReconcilingBinlogReadercreateReconcilingBinlogReader(BinlogReader unifiedReader)Create and return aReconcilingBinlogReaderfor the two binlog readers contained in this ParallelSnapshotReader.voidinitialize()Perform any initialization of the reader before being started.Stringname()Get the name of this reader.List<org.apache.kafka.connect.source.SourceRecord>poll()Poll for the next batch of source records.voidstart()Start the reader and return immediately.Reader.Statestate()Get the current state of this reader.voidstop()Stop the reader from running and transition to theReader.State.STOPPINGstate until all remaining records areconsumed, at which point its state transitions toReader.State.STOPPED.voiduponCompletion(Runnable handler)Set the function that should be called when this reader transitions from theReader.State.STOPPINGtoReader.State.STOPPEDstate, which is after all generated records have been consumed via thepollmethod.
-
-
-
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-Filtersmatching 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 aReconcilingBinlogReaderfor the two binlog readers contained in this ParallelSnapshotReader.- Returns:
- a
ReconcilingBinlogReader
-
uponCompletion
public void uponCompletion(Runnable handler)
Description copied from interface:ReaderSet the function that should be called when this reader transitions from theReader.State.STOPPINGtoReader.State.STOPPEDstate, which is after all generated records have been consumed via thepollmethod.This method should only be called while the reader is in the
Reader.State.STOPPEDstate.- Specified by:
uponCompletionin interfaceReader- Parameters:
handler- the function; may not be null
-
initialize
public void initialize()
Description copied from interface:ReaderPerform 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:
initializein interfaceReader
-
start
public void start()
Description copied from interface:ReaderStart the reader and return immediately. Once started, theSourceRecords 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:ReaderStop the reader from running and transition to theReader.State.STOPPINGstate until all remaining records areconsumed, at which point its state transitions toReader.State.STOPPED.
-
state
public Reader.State state()
Description copied from interface:ReaderGet the current state of this reader.
-
poll
public List<org.apache.kafka.connect.source.SourceRecord> poll() throws InterruptedException
Description copied from interface:ReaderPoll for the next batch of source records. This method returnsnullonly when all records generated by this reader have been processed, following the natural or explicitstoppingof 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:
pollin interfaceReader- Returns:
- the list of source records that may or may not be empty; or
nullwhen 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()
-
-