ljz2051 commented on code in PR #24681:
URL: https://github.com/apache/flink/pull/24681#discussion_r1576167215


##########
flink-state-backends/flink-statebackend-forst/src/main/java/org/apache/flink/state/forst/ContextKey.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.state.forst;
+
+import org.apache.flink.runtime.asyncprocessing.RecordContext;
+import org.apache.flink.util.function.FunctionWithException;
+
+import javax.annotation.concurrent.ThreadSafe;
+
+import java.io.IOException;
+import java.util.Objects;
+
+/**
+ * The composite key which contains some context information, such as 
keyGroup, etc.
+ *
+ * @param <K> The type of the raw key.
+ */
+@ThreadSafe
+public class ContextKey<K> {
+
+    private final RecordContext<K> recordContext;
+
+    public ContextKey(RecordContext<K> recordContext) {
+        this.recordContext = recordContext;
+    }
+
+    public K getRawKey() {
+        return recordContext.getKey();
+    }
+
+    public int getKeyGroup() {
+        return recordContext.getKeyGroup();
+    }
+
+    /**
+     * Get the serialized key. If the cached serialized key within {@code 
RecordContext#payload} is
+     * null, the provided serialization function will be called, and the 
serialization result will
+     * be cached by {@code RecordContext#payload}.
+     *
+     * @param serializeKeyFunc the provided serialization function for this 
contextKey.
+     * @return the serialized bytes.
+     */
+    public byte[] getOrCreateSerializedKey(
+            FunctionWithException<ContextKey<K>, byte[], IOException> 
serializeKeyFunc)
+            throws IOException {
+        if (recordContext.getPayload() != null) {
+            return (byte[]) recordContext.getPayload();
+        }
+        synchronized (recordContext) {
+            if (recordContext.getPayload() == null) {
+                byte[] serializedKey = serializeKeyFunc.apply(this);
+                recordContext.setPayload(serializedKey);

Review Comment:
   No, only the serialized key will be cached in payload.  The `value` cannot 
be reused between different state execution stage, so there is no need to cache 
`value`.



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