Package org.rocksdb

Class AbstractWriteBatch

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractWriteBatch​(long nativeHandle)  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void clear()
      Clear all updates buffered in this batch
      int count()
      Returns the number of updates in the batch.
      void delete​(byte[] key)
      If the database contains a mapping for "key", erase it.
      void delete​(ColumnFamilyHandle columnFamilyHandle, byte[] key)
      If column family contains a mapping for "key", erase it.
      void deleteRange​(byte[] beginKey, byte[] endKey)
      Removes the database entries in the range ["beginKey", "endKey"), i.e., including "beginKey" and excluding "endKey".
      void deleteRange​(ColumnFamilyHandle columnFamilyHandle, byte[] beginKey, byte[] endKey)
      Removes the database entries in the range ["beginKey", "endKey"), i.e., including "beginKey" and excluding "endKey".
      WriteBatch getWriteBatch()
      Get the underlying Write Batch.
      void merge​(byte[] key, byte[] value)
      Merge "value" with the existing value of "key" in the database.
      void merge​(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value)
      Merge "value" with the existing value of "key" in given column family.
      void popSavePoint()
      Pop the most recent save point.
      void put​(byte[] key, byte[] value)
      Store the mapping "key->value" in the database.
      void put​(java.nio.ByteBuffer key, java.nio.ByteBuffer value)
      Store the mapping "key->value" within given column family.
      void put​(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value)
      Store the mapping "key->value" within given column family.
      void put​(ColumnFamilyHandle columnFamilyHandle, java.nio.ByteBuffer key, java.nio.ByteBuffer value)
      Store the mapping "key->value" within given column family.
      void putLogData​(byte[] blob)
      Append a blob of arbitrary size to the records in this batch.
      void remove​(byte[] key)
      Deprecated.
      void remove​(java.nio.ByteBuffer key)
      If column family contains a mapping for "key", erase it.
      void remove​(ColumnFamilyHandle columnFamilyHandle, byte[] key)
      Deprecated.
      void remove​(ColumnFamilyHandle columnFamilyHandle, java.nio.ByteBuffer key)
      If column family contains a mapping for "key", erase it.
      void rollbackToSavePoint()
      Remove all entries in this batch (Put, Merge, Delete, PutLogData) since the most recent call to SetSavePoint() and removes the most recent save point.
      void setMaxBytes​(long maxBytes)
      Set the maximum size of the write batch.
      void setSavePoint()
      Records the state of the batch for future calls to RollbackToSavePoint().
      void singleDelete​(byte[] key)
      Remove the database entry for key.
      void singleDelete​(ColumnFamilyHandle columnFamilyHandle, byte[] key)
      Remove the database entry for key.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractWriteBatch

        protected AbstractWriteBatch​(long nativeHandle)
    • Method Detail

      • count

        public int count()
        Description copied from interface: WriteBatchInterface
        Returns the number of updates in the batch.
        Specified by:
        count in interface WriteBatchInterface
        Returns:
        number of items in WriteBatch
      • put

        public void put​(byte[] key,
                        byte[] value)
                 throws RocksDBException
        Description copied from interface: WriteBatchInterface

        Store the mapping "key->value" in the database.

        Specified by:
        put in interface WriteBatchInterface
        Parameters:
        key - the specified key to be inserted.
        value - the value associated with the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • merge

        public void merge​(byte[] key,
                          byte[] value)
                   throws RocksDBException
        Description copied from interface: WriteBatchInterface

        Merge "value" with the existing value of "key" in the database. "key->merge(existing, value)"

        Specified by:
        merge in interface WriteBatchInterface
        Parameters:
        key - the specified key to be merged.
        value - the value to be merged with the current value for the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • merge

        public void merge​(ColumnFamilyHandle columnFamilyHandle,
                          byte[] key,
                          byte[] value)
                   throws RocksDBException
        Description copied from interface: WriteBatchInterface

        Merge "value" with the existing value of "key" in given column family. "key->merge(existing, value)"

        Specified by:
        merge in interface WriteBatchInterface
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        key - the specified key to be merged.
        value - the value to be merged with the current value for the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • remove

        @Deprecated
        public void remove​(byte[] key)
                    throws RocksDBException
        Deprecated.
        Description copied from interface: WriteBatchInterface

        If the database contains a mapping for "key", erase it. Else do nothing.

        Specified by:
        remove in interface WriteBatchInterface
        Parameters:
        key - Key to delete within database
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • put

        public void put​(java.nio.ByteBuffer key,
                        java.nio.ByteBuffer value)
                 throws RocksDBException
        Description copied from interface: WriteBatchInterface

        Store the mapping "key->value" within given column family.

        Specified by:
        put in interface WriteBatchInterface
        Parameters:
        key - the specified key to be inserted. It is using position and limit. Supports direct buffer only.
        value - the value associated with the specified key. It is using position and limit. Supports direct buffer only.
        Throws:
        RocksDBException
      • put

        public void put​(ColumnFamilyHandle columnFamilyHandle,
                        java.nio.ByteBuffer key,
                        java.nio.ByteBuffer value)
                 throws RocksDBException
        Description copied from interface: WriteBatchInterface

        Store the mapping "key->value" within given column family.

        Specified by:
        put in interface WriteBatchInterface
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        key - the specified key to be inserted. It is using position and limit. Supports direct buffer only.
        value - the value associated with the specified key. It is using position and limit. Supports direct buffer only.
        Throws:
        RocksDBException
      • delete

        public void delete​(byte[] key)
                    throws RocksDBException
        Description copied from interface: WriteBatchInterface

        If the database contains a mapping for "key", erase it. Else do nothing.

        Specified by:
        delete in interface WriteBatchInterface
        Parameters:
        key - Key to delete within database
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • singleDelete

        public void singleDelete​(byte[] key)
                          throws RocksDBException
        Description copied from interface: WriteBatchInterface
        Remove the database entry for key. Requires that the key exists and was not overwritten. It is not an error if the key did not exist in the database. If a key is overwritten (by calling WriteBatchInterface.put(byte[], byte[]) multiple times), then the result of calling SingleDelete() on this key is undefined. SingleDelete() only behaves correctly if there has been only one Put() for this key since the previous call to SingleDelete() for this key. This feature is currently an experimental performance optimization for a very specific workload. It is up to the caller to ensure that SingleDelete is only used for a key that is not deleted using Delete() or written using Merge(). Mixing SingleDelete operations with Deletes and Merges can result in undefined behavior.
        Specified by:
        singleDelete in interface WriteBatchInterface
        Parameters:
        key - Key to delete within database
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • singleDelete

        public void singleDelete​(ColumnFamilyHandle columnFamilyHandle,
                                 byte[] key)
                          throws RocksDBException
        Description copied from interface: WriteBatchInterface
        Remove the database entry for key. Requires that the key exists and was not overwritten. It is not an error if the key did not exist in the database. If a key is overwritten (by calling WriteBatchInterface.put(byte[], byte[]) multiple times), then the result of calling SingleDelete() on this key is undefined. SingleDelete() only behaves correctly if there has been only one Put() for this key since the previous call to SingleDelete() for this key. This feature is currently an experimental performance optimization for a very specific workload. It is up to the caller to ensure that SingleDelete is only used for a key that is not deleted using Delete() or written using Merge(). Mixing SingleDelete operations with Deletes and Merges can result in undefined behavior.
        Specified by:
        singleDelete in interface WriteBatchInterface
        Parameters:
        columnFamilyHandle - The column family to delete the key from
        key - Key to delete within database
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • deleteRange

        public void deleteRange​(byte[] beginKey,
                                byte[] endKey)
                         throws RocksDBException
        Description copied from interface: WriteBatchInterface
        Removes the database entries in the range ["beginKey", "endKey"), i.e., including "beginKey" and excluding "endKey". a non-OK status on error. It is not an error if no keys exist in the range ["beginKey", "endKey"). Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Specified by:
        deleteRange in interface WriteBatchInterface
        Parameters:
        beginKey - First key to delete within database (included)
        endKey - Last key to delete within database (excluded)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • deleteRange

        public void deleteRange​(ColumnFamilyHandle columnFamilyHandle,
                                byte[] beginKey,
                                byte[] endKey)
                         throws RocksDBException
        Description copied from interface: WriteBatchInterface
        Removes the database entries in the range ["beginKey", "endKey"), i.e., including "beginKey" and excluding "endKey". a non-OK status on error. It is not an error if no keys exist in the range ["beginKey", "endKey"). Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Specified by:
        deleteRange in interface WriteBatchInterface
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        beginKey - First key to delete within database (included)
        endKey - Last key to delete within database (excluded)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • remove

        public void remove​(java.nio.ByteBuffer key)
                    throws RocksDBException
        Description copied from interface: WriteBatchInterface

        If column family contains a mapping for "key", erase it. Else do nothing.

        Specified by:
        remove in interface WriteBatchInterface
        Parameters:
        key - Key to delete within database. It is using position and limit. Supports direct buffer only.
        Throws:
        RocksDBException
      • putLogData

        public void putLogData​(byte[] blob)
                        throws RocksDBException
        Description copied from interface: WriteBatchInterface
        Append a blob of arbitrary size to the records in this batch. The blob will be stored in the transaction log but not in any other file. In particular, it will not be persisted to the SST files. When iterating over this WriteBatch, WriteBatch::Handler::LogData will be called with the contents of the blob as it is encountered. Blobs, puts, deletes, and merges will be encountered in the same order in thich they were inserted. The blob will NOT consume sequence number(s) and will NOT increase the count of the batch Example application: add timestamps to the transaction log for use in replication.
        Specified by:
        putLogData in interface WriteBatchInterface
        Parameters:
        blob - binary object to be inserted
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • setSavePoint

        public void setSavePoint()
        Description copied from interface: WriteBatchInterface
        Records the state of the batch for future calls to RollbackToSavePoint(). May be called multiple times to set multiple save points.
        Specified by:
        setSavePoint in interface WriteBatchInterface
      • setMaxBytes

        public void setMaxBytes​(long maxBytes)
        Description copied from interface: WriteBatchInterface
        Set the maximum size of the write batch.
        Specified by:
        setMaxBytes in interface WriteBatchInterface
        Parameters:
        maxBytes - the maximum size in bytes.