shink commented on code in PR #16003:
URL: https://github.com/apache/pulsar/pull/16003#discussion_r894377745
##########
pulsar-io/mongo/src/main/java/org/apache/pulsar/io/mongodb/MongoSource.java:
##########
@@ -79,38 +78,46 @@ public MongoSource(Supplier<MongoClient> clientProvider) {
public void open(Map<String, Object> config, SourceContext sourceContext)
throws Exception {
log.info("Open MongoDB Source");
- mongoConfig = MongoConfig.load(config);
- mongoConfig.validate(false, false);
+ mongoSourceConfig = MongoSourceConfig.load(config);
+ mongoSourceConfig.validate();
if (clientProvider != null) {
mongoClient = clientProvider.get();
} else {
- mongoClient = MongoClients.create(mongoConfig.getMongoUri());
+ mongoClient = MongoClients.create(mongoSourceConfig.getMongoUri());
}
- if (StringUtils.isEmpty(mongoConfig.getDatabase())) {
+ if (StringUtils.isEmpty(mongoSourceConfig.getDatabase())) {
// Watch all databases
log.info("Watch all");
stream = mongoClient.watch();
} else {
- final MongoDatabase db =
mongoClient.getDatabase(mongoConfig.getDatabase());
+ final MongoDatabase db =
mongoClient.getDatabase(mongoSourceConfig.getDatabase());
- if (StringUtils.isEmpty(mongoConfig.getCollection())) {
+ if (StringUtils.isEmpty(mongoSourceConfig.getCollection())) {
// Watch all collections in a database
log.info("Watch db: {}", db.getName());
stream = db.watch();
} else {
// Watch a collection
-
- final MongoCollection<Document> collection =
db.getCollection(mongoConfig.getCollection());
- log.info("Watch collection: {} {}", db.getName(),
mongoConfig.getCollection());
+ final MongoCollection<Document> collection =
db.getCollection(mongoSourceConfig.getCollection());
+ log.info("Watch collection: {}.{}", db.getName(),
mongoSourceConfig.getCollection());
stream = collection.watch();
}
}
-
stream.batchSize(mongoConfig.getBatchSize()).fullDocument(FullDocument.UPDATE_LOOKUP);
+ stream.batchSize(mongoSourceConfig.getBatchSize())
+ .fullDocument(FullDocument.UPDATE_LOOKUP);
+
+ if (SyncType.FULL_SYNC.equals(mongoSourceConfig.getSyncType())) {
+ // sync currently existing messages
+ // startAtOperationTime is the starting point for the change stream
+ // setting startAtOperationTime to 0 means the start point is the
earliest
+ // see
https://www.mongodb.com/docs/v4.2/reference/method/db.collection.watch/ for
more information
+ stream.startAtOperationTime(new BsonTimestamp(0L));
+ }
Review Comment:
Here is the key.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]