Package org.apache.cassandra.io.util
Class SequentialWriter
java.lang.Object
java.io.OutputStream
org.apache.cassandra.io.util.DataOutputStreamPlus
org.apache.cassandra.io.util.BufferedDataOutputStreamPlus
org.apache.cassandra.io.util.SequentialWriter
- All Implemented Interfaces:
Closeable,DataOutput,Flushable,AutoCloseable,DataOutputPlus,Transactional
- Direct Known Subclasses:
ChecksummedSequentialWriter,CompressedSequentialWriter
Adds buffering, mark, and fsyncing to OutputStream. We always fsync on close; we may also
fsync incrementally if Config.trickle_fsync is enabled.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classClass to hold a mark to the position of the fileprotected classNested classes/interfaces inherited from interface org.apache.cassandra.utils.concurrent.Transactional
Transactional.AbstractTransactional -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longprotected final FileChannelprotected longprotected final SequentialWriterOptionprotected LongConsumerFields inherited from class org.apache.cassandra.io.util.BufferedDataOutputStreamPlus
bufferFields inherited from class org.apache.cassandra.io.util.DataOutputStreamPlus
channel -
Constructor Summary
ConstructorsModifierConstructorDescriptionSequentialWriter(File file) Create heap-based, non-compressed SequenialWriter with default buffer size(64k).protectedSequentialWriter(File file, ByteBuffer buffer, SequentialWriterOption option, boolean strictFlushing) SequentialWriter(File file, SequentialWriterOption option) Create SequentialWriter for given file with specific writer option.SequentialWriter(File file, SequentialWriterOption option, boolean strictFlushing) Create SequentialWriter for given file with specific writer option. -
Method Summary
Modifier and TypeMethodDescriptionfinal ThrowableintReturns how many bytes are left in the page.final voidclose()final Throwableprotected longcurrent()protected voiddoFlush(int count) final voidfinish()protected voidOverride this method instead of overriding flush()longgetFile()longlongReturns the current file pointer of the underlying on-disk file.getPath()booleanIf the implementation supports providing a position, this method returnstrue, otherwisefalse.booleanisOpen()longlength()mark()intReturns the number of bytes that a page can take at maximum.longReturns the next padded position.voidPad this with zeroes until the next page boundary.longposition()Returns the current position of the underlying target like a file-pointer or the position withing a buffer.final voidvoidresetAndTruncate(DataPosition mark) Drops all buffered data that's past the limits of our new file mark + buffer capacity, or syncs and truncates the underlying file to the marked positionprotected voidvoidsetPostFlushListener(LongConsumer runPostFlush) voidskipBytes(long numBytes) voidsync()Synchronize file contents with disk.protected voidprotected voidvoidtruncate(long toSize) protected SequentialWriter.TransactionalProxytxnProxy()intMethods inherited from class org.apache.cassandra.io.util.BufferedDataOutputStreamPlus
allocate, flush, order, write, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeMostSignificantBytes, writeShort, writeUTFMethods inherited from class org.apache.cassandra.io.util.DataOutputStreamPlus
newDefaultChannel, retrieveTemporaryBufferMethods inherited from class java.io.OutputStream
nullOutputStreamMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.cassandra.io.util.DataOutputPlus
write, writeUnsignedVInt, writeUnsignedVInt, writeUnsignedVInt32, writeVInt, writeVInt, writeVInt32
-
Field Details
-
bufferOffset
protected long bufferOffset -
fchannel
-
option
-
lastFlushOffset
protected long lastFlushOffset -
runPostFlush
-
-
Constructor Details
-
SequentialWriter
Create heap-based, non-compressed SequenialWriter with default buffer size(64k).- Parameters:
file- File to write
-
SequentialWriter
Create SequentialWriter for given file with specific writer option.- Parameters:
file- File to writeoption- Writer option
-
SequentialWriter
Create SequentialWriter for given file with specific writer option.- Parameters:
file-option-strictFlushing-
-
SequentialWriter
protected SequentialWriter(File file, ByteBuffer buffer, SequentialWriterOption option, boolean strictFlushing)
-
-
Method Details
-
skipBytes
- Throws:
IOException
-
sync
public void sync()Synchronize file contents with disk. -
syncDataOnlyInternal
protected void syncDataOnlyInternal() -
syncInternal
protected void syncInternal() -
doFlush
protected void doFlush(int count) - Overrides:
doFlushin classBufferedDataOutputStreamPlus
-
setPostFlushListener
-
flushData
protected void flushData()Override this method instead of overriding flush()- Throws:
FSWriteError- on any I/O error.
-
hasPosition
public boolean hasPosition()Description copied from interface:DataOutputPlusIf the implementation supports providing a position, this method returnstrue, otherwisefalse.- Specified by:
hasPositionin interfaceDataOutputPlus
-
position
public long position()Description copied from interface:DataOutputPlusReturns the current position of the underlying target like a file-pointer or the position withing a buffer. Not every implementation may support this functionality. Whether or not this functionality is supported can be checked via theDataOutputPlus.hasPosition().- Specified by:
positionin interfaceDataOutputPlus
-
maxBytesInPage
public int maxBytesInPage()Description copied from interface:DataOutputPlusReturns the number of bytes that a page can take at maximum.- Specified by:
maxBytesInPagein interfaceDataOutputPlus
-
padToPageBoundary
Description copied from interface:DataOutputPlusPad this with zeroes until the next page boundary. If the destination position is already at a page boundary, do not do anything.- Specified by:
padToPageBoundaryin interfaceDataOutputPlus- Throws:
IOException
-
bytesLeftInPage
public int bytesLeftInPage()Description copied from interface:DataOutputPlusReturns how many bytes are left in the page.- Specified by:
bytesLeftInPagein interfaceDataOutputPlus
-
paddedPosition
public long paddedPosition()Description copied from interface:DataOutputPlusReturns the next padded position. This is either the current position (if already padded), or the start of next page.- Specified by:
paddedPositionin interfaceDataOutputPlus
-
getOnDiskFilePointer
public long getOnDiskFilePointer()Returns the current file pointer of the underlying on-disk file. Note that since write works by buffering data, the value of this will increase by buffer size and not every write to the writer will modify this value. Furthermore, for compressed files, this value refers to compressed data, while the writer getFilePointer() refers to uncompressedFile- Returns:
- the current file pointer
-
getEstimatedOnDiskBytesWritten
public long getEstimatedOnDiskBytesWritten() -
length
public long length() -
getPath
-
getFile
-
resetBuffer
protected void resetBuffer() -
current
protected long current() -
mark
-
resetAndTruncate
Drops all buffered data that's past the limits of our new file mark + buffer capacity, or syncs and truncates the underlying file to the marked position -
getLastFlushOffset
public long getLastFlushOffset() -
truncate
public void truncate(long toSize) -
isOpen
public boolean isOpen() -
prepareToCommit
public final void prepareToCommit()- Specified by:
prepareToCommitin interfaceTransactional
-
commit
- Specified by:
commitin interfaceTransactional
-
abort
- Specified by:
abortin interfaceTransactional
-
close
public final void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceTransactional- Overrides:
closein classBufferedDataOutputStreamPlus
-
writeDirectlyToChannel
- Throws:
IOException
-
finish
public final void finish() -
txnProxy
-