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/10/19 08:10:37 UTC

[GitHub] [flink-ml] gaoyunhaii commented on a change in pull request #14: [FLINK-8][iteration] Add per-round operator wrappers

gaoyunhaii commented on a change in pull request #14:
URL: https://github.com/apache/flink-ml/pull/14#discussion_r731603315



##########
File path: flink-ml-iteration/src/main/java/org/apache/flink/ml/iteration/proxy/state/ProxyOperatorStateBackend.java
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.ml.iteration.proxy.state;
+
+import org.apache.flink.api.common.state.BroadcastState;
+import org.apache.flink.api.common.state.ListState;
+import org.apache.flink.api.common.state.ListStateDescriptor;
+import org.apache.flink.api.common.state.MapStateDescriptor;
+import org.apache.flink.runtime.checkpoint.CheckpointOptions;
+import org.apache.flink.runtime.state.CheckpointStreamFactory;
+import org.apache.flink.runtime.state.OperatorStateBackend;
+import org.apache.flink.runtime.state.OperatorStateHandle;
+import org.apache.flink.runtime.state.SnapshotResult;
+
+import javax.annotation.Nonnull;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.RunnableFuture;
+
+/** Proxy {@link OperatorStateBackend} for the wrapped Operator. */
+public class ProxyOperatorStateBackend implements OperatorStateBackend {
+
+    private final OperatorStateBackend wrappedBackend;
+
+    private final String stateNamePrefix;
+
+    public ProxyOperatorStateBackend(OperatorStateBackend wrappedBackend, String stateNamePrefix) {
+        this.wrappedBackend = wrappedBackend;
+        this.stateNamePrefix = stateNamePrefix;
+    }
+
+    @Override
+    public <K, V> BroadcastState<K, V> getBroadcastState(MapStateDescriptor<K, V> stateDescriptor)
+            throws Exception {
+        MapStateDescriptor<K, V> newDescriptor =
+                new MapStateDescriptor<>(
+                        stateNamePrefix + stateDescriptor.getName(),
+                        stateDescriptor.getKeySerializer(),
+                        stateDescriptor.getValueSerializer());
+        return wrappedBackend.getBroadcastState(newDescriptor);
+    }
+
+    @Override
+    public <S> ListState<S> getListState(ListStateDescriptor<S> stateDescriptor) throws Exception {
+        ListStateDescriptor<S> newDescriptor =
+                new ListStateDescriptor<>(
+                        stateNamePrefix + stateDescriptor.getName(),
+                        stateDescriptor.getElementSerializer());
+        return wrappedBackend.getListState(newDescriptor);
+    }
+
+    @Override
+    public <S> ListState<S> getUnionListState(ListStateDescriptor<S> stateDescriptor)
+            throws Exception {
+        ListStateDescriptor<S> newDescriptor =
+                new ListStateDescriptor<S>(
+                        stateNamePrefix + stateDescriptor.getName(),
+                        stateDescriptor.getElementSerializer());
+        return wrappedBackend.getUnionListState(stateDescriptor);
+    }
+
+    @Override
+    public Set<String> getRegisteredStateNames() {
+        Set<String> filteredNames = new HashSet<>();
+        Set<String> names = wrappedBackend.getRegisteredStateNames();
+
+        for (String name : names) {
+            if (name.startsWith(stateNamePrefix)) {

Review comment:
       There should be no reverse cases here due to all the state operator would go across the proxy state backend, that means even if users have a state named `r5-xx` for round 6, it would be renamed to `r6-r5-xx`. 




-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org