You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2021/01/28 16:15:23 UTC

[GitHub] [flink] aljoscha commented on a change in pull request #14782: [FLINK-21167] Make StateTable snapshots iterable

aljoscha commented on a change in pull request #14782:
URL: https://github.com/apache/flink/pull/14782#discussion_r566205955



##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/state/IterableStateSnapshot.java
##########
@@ -0,0 +1,32 @@
+/*
+ * 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.runtime.state;
+
+import org.apache.flink.annotation.Internal;
+
+import java.util.Iterator;
+
+/**
+ * A {@link StateSnapshot} that can be represented and thus iterated over {@link StateEntry
+ * StateEntries}.

Review comment:
       ```suggestion
    * A {@link StateSnapshot} that can return an iterator over all contained {@link StateEntry
    * StateEntries}.
   ```

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteStateMapSnapshot.java
##########
@@ -110,6 +110,19 @@ int getSnapshotVersion() {
         return snapshotVersion;
     }
 
+    @Override
+    public SnapshotIterator<K, N, S> getIterator(

Review comment:
       That was easy... 😅

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/state/heap/NestedStateMapSnapshot.java
##########
@@ -48,6 +53,35 @@ public NestedStateMapSnapshot(NestedStateMap<K, N, S> owningStateMap) {
         super(owningStateMap);
     }
 
+    @Override
+    public Iterator<StateEntry<K, N, S>> getIterator(
+            @Nonnull TypeSerializer<K> keySerializer,
+            @Nonnull TypeSerializer<N> namespaceSerializer,
+            @Nonnull TypeSerializer<S> stateSerializer,
+            @Nullable StateSnapshotTransformer<S> stateSnapshotTransformer) {
+        if (stateSnapshotTransformer == null) {
+            return owningStateMap.iterator();
+        } else {
+            return StreamSupport.stream(
+                            Spliterators.spliteratorUnknownSize(owningStateMap.iterator(), 0),
+                            false)
+                    .map(entry -> transformEntry(stateSnapshotTransformer, entry))
+                    .filter(Objects::nonNull)
+                    .iterator();
+        }
+    }
+
+    private StateEntry<K, N, S> transformEntry(
+            StateSnapshotTransformer<S> stateSnapshotTransformer, StateEntry<K, N, S> entry) {
+        S transformedState = stateSnapshotTransformer.filterOrTransform(entry.getState());
+        if (transformedState != null) {
+            return new StateEntry.SimpleStateEntry<>(

Review comment:
       It seems a bit icky that we hardcode `SimpleStateEntry` here. Maybe adding a `StateEntry.filterOrTransform(StateSnapshotTransformer)` that returns a new `StateEntry` could do the trick?




----------------------------------------------------------------
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:
users@infra.apache.org