Class ReconcilingBinlogReader
- java.lang.Object
-
- io.debezium.connector.mysql.legacy.ReconcilingBinlogReader
-
- All Implemented Interfaces:
Reader
public class ReconcilingBinlogReader extends Object implements Reader
A reader that unifies the binlog positions of two binlog readers. To do this, at start time we evaluate the (now completed) states of the two binlog readers we want to unify, and create a newBinlogReaderduplicating the lagging reader, but with a halting predicate that will halt it once it has passed the final position of the leading reader.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classReconcilingBinlogReader.OffsetLimitPredicateA Predicate that returns false for any record beyond a given offset.-
Nested classes/interfaces inherited from interface io.debezium.connector.mysql.legacy.Reader
Reader.State
-
-
Field Summary
Fields Modifier and Type Field Description private BooleanaReaderLeadingprivate BinlogReaderbinlogReaderAprivate BinlogReaderbinlogReaderBprivate AtomicBooleancompletedprivate static org.slf4j.LoggerLOGGERprivate AtomicReference<MySqlPartition>partitionprivate BinlogReaderreconcilingReaderprivate AtomicBooleanrunningprivate longserverIdprivate BinlogReaderunifiedReaderprivate AtomicReference<Consumer<MySqlPartition>>uponCompletion
-
Constructor Summary
Constructors Constructor Description ReconcilingBinlogReader(BinlogReader binlogReaderA, BinlogReader binlogReaderB, BinlogReader unifiedReader, long serverId)Create a reconciling Binlog Reader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckLaggingLeadingInfo()private voidcompleteSuccessfully()private voiddetermineLeadingReader()(package private) BinlogReadergetLaggingReader()(package private) BinlogReadergetLeadingReader()Stringname()Get the name of this reader.List<org.apache.kafka.connect.source.SourceRecord>poll()Poll for the next batch of source records.private voidsetupUnifiedReader()voidstart(MySqlPartition partition)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(Consumer<MySqlPartition> 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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.debezium.connector.mysql.legacy.Reader
destroy, initialize
-
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
binlogReaderA
private final BinlogReader binlogReaderA
-
binlogReaderB
private final BinlogReader binlogReaderB
-
unifiedReader
private final BinlogReader unifiedReader
-
reconcilingReader
private BinlogReader reconcilingReader
-
aReaderLeading
private Boolean aReaderLeading
-
partition
private final AtomicReference<MySqlPartition> partition
-
running
private final AtomicBoolean running
-
completed
private final AtomicBoolean completed
-
uponCompletion
private final AtomicReference<Consumer<MySqlPartition>> uponCompletion
-
serverId
private final long serverId
-
-
Constructor Detail
-
ReconcilingBinlogReader
public ReconcilingBinlogReader(BinlogReader binlogReaderA, BinlogReader binlogReaderB, BinlogReader unifiedReader, long serverId)
Create a reconciling Binlog Reader.- Parameters:
binlogReaderA- the first binlog reader to unify.binlogReaderB- the second binlog reader to unify.unifiedReader- the final, unified binlog reader that will run once the reconciliation is complete.
-
-
Method Detail
-
state
public Reader.State state()
Description copied from interface:ReaderGet the current state of this reader.
-
uponCompletion
public void uponCompletion(Consumer<MySqlPartition> 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
-
start
public void start(MySqlPartition partition)
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.
-
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()
-
setupUnifiedReader
private void setupUnifiedReader()
-
determineLeadingReader
private void determineLeadingReader()
-
getLeadingReader
BinlogReader getLeadingReader()
-
getLaggingReader
BinlogReader getLaggingReader()
-
checkLaggingLeadingInfo
private void checkLaggingLeadingInfo()
-
-