SequentialWriter (apache-cassandra API)
Date: 2018-02-12

org.apache.cassandra.io.util

## Class SequentialWriter

- java.lang.Object
- - java.io.OutputStream
  - - org.apache.cassandra.io.util.SequentialWriter

- All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, java.nio.channels.Channel, java.nio.channels.WritableByteChannel, Transactional
  Direct Known Subclasses:
    ChecksummedSequentialWriter, CompressedSequentialWriter

      public class SequentialWriter
      extends java.io.OutputStream
      implements java.nio.channels.WritableByteChannel, 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 and Description
    --- | ---
    `protected static class` | `SequentialWriter.BufferedFileWriterMark` Class to hold a mark to the position of the file
    `protected class` | `SequentialWriter.TransactionalProxy`

    - ### Nested classes/interfaces inherited from interface org.apache.cassandra.utils.concurrent.Transactional

      `Transactional.AbstractTransactional`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.nio.ByteBuffer` | `buffer`
    `protected long` | `bufferOffset`
    `protected java.nio.channels.FileChannel` | `channel`
    `protected Descriptor` | `descriptor`
    `protected boolean` | `isDirty`
    `protected long` | `lastFlushOffset`
    `protected java.lang.Runnable` | `runPostFlush`
    `DataOutputPlus` | `stream`
    `protected boolean` | `syncNeeded`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SequentialWriter(java.io.File file, int bufferSize, BufferType bufferType)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.Throwable` | `abort(java.lang.Throwable accumulate)`
    `void` | `close()`
    `java.lang.Throwable` | `commit(java.lang.Throwable accumulate)`
    `protected long` | `current()`
    `void` | `finish()`
    `SequentialWriter` | `finishOnClose()`
    `void` | `flush()` If buffer is dirty, flush it's contents to the operating system.
    `protected void` | `flushData()` Override this method instead of overriding flush()
    `protected void` | `flushInternal()`
    `long` | `getFilePointer()`
    `long` | `getLastFlushOffset()`
    `long` | `getOnDiskFilePointer()` Returns the current file pointer of the underlying on-disk file.
    `java.lang.String` | `getPath()`
    `boolean` | `isOpen()`
    `long` | `length()`
    `FileMark` | `mark()`
    `static SequentialWriter` | `open(java.io.File file)` Open a heap-based, non-compressed SequentialWriter
    `static ChecksummedSequentialWriter` | `open(java.io.File file, java.io.File crcPath)`
    `static CompressedSequentialWriter` | `open(java.lang.String dataFilePath, java.lang.String offsetsPath, CompressionParameters parameters, MetadataCollector sstableMetadataCollector)`
    `void` | `prepareToCommit()`
    `protected void` | `reBuffer()`
    `void` | `releaseFileHandle()`
    `void` | `resetAndTruncate(FileMark 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
    `protected void` | `resetBuffer()`
    `SequentialWriter` | `setDescriptor(Descriptor descriptor)`
    `void` | `setPostFlushListener(java.lang.Runnable runPostFlush)`
    `void` | `sync()` Synchronize file contents with disk.
    `protected void` | `syncDataOnlyInternal()`
    `protected void` | `syncInternal()`
    `void` | `truncate(long toSize)`
    `protected SequentialWriter.TransactionalProxy` | `txnProxy()`
    `void` | `write(byte[] buffer)`
    `void` | `write(byte[] data, int offset, int length)`
    `int` | `write(java.nio.ByteBuffer src)`
    `void` | `write(int value)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### isDirty

          protected boolean isDirty

    - #### syncNeeded

          protected boolean syncNeeded

    - #### buffer

          protected java.nio.ByteBuffer buffer

    - #### bufferOffset

          protected long bufferOffset

    - #### channel

          protected final java.nio.channels.FileChannel channel

    - #### stream

          public final DataOutputPlus stream

    - #### lastFlushOffset

          protected long lastFlushOffset

    - #### runPostFlush

          protected java.lang.Runnable runPostFlush

    - #### descriptor

          protected Descriptor descriptor

  - ### Constructor Detail

    - #### SequentialWriter

          public SequentialWriter(java.io.File file,
                                  int bufferSize,
                                  BufferType bufferType)

  - ### Method Detail

    - #### open

          public static SequentialWriter open(java.io.File file)

      Open a heap-based, non-compressed SequentialWriter

    - #### open

          public static ChecksummedSequentialWriter open(java.io.File file,
                                                         java.io.File crcPath)

    - #### open

          public static CompressedSequentialWriter open(java.lang.String dataFilePath,
                                                        java.lang.String offsetsPath,
                                                        CompressionParameters parameters,
                                                        MetadataCollector sstableMetadataCollector)

    - #### finishOnClose

          public SequentialWriter finishOnClose()

    - #### write

          public void write(int value)
                     throws java.nio.channels.ClosedChannelException

      Specified by:
        `write` in class `java.io.OutputStream`
      Throws:
        `java.nio.channels.ClosedChannelException`

    - #### write

          public void write(byte[] buffer)
                     throws java.io.IOException

      Overrides:
        `write` in class `java.io.OutputStream`
      Throws:
        `java.io.IOException`

    - #### write

          public void write(byte[] data,
                            int offset,
                            int length)
                     throws java.io.IOException

      Overrides:
        `write` in class `java.io.OutputStream`
      Throws:
        `java.io.IOException`

    - #### write

          public int write(java.nio.ByteBuffer src)
                    throws java.io.IOException

      Specified by:
        `write` in interface `java.nio.channels.WritableByteChannel`
      Throws:
        `java.io.IOException`

    - #### sync

          public void sync()

      Synchronize file contents with disk.

    - #### syncDataOnlyInternal

          protected void syncDataOnlyInternal()

    - #### syncInternal

          protected void syncInternal()

    - #### flush

          public void flush()

      If buffer is dirty, flush it's contents to the operating system. Does not imply fsync(). Currently, for implementation reasons, this also invalidates the buffer.
      Specified by:
        `flush` in interface `java.io.Flushable`
      Overrides:
        `flush` in class `java.io.OutputStream`

    - #### flushInternal

          protected void flushInternal()

    - #### 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.

    - #### getFilePointer

          public long getFilePointer()

    - #### 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

    - #### length

          public long length()

    - #### getPath

          public java.lang.String getPath()

    - #### reBuffer

          protected void reBuffer()

    - #### resetBuffer

          protected void resetBuffer()

    - #### current

          protected long current()

    - #### mark

          public FileMark mark()

    - #### resetAndTruncate

          public void resetAndTruncate(FileMark 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()

      Specified by:
        `isOpen` in interface `java.nio.channels.Channel`

    - #### setDescriptor

          public SequentialWriter setDescriptor(Descriptor descriptor)

    - #### prepareToCommit

          public final void prepareToCommit()

      Specified by:
        `prepareToCommit` in interface `Transactional`

    - #### commit

          public final java.lang.Throwable commit(java.lang.Throwable accumulate)

      Specified by:
        `commit` in interface `Transactional`

    - #### abort

          public final java.lang.Throwable abort(java.lang.Throwable accumulate)

      Specified by:
        `abort` in interface `Transactional`

    - #### close

          public final void close()

      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Specified by:
        `close` in interface `java.nio.channels.Channel`
      Overrides:
        `close` in class `java.io.OutputStream`

    - #### finish

          public final void finish()

    - #### txnProxy

          protected SequentialWriter.TransactionalProxy txnProxy()

    - #### releaseFileHandle

          public void releaseFileHandle()

Copyright © 2018 The Apache Software Foundation