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

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

      • getDirectory

        @Nonnull
        public Path getDirectory()
      • 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".
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object