Class CheckpointStateOutputStream

java.lang.Object
java.io.OutputStream
org.apache.flink.core.fs.FSDataOutputStream
org.apache.flink.runtime.state.CheckpointStateOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
Direct Known Subclasses:
DuplicatingCheckpointOutputStream, FileBasedStateOutputStream, FsCheckpointStreamFactory.FsCheckpointStateOutputStream, MemCheckpointStreamFactory.MemoryCheckpointOutputStream

@Internal public abstract class CheckpointStateOutputStream extends org.apache.flink.core.fs.FSDataOutputStream
A dedicated output stream that produces a StreamStateHandle when closed.

Important: When closing this stream after the successful case, you must call closeAndGetHandle() - only that method will actually retain the resource written to. The method has the semantics of "close on success". The close() method is supposed to remove the target resource if called before closeAndGetHandle(), hence having the semantics of "close on failure". That way, simple try-with-resources statements automatically clean up unsuccessful partial state resources in case the writing does not complete.

Note: This is an abstract class and not an interface because OutputStream is an abstract class.

  • Constructor Details

    • CheckpointStateOutputStream

      public CheckpointStateOutputStream()
  • Method Details

    • closeAndGetHandle

      @Nullable public abstract StreamStateHandle closeAndGetHandle() throws IOException
      Closes the stream and gets a state handle that can create an input stream producing the data written to this stream.

      This closing must be called (also when the caller is not interested in the handle) to successfully close the stream and retain the produced resource. In contrast, the close() method removes the target resource when called.

      Returns:
      A state handle that can create an input stream producing the data written to this stream.
      Throws:
      IOException - Thrown, if the stream cannot be closed.
    • close

      public abstract void close() throws IOException
      This method should close the stream, if has not been closed before. If this method actually closes the stream, it should delete/release the resource behind the stream, such as the file that the stream writes to.

      The above implies that this method is intended to be the "unsuccessful close", such as when cancelling the stream writing, or when an exception occurs. Closing the stream for the successful case must go through closeAndGetHandle().

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class org.apache.flink.core.fs.FSDataOutputStream
      Throws:
      IOException - Thrown, if the stream cannot be closed.