StefanRRichter commented on a change in pull request #7899: [FLINK-11731] 
[State Backends] Make DefaultOperatorStateBackend follow the builder pattern
URL: https://github.com/apache/flink/pull/7899#discussion_r262434116
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/state/DefaultOperatorStateBackendBuilder.java
 ##########
 @@ -0,0 +1,103 @@
+/*
+ * 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.VisibleForTesting;
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.util.IOUtils;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Builder class for {@link DefaultOperatorStateBackend} which handles all 
necessary initializations and clean ups.
+ */
+public class DefaultOperatorStateBackendBuilder implements
+       StateBackendBuilder<DefaultOperatorStateBackend, 
BackendBuildingException> {
+       /** The user code classloader. */
+       @VisibleForTesting
+       protected final ClassLoader userClassloader;
+       /** The execution configuration. */
+       @VisibleForTesting
+       protected final ExecutionConfig executionConfig;
+       /** Flag to de/activate asynchronous snapshots. */
+       @VisibleForTesting
+       protected final boolean asynchronousSnapshots;
+       /** State handles for restore. */
+       @VisibleForTesting
+       protected final Collection<OperatorStateHandle> restoreStateHandles;
+       @VisibleForTesting
+       protected final CloseableRegistry cancelStreamRegistry;
+
+
+       public DefaultOperatorStateBackendBuilder(
+               ClassLoader userClassloader,
+               ExecutionConfig executionConfig,
+               boolean asynchronousSnapshots,
+               Collection<OperatorStateHandle> stateHandles,
+               CloseableRegistry cancelStreamRegistry) {
+               this.userClassloader = userClassloader;
+               this.executionConfig = executionConfig;
+               this.asynchronousSnapshots = asynchronousSnapshots;
+               this.restoreStateHandles = stateHandles;
+               this.cancelStreamRegistry = cancelStreamRegistry;
+       }
+
+       @Override
+       public DefaultOperatorStateBackend build() throws 
BackendBuildingException {
+               JavaSerializer<Serializable> serializer = new 
JavaSerializer<>();
+               Map<String, PartitionableListState<?>> registeredOperatorStates 
= new HashMap<>();
+               Map<String, BackendWritableBroadcastState<?, ?>> 
registeredBroadcastStates = new HashMap<>();
+               Map<String, PartitionableListState<?>> accessedStatesByName = 
new HashMap<>();
+               Map<String, BackendWritableBroadcastState<?, ?>> 
accessedBroadcastStatesByName = new HashMap<>();
+               CloseableRegistry cancelStreamRegistryForBackend = new 
CloseableRegistry();
+               AbstractSnapshotStrategy<OperatorStateHandle> snapshotStrategy =
+                       new DefaultOperatorStateBackendSnapshotStrategy(
+                               userClassloader,
+                               asynchronousSnapshots,
+                               registeredOperatorStates,
+                               registeredBroadcastStates,
+                               cancelStreamRegistryForBackend);
+               OperatorStateRestoreOperation restoreOperation = new 
OperatorStateRestoreOperation(
+                       cancelStreamRegistry,
+                       userClassloader,
+                       registeredOperatorStates,
+                       registeredBroadcastStates,
+                       restoreStateHandles
+               );
+               try {
+                       restoreOperation.restore();
+               } catch (Throwable e) {
 
 Review comment:
   I would suggest to only catch `Exception` here, not `Throwable`.

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