Class SnapshotDirectory

java.lang.Object
org.apache.flink.runtime.state.SnapshotDirectory

public abstract class SnapshotDirectory extends Object
This class represents a directory that is the target for a state snapshot. This class provides some method that simplify resource management when dealing with such directories, e.g. it can produce a DirectoryStateHandle when the snapshot is completed and disposal considers whether or not a snapshot was already completed. For a completed snapshot, the ownership for cleanup is transferred to the created directory state handle. For incomplete snapshots, calling cleanup() will delete the underlying directory resource.
  • Field Details

    • directory

      @Nonnull protected final Path directory
      This path describes the underlying directory for the snapshot.
    • state

      @Nonnull protected AtomicReference<org.apache.flink.runtime.state.SnapshotDirectory.State> state
      This reference tracks the lifecycle state of the snapshot directory.
  • Method Details

    • getDirectory

      @Nonnull public Path getDirectory()
    • mkdirs

      public boolean mkdirs() throws IOException
      Throws:
      IOException
    • exists

      public boolean exists() throws IOException
      Throws:
      IOException
    • listDirectory

      public Path[] listDirectory() throws IOException
      List the files in the snapshot directory.
      Returns:
      the files in the snapshot directory.
      Throws:
      IOException - if there is a problem creating the file statuses.
    • cleanup

      public boolean cleanup() throws IOException
      Calling this method will attempt delete the underlying snapshot directory recursively, if the state is "ongoing". In this case, the state will be set to "deleted" as a result of this call.
      Returns:
      true if delete is successful, false otherwise.
      Throws:
      IOException - if an exception happens during the delete.
    • isSnapshotCompleted

      public boolean isSnapshotCompleted()
      Returns true if the snapshot is marked as completed.
    • completeSnapshotAndGetHandle

      @Nullable public abstract DirectoryStateHandle completeSnapshotAndGetHandle() throws IOException
      Calling this method completes the snapshot for this snapshot directory, if possible, and creates a corresponding DirectoryStateHandle that points to the snapshot directory. Calling this method can change the lifecycle state from ONGOING to COMPLETED if the directory should no longer deleted in cleanup(). This method can return Can return true if the directory is temporary and should therefore not be referenced in a handle.
      Returns:
      A directory state handle that points to the snapshot directory. Can return true if the directory is temporary and should therefore not be referenced in a handle.
      Throws:
      IOException - if the state of this snapshot directory object is different from "ongoing".
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • temporary

      public static SnapshotDirectory temporary(@Nonnull File directory) throws IOException
      Creates a local temporary snapshot directory for the given path. This will always return "null" as result of completeSnapshotAndGetHandle() and always attempt to delete the underlying directory in cleanup().
      Throws:
      IOException
    • permanent

      public static SnapshotDirectory permanent(@Nonnull Path directory) throws IOException
      Creates a permanent snapshot directory for the given path, which will not delete the underlying directory in cleanup() after completeSnapshotAndGetHandle() was called.
      Throws:
      IOException