You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/06/18 14:00:19 UTC

[GitHub] [incubator-seatunnel] Hisoka-X commented on a diff in pull request #2029: [api-draft][connector] Add MongoDB source connector

Hisoka-X commented on code in PR #2029:
URL: https://github.com/apache/incubator-seatunnel/pull/2029#discussion_r900920859


##########
seatunnel-connectors/seatunnel-connectors-seatunnel/seatunnel-connector-seatunnel-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/source/MongodbSourceSplitEnumerator.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.connectors.seatunnel.mongodb.source;
+
+import org.apache.seatunnel.api.source.SourceSplitEnumerator;
+import org.apache.seatunnel.connectors.seatunnel.mongodb.state.MongodbSourceState;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+
+public class MongodbSourceSplitEnumerator implements SourceSplitEnumerator<MongodbSourceSplit, MongodbSourceState> {
+
+    private final Context<MongodbSourceSplit> context;
+
+    private final Set<Integer> readers;
+
+    private volatile int assigned = -1;
+
+    MongodbSourceSplitEnumerator(Context<MongodbSourceSplit> enumeratorContext) {
+        this.context = enumeratorContext;
+        this.readers = new HashSet<>();
+    }
+
+    @Override
+    public void open() {
+
+    }
+
+    @Override
+    public void run() throws Exception {
+
+    }
+
+    @Override
+    public void close() throws IOException {
+
+    }
+
+    @Override
+    public void addSplitsBack(List<MongodbSourceSplit> splits, int subtaskId) {
+        if (splits.isEmpty()) {
+            return;
+        }
+        if (subtaskId == assigned) {
+            Optional<Integer> otherReader = readers.stream().filter(r -> r != subtaskId).findAny();
+            if (otherReader.isPresent()) {
+                context.assignSplit(otherReader.get(), splits);
+            } else {
+                assigned = -1;
+            }
+        }
+    }
+
+    @Override
+    public int currentUnassignedSplitSize() {
+        return assigned < 0 ? 0 : 1;
+    }
+
+    @Override
+    public void handleSplitRequest(int subtaskId) {
+
+    }
+
+    @Override
+    public void registerReader(int subtaskId) {
+        readers.add(subtaskId);
+        if (assigned < 0) {
+            assigned = subtaskId;
+            context.assignSplit(subtaskId, new MongodbSourceSplit());

Review Comment:
   If every reader will get same split, will it cause duplicate data to be read?



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org