lamber-ken commented on a change in pull request #2593: URL: https://github.com/apache/hudi/pull/2593#discussion_r581810262
########## File path: hudi-flink/src/main/java/org/apache/hudi/operator/compact/CompactionCommitSink.java ########## @@ -0,0 +1,150 @@ +/* + * 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.hudi.operator.compact; + +import org.apache.hudi.avro.model.HoodieCompactionPlan; +import org.apache.hudi.client.FlinkTaskContextSupplier; +import org.apache.hudi.client.HoodieFlinkWriteClient; +import org.apache.hudi.client.WriteStatus; +import org.apache.hudi.client.common.HoodieFlinkEngineContext; +import org.apache.hudi.common.config.SerializableConfiguration; +import org.apache.hudi.common.model.HoodieCommitMetadata; +import org.apache.hudi.common.model.HoodieWriteStat; +import org.apache.hudi.common.table.timeline.HoodieInstant; +import org.apache.hudi.common.table.timeline.HoodieTimeline; +import org.apache.hudi.common.util.CompactionUtils; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.util.StreamerUtil; + +import org.apache.flink.configuration.Configuration; +import org.apache.flink.streaming.api.functions.sink.RichSinkFunction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * Function to check and commit the compaction action. + * + * <p> Each time after receiving a compaction commit event {@link CompactCommitEvent}, + * it loads and checks the compaction plan {@link HoodieCompactionPlan}, + * if all the compaction operations {@link org.apache.hudi.common.model.CompactionOperation} + * of the plan are finished, tries to commit the compaction action. + */ +public class CompactionCommitSink extends RichSinkFunction<CompactCommitEvent> { + private static final Logger LOG = LoggerFactory.getLogger(CompactionCommitSink.class); + + /** + * Config options. + */ + private final Configuration conf; + + /** + * Write Client. + */ + private transient HoodieFlinkWriteClient writeClient; + + /** + * Buffer to collect the event from each compact task {@code CompactFunction}. + */ + private transient List<CompactCommitEvent> commitBuffer; + + /** + * Current on-going compaction instant time. + */ + private String compactionInstantTime; + + public CompactionCommitSink(Configuration conf, int numTasks) { Review comment: Will this parameter work in the future? If not, we can remove it. : ) ---------------------------------------------------------------- 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]
