flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] klion26 commented on a change in pull request #6777: [FLINK-10461] [State Backends, Checkpointing] Speed up download files when restore from DFS
Date Fri, 14 Dec 2018 04:10:09 GMT
klion26 commented on a change in pull request #6777: [FLINK-10461] [State Backends, Checkpointing]
Speed up download files when restore from DFS
URL: https://github.com/apache/flink/pull/6777#discussion_r241639512
 
 

 ##########
 File path: flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/contrib/streaming/state/RocksDbStateDataTransfer.java
 ##########
 @@ -0,0 +1,158 @@
+/*
+ * 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.contrib.streaming.state;
+
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.core.fs.FSDataInputStream;
+import org.apache.flink.core.fs.FSDataOutputStream;
+import org.apache.flink.core.fs.FileSystem;
+import org.apache.flink.core.fs.Path;
+import org.apache.flink.runtime.concurrent.FutureUtils;
+import org.apache.flink.runtime.state.IncrementalKeyedStateHandle;
+import org.apache.flink.runtime.state.StateHandleID;
+import org.apache.flink.runtime.state.StreamStateHandle;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.function.ThrowingRunnable;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import static org.apache.flink.runtime.concurrent.Executors.directExecutorService;
+
+/**
+ * Data transfer utils for RocksDbKeyedStateBackend.
+ */
+class RocksDbStateDataTransfer {
+
+	static void transferAllStateDataToDirectory(
+		IncrementalKeyedStateHandle restoreStateHandle,
+		Path dest,
+		int restoringThreadNum,
+		CloseableRegistry closeableRegistry) throws Exception {
+
+		final Map<StateHandleID, StreamStateHandle> sstFiles =
+			restoreStateHandle.getSharedState();
+		final Map<StateHandleID, StreamStateHandle> miscFiles =
+			restoreStateHandle.getPrivateState();
+
+		downloadDataForAllStateHandles(sstFiles, dest, restoringThreadNum, closeableRegistry);
+		downloadDataForAllStateHandles(miscFiles, dest, restoringThreadNum, closeableRegistry);
+	}
+
+	/**
+	 * Copies all the files from the given stream state handles to the given path, renaming
the files w.r.t. their
+	 * {@link StateHandleID}.
+	 */
+	private static void downloadDataForAllStateHandles(
+		Map<StateHandleID, StreamStateHandle> stateHandleMap,
+		Path restoreInstancePath,
+		int restoringThreadNum,
+		CloseableRegistry closeableRegistry) throws InterruptedException, IOException {
+
+		final ExecutorService executorService = createExecutorService(restoringThreadNum);
+
+		try {
+			List<Runnable> runnables = createDownloadRunnables(stateHandleMap, restoreInstancePath,
closeableRegistry);
+			List<CompletableFuture<Void>> futures = new ArrayList<>(runnables.size());
+			for (Runnable runnable : runnables) {
+				futures.add(CompletableFuture.runAsync(runnable, executorService));
+			}
+
+			FutureUtils.waitForAll(futures).get();
+		} catch (ExecutionException e) {
+			final Throwable throwable = ExceptionUtils.stripExecutionException(e);
+			if (throwable instanceof IOException) {
+				throw (IOException) throwable;
 
 Review comment:
   I followed [AbstractTaskManagerFileHandle](https://github.com/apache/flink/blob/951ae9a813cbf8a2db95519853f940277e4ea088/flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/taskmanager/AbstractTaskManagerFileHandler.java#L127)
and [JobClient](https://github.com/apache/flink/blob/951ae9a813cbf8a2db95519853f940277e4ea088/flink-runtime/src/main/java/org/apache/flink/runtime/client/JobClient.java#L445)
to throw `IOException` after `ExceptionUtils.stripExecutionException(e)` here, please correct
me if have to change the behavior.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services

Mime
View raw message