You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/10/12 00:30:17 UTC

[GitHub] [flink] guoweiM commented on a change in pull request #13576: [FLINK-19512] Introduce the new sink API

guoweiM commented on a change in pull request #13576:
URL: https://github.com/apache/flink/pull/13576#discussion_r502987944



##########
File path: flink-core/src/main/java/org/apache/flink/api/connector/sink/Writer.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.api.connector.sink;
+
+import org.apache.flink.annotation.Experimental;
+
+import java.util.List;
+
+/**
+ * The interface is responsible for writing data and handling any potential tmp area used to write yet un-staged data, e.g. in-progress files.
+ * The data (or metadata pointing to where the actual data is staged) ready to commit is returned to the system by the {@link #prepareCommit(boolean)}.
+ *
+ * @param <InputT>         The type of the writer's input
+ * @param <CommT>          The type of the committable data
+ * @param <WriterStateT>   The type of the writer's state
+ */
+@Experimental
+public interface Writer<InputT, CommT, WriterStateT> extends AutoCloseable {
+
+	/**
+	 * Add an element to the writer.
+	 * @param element The input record
+	 * @param context The additional information about the input record
+	 */
+	void write(InputT element, Context context);
+
+	/**
+	 * Prepare for a commit.
+	 * @param flush whether flushing the un-staged data or not
+	 * @return The data is ready to commit.
+	 */
+	List<CommT> prepareCommit(boolean flush);
+
+	/**
+	 * @return the writer's state.
+	 */
+	List<WriterStateT> snapshotState();

Review comment:
       Currently the benefit of `List<WriterStateT>` is that this could rebalance the workload when changing the parallelism. For example currently the `StreamingFileSink` redistributed the `Bucket` when the parallelism scales up or down.




----------------------------------------------------------------
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:
users@infra.apache.org