banmoy commented on a change in pull request #8611: [FLINK-12693][state] Store 
state per key-group in CopyOnWriteStateTable
URL: https://github.com/apache/flink/pull/8611#discussion_r300216045
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/state/heap/StateTable.java
 ##########
 @@ -172,14 +229,110 @@ public boolean isEmpty() {
         * @return the state of the mapping with the specified key/namespace 
composite key, or {@code null}
         * if no mapping for the specified key is found.
         */
-       public abstract S get(K key, N namespace);
+       public S get(K key, N namespace) {
+               int keyGroup = KeyGroupRangeAssignment.assignToKeyGroup(key, 
keyContext.getNumberOfKeyGroups());
+               return get(key, keyGroup, namespace);
+       }
+
+       public Stream<K> getKeys(N namespace) {
+               return Arrays.stream(state)
+                       .flatMap(stateMap -> 
StreamSupport.stream(Spliterators.spliteratorUnknownSize(stateMap.iterator(), 
0), false))
+                       .filter(entry -> entry.getNamespace().equals(namespace))
+                       .map(StateEntry::getKey);
+       }
+
+       public StateIncrementalVisitor<K, N, S> getStateIncrementalVisitor(int 
recommendedMaxNumberOfReturnedRecords) {
+               return new 
StateEntryIterator(recommendedMaxNumberOfReturnedRecords);
+       }
 
-       public abstract Stream<K> getKeys(N namespace);
+       // 
------------------------------------------------------------------------
 
-       public abstract StateIncrementalVisitor<K, N, S> 
getStateIncrementalVisitor(int recommendedMaxNumberOfReturnedRecords);
+       private S get(K key, int keyGroupIndex, N namespace) {
+               checkKeyNamespacePreconditions(key, namespace);
+
+               StateMap<K, N, S> stateMap = getMapForKeyGroup(keyGroupIndex);
+
+               if (stateMap == null) {
 
 Review comment:
   This check is to pass the UT of 
StateBackendTestBase#testKeyGroupSnapshotRestore. The UT will get a key from 
the backend, but the key is in a key group which not belongs to this backend.

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


With regards,
Apache Git Services

Reply via email to