Github user StephanEwen commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3466#discussion_r105127429
  
    --- Diff: 
flink-runtime/src/main/java/org/apache/flink/runtime/state/heap/HeapReducingState.java
 ---
    @@ -68,62 +63,29 @@ public HeapReducingState(
     
        @Override
        public V get() {
    -           Preconditions.checkState(currentNamespace != null, "No 
namespace set.");
    -           Preconditions.checkState(backend.getCurrentKey() != null, "No 
key set.");
    -
    -           Map<N, Map<K, V>> namespaceMap =
    -                           
stateTable.get(backend.getCurrentKeyGroupIndex());
    -
    -           if (namespaceMap == null) {
    -                   return null;
    -           }
    -
    -           Map<K, V> keyedMap = namespaceMap.get(currentNamespace);
    -
    -           if (keyedMap == null) {
    -                   return null;
    -           }
    -
    -           return keyedMap.get(backend.<K>getCurrentKey());
    +           return stateTable.get(currentNamespace);
        }
     
        @Override
        public void add(V value) throws IOException {
    -           Preconditions.checkState(currentNamespace != null, "No 
namespace set.");
    -           Preconditions.checkState(backend.getCurrentKey() != null, "No 
key set.");
    +           final N namespace = currentNamespace;
     
                if (value == null) {
                        clear();
                        return;
                }
     
    -           Map<N, Map<K, V>> namespaceMap =
    -                           
stateTable.get(backend.getCurrentKeyGroupIndex());
    -
    -           if (namespaceMap == null) {
    -                   namespaceMap = createNewMap();
    -                   stateTable.set(backend.getCurrentKeyGroupIndex(), 
namespaceMap);
    -           }
    -
    -           Map<K, V> keyedMap = namespaceMap.get(currentNamespace);
    -
    -           if (keyedMap == null) {
    -                   keyedMap = createNewMap();
    -                   namespaceMap.put(currentNamespace, keyedMap);
    -           }
    -
    -           V currentValue = keyedMap.put(backend.<K>getCurrentKey(), 
value);
    +           final StateTable<K, N, V> map = stateTable;
    +           final V currentValue = map.putAndGetOld(namespace, value);
    --- End diff --
    
    Why not push the Reduce into the table? `map.reduce(namespace, value, 
ReduceFunction)`? That gives the minimal number of navigations possible, 
similar to using `putIfAbsent()` rather then a `get()/put()`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to