Class SourceInfo
The source partition information describes the database whose log is being consumed. Typically, the
database is identified by the host address port number of the MySQL server and the name of the database. Here's a JSON-like
representation of an example database:
{
"server" : "production-server"
}
The source offset information is included in each event and captures where the connector should restart
if this event's offset is the last one recorded. The offset includes the binlog filename,
the position of the first event in the binlog, the
number of events to skip, and the
number of rows to also skip.
Here's a JSON-like representation of an example offset:
{
"server_id": 112233,
"ts_sec": 1465937,
"gtid": "db58b0ae-2c10-11e6-b284-0242ac110002:199",
"file": "mysql-bin.000003",
"pos" = 990,
"event" = 0,
"row": 0,
"snapshot": true
}
The "gtids" field only appears in offsets produced when GTIDs are enabled. The "snapshot" field only appears in
offsets produced when the connector is in the middle of a snapshot. And finally, the "ts" field contains the
seconds since Unix epoch (since Jan 1, 1970) of the MySQL event; the message envelopes also have a
timestamp, but that timestamp is the milliseconds since since Jan 1, 1970.
Each change event envelope also includes the source struct that contains MySQL information about that
particular event, including a mixture the fields from the partition (which is renamed in the source to
make more sense), the binlog filename and position where the event can be found, and when GTIDs are enabled the GTID of the
transaction in which the event occurs. Like with the offset, the "snapshot" field only appears for events produced
when the connector is in the middle of a snapshot. Note that this information is likely different than the offset information,
since the connector may need to restart from either just after the most recently completed transaction or the beginning
of the most recently started transaction (whichever appears later in the binlog).
Here's a JSON-like representation of the source for the metadata for an event that corresponds to the above partition and offset:
{
"name": "production-server",
"server_id": 112233,
"ts_sec": 1465937,
"gtid": "db58b0ae-2c10-11e6-b284-0242ac110002:199",
"file": "mysql-bin.000003",
"pos" = 1081,
"row": 0,
"snapshot": true,
"thread" : 1,
"db" : "inventory",
"table" : "products"
}
- Author:
- Randall Hauch
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringprivate Stringprivate longprivate longprivate Stringprivate Stringprivate Stringprivate intstatic final Stringstatic final Stringstatic final Stringstatic final Stringprivate Stringprivate Stringprivate Stringstatic final Stringstatic final Stringstatic final Stringprivate booleanprivate booleanprivate booleanstatic final Stringstatic final Stringprivate Stringprivate longprivate longprivate Stringprivate intstatic final Stringstatic final Stringprivate longprivate Instantstatic final Stringstatic final Stringstatic final Stringstatic final Stringprivate Stringprivate Stringstatic final Stringprivate longstatic final StringFields inherited from class io.debezium.connector.common.BaseSourceInfo
snapshotRecordFields inherited from class io.debezium.connector.AbstractSourceInfo
COLLECTION_NAME_KEY, DATABASE_NAME_KEY, DEBEZIUM_CONNECTOR_KEY, DEBEZIUM_VERSION_KEY, SCHEMA_NAME_KEY, SEQUENCE_KEY, SERVER_NAME_KEY, SNAPSHOT_KEY, TABLE_NAME_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet the name of the MySQL binary log file that has last been processed.longGet the position within the MySQL binary log file of the next event to be processed.private booleanbooleanOffsetValue(Map<String, ?> values, String key) voidvoidvoidCapture that we're starting a new event.voidDenote that a snapshot has completed successfully.static DocumentcreateDocumentFromOffset(Map<String, ?> offset) Create aDocumentfrom the given offset.protected Stringdatabase()voiddatabaseEvent(String databaseName) longGet the number of events after the last transaction BEGIN that we've already processed.(package private) long(package private) String(package private) long(package private) String(package private) intgetQuery()(package private) long(package private) longgtidSet()Get the string representation of the GTID range for the MySQL binary log file.boolean(package private) booleanstatic booleanisPositionAtOrBefore(Document recorded, Document desired, Predicate<String> gtidFilter) booleanDetermine whether a snapshot is currently in effect.private longlongOffsetValue(Map<String, ?> values, String key) voidmarkLastSnapshot(Configuration config) Denote that a snapshot will be complete after one last record.voidSet filter data from config if and only if parallel snapshotting of new tables is turned onoffset()Get the Kafka Connect detail about the source "offset", which describes the position within the source where we last have last read.offsetForRow(int eventRowNumber, int totalNumberOfRows) Given the row number within a binlog event and the total number of rows in that event, compute and return the Kafka Connect offset that is be included in the produced change event describing the row.static booleanoffsetsHaveFilterInfo(Map<String, ?> sourceOffset) offsetUsingPosition(long rowsToSkip) Get the Kafka Connect detail about the source "partition", which describes the portion of the source that we are consuming.protected longGet the position within the MySQL binary log file of the most recently processed event.intGet the number of rows beyond thelast completely processed eventto be skipped upon restart.voidsetBinlogServerId(long serverId) Set the server ID as found within the MySQL binary log file.voidsetBinlogStartPoint(String binlogFilename, long positionOfFirstEvent) Set the position in the MySQL binlog where we will start reading.voidsetBinlogThread(long threadId) Set the identifier of the MySQL thread that generated the most recent event.voidsetBinlogTimestampSeconds(long timestampInSeconds) Set the number of seconds since Unix epoch (January 1, 1970) as found within the MySQL binary log file.voidsetCompletedGtidSet(String gtidSet) Set the GTID set that captures all of the GTID transactions that have been completely processed.voidsetEventPosition(long positionOfCurrentEvent, long eventSizeInBytes) Set the position within the MySQL binary log file of the current event.voidsetFilterDataFromConfig(Configuration config) Set the filter data for the offset from the givenConfigurationvoidSet the source offset, as read from Kafka Connect.voidSet the original SQL query.voidsetSourceTime(Instant timestamp) protected SnapshotRecordsnapshot()voidRecord that a new GTID transaction has been started and has been included in the set of GTIDs known to the MySQL server.voidvoidDenote that a snapshot is being (or has been) started.(package private) Stringtable()Returns a string representation of the table(s) affected by the current event.voidtableEvent(TableId tableId) voidtableEvent(Set<TableId> tableIds) protected InstanttoString()Methods inherited from class io.debezium.connector.common.BaseSourceInfo
isSnapshot, setSnapshotMethods inherited from class io.debezium.connector.AbstractSourceInfo
schema, sequence, serverName, struct, structMaker
-
Field Details
-
SERVER_ID_KEY
- See Also:
-
SERVER_PARTITION_KEY
- See Also:
-
GTID_SET_KEY
- See Also:
-
GTID_KEY
- See Also:
-
EVENTS_TO_SKIP_OFFSET_KEY
- See Also:
-
BINLOG_FILENAME_OFFSET_KEY
- See Also:
-
BINLOG_POSITION_OFFSET_KEY
- See Also:
-
BINLOG_ROW_IN_EVENT_OFFSET_KEY
- See Also:
-
TIMESTAMP_KEY
- See Also:
-
THREAD_KEY
- See Also:
-
QUERY_KEY
- See Also:
-
DATABASE_WHITELIST_KEY
- See Also:
-
DATABASE_INCLUDE_LIST_KEY
- See Also:
-
DATABASE_BLACKLIST_KEY
- See Also:
-
DATABASE_EXCLUDE_LIST_KEY
- See Also:
-
TABLE_WHITELIST_KEY
- See Also:
-
TABLE_INCLUDE_LIST_KEY
- See Also:
-
TABLE_BLACKLIST_KEY
- See Also:
-
TABLE_EXCLUDE_LIST_KEY
- See Also:
-
RESTART_PREFIX
- See Also:
-
currentGtidSet
-
currentGtid
-
currentBinlogFilename
-
currentBinlogPosition
private long currentBinlogPosition -
currentRowNumber
private int currentRowNumber -
currentEventLengthInBytes
private long currentEventLengthInBytes -
restartGtidSet
-
restartBinlogFilename
-
restartBinlogPosition
private long restartBinlogPosition -
restartEventsToSkip
private long restartEventsToSkip -
restartRowsToSkip
private int restartRowsToSkip -
inTransaction
private boolean inTransaction -
serverId
private long serverId -
sourceTime
-
threadId
private long threadId -
sourcePartition
-
lastSnapshot
private boolean lastSnapshot -
nextSnapshot
private boolean nextSnapshot -
currentQuery
-
databaseIncludeList
-
databaseExcludeList
-
tableIncludeList
-
tableExcludeList
-
tableIds
-
databaseName
-
-
Constructor Details
-
SourceInfo
-
-
Method Details
-
setQuery
Set the original SQL query.- Parameters:
query- the original SQL query that generated the event.
-
getQuery
- Returns:
- the original SQL query that generated the event. NULL if no such query is associated.
-
partition
Get the Kafka Connect detail about the source "partition", which describes the portion of the source that we are consuming. Since we're reading the binary log for a single database, the source partition specifies thedatabase server.The resulting map is mutable for efficiency reasons (this information rarely changes), but should not be mutated.
- Returns:
- the source partition information; never null
-
setBinlogStartPoint
Set the position in the MySQL binlog where we will start reading.- Parameters:
binlogFilename- the name of the binary log file; may not be nullpositionOfFirstEvent- the position in the binary log file to begin processing
-
setEventPosition
public void setEventPosition(long positionOfCurrentEvent, long eventSizeInBytes) Set the position within the MySQL binary log file of the current event.- Parameters:
positionOfCurrentEvent- the position within the binary log file of the current eventeventSizeInBytes- the size in bytes of this event
-
offset
Get the Kafka Connect detail about the source "offset", which describes the position within the source where we last have last read.- Returns:
- a copy of the current offset; never null
-
offsetForRow
Given the row number within a binlog event and the total number of rows in that event, compute and return the Kafka Connect offset that is be included in the produced change event describing the row.This method should always be called before
AbstractSourceInfo.struct().- Parameters:
eventRowNumber- the 0-based row number within the event for which the offset is to be producedtotalNumberOfRows- the total number of rows within the event being processed- Returns:
- a copy of the current offset; never null
- See Also:
-
changeEventCompleted
public void changeEventCompleted() -
offsetUsingPosition
-
databaseEvent
-
tableEvent
-
tableEvent
-
isSnapshotInEffect
public boolean isSnapshotInEffect()Determine whether a snapshot is currently in effect.- Returns:
trueif a snapshot is in effect, orfalseotherwise
-
startNextTransaction
public void startNextTransaction() -
completeEvent
public void completeEvent()Capture that we're starting a new event. -
eventsToSkipUponRestart
public long eventsToSkipUponRestart()Get the number of events after the last transaction BEGIN that we've already processed.- Returns:
- the number of events in the transaction that have been processed completely
- See Also:
-
commitTransaction
public void commitTransaction() -
startGtid
Record that a new GTID transaction has been started and has been included in the set of GTIDs known to the MySQL server.- Parameters:
gtid- the string representation of a specific GTID that has been begun; may not be nullgtidSet- the string representation of GTID set that includes the newly begun GTID; may not be null
-
setCompletedGtidSet
Set the GTID set that captures all of the GTID transactions that have been completely processed.- Parameters:
gtidSet- the string representation of the GTID set; may not be null, but may be an empty string if no GTIDs have been previously processed
-
setBinlogServerId
public void setBinlogServerId(long serverId) Set the server ID as found within the MySQL binary log file.- Parameters:
serverId- the server ID found within the binary log file
-
setBinlogTimestampSeconds
public void setBinlogTimestampSeconds(long timestampInSeconds) Set the number of seconds since Unix epoch (January 1, 1970) as found within the MySQL binary log file. Note that the value in the binlog events is in seconds, but the library we use returns the value in milliseconds (with only second precision and therefore all fractions of a second are zero). We capture this as seconds since that is the precision that MySQL uses.- Parameters:
timestampInSeconds- the timestamp in seconds found within the binary log file
-
setSourceTime
-
setBinlogThread
public void setBinlogThread(long threadId) Set the identifier of the MySQL thread that generated the most recent event.- Parameters:
threadId- the thread identifier; may be negative if not known
-
startSnapshot
public void startSnapshot()Denote that a snapshot is being (or has been) started. -
markLastSnapshot
Denote that a snapshot will be complete after one last record. -
completeSnapshot
public void completeSnapshot()Denote that a snapshot has completed successfully. -
setFilterDataFromConfig
Set the filter data for the offset from the givenConfiguration- Parameters:
config- the configuration
-
maybeSetFilterDataFromConfig
Set filter data from config if and only if parallel snapshotting of new tables is turned on- Parameters:
config- the configuration.
-
hasFilterInfo
public boolean hasFilterInfo()- Returns:
- true if this offset has filter info, false otherwise.
-
getDatabaseIncludeList
-
getDatabaseExcludeList
-
getTableIncludeList
-
getTableExcludeList
-
setOffset
Set the source offset, as read from Kafka Connect. This method does nothing if the supplied map is null.- Parameters:
sourceOffset- the previously-recorded Kafka Connect source offset- Throws:
org.apache.kafka.connect.errors.ConnectException- if any offset parameter values are missing, invalid, or of the wrong type
-
offsetsHaveFilterInfo
-
longOffsetValue
-
booleanOffsetValue
-
gtidSet
Get the string representation of the GTID range for the MySQL binary log file.- Returns:
- the string representation of the binlog GTID ranges; may be null
-
binlogFilename
Get the name of the MySQL binary log file that has last been processed.- Returns:
- the name of the binary log file; null if it has not been
set
-
binlogPosition
public long binlogPosition()Get the position within the MySQL binary log file of the next event to be processed.- Returns:
- the position within the binary log file; null if it has not been
set
-
restartBinlogPosition
protected long restartBinlogPosition()Get the position within the MySQL binary log file of the most recently processed event.- Returns:
- the position within the binary log file; null if it has not been
set
-
rowsToSkipUponRestart
public int rowsToSkipUponRestart()Get the number of rows beyond thelast completely processed eventto be skipped upon restart.- Returns:
- the number of rows to be skipped
-
getServerId
long getServerId() -
getThreadId
long getThreadId() -
table
String table()Returns a string representation of the table(s) affected by the current event. Will only represent more than a single table for events in the user-facing schema history topic for certain types of DDL. Will benullfor DDL events not applying to tables (CREATE DATABASE etc.). -
getCurrentGtid
String getCurrentGtid() -
isLastSnapshot
boolean isLastSnapshot() -
getCurrentBinlogFilename
String getCurrentBinlogFilename() -
getCurrentBinlogPosition
long getCurrentBinlogPosition() -
getBinlogTimestampSeconds
long getBinlogTimestampSeconds() -
getCurrentRowNumber
int getCurrentRowNumber() -
toString
-
createDocumentFromOffset
Create aDocumentfrom the given offset.- Parameters:
offset- the offset to create the document from.- Returns:
- a
Documentwith the offset data.
-
isPositionAtOrBefore
public static boolean isPositionAtOrBefore(Document recorded, Document desired, Predicate<String> gtidFilter) Determine whether the firstoffsetis at or before the point in time of the second offset, where the offsets are given in JSON representation of the maps returned byoffset().This logic makes a significant assumption: once a MySQL server/cluster has GTIDs enabled, they will never be disabled. This is the only way to compare a position with a GTID to a position without a GTID, and we conclude that any position with a GTID is *after* the position without.
When both positions have GTIDs, then we compare the positions by using only the GTIDs. Of course, if the GTIDs are the same, then we also look at whether they have snapshots enabled.
- Parameters:
recorded- the position obtained from recorded history; never nulldesired- the desired position that we want to obtain, which should be after some recorded positions, at some recorded positions, and before other recorded positions; never nullgtidFilter- the predicate function that will returntrueif a GTID source is to be included, orfalseif a GTID source is to be excluded; may be null if no filtering is to be done- Returns:
trueif the recorded position is at or before the desired position; orfalseotherwise
-
timestamp
- Specified by:
timestampin classAbstractSourceInfo
-
snapshot
- Overrides:
snapshotin classBaseSourceInfo
-
database
- Specified by:
databasein classAbstractSourceInfo
-