stevenzwu commented on a change in pull request #2105: URL: https://github.com/apache/iceberg/pull/2105#discussion_r574898819
########## File path: flink/src/main/java/org/apache/iceberg/flink/source/enumerator/AbstractIcebergEnumerator.java ########## @@ -0,0 +1,173 @@ +/* + * 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.iceberg.flink.source.enumerator; + +import java.io.IOException; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicReference; +import javax.annotation.Nullable; +import org.apache.flink.api.connector.source.SourceEvent; +import org.apache.flink.api.connector.source.SplitEnumerator; +import org.apache.flink.api.connector.source.SplitEnumeratorContext; +import org.apache.iceberg.flink.source.IcebergSourceEvents; +import org.apache.iceberg.flink.source.assigner.GetSplitResult; +import org.apache.iceberg.flink.source.assigner.SplitAssigner; +import org.apache.iceberg.flink.source.split.IcebergSourceSplit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * TODO: publish enumerator monitor metrics like number of pending metrics + * after FLINK-21000 is resolved + */ +abstract class AbstractIcebergEnumerator implements + SplitEnumerator<IcebergSourceSplit, IcebergEnumeratorState> { + + private static final Logger LOG = LoggerFactory.getLogger(AbstractIcebergEnumerator.class); + + private final SplitEnumeratorContext<IcebergSourceSplit> enumeratorContext; + private final SplitAssigner assigner; + private final IcebergEnumeratorConfig enumeratorConfig; + private final Map<Integer, String> readersAwaitingSplit; + private final AtomicReference<CompletableFuture<Void>> availableFuture; + + AbstractIcebergEnumerator( + SplitEnumeratorContext<IcebergSourceSplit> enumeratorContext, + SplitAssigner assigner, + IcebergEnumeratorConfig enumeratorConfig) { + this.enumeratorContext = enumeratorContext; + this.assigner = assigner; + this.enumeratorConfig = enumeratorConfig; + this.readersAwaitingSplit = new LinkedHashMap<>(); + this.availableFuture = new AtomicReference<>(); + } + + @Override + public void start() { + assigner.start(); + } + + @Override + public void close() throws IOException { + assigner.close(); + } + + @Override + public void handleSplitRequest(int subtaskId, @Nullable String requesterHostname) { + // Iceberg source uses a custom event inside handleSourceEvent + // so that we can carry over the finishedSplitIds + throw new UnsupportedOperationException("Iceberg source uses its own SplitRequestEvent"); + } + + @Override + public void handleSourceEvent(int subtaskId, SourceEvent sourceEvent) { + if (sourceEvent instanceof IcebergSourceEvents.SplitRequestEvent) { + final IcebergSourceEvents.SplitRequestEvent splitRequestEvent = + (IcebergSourceEvents.SplitRequestEvent) sourceEvent; + LOG.error("Received request split event from subtask {}", subtaskId); + assigner.onCompletedSplits(splitRequestEvent.finishedSplitIds()); + readersAwaitingSplit.put(subtaskId, splitRequestEvent.requesterHostname()); + assignSplits(); + } else { + LOG.error("Received unrecognized event from subtask {}: {}", subtaskId, sourceEvent); Review comment: good question. throwing exception will cause job to fail and restart. explicit failure is probably better. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
