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

 ##########
 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:
   I think that there is also a problem with the test because it is attempting 
to access a key on a backend that is not from a key-group that belongs to the 
backend. In production this would indicate a bug, so maybe it is better to have 
this as a precondition check on the backends and throw `IllegalStateException` 
and adjust the test accordingly.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to