@NotThreadSafe public final class SourceInfo extends BaseSourceInfo
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
}
| Modifier and Type | Class and Description |
|---|---|
protected static class |
SourceInfo.Position |
| Modifier and Type | Field and Description |
|---|---|
static String |
COLLECTION |
private CollectionId |
collectionId
Id of collection the current event applies to.
|
private static SourceInfo.Position |
INITIAL_POSITION |
static String |
INITIAL_SYNC |
private static org.bson.BsonTimestamp |
INITIAL_TIMESTAMP |
private Set<String> |
initialSyncReplicaSets |
static String |
NAMESPACE |
static String |
OPERATION_ID |
static String |
ORDER |
private SourceInfo.Position |
position |
private ConcurrentMap<String,SourceInfo.Position> |
positionsByReplicaSetName |
static String |
REPLICA_SET_NAME |
private String |
replicaSetName |
static int |
SCHEMA_VERSION |
static String |
SERVER_ID_KEY |
static String |
SESSION_TXN_ID |
private ConcurrentMap<String,Map<String,String>> |
sourcePartitionsByReplicaSetName |
static String |
TIMESTAMP |
static String |
TX_ORD |
snapshotRecordCOLLECTION_NAME_KEY, DATABASE_NAME_KEY, DEBEZIUM_CONNECTOR_KEY, DEBEZIUM_VERSION_KEY, SCHEMA_NAME_KEY, SERVER_NAME_KEY, SNAPSHOT_KEY, TABLE_NAME_KEY, TIMESTAMP_KEY| Constructor and Description |
|---|
SourceInfo(MongoDbConnectorConfig connectorConfig) |
| Modifier and Type | Method and Description |
|---|---|
private static boolean |
booleanOffsetValue(Map<String,?> values,
String key) |
void |
collectionEvent(String replicaSetName,
CollectionId collectionId)
|
(package private) CollectionId |
collectionId() |
protected String |
database() |
protected static org.bson.BsonTimestamp |
extractEventTimestamp(org.bson.Document oplogEvent)
Utility to extract the
timestamp value from the event. |
protected static String |
extractSessionTxnId(org.bson.Document oplogEvent)
Utility to extract the
unique transaction id value from the event. |
boolean |
hasOffset(String replicaSetName)
Determine whether we have previously recorded a MongoDB timestamp for the replica set.
|
private static int |
intOffsetValue(Map<String,?> values,
String key) |
boolean |
isInitialSyncOngoing(String replicaSetName)
Determine if the initial sync for the given replica set is still ongoing.
|
boolean |
isSnapshotRunning()
Returns whether any replica sets are still running a snapshot.
|
Map<String,?> |
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.
|
org.bson.BsonTimestamp |
lastOffsetTimestamp(String replicaSetName)
Get the MongoDB timestamp of the last offset position for the replica set.
|
OptionalLong |
lastOffsetTxOrder(String replicaSetName)
Get the MongoDB transaction order of the last offset position for the replica set.
|
private static long |
longOffsetValue(Map<String,?> values,
String key) |
private void |
onEvent(String replicaSetName,
CollectionId collectionId,
SourceInfo.Position position) |
void |
opLogEvent(String replicaSetName,
org.bson.Document oplogEvent)
|
void |
opLogEvent(String replicaSetName,
org.bson.Document oplogEvent,
org.bson.Document masterEvent,
long orderInTx)
|
Map<String,String> |
partition(String replicaSetName)
Get the Kafka Connect detail about the source "partition" for the given database in the replica set.
|
(package private) SourceInfo.Position |
position() |
(package private) String |
replicaSetName() |
static String |
replicaSetNameForPartition(Map<String,?> partition)
Get the replica set name for the given partition.
|
boolean |
setOffsetFor(Map<String,String> partition,
Map<String,?> sourceOffset)
Set the source offset, as read from Kafka Connect, for the given replica set.
|
boolean |
setOffsetFor(String replicaSetName,
Map<String,?> sourceOffset)
Set the source offset, as read from Kafka Connect, for the given replica set.
|
protected SnapshotRecord |
snapshot() |
void |
startInitialSync(String replicaSetName)
Record that an initial sync has started for the given replica set.
|
void |
stopInitialSync(String replicaSetName)
Record that an initial sync has stopped for the given replica set.
|
private static String |
stringOffsetValue(Map<String,?> values,
String key) |
protected Instant |
timestamp() |
protected OptionalLong |
transactionPosition() |
isSnapshot, setSnapshotschema, serverName, struct, structMakerpublic static final int SCHEMA_VERSION
public static final String SERVER_ID_KEY
public static final String REPLICA_SET_NAME
public static final String NAMESPACE
public static final String TIMESTAMP
public static final String ORDER
public static final String OPERATION_ID
public static final String TX_ORD
public static final String SESSION_TXN_ID
public static final String INITIAL_SYNC
public static final String COLLECTION
private static final org.bson.BsonTimestamp INITIAL_TIMESTAMP
private static final SourceInfo.Position INITIAL_POSITION
private final ConcurrentMap<String,Map<String,String>> sourcePartitionsByReplicaSetName
private final ConcurrentMap<String,SourceInfo.Position> positionsByReplicaSetName
private String replicaSetName
private CollectionId collectionId
null after noop events,
after which the recorded offset may be retrieved but not the source struct.private SourceInfo.Position position
public SourceInfo(MongoDbConnectorConfig connectorConfig)
public static String replicaSetNameForPartition(Map<String,?> partition)
partition - the partition mapnull if the partition is null or has no replica
set name entryCollectionId collectionId()
SourceInfo.Position position()
public Map<String,String> partition(String replicaSetName)
replicaSetName - the name of the replica set name for which the partition is to be obtained; may not be nullpublic org.bson.BsonTimestamp lastOffsetTimestamp(String replicaSetName)
replicaSetName - the name of the replica set name for which the new offset is to be obtained; may not be nullpublic OptionalLong lastOffsetTxOrder(String replicaSetName)
replicaSetName - the name of the replica set name for which the new offset is to be obtained; may not be nullpublic Map<String,?> lastOffset(String replicaSetName)
replicaSetName - the name of the replica set name for which the new offset is to be obtained; may not be nullpublic void collectionEvent(String replicaSetName, CollectionId collectionId)
Struct representation of the source partition and offset information where we have last read. The Struct complies with the AbstractSourceInfo.schema() for the MongoDB connector.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 nullAbstractSourceInfo.schema()public void opLogEvent(String replicaSetName, org.bson.Document oplogEvent, org.bson.Document masterEvent, long orderInTx)
Struct representation of the source partition and offset information. The Struct complies with the AbstractSourceInfo.schema() for the MongoDB connector.replicaSetName - the name of the replica set name for which the new offset is to be obtained; may not be nulloplogEvent - the replica set oplog event that was last read; may be null if the position is the start of
the oplogmasterEvent - the replica set oplog event that contains event metadata; same as oplogEvent for non-transactional changesorderInTx - order in transaction batch, 0 for non-transactional eventsAbstractSourceInfo.schema()public void opLogEvent(String replicaSetName, org.bson.Document oplogEvent)
Struct representation of the source partition and offset information. The Struct complies with the AbstractSourceInfo.schema() for the MongoDB connector.replicaSetName - the name of the replica set name for which the new offset is to be obtained; may not be nulloplogEvent - the replica set oplog event that was last read; may be null if the position is the start of
the oplogAbstractSourceInfo.schema()protected static org.bson.BsonTimestamp extractEventTimestamp(org.bson.Document oplogEvent)
timestamp value from the event.oplogEvent - the eventts fieldprotected static String extractSessionTxnId(org.bson.Document oplogEvent)
unique transaction id value from the event.oplogEvent - the eventprivate void onEvent(String replicaSetName, CollectionId collectionId, SourceInfo.Position position)
public boolean hasOffset(String replicaSetName)
replicaSetName - the name of the replica set name; may not be nulltrue if an offset has been recorded for the replica set, or false if the replica set has not
yet been seenpublic boolean setOffsetFor(String replicaSetName, Map<String,?> sourceOffset)
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 nulltrue if the offset was recorded, or false if the source offset is nullorg.apache.kafka.connect.errors.ConnectException - if any offset parameter values are missing, invalid, or of the wrong typepublic boolean setOffsetFor(Map<String,String> partition, Map<String,?> sourceOffset)
partition - the partition information; may not be nullsourceOffset - the previously-recorded Kafka Connect source offset; may be nulltrue if the offset was recorded, or false if the source offset is nullorg.apache.kafka.connect.errors.ConnectException - if any offset parameter values are missing, invalid, or of the wrong typepublic void startInitialSync(String replicaSetName)
replicaSetName - the name of the replica set; never nullpublic void stopInitialSync(String replicaSetName)
replicaSetName - the name of the replica set; never nullpublic boolean isInitialSyncOngoing(String replicaSetName)
replicaSetName - the name of the replica set; never nulltrue if the initial sync for this replica is still ongoing or was not completed before restarting, or
false if there is currently no initial sync operation for this replica setpublic boolean isSnapshotRunning()
protected Instant timestamp()
timestamp in class AbstractSourceInfoprotected SnapshotRecord snapshot()
snapshot in class BaseSourceInfoprotected String database()
database in class AbstractSourceInfoString replicaSetName()
protected OptionalLong transactionPosition()
Copyright © 2021 JBoss by Red Hat. All rights reserved.