liming30 commented on code in PR #20405:
URL: https://github.com/apache/flink/pull/20405#discussion_r945411319


##########
flink-state-backends/flink-statebackend-rocksdb/src/test/java/org/apache/flink/contrib/streaming/state/EmbeddedRocksDBStateBackendTest.java:
##########
@@ -637,11 +642,75 @@ public void testMapStateClear() throws Exception {
                             throw new RocksDBException("Artificial failure");
                         })
                 .when(keyedStateBackend.db)
-                .newIterator(any(ColumnFamilyHandle.class), 
any(ReadOptions.class));
+                .deleteRange(any(ColumnFamilyHandle.class), any(byte[].class), 
any(byte[].class));
 
         state.clear();
     }
 
+    @Test
+    public void testMapStateClearWithOneBytePrefix() throws Exception {
+        verifyMapStateClear(Byte.MAX_VALUE + 1);
+    }
+
+    @Test
+    public void testMapStateClearWithTwoBytesPrefix() throws Exception {
+        
verifyMapStateClear(KeyGroupRangeAssignment.UPPER_BOUND_MAX_PARALLELISM);
+    }
+
+    public void verifyMapStateClear(int maxParallelism) throws Exception {
+        try {
+            prepareRocksDB();
+
+            RocksDBKeyedStateBackendBuilder keyedStateBackendBuilder =
+                    RocksDBTestUtils.builderForTestDB(
+                            TEMP_FOLDER.newFolder(),
+                            IntSerializer.INSTANCE,
+                            db,
+                            defaultCFHandle,
+                            optionsContainer.getColumnOptions(),
+                            maxParallelism);
+            keyedStateBackend = keyedStateBackendBuilder.build();
+
+            MapStateDescriptor<Integer, String> kvId =
+                    new MapStateDescriptor<>("id", Integer.class, 
String.class);
+            MapState<Integer, String> state =
+                    keyedStateBackend.getPartitionedState(
+                            VoidNamespace.INSTANCE, 
VoidNamespaceSerializer.INSTANCE, kvId);
+
+            int[] keys = new int[maxParallelism];
+            BitSet bitSet = new BitSet(maxParallelism);
+            // Make sure each keyGroup has a key
+            for (int i = 0; bitSet.cardinality() != maxParallelism; i++) {
+                int keyGroup = KeyGroupRangeAssignment.assignToKeyGroup(i, 
maxParallelism);
+                if (!bitSet.get(keyGroup)) {
+                    bitSet.set(keyGroup);
+                    keys[keyGroup] = i;
+                }
+            }
+
+            for (int key : keys) {
+                keyedStateBackend.setCurrentKey(key);
+                state.put(key, "retain " + key);
+            }
+
+            int clearKeyGroup = RandomUtils.nextInt(0, maxParallelism);
+            keyedStateBackend.setCurrentKey(keys[clearKeyGroup]);
+            state.clear();

Review Comment:
   I tried to verify on my local mac with the following code. At 
maxParallelism=32768, the run time is over 10 minutes, which is too slow, or do 
I need to use multi-thread for validation?
   ```
               for (int i = 0; i < maxParallelism; i++) {
                   keyedStateBackend.setCurrentKey(keys[i]);
                   state.clear();
                   for (int j = 0; j < maxParallelism; j++) {
                       keyedStateBackend.setCurrentKey(keys[j]);
                       if (j <= i) {
                           assertTrue(state.isEmpty());
                       } else {
                           Integer expected = keys[j];
                           assertEquals(expected, state.get(keys[j]));
                       }
                   }
               }
   ```



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