Zakelly commented on code in PR #25918:
URL: https://github.com/apache/flink/pull/25918#discussion_r1908304569


##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/v2/StateSerializerReference.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.runtime.state.v2;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.api.common.functions.SerializerFactory;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * A reference to a serializer. This also provides functions for lazy 
initialization.
+ *
+ * @param <T> the type for serialization.
+ */
+public class StateSerializerReference<T> extends 
AtomicReference<TypeSerializer<T>> {
+    private static final Logger LOG = 
LoggerFactory.getLogger(StateSerializerReference.class);
+
+    /**
+     * The type information describing the value type. Only used to if the 
serializer is created
+     * lazily.
+     */
+    @Nullable private final TypeInformation<T> typeInfo;
+
+    public StateSerializerReference(TypeInformation<T> typeInfo) {
+        super(null);
+        this.typeInfo = checkNotNull(typeInfo, "type information must not be 
null");
+    }
+
+    public StateSerializerReference(TypeSerializer<T> typeSerializer) {

Review Comment:
   Yes, it is for eager initialization. I introduced `StateSerializerReference` 
to hold the state serializer regardless of lazy or eager initialization. It 
simplifies the code.
   
   And the lazy initialization is mostly used by DS jobs, where user may only 
specify the `TypeInformation` in their state descriptors, and create the 
serializer in runtime according to the `ExecutionConfig`. In SQL scenario or 
some DS jobs, the eager initialization will be used, that's depends on how it 
is implemented.



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to