Package org.apache.flink.runtime.state
Class DuplicatingCheckpointOutputStream
java.lang.Object
java.io.OutputStream
org.apache.flink.core.fs.FSDataOutputStream
org.apache.flink.runtime.state.CheckpointStateOutputStream
org.apache.flink.runtime.state.DuplicatingCheckpointOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
A CheckpointStateOutputStream that wraps a primary and a secondary CheckpointStateOutputStream
and duplicates all writes into both streams. This stream applies buffering to reduce the amount
of dual-method calling. Furthermore, exceptions that happen in interactions with the secondary
stream are not exposed, until the user calls
closeAndGetSecondaryHandle(). In contrast
to that, exceptions from interactions with the primary stream are immediately returned to the
user. This class is used to write state for local recovery as a local (secondary) copy of the
(primary) state snapshot that is written to a (slower but highly-available) remote filesystem.-
Constructor Summary
ConstructorsConstructorDescriptionDuplicatingCheckpointOutputStream(CheckpointStateOutputStream primaryOutputStream, CheckpointStateOutputStream secondaryOutputStream) DuplicatingCheckpointOutputStream(CheckpointStateOutputStream primaryOutputStream, CheckpointStateOutputStream secondaryOutputStream, int bufferSize) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()This method should close the stream, if has not been closed before.Closes the stream and gets a state handle that can create an input stream producing the data written to this stream.Returns the state handle from theprimaryOutputStream.Returns the state handle from thesecondaryOutputStream.voidflush()longgetPos()voidsync()voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int b) Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
DuplicatingCheckpointOutputStream
public DuplicatingCheckpointOutputStream(CheckpointStateOutputStream primaryOutputStream, CheckpointStateOutputStream secondaryOutputStream) throws IOException - Throws:
IOException
-
DuplicatingCheckpointOutputStream
public DuplicatingCheckpointOutputStream(CheckpointStateOutputStream primaryOutputStream, CheckpointStateOutputStream secondaryOutputStream, int bufferSize) throws IOException - Throws:
IOException
-
-
Method Details
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
getPos
- Specified by:
getPosin classorg.apache.flink.core.fs.FSDataOutputStream- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Specified by:
flushin classorg.apache.flink.core.fs.FSDataOutputStream- Throws:
IOException
-
sync
- Specified by:
syncin classorg.apache.flink.core.fs.FSDataOutputStream- Throws:
IOException
-
close
Description copied from class:CheckpointStateOutputStreamThis 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
CheckpointStateOutputStream.closeAndGetHandle().- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classCheckpointStateOutputStream- Throws:
IOException- Thrown, if the stream cannot be closed.
-
closeAndGetHandle
Description copied from class:CheckpointStateOutputStreamCloses 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
CheckpointStateOutputStream.close()method removes the target resource when called.- Specified by:
closeAndGetHandlein classCheckpointStateOutputStream- 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.
-
closeAndGetPrimaryHandle
Returns the state handle from theprimaryOutputStream.- Throws:
IOException
-
closeAndGetSecondaryHandle
Returns the state handle from thesecondaryOutputStream. Also reports suppressed exceptions from earlier interactions with that stream.- Throws:
IOException
-
getSecondaryStreamException
-