eskabetxe commented on code in PR #209: URL: https://github.com/apache/flink-connector-jdbc/pull/209#discussion_r3785351333
########## flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/core/datastream/source/enumerator/splitter/snapshot/AsyncSnapshotSplitterEnumerator.java: ########## @@ -0,0 +1,189 @@ +/* + * 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.flink.connector.jdbc.core.datastream.source.enumerator.splitter.snapshot; + +import org.apache.flink.api.connector.source.Boundedness; +import org.apache.flink.connector.jdbc.core.datastream.connection.ConnectionProvider; +import org.apache.flink.connector.jdbc.core.datastream.source.enumerator.splitter.SplitterEnumerator; +import org.apache.flink.connector.jdbc.core.datastream.source.split.JdbcSourceSplit; +import org.apache.flink.connector.jdbc.datasource.connections.JdbcConnectionProvider; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * Shared async background-computation machinery for the snapshot splitters ({@link + * TableSplitterEnumerator}, {@link DatabaseSplitterEnumerator}): a single background daemon thread + * computes {@code T} items and offers them into a queue, while {@link #enumerateSplits()} drains + * and converts whatever's ready — non-blocking apart from a short wait for the very first item. + * + * @param <T> the type of item the background thread produces, converted to a {@link + * JdbcSourceSplit} at drain time via {@link #toSplit} + */ +abstract class AsyncSnapshotSplitterEnumerator<T> implements SplitterEnumerator { + + private final Logger log = LoggerFactory.getLogger(getClass()); + private final String name; + private final Queue<T> outputQueue = new ConcurrentLinkedQueue<>(); + + protected transient ConnectionProvider connection; + + private transient ExecutorService executor; + private transient AtomicBoolean workDone; + private transient CountDownLatch firstReady; + private transient volatile Throwable backgroundFailure; + + protected AsyncSnapshotSplitterEnumerator(String name) { + this.name = name; + } + + /** Validates and stores the connection provider for use by subclasses. */ + protected final void initConnection(JdbcConnectionProvider connectionProvider) { + if (!(connectionProvider instanceof ConnectionProvider)) { + throw new IllegalArgumentException( + "Connection provider must be an instance of " + + ConnectionProvider.class.getSimpleName()); + } + this.connection = (ConnectionProvider) connectionProvider; + } + + @Override + public final Boundedness getBoundedness() { + return Boundedness.CONTINUOUS_UNBOUNDED; Review Comment: It will end because the splitter when finished will tell that no more splits available.. the splits are bounded. it continuous_bounded to allow process big tables, a table with 1T of data will be problematic witn bounded. -- 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]
