guoweiM commented on a change in pull request #13678: URL: https://github.com/apache/flink/pull/13678#discussion_r508509632
########## File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/sink/AbstractStreamingCommitterOperator.java ########## @@ -0,0 +1,179 @@ +/* + * 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.streaming.runtime.operators.sink; + +import org.apache.flink.annotation.VisibleForTesting; +import org.apache.flink.api.common.state.ListState; +import org.apache.flink.api.common.state.ListStateDescriptor; +import org.apache.flink.api.common.typeutils.base.array.BytePrimitiveArraySerializer; +import org.apache.flink.api.connector.sink.Committer; +import org.apache.flink.core.io.SimpleVersionedSerializer; +import org.apache.flink.runtime.state.StateInitializationContext; +import org.apache.flink.runtime.state.StateSnapshotContext; +import org.apache.flink.streaming.api.operators.AbstractStreamOperator; +import org.apache.flink.streaming.api.operators.OneInputStreamOperator; +import org.apache.flink.streaming.api.operators.util.SimpleVersionedListState; +import org.apache.flink.streaming.runtime.streamrecord.StreamRecord; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.NavigableMap; +import java.util.TreeMap; + +import static org.apache.flink.util.Preconditions.checkNotNull; + +/** + * Abstract base class for operators that work with a {@link Committer} or a + * {@link org.apache.flink.api.connector.sink.GlobalCommitter} in the streaming execution mode. + * + * <p>Sub-classes are responsible for implementing {@link #recoveredCommittables(List)} and {@link #preCommit(List)}. + * + * @param <InputT> The input type of the {@link Committer}. + * @param <CommT> The committable type of the {@link Committer}. + */ +abstract class AbstractStreamingCommitterOperator<InputT, CommT> extends AbstractStreamOperator<CommT> + implements OneInputStreamOperator<InputT, CommT> { + + private static final long serialVersionUID = 1L; + + /** The operator's state descriptor. */ + private static final ListStateDescriptor<byte[]> STREAMING_COMMITTER_RAW_STATES_DESC = + new ListStateDescriptor<>( + "streaming_committer_raw_states", + BytePrimitiveArraySerializer.INSTANCE); + + /** Group the committable by the checkpoint id. */ + private final NavigableMap<Long, List<CommT>> committablesPerCheckpoint; + + /** The committable's serializer. */ + private final StreamingCommitterStateSerializer<CommT> streamingCommitterStateSerializer; + + /** Responsible for committing the committable to the external system. **/ + protected final Committer<CommT> committer; Review comment: You raise a good point. I would like to open a following pr for this. ---------------------------------------------------------------- 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]
