Class ReconcilingBinlogReader
java.lang.Object
io.debezium.connector.mysql.legacy.ReconcilingBinlogReader
- All Implemented Interfaces:
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 new
BinlogReader
duplicating 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
Modifier and TypeClassDescription(package private) static class
A 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
Modifier and TypeFieldDescriptionprivate Boolean
private final BinlogReader
private final BinlogReader
private final AtomicBoolean
private static final org.slf4j.Logger
private final AtomicReference<MySqlPartition>
private BinlogReader
private final AtomicBoolean
private final long
private final BinlogReader
private final AtomicReference<Consumer<MySqlPartition>>
-
Constructor Summary
ConstructorDescriptionReconcilingBinlogReader
(BinlogReader binlogReaderA, BinlogReader binlogReaderB, BinlogReader unifiedReader, long serverId) Create a reconciling Binlog Reader. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
private void
private void
(package private) BinlogReader
(package private) BinlogReader
name()
Get the name of this reader.List<org.apache.kafka.connect.source.SourceRecord>
poll()
Poll for the next batch of source records.private void
void
start
(MySqlPartition partition) Start the reader and return immediately.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
(Consumer<MySqlPartition> 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.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 Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
binlogReaderA
-
binlogReaderB
-
unifiedReader
-
reconcilingReader
-
aReaderLeading
-
partition
-
running
-
completed
-
uponCompletion
-
serverId
private final long serverId
-
-
Constructor Details
-
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 Details
-
name
Description copied from interface:Reader
Get the name of this reader. -
state
Description copied from interface:Reader
Get the current state of this reader. -
uponCompletion
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
-
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
. -
poll
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() -
setupUnifiedReader
private void setupUnifiedReader() -
determineLeadingReader
private void determineLeadingReader() -
getLeadingReader
BinlogReader getLeadingReader() -
getLaggingReader
BinlogReader getLaggingReader() -
checkLaggingLeadingInfo
private void checkLaggingLeadingInfo()
-