flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uce <...@git.apache.org>
Subject [GitHub] flink pull request #2194: [FLINK-4067] [runtime] Add savepoint headers
Date Wed, 06 Jul 2016 12:53:56 GMT
Github user uce commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2194#discussion_r69723923
  
    --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/savepoint/FsSavepointStore.java
---
    @@ -0,0 +1,225 @@
    +/*
    + * 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.checkpoint.savepoint;
    +
    +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.util.FileUtils;
    +import org.apache.flink.util.Preconditions;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.io.DataInputStream;
    +import java.io.DataOutputStream;
    +import java.io.IOException;
    +
    +import static org.apache.flink.util.Preconditions.checkNotNull;
    +
    +/**
    + * A file system based {@link SavepointStore}.
    + *
    + * <p>Stored savepoints have the following format:
    + * <pre>
    + * MagicNumber SavepointVersion Savepoint
    + *   - MagicNumber => int
    + *   - SavepointVersion => int (returned by Savepoint#getVersion())
    + *   - Savepoint => bytes (serialized via version-specific SavepointSerializer)
    + * </pre>
    + */
    +public class FsSavepointStore implements SavepointStore {
    +
    +	private static final Logger LOG = LoggerFactory.getLogger(FsSavepointStore.class);
    +
    +	/** Magic number for sanity checks against stored savepoints. */
    +	int MAGIC_NUMBER = 0x4960672d;
    +
    +	/** Root path for savepoints. */
    +	private final Path rootPath;
    +
    +	/** Prefix for savepoint files. */
    +	private final String prefix;
    +
    +	/** File system to use for file access. */
    +	private final FileSystem fileSystem;
    +
    +	/**
    +	 * Creates a new file system based {@link SavepointStore}.
    +	 *
    +	 * @param rootPath Root path for savepoints
    +	 * @param prefix   Prefix for savepoint files
    +	 * @throws IOException On failure to access root path
    +	 */
    +	FsSavepointStore(String rootPath, String prefix) throws IOException {
    +		this.rootPath = new Path(checkNotNull(rootPath, "Root path"));
    +		this.prefix = checkNotNull(prefix, "Prefix");
    +
    +		this.fileSystem = FileSystem.get(this.rootPath.toUri());
    +	}
    +
    +	@Override
    +	public <T extends Savepoint> String storeSavepoint(T savepoint) throws IOException
{
    +		Preconditions.checkNotNull(savepoint, "Savepoint");
    +
    +		Exception latestException = null;
    +		Path path = null;
    +		FSDataOutputStream fdos = null;
    +
    +		// Try to create a FS output stream
    +		for (int attempt = 0; attempt < 10; attempt++) {
    --- End diff --
    
    Since it can be also a distributed FS like HDFS, it can fail for various reasons. The
code here is moved from what we currently have in master (including number of retries etc.).
I think initially from `FileSystemStateStorageHelper` to `FileSystemStateStore` to here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message