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 2019/06/24 12:04:20 UTC

[GitHub] [flink] sjwiesman commented on a change in pull request #8615: [FLINK-12729][state-processor-api] Add state reader for consuming non-partitioned operator state

sjwiesman commented on a change in pull request #8615:  [FLINK-12729][state-processor-api] Add state reader for consuming non-partitioned operator state
URL: https://github.com/apache/flink/pull/8615#discussion_r296688271
 
 

 ##########
 File path: flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/runtime/SavepointLoader.java
 ##########
 @@ -0,0 +1,54 @@
+/*
+ * 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.state.api.runtime;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.runtime.checkpoint.Checkpoints;
+import org.apache.flink.runtime.checkpoint.savepoint.Savepoint;
+import org.apache.flink.runtime.state.CompletedCheckpointStorageLocation;
+import org.apache.flink.runtime.state.filesystem.AbstractFsCheckpointStorage;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+
+/**
+ * Utility class for loading {@link Savepoint} metadata.
+ */
+@Internal
+public final class SavepointLoader {
+	private SavepointLoader() {}
+
+	/**
+	 * Takes the given string (representing a pointer to a checkpoint) and resolves it to a file
+	 * status for the checkpoint's metadata file.
+	 *
+	 * @param savepointPath The path to an external savepoint.
+	 * @return A state handle to savepoint's metadata.
+	 * @throws IOException Thrown, if the path cannot be resolved, the file system not accessed, or
+	 *     the path points to a location that does not seem to be a savepoint.
+	 */
+	public static Savepoint loadSavepoint(String savepointPath) throws IOException {
+		CompletedCheckpointStorageLocation location = AbstractFsCheckpointStorage
+			.resolveCheckpointPointer(savepointPath);
+
+		try (DataInputStream stream = new DataInputStream(location.getMetadataHandle().openInputStream())) {
+			return Checkpoints.loadCheckpointMetadata(stream, NullClassLoader.INSTANCE);
 
 Review comment:
   There was one place where I couldn't get access to the user classloader but it wasn't being used so I decided to go this route. However, if we do the reading on the client the current thread class loader should be the user class loader so that makes it easier. 

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


With regards,
Apache Git Services