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:
java.io.Closeable,java.io.DataOutput,java.io.Flushable,java.lang.AutoCloseable,DataOutputPlus,Transactional
- Direct Known Subclasses:
ChecksummedSequentialWriter,CompressedSequentialWriter
public class SequentialWriter extends BufferedDataOutputStreamPlus implements Transactional
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 Classes Modifier and Type Class Description protected static classSequentialWriter.BufferedFileWriterMarkClass to hold a mark to the position of the fileprotected classSequentialWriter.TransactionalProxy-
Nested classes/interfaces inherited from interface org.apache.cassandra.utils.concurrent.Transactional
Transactional.AbstractTransactional
-
-
Field Summary
Fields Modifier and Type Field Description protected longbufferOffsetprotected java.nio.channels.FileChannelfchannelprotected longlastFlushOffsetprotected java.lang.RunnablerunPostFlush-
Fields inherited from class org.apache.cassandra.io.util.BufferedDataOutputStreamPlus
buffer
-
Fields inherited from class org.apache.cassandra.io.util.DataOutputStreamPlus
channel
-
-
Constructor Summary
Constructors Constructor Description SequentialWriter(File file)Create heap-based, non-compressed SequenialWriter with default buffer size(64k).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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Throwableabort(java.lang.Throwable accumulate)voidclose()java.lang.Throwablecommit(java.lang.Throwable accumulate)protected longcurrent()protected voiddoFlush(int count)voidfinish()protected voidflushData()Override this method instead of overriding flush()longgetEstimatedOnDiskBytesWritten()longgetLastFlushOffset()longgetOnDiskFilePointer()Returns the current file pointer of the underlying on-disk file.java.lang.StringgetPath()booleanhasPosition()If the implementation supports providing a position, this method returnstrue, otherwisefalse.booleanisOpen()longlength()DataPositionmark()longposition()Returns the current position of the underlying target like a file-pointer or the position withing a buffer.voidprepareToCommit()voidresetAndTruncate(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 voidresetBuffer()voidsetPostFlushListener(java.lang.Runnable runPostFlush)voidskipBytes(int numBytes)voidsync()Synchronize file contents with disk.protected voidsyncDataOnlyInternal()protected voidsyncInternal()voidtruncate(long toSize)protected SequentialWriter.TransactionalProxytxnProxy()intwriteDirectlyToChannel(java.nio.ByteBuffer buf)-
Methods inherited from class org.apache.cassandra.io.util.BufferedDataOutputStreamPlus
flush, order, write, write, write, write, writeBoolean, writeByte, writeBytes, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
-
Methods inherited from class org.apache.cassandra.io.util.DataOutputStreamPlus
newDefaultChannel, retrieveTemporaryBuffer
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.io.util.DataOutputPlus
write, writeUnsignedVInt, writeVInt
-
-
-
-
Constructor Detail
-
SequentialWriter
public SequentialWriter(File file)
Create heap-based, non-compressed SequenialWriter with default buffer size(64k).- Parameters:
file- File to write
-
SequentialWriter
public SequentialWriter(File file, SequentialWriterOption option)
Create SequentialWriter for given file with specific writer option.- Parameters:
file- File to writeoption- Writer option
-
SequentialWriter
public SequentialWriter(File file, SequentialWriterOption option, boolean strictFlushing)
Create SequentialWriter for given file with specific writer option.- Parameters:
file-option-strictFlushing-
-
-
Method Detail
-
skipBytes
public void skipBytes(int numBytes) throws java.io.IOException- Throws:
java.io.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
public void setPostFlushListener(java.lang.Runnable runPostFlush)
-
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
-
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
public java.lang.String getPath()
-
resetBuffer
protected void resetBuffer()
-
current
protected long current()
-
mark
public DataPosition mark()
-
resetAndTruncate
public void resetAndTruncate(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 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
public final java.lang.Throwable commit(java.lang.Throwable accumulate)
- Specified by:
commitin interfaceTransactional
-
abort
public final java.lang.Throwable abort(java.lang.Throwable accumulate)
- Specified by:
abortin interfaceTransactional
-
close
public final void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceTransactional- Overrides:
closein classBufferedDataOutputStreamPlus
-
writeDirectlyToChannel
public int writeDirectlyToChannel(java.nio.ByteBuffer buf) throws java.io.IOException- Throws:
java.io.IOException
-
finish
public final void finish()
-
txnProxy
protected SequentialWriter.TransactionalProxy txnProxy()
-
-