@NotThreadSafe public final class SourceInfo extends AbstractSourceInfo
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 |
|---|---|
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 ConcurrentMap<String,SourceInfo.Position> |
positionsByReplicaSetName |
static String |
REPLICA_SET_NAME |
static int |
SCHEMA_VERSION |
static String |
SERVER_ID_KEY |
static String |
SERVER_NAME |
private String |
serverName |
private org.apache.kafka.connect.data.Schema |
SOURCE_SCHEMA
A
Schema definition for a Struct used to store the partition(String) and lastOffset(java.lang.String)
information. |
private ConcurrentMap<String,Map<String,String>> |
sourcePartitionsByReplicaSetName |
static String |
TIMESTAMP |
DEBEZIUM_VERSION_KEY| Constructor and Description |
|---|
SourceInfo(String serverName) |
| Modifier and Type | Method and Description |
|---|---|
protected static org.bson.BsonTimestamp |
extractEventTimestamp(org.bson.Document oplogEvent)
Utility to extract the
timestamp 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.
|
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.apache.kafka.connect.data.Struct |
lastOffsetStruct(String replicaSetName,
CollectionId collectionId)
|
org.bson.BsonTimestamp |
lastOffsetTimestamp(String replicaSetName)
Get the MongoDB timestamp of the last offset position for the replica set.
|
private static long |
longOffsetValue(Map<String,?> values,
String key) |
private org.apache.kafka.connect.data.Struct |
offsetStructFor(String replicaSetName,
String namespace,
SourceInfo.Position position,
boolean isInitialSync) |
org.apache.kafka.connect.data.Struct |
offsetStructForEvent(String replicaSetName,
org.bson.Document oplogEvent)
|
Map<String,String> |
partition(String replicaSetName)
Get the Kafka Connect detail about the source "partition" for the given database in the replica set.
|
static String |
replicaSetNameForPartition(Map<String,?> partition)
Get the replica set name for the given partition.
|
org.apache.kafka.connect.data.Schema |
schema()
|
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.
|
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.
|
schemaBuilder, structpublic static final int SCHEMA_VERSION
public static final String SERVER_ID_KEY
public static final String SERVER_NAME
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 INITIAL_SYNC
private static final org.bson.BsonTimestamp INITIAL_TIMESTAMP
private static final SourceInfo.Position INITIAL_POSITION
private final org.apache.kafka.connect.data.Schema SOURCE_SCHEMA
Schema definition for a Struct used to store the partition(String) and lastOffset(java.lang.String)
information.private final ConcurrentMap<String,Map<String,String>> sourcePartitionsByReplicaSetName
private final ConcurrentMap<String,SourceInfo.Position> positionsByReplicaSetName
private final String serverName
public SourceInfo(String serverName)
public static String replicaSetNameForPartition(Map<String,?> partition)
partition - the partition mapnull if the partition is null or has no replica
set name entrypublic org.apache.kafka.connect.data.Schema schema()
schema in class AbstractSourceInfoSchema; never nulloffsetStructForEvent(String, Document)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 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 org.apache.kafka.connect.data.Struct lastOffsetStruct(String replicaSetName, CollectionId collectionId)
Struct representation of the source partition and offset information where we have last read. The Struct complies with the 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 nullStruct; never nullschema()public org.apache.kafka.connect.data.Struct offsetStructForEvent(String replicaSetName, org.bson.Document oplogEvent)
Struct representation of the source partition and offset information. The Struct complies with the 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 oplogStruct; never nullschema()protected static org.bson.BsonTimestamp extractEventTimestamp(org.bson.Document oplogEvent)
timestamp value from the event.oplogEvent - the eventts fieldprivate org.apache.kafka.connect.data.Struct offsetStructFor(String replicaSetName, String namespace, SourceInfo.Position position, boolean isInitialSync)
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 setCopyright © 2018 JBoss by Red Hat. All rights reserved.