hk-lrzy commented on code in PR #1212:
URL: https://github.com/apache/incubator-paimon/pull/1212#discussion_r1230605356


##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/cdc/CdcRecordStoreMultiWriteOperator.java:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.paimon.flink.sink.cdc;
+
+import org.apache.paimon.catalog.Catalog;
+import org.apache.paimon.catalog.Identifier;
+import org.apache.paimon.data.GenericRow;
+import org.apache.paimon.flink.sink.MultiTableCommittable;
+import org.apache.paimon.flink.sink.PrepareCommitOperator;
+import org.apache.paimon.flink.sink.StateUtils;
+import org.apache.paimon.flink.sink.StoreSinkWrite;
+import org.apache.paimon.flink.sink.StoreSinkWriteState;
+import org.apache.paimon.table.FileStoreTable;
+
+import org.apache.flink.runtime.state.StateInitializationContext;
+import org.apache.flink.runtime.state.StateSnapshotContext;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static 
org.apache.paimon.flink.sink.cdc.CdcRecordStoreWriteOperator.RETRY_SLEEP_TIME;
+
+/**
+ * A {@link PrepareCommitOperator} to write {@link CdcRecord}. Record schema 
may change. If current
+ * known schema does not fit record schema, this operator will wait for schema 
changes.
+ */
+public class CdcRecordStoreMultiWriteOperator
+        extends PrepareCommitOperator<CdcMultiplexRecord, 
MultiTableCommittable> {
+
+    private static final long serialVersionUID = 1L;
+    private final long retrySleepMillis;
+    private final StoreSinkWrite.Provider storeSinkWriteProvider;
+    private final String initialCommitUser;
+    private final Catalog.Loader catalogLoader;
+    protected Catalog catalog;
+    protected FileStoreTable table;
+    protected Map<Identifier, FileStoreTable> tables;
+    protected StoreSinkWriteState state;
+    protected StoreSinkWrite write;
+    protected Map<Identifier, StoreSinkWrite> writes;
+    protected String commitUser;
+
+    public CdcRecordStoreMultiWriteOperator(
+            Catalog.Loader catalogLoader,
+            StoreSinkWrite.Provider storeSinkWriteProvider,
+            String initialCommitUser) {
+        this.catalogLoader = catalogLoader;
+        this.storeSinkWriteProvider = storeSinkWriteProvider;
+        this.initialCommitUser = initialCommitUser;
+        this.retrySleepMillis = RETRY_SLEEP_TIME.defaultValue().toMillis();
+    }
+
+    @Override
+    public void initializeState(StateInitializationContext context) throws 
Exception {
+        super.initializeState(context);
+
+        catalog = catalogLoader.load();
+
+        // Each job can only have one user name and this name must be 
consistent across restarts.
+        // We cannot use job id as commit user name here because user may 
change job id by creating
+        // a savepoint, stop the job and then resume from savepoint.
+        commitUser =
+                StateUtils.getSingleValueFromState(
+                        context, "commit_user_state", String.class, 
initialCommitUser);
+
+        state = new StoreSinkWriteState(context, (tableName, partition, 
bucket) -> true);

Review Comment:
   Now, State will be expand when we try to scale out right? every task will 
store all table's states maybe .



-- 
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]

Reply via email to