6harat commented on code in PR #12:
URL:
https://github.com/apache/flink-connector-mongodb/pull/12#discussion_r1244686115
##########
flink-connector-mongodb/src/main/java/org/apache/flink/connector/mongodb/sink/writer/MongoWriter.java:
##########
@@ -105,10 +119,37 @@ public MongoWriter(
// Initialize the mongo client.
this.mongoClient = MongoClients.create(connectionOptions.getUri());
+
+ boolean flushOnlyOnCheckpoint = batchIntervalMs == -1 && batchSize ==
-1;
+
+ if (!flushOnlyOnCheckpoint && batchIntervalMs > 0) {
+ this.scheduler =
+ Executors.newScheduledThreadPool(1, new
ExecutorThreadFactory("mongo-writer"));
+
+ this.scheduledFuture =
+ this.scheduler.scheduleWithFixedDelay(
+ () -> {
+ synchronized (MongoWriter.this) {
+ if (!closed &&
isOverMaxBatchIntervalLimit()) {
+ try {
+ doBulkWrite();
+ } catch (Exception e) {
+ flushException = e;
+ }
+ }
+ }
+ },
+ batchIntervalMs,
+ batchIntervalMs,
+ TimeUnit.MILLISECONDS);
+ }
}
@Override
- public void write(IN element, Context context) throws IOException,
InterruptedException {
+ public synchronized void write(IN element, Context context)
Review Comment:
@Jiabao-Sun just curious, wouldn't adding `synchronized` here hurt the
performance for write operation?
--
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]