jectpro7 commented on code in PR #24812:
URL: https://github.com/apache/flink/pull/24812#discussion_r1610081555


##########
flink-state-backends/flink-statebackend-forst/src/main/java/org/apache/flink/state/forst/ForStDBBunchPutRequest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.api.common.typeutils.TypeSerializer;
+import org.apache.flink.core.memory.DataInputDeserializer;
+import org.apache.flink.core.memory.DataOutputSerializer;
+import org.apache.flink.core.state.InternalStateFuture;
+import org.apache.flink.util.Preconditions;
+
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * The Bunch Put access request for ForStDB.
+ *
+ * @param <K> The type of key in original state access request.
+ */
+public class ForStDBBunchPutRequest<K> extends 
ForStDBPutRequest<ContextKey<K>, Map<?, ?>> {
+
+    /** Serializer for the user values. */
+    final TypeSerializer<Object> userValueSerializer;
+
+    /** The data outputStream used for value serializer, which should be 
thread-safe. */
+    final ThreadLocal<DataOutputSerializer> valueSerializerView;
+
+    /** The data inputStream used for value deserializer, which should be 
thread-safe. */
+    final ThreadLocal<DataInputDeserializer> valueDeserializerView;
+
+    public ForStDBBunchPutRequest(
+            ContextKey<K> key, Map value, ForStMapState table, 
InternalStateFuture<Void> future) {
+        super(key, value, table, future);
+        Preconditions.checkArgument(table instanceof ForStMapState);

Review Comment:
   this check seems redundant.



##########
flink-state-backends/flink-statebackend-forst/src/main/java/org/apache/flink/state/forst/ForStWriteBatchOperation.java:
##########
@@ -55,22 +54,44 @@ public class ForStWriteBatchOperation implements 
ForStDBOperation {
     public CompletableFuture<Void> process() {
         return CompletableFuture.runAsync(
                 () -> {
-                    try (WriteBatch writeBatch =
-                            new WriteBatch(batchRequest.size() * 
PER_RECORD_ESTIMATE_BYTES)) {
+                    try (ForStDBWriteBatchWrapper writeBatch =
+                            new ForStDBWriteBatchWrapper(db, writeOptions, 
batchRequest.size())) {
                         for (ForStDBPutRequest<?, ?> request : batchRequest) {
+                            ColumnFamilyHandle cf = 
request.getColumnFamilyHandle();
                             if (request.valueIsNull()) {
-                                // put(key, null) == delete(key)
-                                writeBatch.delete(
-                                        request.getColumnFamilyHandle(),
-                                        request.buildSerializedKey());
+                                if (request instanceof ForStDBBunchPutRequest) 
{
+                                    ForStDBBunchPutRequest<?> bunchPutRequest =
+                                            (ForStDBBunchPutRequest<?>) 
request;
+                                    byte[] primaryKey = 
bunchPutRequest.buildSerializedKey(null);

Review Comment:
   Sorry, I cannot understand this line, why serialize `null` here? Why the 
`Bunch remove` and `Single remove` are using different serialization method.



##########
flink-state-backends/flink-statebackend-forst/src/main/java/org/apache/flink/state/forst/ForStDBBunchPutRequest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.api.common.typeutils.TypeSerializer;
+import org.apache.flink.core.memory.DataInputDeserializer;
+import org.apache.flink.core.memory.DataOutputSerializer;
+import org.apache.flink.core.state.InternalStateFuture;
+import org.apache.flink.util.Preconditions;
+
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * The Bunch Put access request for ForStDB.
+ *
+ * @param <K> The type of key in original state access request.
+ */
+public class ForStDBBunchPutRequest<K> extends 
ForStDBPutRequest<ContextKey<K>, Map<?, ?>> {
+
+    /** Serializer for the user values. */
+    final TypeSerializer<Object> userValueSerializer;
+
+    /** The data outputStream used for value serializer, which should be 
thread-safe. */
+    final ThreadLocal<DataOutputSerializer> valueSerializerView;
+
+    /** The data inputStream used for value deserializer, which should be 
thread-safe. */
+    final ThreadLocal<DataInputDeserializer> valueDeserializerView;
+
+    public ForStDBBunchPutRequest(
+            ContextKey<K> key, Map value, ForStMapState table, 
InternalStateFuture<Void> future) {
+        super(key, value, table, future);
+        Preconditions.checkArgument(table instanceof ForStMapState);
+        this.userValueSerializer = table.userValueSerializer;
+        this.valueSerializerView = table.valueSerializerView;
+        this.valueDeserializerView = table.valueDeserializerView;
+    }
+
+    public Map<?, ?> getBunchValue() {
+        return value;
+    }
+
+    @Override
+    public byte[] buildSerializedKey() throws IOException {
+        key.resetExtra();
+        return table.serializeKey(key);
+    }
+
+    public byte[] buildSerializedKey(Object userKey) throws IOException {
+        key.setUserKey(userKey);
+        return table.serializeKey(key);
+    }
+
+    public byte[] buildSerializedValue(Object singleValue) throws IOException {
+        DataOutputSerializer outputView = valueSerializerView.get();
+        outputView.clear();
+        userValueSerializer.serialize(singleValue, outputView);
+        return outputView.getCopyOfBuffer();
+    }
+
+    /**
+     * Find the next byte array that is lexicographically larger than input 
byte array.
+     *
+     * @param bytes the input byte array.
+     * @return the next byte array.
+     */
+    public static byte[] nextBytes(byte[] bytes) {
+        Preconditions.checkState(bytes != null && bytes.length > 0);
+        int len = bytes.length;
+        byte[] nextBytes = new byte[len];
+        System.arraycopy(bytes, 0, nextBytes, 0, len);
+        boolean find = false;
+        for (int i = len - 1; i >= 0; i--) {
+            byte currentByte = ++nextBytes[i];
+            if (currentByte != Byte.MIN_VALUE) {
+                find = true;
+                break;
+            }
+        }
+        if (!find) {
+            byte[] newBytes = new byte[len + 1];
+            System.arraycopy(bytes, 0, newBytes, 0, len);
+            newBytes[len] = 1;
+            return newBytes;
+        }

Review Comment:
   From my understanding, if the `byteArr` is maximum value. The next should 
like this:
   ```suggestion
           if (!find) {
               byte[] newBytes = new byte[len + 1];
               System.arraycopy(nextBytes, 0, newBytes, 1, len);
               newBytes[0] = Byte.MIN_VALUE + 1;
               return newBytes;
           }
   ```
   Take integer as example is simpler:
   when input is `999`, the next value should be `1000`



##########
flink-state-backends/flink-statebackend-forst/src/main/java/org/apache/flink/state/forst/ForStDBGetRequest.java:
##########
@@ -34,12 +34,35 @@ public class ForStDBGetRequest<K, V> {
 
     private final K key;
     private final ForStInnerTable<K, V> table;
-    private final InternalStateFuture<V> future;
+    private final InternalStateFuture future;
 
-    private ForStDBGetRequest(K key, ForStInnerTable<K, V> table, 
InternalStateFuture<V> future) {
+    private final boolean toBoolean;
+    private final boolean checkMapEmpty;
+
+    private int keyGroupPrefixBytes = 1;
+
+    private ForStDBGetRequest(
+            K key,
+            ForStInnerTable<K, V> table,
+            InternalStateFuture future,
+            boolean toBoolean,
+            boolean checkMapEmpty) {
         this.key = key;
         this.table = table;
         this.future = future;
+        this.toBoolean = toBoolean;

Review Comment:
   `toBoolean` seems not very clear. I would suggest to add 
`ForStDBExistRequest` for this kind of operation.



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