LadyForest commented on a change in pull request #28:
URL: https://github.com/apache/flink-table-store/pull/28#discussion_r821294254



##########
File path: 
flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/sink/StoreSink.java
##########
@@ -84,24 +98,78 @@ public StoreSink(
     @Override
     public StoreSinkWriter<WriterStateT> restoreWriter(
             InitContext initContext, Collection<WriterStateT> states) throws 
IOException {
+        SinkWriter<SinkRecord> logWriter = null;
+        LogWriteCallback logCallback = null;
+        if (logSinkProvider != null) {
+            logCallback = new LogWriteCallback();
+            Consumer<?> metadataConsumer = 
logSinkProvider.createMetadataConsumer(logCallback);
+            LogInitContext logInitContext = new LogInitContext(initContext, 
metadataConsumer);
+            Sink<SinkRecord> logSink = logSinkProvider.createSink();
+            logWriter =
+                    states == null
+                            ? logSink.createWriter(logInitContext)
+                            : ((StatefulSink<SinkRecord, WriterStateT>) 
logSink)
+                                    .restoreWriter(logInitContext, states);
+        }
         return new StoreSinkWriter<>(
                 fileStore.newWrite(),
                 new SinkRecordConverter(
                         numBucket,
                         primaryKeys.length > 0 ? fileStore.valueType() : 
fileStore.keyType(),
                         partitions,
                         primaryKeys),
-                fileCommitSerializer(),
-                overwritePartition != null);
+                overwritePartition != null,
+                logWriter,
+                logCallback);
     }
 
     @Override
     public SimpleVersionedSerializer<WriterStateT> getWriterStateSerializer() {
-        return new NoOutputSerializer<>();
+        return logSinkProvider == null
+                ? new NoOutputSerializer<>()
+                : ((StatefulSink<SinkRecord, WriterStateT>) 
logSinkProvider.createSink())
+                        .getWriterStateSerializer();
+    }
+
+    @Nullable
+    private Committer<LogCommT> logCommitter() {
+        if (logSinkProvider != null) {
+            Sink<SinkRecord> sink = logSinkProvider.createSink();
+            if (sink instanceof TwoPhaseCommittingSink) {
+                TwoPhaseCommittingSink<SinkRecord, LogCommT> twoPhaseSink =
+                        (TwoPhaseCommittingSink<SinkRecord, LogCommT>) 
logSinkProvider.createSink();

Review comment:
       Why create the sink twice?




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