Class FileStateHandle

java.lang.Object
org.apache.flink.runtime.state.filesystem.FileStateHandle
All Implemented Interfaces:
Serializable, StateObject, StreamStateHandle
Direct Known Subclasses:
RelativeFileStateHandle

public class FileStateHandle extends Object implements StreamStateHandle
StreamStateHandle for state that was written to a file stream. The written data is identified by the file path. The state can be read again by calling openInputStream().
See Also:
  • Constructor Details

    • FileStateHandle

      public FileStateHandle(org.apache.flink.core.fs.Path filePath, long stateSize)
      Creates a new file state for the given file path.
      Parameters:
      filePath - The path to the file that stores the state.
  • Method Details

    • maybeGetPath

      public Optional<org.apache.flink.core.fs.Path> maybeGetPath()
      Specified by:
      maybeGetPath in interface StreamStateHandle
      Returns:
      Path to an underlying file represented by this StreamStateHandle or Optional.empty() if there is no such file.
    • getFilePath

      public org.apache.flink.core.fs.Path getFilePath()
      Gets the path where this handle's state is stored.
      Returns:
      The path where this handle's state is stored.
    • openInputStream

      public org.apache.flink.core.fs.FSDataInputStream openInputStream() throws IOException
      Description copied from interface: StreamStateHandle
      Returns an FSDataInputStream that can be used to read back the data that was previously written to the stream.
      Specified by:
      openInputStream in interface StreamStateHandle
      Throws:
      IOException
    • asBytesIfInMemory

      public Optional<byte[]> asBytesIfInMemory()
      Specified by:
      asBytesIfInMemory in interface StreamStateHandle
      Returns:
      Content of this handle as bytes array if it is already in memory.
    • getStreamStateHandleID

      public PhysicalStateHandleID getStreamStateHandleID()
      Specified by:
      getStreamStateHandleID in interface StreamStateHandle
      Returns:
      a unique identifier of this handle.
    • discardState

      public void discardState() throws Exception
      Discard the state by deleting the file that stores the state. If the parent directory of the state is empty after deleting the state file, it is also deleted.
      Specified by:
      discardState in interface StateObject
      Throws:
      Exception - Thrown, if the file deletion (not the directory deletion) fails.
    • getStateSize

      public long getStateSize()
      Returns the file size in bytes.
      Specified by:
      getStateSize in interface StateObject
      Returns:
      The file size in bytes.
    • collectSizeStats

      public void collectSizeStats(StateObject.StateObjectSizeStatsCollector collector)
      Description copied from interface: StateObject
      Collects statistics about state size and location from the state object.
      Specified by:
      collectSizeStats in interface StateObject
      Parameters:
      collector - the statistics collector.
    • 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