dchristle commented on code in PR #7366: URL: https://github.com/apache/iceberg/pull/7366#discussion_r1181412955
########## flink/v1.16/flink/src/main/java/org/apache/iceberg/flink/source/assigner/EventTimeAlignedAssigner.java: ########## @@ -0,0 +1,301 @@ +/* + * + * * 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.assigner; + +import java.io.Serializable; +import java.time.Duration; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Set; +import java.util.TreeSet; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; +import javax.annotation.Nullable; +import javax.annotation.concurrent.NotThreadSafe; +import org.apache.flink.api.common.eventtime.TimestampAssigner; +import org.apache.iceberg.flink.source.split.IcebergSourceSplit; +import org.apache.iceberg.flink.source.split.IcebergSourceSplitState; +import org.apache.iceberg.flink.source.split.IcebergSourceSplitStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.flink.calcite.shaded.com.google.common.collect.Iterables.getFirst; + +public class EventTimeAlignedAssigner implements SplitAssigner, WatermarkTracker.Listener { Review Comment: @pvary It would be great if we could generate real Flink watermarks within the source. I believe one complication, though, is that rather than emitting the `extractTimestamp` value for each new `splitId`, the emitted watermarks need to (somehow) follow the same logic as `WatermarkTracker`'s `updateWatermark` method. When a split is completed, that split is removed from `assignedSplits` by `onCompletedSplits`. The minimum of all minimum timestamps of assigned + unassigned splits gives a value that correctly delineates all completed data from all possible future data (a proper watermark), and this is what `updateWatermark` computes. Only the _maximum_ timestamp of a potential split `S_i` is constrained by the split assignment constraint `max_timestamp(S_i) - min(min_timestamp({assigned}), min_timestamp({unassigned})) < maxMisalignmentThreshold`. So, the _minimum_ timestamp of `S_i` that `extractTimestamp` yields could be larger than the proper watermark value. Since only the assigner is aware of all assigned & unassigned splits, and it's instantiated inside the SplitEnumerator, which runs on the JobManager, some way to communicate watermark updates to the SourceReaders running on the TaskManagers could make it work. Then, perhaps they could call `emitWatermark` with the latest global watermark value they've received whenever a new split is assigned. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
