Package org.rocksdb

Class WriteBatch

All Implemented Interfaces:
AutoCloseable, WriteBatchInterface

public class WriteBatch extends AbstractWriteBatch
WriteBatch holds a collection of updates to apply atomically to a DB.

The updates are applied in the order in which they are added to the WriteBatch. For example, the value of "key" will be "v3" after the following batch is written:

batch.put("key", "v1"); batch.remove("key"); batch.put("key", "v2"); batch.put("key", "v3");

Multiple threads can invoke const methods on a WriteBatch without external synchronization, but if any of the threads may call a non-const method, all threads accessing the same WriteBatch must use external synchronization.

  • Constructor Details

    • WriteBatch

      public WriteBatch()
      Constructs a WriteBatch instance.
    • WriteBatch

      public WriteBatch(int reserved_bytes)
      Constructs a WriteBatch instance with a given size.
      Parameters:
      reserved_bytes - reserved size for WriteBatch
    • WriteBatch

      public WriteBatch(byte[] serialized)
      Constructs a WriteBatch instance from a serialized representation as returned by data().
      Parameters:
      serialized - the serialized representation.
  • Method Details

    • iterate

      public void iterate(WriteBatch.Handler handler) throws RocksDBException
      Support for iterating over the contents of a batch.
      Parameters:
      handler - A handler that is called back for each update present in the batch
      Throws:
      RocksDBException - If we cannot iterate over the batch
    • data

      public byte[] data() throws RocksDBException
      Retrieve the serialized version of this batch.
      Returns:
      the serialized representation of this write batch.
      Throws:
      RocksDBException - if an error occurs whilst retrieving the serialized batch data.
    • getDataSize

      public long getDataSize()
      Retrieve data size of the batch.
      Returns:
      the serialized data size of the batch.
    • hasPut

      public boolean hasPut()
      Returns true if Put will be called during Iterate.
      Returns:
      true if Put will be called during Iterate.
    • hasDelete

      public boolean hasDelete()
      Returns true if Delete will be called during Iterate.
      Returns:
      true if Delete will be called during Iterate.
    • hasSingleDelete

      public boolean hasSingleDelete()
      Returns true if SingleDelete will be called during Iterate.
      Returns:
      true if SingleDelete will be called during Iterate.
    • hasDeleteRange

      public boolean hasDeleteRange()
      Returns true if DeleteRange will be called during Iterate.
      Returns:
      true if DeleteRange will be called during Iterate.
    • hasMerge

      public boolean hasMerge()
      Returns true if Merge will be called during Iterate.
      Returns:
      true if Merge will be called during Iterate.
    • hasBeginPrepare

      public boolean hasBeginPrepare()
      Returns true if MarkBeginPrepare will be called during Iterate.
      Returns:
      true if MarkBeginPrepare will be called during Iterate.
    • hasEndPrepare

      public boolean hasEndPrepare()
      Returns true if MarkEndPrepare will be called during Iterate.
      Returns:
      true if MarkEndPrepare will be called during Iterate.
    • hasCommit

      public boolean hasCommit()
      Returns true if MarkCommit will be called during Iterate.
      Returns:
      true if MarkCommit will be called during Iterate.
    • hasRollback

      public boolean hasRollback()
      Returns true if MarkRollback will be called during Iterate.
      Returns:
      true if MarkRollback will be called during Iterate.
    • getWriteBatch

      public WriteBatch getWriteBatch()
      Description copied from interface: WriteBatchInterface
      Get the underlying Write Batch.
      Specified by:
      getWriteBatch in interface WriteBatchInterface
      Overrides:
      getWriteBatch in class AbstractWriteBatch
      Returns:
      the underlying WriteBatch.
    • markWalTerminationPoint

      public void markWalTerminationPoint()
      Marks this point in the WriteBatch as the last record to be inserted into the WAL, provided the WAL is enabled.
    • getWalTerminationPoint

      public WriteBatch.SavePoint getWalTerminationPoint()
      Gets the WAL termination point.

      See markWalTerminationPoint()

      Returns:
      the WAL termination point
    • disposeInternal

      protected final void disposeInternal(long handle)
      Specified by:
      disposeInternal in class RocksObject