gaoyunhaii commented on a change in pull request #14208:
URL: https://github.com/apache/flink/pull/14208#discussion_r530178458


##########
File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/sink/StatefulSinkWriterOperator.java
##########
@@ -74,17 +89,40 @@ public void initializeState(StateInitializationContext 
context) throws Exception
 
                final ListState<byte[]> rawState = 
context.getOperatorStateStore().getListState(WRITER_RAW_STATES_DESC);
                writerState = new SimpleVersionedListState<>(rawState, 
writerStateSimpleVersionedSerializer);
+
+               if (previousSinkStateName != null) {
+                       final ListStateDescriptor<byte[]> preSinkStateDesc = 
new ListStateDescriptor<>(
+                                       previousSinkStateName,
+                                       BytePrimitiveArraySerializer.INSTANCE);
+
+                       final ListState<byte[]> preRawState = context
+                                       .getOperatorStateStore()
+                                       .getListState(preSinkStateDesc);
+                       this.previousSinkState = new SimpleVersionedListState<>(
+                                       preRawState,
+                                       writerStateSimpleVersionedSerializer);
+               }
        }
 
        @SuppressWarnings("unchecked")
        @Override
        public void snapshotState(StateSnapshotContext context) throws 
Exception {
                writerState.update((List<WriterStateT>) 
sinkWriter.snapshotState());
+               if (previousSinkState != null) {
+                       previousSinkState.clear();
+               }
        }
 
        @Override
        SinkWriter<InputT, CommT, WriterStateT> createWriter() throws Exception 
{
-               final List<WriterStateT> committables = 
CollectionUtil.iterableToList(writerState.get());
-               return sink.createWriter(createInitContext(), committables);
+               final List<WriterStateT> writerStates = 
CollectionUtil.iterableToList(writerState.get());
+               final List<WriterStateT> states = new ArrayList<>(writerStates);

Review comment:
       May be simplified as `final List<WriterStateT> states = new 
ArrayList<>(CollectionUtil.iterableToList(writerState.get()));` so that we 
could avoid using both `writerStates` and `states` variable names.




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


Reply via email to