Class SourceInfo
The source partition information identifies the particular MongoDB replica set and the connector's
logical name of the MongoDB server. A JSON-like representation of the source partition for a database named "customers" hosted
in a MongoDB replica set named "myMongoServer" is as follows:
{
"server_id" : "myMongoServer",
"replicaSetName" : "rs0"
}
The source offset information describes the position within a particular partition of each record.
Since each event in MongoDB's oplog is identified by a BSONTimestamp that tracks the time and the order of the
event for that particular time (e.g., multiple events that occur at the same time will have unique orders), the offset
includes the BSONTimetamp representation. (The event's h field is the unique ID for the operation, so this is also
included in the offset.) And, if an initial sync is in progress, the offset will include the initsync field.
Here's a JSON-like representation of an example timestamp:
{
"sec" = 1422998530,
"ord" = 0,
"h" = 398278732173914406,
"initsync" = true
}
- Author:
- Randall Hauch
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final class(package private) static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprivate CollectionIdId of collection the current event applies to.private static final SourceInfo.Positionstatic final Stringprivate static final org.bson.BsonTimestampstatic final Stringstatic final Stringprivate SourceInfo.Positionprivate final ConcurrentMap<String,SourceInfo.Position> static final Stringprivate Stringprivate static final Stringstatic final Stringprivate final ConcurrentMap<String,Map<String, String>> static final Stringstatic final Stringstatic final Stringprivate longFields 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, TIMESTAMP_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddSessionTxnIdToOffset(SourceInfo.Position position, Map<String, Object> offset) private static booleanbooleanOffsetValue(Map<String, ?> values, String key) voidchangeStreamEvent(String replicaSetName, com.mongodb.client.model.changestream.ChangeStreamDocument<org.bson.BsonDocument> changeStreamEvent) voidcollectionEvent(String replicaSetName, CollectionId collectionId, long wallTime) (package private) CollectionIdprotected Stringdatabase()booleanDetermine whether we have previously recorded a MongoDB timestamp for the replica set.voidinitEvent(String replicaSetName, com.mongodb.client.MongoChangeStreamCursor<com.mongodb.client.model.changestream.ChangeStreamDocument<org.bson.BsonDocument>> cursor) private static intintOffsetValue(Map<String, ?> values, String key) booleanisInitialSyncOngoing(String replicaSetName) Determine if the initial sync for the given replica set is still ongoing.booleanReturns whether any replica sets are still running a snapshot.lastOffset(String replicaSetName) Get the Kafka Connect detail about the source "offset" for the named database, which describes the given position in the database where we have last read.lastResumeToken(String replicaSetName) private static longlongOffsetValue(Map<String, ?> values, String key) voidprivate voidonEvent(String replicaSetName, CollectionId collectionId, SourceInfo.Position position, long wallTime) Get the Kafka Connect detail about the source "partition" for the given database in the replica set.(package private) SourceInfo.Positionposition()(package private) StringserverId()booleansetOffsetFor(String replicaSetName, Map<String, ?> sourceOffset) Set the source offset, as read from Kafka Connect, for the given replica set.booleanSet the source offset, as read from Kafka Connect, for the given replica set.snapshot()voidstartInitialSync(String replicaSetName) Record that an initial sync has started for the given replica set.voidstopInitialSync(String replicaSetName) Record that an initial sync has stopped for the given replica set.private static StringstringOffsetValue(Map<String, ?> values, String key) protected InstanttoString()(package private) longwallTime()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
-
RESUME_TOKEN
- See Also:
-
SERVER_ID_KEY
- See Also:
-
REPLICA_SET_NAME
- See Also:
-
TIMESTAMP
- See Also:
-
ORDER
- See Also:
-
INITIAL_SYNC
- See Also:
-
COLLECTION
- See Also:
-
LSID
- See Also:
-
TXN_NUMBER
- See Also:
-
WALL_TIME
- See Also:
-
INITIAL_TIMESTAMP
private static final org.bson.BsonTimestamp INITIAL_TIMESTAMP -
INITIAL_POSITION
-
sourcePartitionsByReplicaSetName
-
positionsByReplicaSetName
-
initialSyncReplicaSets
-
replicaSetName
-
collectionId
Id of collection the current event applies to. May benullafter noop events, after which the recorded offset may be retrieved but not the source struct. -
position
-
wallTime
private long wallTime
-
-
Constructor Details
-
SourceInfo
-
-
Method Details
-
collectionId
CollectionId collectionId() -
position
SourceInfo.Position position() -
serverId
- Returns:
- server id
-
partition
Get the Kafka Connect detail about the source "partition" for the given database in the replica set. If the database is not known, this method records the new partition.- Parameters:
replicaSetName- the name of the replica set name for which the partition is to be obtained; may not be null- Returns:
- the source partition information; never null
-
lastResumeToken
-
lastOffset
Get the Kafka Connect detail about the source "offset" for the named database, which describes the given position in the database where we have last read. If the database has not yet been seen, this records the starting position for that database. However, if there is a position for the database, the offset representation is returned.- Parameters:
replicaSetName- the name of the replica set name for which the new offset is to be obtained; may not be null- Returns:
- a copy of the current offset for the database; never null
-
addSessionTxnIdToOffset
-
collectionEvent
Get aStructrepresentation of the sourcepartitionandoffsetinformation where we have last read. The Struct complies with theAbstractSourceInfo.schema()for the MongoDB connector.- Parameters:
replicaSetName- the name of the replica set name for which the new offset is to be obtained; may not be nullcollectionId- the event's collection identifier; may not be null- See Also:
-
initEvent
public void initEvent(String replicaSetName, com.mongodb.client.MongoChangeStreamCursor<com.mongodb.client.model.changestream.ChangeStreamDocument<org.bson.BsonDocument>> cursor) -
noEvent
-
changeStreamEvent
public void changeStreamEvent(String replicaSetName, com.mongodb.client.model.changestream.ChangeStreamDocument<org.bson.BsonDocument> changeStreamEvent) -
onEvent
private void onEvent(String replicaSetName, CollectionId collectionId, SourceInfo.Position position, long wallTime) -
hasOffset
Determine whether we have previously recorded a MongoDB timestamp for the replica set.- Parameters:
replicaSetName- the name of the replica set name; may not be null- Returns:
trueif an offset has been recorded for the replica set, orfalseif the replica set has not yet been seen
-
setOffsetFor
Set the source offset, as read from Kafka Connect, for the given replica set. This method does nothing if the supplied map is null.- Parameters:
replicaSetName- the name of the replica set name for which the new offset is to be obtained; may not be nullsourceOffset- the previously-recorded Kafka Connect source offset; may be null- Returns:
trueif the offset was recorded, orfalseif the source offset is null- Throws:
io.debezium.DebeziumException- if any offset parameter values are missing, invalid, or of the wrong type
-
setOffsetFor
Set the source offset, as read from Kafka Connect, for the given replica set. This method does nothing if the supplied map is null.- Parameters:
partition- the partition information; may not be nullsourceOffset- the previously-recorded Kafka Connect source offset; may be null- Returns:
trueif the offset was recorded, orfalseif the source offset is null- Throws:
io.debezium.DebeziumException- if any offset parameter values are missing, invalid, or of the wrong type
-
startInitialSync
Record that an initial sync has started for the given replica set.- Parameters:
replicaSetName- the name of the replica set; never null
-
stopInitialSync
Record that an initial sync has stopped for the given replica set.- Parameters:
replicaSetName- the name of the replica set; never null
-
isInitialSyncOngoing
Determine if the initial sync for the given replica set is still ongoing.- Parameters:
replicaSetName- the name of the replica set; never null- Returns:
trueif the initial sync for this replica is still ongoing or was not completed before restarting, orfalseif there is currently no initial sync operation for this replica set
-
isSnapshotRunning
public boolean isSnapshotRunning()Returns whether any replica sets are still running a snapshot. -
intOffsetValue
-
longOffsetValue
-
stringOffsetValue
-
booleanOffsetValue
-
timestamp
- Specified by:
timestampin classAbstractSourceInfo
-
snapshot
- Overrides:
snapshotin classBaseSourceInfo
-
database
- Specified by:
databasein classAbstractSourceInfo
-
replicaSetName
String replicaSetName() -
wallTime
long wallTime() -
toString
-