Package org.rocksdb
Class Transaction
- java.lang.Object
-
- org.rocksdb.AbstractNativeReference
-
- org.rocksdb.AbstractImmutableNativeReference
-
- org.rocksdb.RocksObject
-
- org.rocksdb.Transaction
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class Transaction extends RocksObject
Provides BEGIN/COMMIT/ROLLBACK transactions. To use transactions, you must first create either anOptimisticTransactionDBor aTransactionDBTo create a transaction, useOptimisticTransactionDB.beginTransaction(org.rocksdb.WriteOptions)orTransactionDB.beginTransaction(org.rocksdb.WriteOptions)It is up to the caller to synchronize access to this object. See samples/src/main/java/OptimisticTransactionSample.java and samples/src/main/java/TransactionSample.java for some simple examples.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTransaction.TransactionStatestatic classTransaction.WaitingTransactions
-
Field Summary
-
Fields inherited from class org.rocksdb.RocksObject
nativeHandle_
-
Fields inherited from class org.rocksdb.AbstractImmutableNativeReference
owningHandle_
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearSnapshot()Clears the current snapshot (i.e.voidcommit()Write all batched keys to the db atomically.voiddelete(byte[] key)Similar toRocksDB.delete(byte[]), but will also perform conflict checking on the keys be written.voiddelete(byte[][] keyParts)Similar todelete(byte[])but allows you to specify key the in several parts that will be concatenated together.voiddelete(ColumnFamilyHandle columnFamilyHandle, byte[] key)Similar todelete(ColumnFamilyHandle, byte[], boolean)but withassumeTracked = false.voiddelete(ColumnFamilyHandle columnFamilyHandle, byte[][] keyParts)Similar todelete(ColumnFamilyHandle, byte[][], boolean)but withassumeTracked = false.voiddelete(ColumnFamilyHandle columnFamilyHandle, byte[][] keyParts, boolean assumeTracked)Similar todelete(ColumnFamilyHandle, byte[])but allows you to specify the key in several parts that will be concatenated together.voiddelete(ColumnFamilyHandle columnFamilyHandle, byte[] key, boolean assumeTracked)Similar toRocksDB.delete(ColumnFamilyHandle, byte[]), but will also perform conflict checking on the keys be written.voiddeleteUntracked(byte[] key)Similar toRocksDB.delete(byte[]), but operates on the transactions write batch.voiddeleteUntracked(byte[][] keyParts)Similar todeleteUntracked(byte[])but allows you to specify the key in several parts that will be concatenated together.voiddeleteUntracked(ColumnFamilyHandle columnFamilyHandle, byte[] key)Similar toRocksDB.delete(ColumnFamilyHandle, byte[]), but operates on the transactions write batch.voiddeleteUntracked(ColumnFamilyHandle columnFamilyHandle, byte[][] keyParts)Similar todeleteUntracked(ColumnFamilyHandle, byte[])but allows you to specify the key in several parts that will be concatenated together.voiddisableIndexing()By default, all put/merge/delete operations will be indexed in the transaction so that get/getForUpdate/getIterator can search for these keys.protected voiddisposeInternal(long handle)voidenableIndexing()Re-enables indexing after a previous call todisableIndexing()byte[]get(ColumnFamilyHandle columnFamilyHandle, ReadOptions readOptions, byte[] key)This function is similar toRocksDB.get(ColumnFamilyHandle, ReadOptions, byte[])except it will also read pending changes in this transaction.byte[]get(ReadOptions readOptions, byte[] key)This function is similar toRocksDB.get(ReadOptions, byte[])except it will also read pending changes in this transaction.WriteBatchgetCommitTimeWriteBatch()Get the Commit time Write Batch.longgetElapsedTime()Returns the elapsed time in milliseconds since this Transaction began.byte[]getForUpdate(ReadOptions readOptions, byte[] key, boolean exclusive)Read this key and ensure that this transaction will only be able to be committed if this key is not written outside this transaction after it has first been read (or after the snapshot if a snapshot is set in this transaction).byte[]getForUpdate(ReadOptions readOptions, ColumnFamilyHandle columnFamilyHandle, byte[] key, boolean exclusive)Same asgetForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean, boolean)with doValidate=true.byte[]getForUpdate(ReadOptions readOptions, ColumnFamilyHandle columnFamilyHandle, byte[] key, boolean exclusive, boolean doValidate)Read this key and ensure that this transaction will only be able to be committed if this key is not written outside this transaction after it has first been read (or after the snapshot if a snapshot is set in this transaction).longgetId()The globally unique id with which the transaction is identified.longgetID()Get the ID of the transaction.RocksIteratorgetIterator(ReadOptions readOptions)Returns an iterator that will iterate on all keys in the default column family including both keys in the DB and uncommitted keys in this transaction.RocksIteratorgetIterator(ReadOptions readOptions, ColumnFamilyHandle columnFamilyHandle)Returns an iterator that will iterate on all keys in the column family specified bycolumnFamilyHandleincluding both keys in the DB and uncommitted keys in this transaction.longgetLogNumber()Get the log number.java.lang.StringgetName()Get the name of the transaction.longgetNumDeletes()Returns the number of deletes that have been applied to this transaction so far.longgetNumKeys()Returns the number of distinct Keys being tracked by this transaction.longgetNumMerges()Returns the number of merges that have been applied to this transaction so far.longgetNumPuts()Returns the number of puts that have been applied to this transaction so far.SnapshotgetSnapshot()Returns the Snapshot created by the last call tosetSnapshot().Transaction.TransactionStategetState()Get the execution status of the transaction.Transaction.WaitingTransactionsgetWaitingTxns()Get the list of waiting transactions.WriteBatchWithIndexgetWriteBatch()Fetch the underlying write batch that contains all pending changes to be committed.WriteOptionsgetWriteOptions()Return the WriteOptions that will be used duringcommit().booleanisDeadlockDetect()Determine if a deadlock has been detected.voidmerge(byte[] key, byte[] value)Similar toRocksDB.merge(byte[], byte[]), but will also perform conflict checking on the keys be written.voidmerge(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value)Similar tomerge(ColumnFamilyHandle, byte[], byte[], boolean)but withassumeTracked = false.voidmerge(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value, boolean assumeTracked)Similar toRocksDB.merge(ColumnFamilyHandle, byte[], byte[]), but will also perform conflict checking on the keys be written.voidmergeUntracked(byte[] key, byte[] value)Similar toRocksDB.merge(byte[], byte[]), but operates on the transactions write batch.voidmergeUntracked(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value)Similar toRocksDB.merge(ColumnFamilyHandle, byte[], byte[]), but operates on the transactions write batch.byte[][]multiGet(ReadOptions readOptions, byte[][] keys)This function is similar toRocksDB.multiGet(ReadOptions, List)except it will also read pending changes in this transaction.byte[][]multiGet(ReadOptions readOptions, java.util.List<ColumnFamilyHandle> columnFamilyHandles, byte[][] keys)This function is similar toRocksDB.multiGet(ReadOptions, List, List)except it will also read pending changes in this transaction.byte[][]multiGetForUpdate(ReadOptions readOptions, byte[][] keys)A multi-key version ofgetForUpdate(ReadOptions, byte[], boolean).byte[][]multiGetForUpdate(ReadOptions readOptions, java.util.List<ColumnFamilyHandle> columnFamilyHandles, byte[][] keys)A multi-key version ofgetForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean).voidput(byte[][] keyParts, byte[][] valueParts)Similar toput(byte[], byte[])but allows you to specify the key and value in several parts that will be concatenated togethervoidput(byte[] key, byte[] value)Similar toRocksDB.put(byte[], byte[]), but will also perform conflict checking on the keys be written.voidput(ColumnFamilyHandle columnFamilyHandle, byte[][] keyParts, byte[][] valueParts)Similar toput(ColumnFamilyHandle, byte[][], byte[][], boolean)but with withassumeTracked = false.voidput(ColumnFamilyHandle columnFamilyHandle, byte[][] keyParts, byte[][] valueParts, boolean assumeTracked)Similar toput(ColumnFamilyHandle, byte[], byte[])but allows you to specify the key and value in several parts that will be concatenated together.voidput(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value)Similar toput(ColumnFamilyHandle, byte[], byte[], boolean)but withassumeTracked = false.voidput(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value, boolean assumeTracked)Similar toRocksDB.put(ColumnFamilyHandle, byte[], byte[]), but will also perform conflict checking on the keys be written.voidputLogData(byte[] blob)Similar toAbstractWriteBatch.putLogData(byte[])voidputUntracked(byte[][] keyParts, byte[][] valueParts)Similar toputUntracked(byte[], byte[])but allows you to specify the key and value in several parts that will be concatenated together.voidputUntracked(byte[] key, byte[] value)Similar toRocksDB.put(byte[], byte[]), but operates on the transactions write batch.voidputUntracked(ColumnFamilyHandle columnFamilyHandle, byte[][] keyParts, byte[][] valueParts)Similar toputUntracked(ColumnFamilyHandle, byte[], byte[])but allows you to specify the key and value in several parts that will be concatenated together.voidputUntracked(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value)Similar toRocksDB.put(ColumnFamilyHandle, byte[], byte[]), but operates on the transactions write batch.voidrebuildFromWriteBatch(WriteBatch writeBatch)Adds the keys from the WriteBatch to the transactionvoidrollback()Discard all batched writes in this transaction.voidrollbackToSavePoint()Undo all operations in this transaction (put, merge, delete, putLogData) since the most recent call tosetSavePoint()and removes the most recentsetSavePoint().voidsetLockTimeout(long lockTimeout)Change the value ofTransactionOptions.getLockTimeout()(in milliseconds) for this transaction.voidsetLogNumber(long logNumber)Set the log number.voidsetName(java.lang.String transactionName)Set the name of the transaction.voidsetSavePoint()Records the state of the transaction for future calls torollbackToSavePoint().voidsetSnapshot()If a transaction has a snapshot set, the transaction will ensure that any keys successfully written(or fetched viagetForUpdate(org.rocksdb.ReadOptions, org.rocksdb.ColumnFamilyHandle, byte[], boolean, boolean)) have not been modified outside of this transaction since the time the snapshot was set.voidsetSnapshotOnNextOperation()Similar tosetSnapshot(), but will not change the current snapshot until put/merge/delete/getForUpdate/multiGetForUpdate is called.voidsetSnapshotOnNextOperation(AbstractTransactionNotifier transactionNotifier)Similar tosetSnapshot(), but will not change the current snapshot until put/merge/delete/getForUpdate/multiGetForUpdate is called.voidsetWriteOptions(WriteOptions writeOptions)Reset the WriteOptions that will be used duringcommit().voidsingleDelete(byte[] key)Similar toRocksDB.singleDelete(byte[]), but will also perform conflict checking on the keys be written.voidsingleDelete(byte[][] keyParts)Similar tosingleDelete(byte[])but allows you to specify the key in several parts that will be concatenated together.voidsingleDelete(ColumnFamilyHandle columnFamilyHandle, byte[] key)Similar tosingleDelete(ColumnFamilyHandle, byte[], boolean)but withassumeTracked = false.voidsingleDelete(ColumnFamilyHandle columnFamilyHandle, byte[][] keyParts)Similar tosingleDelete(ColumnFamilyHandle, byte[][], boolean)but withassumeTracked = false.voidsingleDelete(ColumnFamilyHandle columnFamilyHandle, byte[][] keyParts, boolean assumeTracked)Similar tosingleDelete(ColumnFamilyHandle, byte[])but allows you to specify the key in several parts that will be concatenated together.voidsingleDelete(ColumnFamilyHandle columnFamilyHandle, byte[] key, boolean assumeTracked)Similar toRocksDB.singleDelete(ColumnFamilyHandle, byte[]), but will also perform conflict checking on the keys be written.voidundoGetForUpdate(byte[] key)If this key was previously fetched in this transaction usinggetForUpdate(ReadOptions, byte[], boolean)/multiGetForUpdate(ReadOptions, List, byte[][]), callingundoGetForUpdate(byte[])will tell the transaction that it no longer needs to do any conflict checking for this key.voidundoGetForUpdate(ColumnFamilyHandle columnFamilyHandle, byte[] key)If this key was previously fetched in this transaction usinggetForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean)/multiGetForUpdate(ReadOptions, List, byte[][]), callingundoGetForUpdate(ColumnFamilyHandle, byte[])will tell the transaction that it no longer needs to do any conflict checking for this key.-
Methods inherited from class org.rocksdb.RocksObject
disposeInternal, getNativeHandle
-
Methods inherited from class org.rocksdb.AbstractImmutableNativeReference
close, disOwnNativeHandle, isOwningHandle
-
Methods inherited from class org.rocksdb.AbstractNativeReference
dispose, finalize
-
-
-
-
Method Detail
-
setSnapshot
public void setSnapshot()
If a transaction has a snapshot set, the transaction will ensure that any keys successfully written(or fetched viagetForUpdate(org.rocksdb.ReadOptions, org.rocksdb.ColumnFamilyHandle, byte[], boolean, boolean)) have not been modified outside of this transaction since the time the snapshot was set. If a snapshot has not been set, the transaction guarantees that keys have not been modified since the time each key was first written (or fetched viagetForUpdate(org.rocksdb.ReadOptions, org.rocksdb.ColumnFamilyHandle, byte[], boolean, boolean)). UsingsetSnapshot()will provide stricter isolation guarantees at the expense of potentially more transaction failures due to conflicts with other writes. CallingsetSnapshot()has no effect on keys written before this function has been called.setSnapshot()may be called multiple times if you would like to change the snapshot used for different operations in this transaction. CallingsetSnapshot()will not affect the version of Data returned by get(...) methods. Seeget(org.rocksdb.ColumnFamilyHandle, org.rocksdb.ReadOptions, byte[])for more details.
-
setSnapshotOnNextOperation
public void setSnapshotOnNextOperation()
Similar tosetSnapshot(), but will not change the current snapshot until put/merge/delete/getForUpdate/multiGetForUpdate is called. By calling this function, the transaction will essentially callsetSnapshot()for you right before performing the next write/getForUpdate. CallingsetSnapshotOnNextOperation()will not affect what snapshot is returned bygetSnapshot()until the next write/getForUpdate is executed. When the snapshot is created the notifier's snapshotCreated method will be called so that the caller can get access to the snapshot. This is an optimization to reduce the likelihood of conflicts that could occur in between the timesetSnapshot()is called and the first write/getForUpdate operation. i.e. this prevents the following race-condition: txn1->setSnapshot(); txn2->put("A", ...); txn2->commit(); txn1->getForUpdate(opts, "A", ...); * FAIL!
-
setSnapshotOnNextOperation
public void setSnapshotOnNextOperation(AbstractTransactionNotifier transactionNotifier)
Similar tosetSnapshot(), but will not change the current snapshot until put/merge/delete/getForUpdate/multiGetForUpdate is called. By calling this function, the transaction will essentially callsetSnapshot()for you right before performing the next write/getForUpdate. CallingsetSnapshotOnNextOperation()will not affect what snapshot is returned bygetSnapshot()until the next write/getForUpdate is executed. When the snapshot is created theAbstractTransactionNotifier.snapshotCreated(Snapshot)method will be called so that the caller can get access to the snapshot. This is an optimization to reduce the likelihood of conflicts that could occur in between the timesetSnapshot()is called and the first write/getForUpdate operation. i.e. this prevents the following race-condition: txn1->setSnapshot(); txn2->put("A", ...); txn2->commit(); txn1->getForUpdate(opts, "A", ...); * FAIL!- Parameters:
transactionNotifier- A handler for receiving snapshot notifications for the transaction
-
getSnapshot
public Snapshot getSnapshot()
Returns the Snapshot created by the last call tosetSnapshot(). REQUIRED: The returned Snapshot is only valid up until the next timesetSnapshot()/setSnapshotOnNextOperation()is called,clearSnapshot()is called, or the Transaction is deleted.- Returns:
- The snapshot or null if there is no snapshot
-
clearSnapshot
public void clearSnapshot()
Clears the current snapshot (i.e. no snapshot will be 'set') This removes any snapshot that currently exists or is set to be created on the next update operation (setSnapshotOnNextOperation()). CallingclearSnapshot()has no effect on keys written before this function has been called. If a reference to a snapshot was retrieved viagetSnapshot(), it will no longer be valid and should be discarded after a call toclearSnapshot().
-
commit
public void commit() throws RocksDBExceptionWrite all batched keys to the db atomically. Returns OK on success. May return any error status that could be returned by DB:Write(). If this transaction was created by anOptimisticTransactionDBStatus::Busy() may be returned if the transaction could not guarantee that there are no write conflicts. Status::TryAgain() may be returned if the memtable history size is not large enough (See max_write_buffer_number_to_maintain). If this transaction was created by aTransactionDB, Status::Expired() may be returned if this transaction has lived for longer thanTransactionOptions.getExpiration().- Throws:
RocksDBException- if an error occurs when committing the transaction
-
rollback
public void rollback() throws RocksDBExceptionDiscard all batched writes in this transaction.- Throws:
RocksDBException- if an error occurs when rolling back the transaction
-
setSavePoint
public void setSavePoint() throws RocksDBExceptionRecords the state of the transaction for future calls torollbackToSavePoint(). May be called multiple times to set multiple save points.- Throws:
RocksDBException- if an error occurs whilst setting a save point
-
rollbackToSavePoint
public void rollbackToSavePoint() throws RocksDBExceptionUndo all operations in this transaction (put, merge, delete, putLogData) since the most recent call tosetSavePoint()and removes the most recentsetSavePoint(). If there is no previous call tosetSavePoint(), returns Status::NotFound()- Throws:
RocksDBException- if an error occurs when rolling back to a save point
-
get
public byte[] get(ColumnFamilyHandle columnFamilyHandle, ReadOptions readOptions, byte[] key) throws RocksDBException
This function is similar toRocksDB.get(ColumnFamilyHandle, ReadOptions, byte[])except it will also read pending changes in this transaction. Currently, this function will return Status::MergeInProgress if the most recent write to the queried key in this batch is a Merge. IfReadOptions.snapshot()is not set, the current version of the key will be read. CallingsetSnapshot()does not affect the version of the data returned. Note that settingReadOptions.setSnapshot(Snapshot)will affect what is read from the DB but will NOT change which keys are read from this transaction (the keys in this transaction do not yet belong to any snapshot and will be fetched regardless).- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstancereadOptions- Read options.key- the key to retrieve the value for.- Returns:
- a byte array storing the value associated with the input key if any. null if it does not find the specified key.
- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
get
public byte[] get(ReadOptions readOptions, byte[] key) throws RocksDBException
This function is similar toRocksDB.get(ReadOptions, byte[])except it will also read pending changes in this transaction. Currently, this function will return Status::MergeInProgress if the most recent write to the queried key in this batch is a Merge. IfReadOptions.snapshot()is not set, the current version of the key will be read. CallingsetSnapshot()does not affect the version of the data returned. Note that settingReadOptions.setSnapshot(Snapshot)will affect what is read from the DB but will NOT change which keys are read from this transaction (the keys in this transaction do not yet belong to any snapshot and will be fetched regardless).- Parameters:
readOptions- Read options.key- the key to retrieve the value for.- Returns:
- a byte array storing the value associated with the input key if any. null if it does not find the specified key.
- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
multiGet
public byte[][] multiGet(ReadOptions readOptions, java.util.List<ColumnFamilyHandle> columnFamilyHandles, byte[][] keys) throws RocksDBException
This function is similar toRocksDB.multiGet(ReadOptions, List, List)except it will also read pending changes in this transaction. Currently, this function will return Status::MergeInProgress if the most recent write to the queried key in this batch is a Merge. IfReadOptions.snapshot()is not set, the current version of the key will be read. CallingsetSnapshot()does not affect the version of the data returned. Note that settingReadOptions.setSnapshot(Snapshot)will affect what is read from the DB but will NOT change which keys are read from this transaction (the keys in this transaction do not yet belong to any snapshot and will be fetched regardless).- Parameters:
readOptions- Read options.columnFamilyHandles-ListcontainingColumnFamilyHandleinstances.keys- of keys for which values need to be retrieved.- Returns:
- Array of values, one for each key
- Throws:
RocksDBException- thrown if error happens in underlying native library.java.lang.IllegalArgumentException- thrown if the size of passed keys is not equal to the amount of passed column family handles.
-
multiGet
public byte[][] multiGet(ReadOptions readOptions, byte[][] keys) throws RocksDBException
This function is similar toRocksDB.multiGet(ReadOptions, List)except it will also read pending changes in this transaction. Currently, this function will return Status::MergeInProgress if the most recent write to the queried key in this batch is a Merge. IfReadOptions.snapshot()is not set, the current version of the key will be read. CallingsetSnapshot()does not affect the version of the data returned. Note that settingReadOptions.setSnapshot(Snapshot)will affect what is read from the DB but will NOT change which keys are read from this transaction (the keys in this transaction do not yet belong to any snapshot and will be fetched regardless).- Parameters:
readOptions- Read options.=ColumnFamilyHandleinstances.keys- of keys for which values need to be retrieved.- Returns:
- Array of values, one for each key
- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
getForUpdate
public byte[] getForUpdate(ReadOptions readOptions, ColumnFamilyHandle columnFamilyHandle, byte[] key, boolean exclusive, boolean doValidate) throws RocksDBException
Read this key and ensure that this transaction will only be able to be committed if this key is not written outside this transaction after it has first been read (or after the snapshot if a snapshot is set in this transaction). The transaction behavior is the same regardless of whether the key exists or not. Note: Currently, this function will return Status::MergeInProgress if the most recent write to the queried key in this batch is a Merge. The values returned by this function are similar toRocksDB.get(ColumnFamilyHandle, ReadOptions, byte[]). If value==nullptr, then this function will not read any data, but will still ensure that this key cannot be written to by outside of this transaction. If this transaction was created by anOptimisticTransactionDB,getForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean)could causecommit()to fail. Otherwise, it could return any error that could be returned byRocksDB.get(ColumnFamilyHandle, ReadOptions, byte[]). If this transaction was created on aTransactionDB, anRocksDBExceptionmay be thrown with an accompanyingStatuswhen:Status.Code.Busyif there is a write conflict,Status.Code.TimedOutif a lock could not be acquired,Status.Code.TryAgainif the memtable history size is not large enough. SeeColumnFamilyOptions.maxWriteBufferNumberToMaintain()Status.Code.MergeInProgressif merge operations cannot be resolved.- Parameters:
readOptions- Read options.columnFamilyHandle-ColumnFamilyHandleinstancekey- the key to retrieve the value for.exclusive- true if the transaction should have exclusive access to the key, otherwise false for shared access.doValidate- true if it should validate the snapshot before doing the read- Returns:
- a byte array storing the value associated with the input key if any. null if it does not find the specified key.
- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
getForUpdate
public byte[] getForUpdate(ReadOptions readOptions, ColumnFamilyHandle columnFamilyHandle, byte[] key, boolean exclusive) throws RocksDBException
Same asgetForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean, boolean)with doValidate=true.- Parameters:
readOptions- Read options.columnFamilyHandle-ColumnFamilyHandleinstancekey- the key to retrieve the value for.exclusive- true if the transaction should have exclusive access to the key, otherwise false for shared access.- Returns:
- a byte array storing the value associated with the input key if any. null if it does not find the specified key.
- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
getForUpdate
public byte[] getForUpdate(ReadOptions readOptions, byte[] key, boolean exclusive) throws RocksDBException
Read this key and ensure that this transaction will only be able to be committed if this key is not written outside this transaction after it has first been read (or after the snapshot if a snapshot is set in this transaction). The transaction behavior is the same regardless of whether the key exists or not. Note: Currently, this function will return Status::MergeInProgress if the most recent write to the queried key in this batch is a Merge. The values returned by this function are similar toRocksDB.get(ReadOptions, byte[]). If value==nullptr, then this function will not read any data, but will still ensure that this key cannot be written to by outside of this transaction. If this transaction was created on anOptimisticTransactionDB,getForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean)could causecommit()to fail. Otherwise, it could return any error that could be returned byRocksDB.get(ReadOptions, byte[]). If this transaction was created on aTransactionDB, anRocksDBExceptionmay be thrown with an accompanyingStatuswhen:Status.Code.Busyif there is a write conflict,Status.Code.TimedOutif a lock could not be acquired,Status.Code.TryAgainif the memtable history size is not large enough. SeeColumnFamilyOptions.maxWriteBufferNumberToMaintain()Status.Code.MergeInProgressif merge operations cannot be resolved.- Parameters:
readOptions- Read options.key- the key to retrieve the value for.exclusive- true if the transaction should have exclusive access to the key, otherwise false for shared access.- Returns:
- a byte array storing the value associated with the input key if any. null if it does not find the specified key.
- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
multiGetForUpdate
public byte[][] multiGetForUpdate(ReadOptions readOptions, java.util.List<ColumnFamilyHandle> columnFamilyHandles, byte[][] keys) throws RocksDBException
A multi-key version ofgetForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean).- Parameters:
readOptions- Read options.columnFamilyHandles-ColumnFamilyHandleinstanceskeys- the keys to retrieve the values for.- Returns:
- Array of values, one for each key
- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
multiGetForUpdate
public byte[][] multiGetForUpdate(ReadOptions readOptions, byte[][] keys) throws RocksDBException
A multi-key version ofgetForUpdate(ReadOptions, byte[], boolean).- Parameters:
readOptions- Read options.keys- the keys to retrieve the values for.- Returns:
- Array of values, one for each key
- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
getIterator
public RocksIterator getIterator(ReadOptions readOptions)
Returns an iterator that will iterate on all keys in the default column family including both keys in the DB and uncommitted keys in this transaction. SettingReadOptions.setSnapshot(Snapshot)will affect what is read from the DB but will NOT change which keys are read from this transaction (the keys in this transaction do not yet belong to any snapshot and will be fetched regardless). Caller is responsible for deleting the returned Iterator. The returned iterator is only valid untilcommit(),rollback(), orrollbackToSavePoint()is called.- Parameters:
readOptions- Read options.- Returns:
- instance of iterator object.
-
getIterator
public RocksIterator getIterator(ReadOptions readOptions, ColumnFamilyHandle columnFamilyHandle)
Returns an iterator that will iterate on all keys in the column family specified bycolumnFamilyHandleincluding both keys in the DB and uncommitted keys in this transaction. SettingReadOptions.setSnapshot(Snapshot)will affect what is read from the DB but will NOT change which keys are read from this transaction (the keys in this transaction do not yet belong to any snapshot and will be fetched regardless). Caller is responsible for callingAbstractImmutableNativeReference.close()on the returned Iterator. The returned iterator is only valid untilcommit(),rollback(), orrollbackToSavePoint()is called.- Parameters:
readOptions- Read options.columnFamilyHandle-ColumnFamilyHandleinstance- Returns:
- instance of iterator object.
-
put
public void put(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value, boolean assumeTracked) throws RocksDBException
Similar toRocksDB.put(ColumnFamilyHandle, byte[], byte[]), but will also perform conflict checking on the keys be written. If this Transaction was created on anOptimisticTransactionDB, these functions should always succeed. If this Transaction was created on aTransactionDB, anRocksDBExceptionmay be thrown with an accompanyingStatuswhen:Status.Code.Busyif there is a write conflict,Status.Code.TimedOutif a lock could not be acquired,Status.Code.TryAgainif the memtable history size is not large enough. SeeColumnFamilyOptions.maxWriteBufferNumberToMaintain()- Parameters:
columnFamilyHandle- The column family to put the key/value intokey- the specified key to be inserted.value- the value associated with the specified key.assumeTracked- true when it is expected that the key is already tracked. More specifically, it means the the key was previous tracked in the same savepoint, with the same exclusive flag, and at a lower sequence number. If valid then it skips ValidateSnapshot, throws an error otherwise.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
put
public void put(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value) throws RocksDBException
Similar toput(ColumnFamilyHandle, byte[], byte[], boolean)but withassumeTracked = false. Will also perform conflict checking on the keys be written. If this Transaction was created on anOptimisticTransactionDB, these functions should always succeed. If this Transaction was created on aTransactionDB, anRocksDBExceptionmay be thrown with an accompanyingStatuswhen:Status.Code.Busyif there is a write conflict,Status.Code.TimedOutif a lock could not be acquired,Status.Code.TryAgainif the memtable history size is not large enough. SeeColumnFamilyOptions.maxWriteBufferNumberToMaintain()- Parameters:
columnFamilyHandle- The column family to put the key/value intokey- the specified key to be inserted.value- the value associated with the specified key.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
put
public void put(byte[] key, byte[] value) throws RocksDBExceptionSimilar toRocksDB.put(byte[], byte[]), but will also perform conflict checking on the keys be written. If this Transaction was created on anOptimisticTransactionDB, these functions should always succeed. If this Transaction was created on aTransactionDB, anRocksDBExceptionmay be thrown with an accompanyingStatuswhen:Status.Code.Busyif there is a write conflict,Status.Code.TimedOutif a lock could not be acquired,Status.Code.TryAgainif the memtable history size is not large enough. SeeColumnFamilyOptions.maxWriteBufferNumberToMaintain()- Parameters:
key- the specified key to be inserted.value- the value associated with the specified key.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
put
public void put(ColumnFamilyHandle columnFamilyHandle, byte[][] keyParts, byte[][] valueParts, boolean assumeTracked) throws RocksDBException
Similar toput(ColumnFamilyHandle, byte[], byte[])but allows you to specify the key and value in several parts that will be concatenated together.- Parameters:
columnFamilyHandle- The column family to put the key/value intokeyParts- the specified key to be inserted.valueParts- the value associated with the specified key.assumeTracked- true when it is expected that the key is already tracked. More specifically, it means the the key was previous tracked in the same savepoint, with the same exclusive flag, and at a lower sequence number. If valid then it skips ValidateSnapshot, throws an error otherwise.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
put
public void put(ColumnFamilyHandle columnFamilyHandle, byte[][] keyParts, byte[][] valueParts) throws RocksDBException
Similar toput(ColumnFamilyHandle, byte[][], byte[][], boolean)but with withassumeTracked = false. Allows you to specify the key and value in several parts that will be concatenated together.- Parameters:
columnFamilyHandle- The column family to put the key/value intokeyParts- the specified key to be inserted.valueParts- the value associated with the specified key.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
put
public void put(byte[][] keyParts, byte[][] valueParts) throws RocksDBExceptionSimilar toput(byte[], byte[])but allows you to specify the key and value in several parts that will be concatenated together- Parameters:
keyParts- the specified key to be inserted.valueParts- the value associated with the specified key.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
merge
public void merge(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value, boolean assumeTracked) throws RocksDBException
Similar toRocksDB.merge(ColumnFamilyHandle, byte[], byte[]), but will also perform conflict checking on the keys be written. If this Transaction was created on anOptimisticTransactionDB, these functions should always succeed. If this Transaction was created on aTransactionDB, anRocksDBExceptionmay be thrown with an accompanyingStatuswhen:Status.Code.Busyif there is a write conflict,Status.Code.TimedOutif a lock could not be acquired,Status.Code.TryAgainif the memtable history size is not large enough. SeeColumnFamilyOptions.maxWriteBufferNumberToMaintain()- Parameters:
columnFamilyHandle- The column family to merge the key/value intokey- the specified key to be merged.value- the value associated with the specified key.assumeTracked- true when it is expected that the key is already tracked. More specifically, it means the the key was previous tracked in the same savepoint, with the same exclusive flag, and at a lower sequence number. If valid then it skips ValidateSnapshot, throws an error otherwise.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
merge
public void merge(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value) throws RocksDBException
Similar tomerge(ColumnFamilyHandle, byte[], byte[], boolean)but withassumeTracked = false. Will also perform conflict checking on the keys be written. If this Transaction was created on anOptimisticTransactionDB, these functions should always succeed. If this Transaction was created on aTransactionDB, anRocksDBExceptionmay be thrown with an accompanyingStatuswhen:Status.Code.Busyif there is a write conflict,Status.Code.TimedOutif a lock could not be acquired,Status.Code.TryAgainif the memtable history size is not large enough. SeeColumnFamilyOptions.maxWriteBufferNumberToMaintain()- Parameters:
columnFamilyHandle- The column family to merge the key/value intokey- the specified key to be merged.value- the value associated with the specified key.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
merge
public void merge(byte[] key, byte[] value) throws RocksDBExceptionSimilar toRocksDB.merge(byte[], byte[]), but will also perform conflict checking on the keys be written. If this Transaction was created on anOptimisticTransactionDB, these functions should always succeed. If this Transaction was created on aTransactionDB, anRocksDBExceptionmay be thrown with an accompanyingStatuswhen:Status.Code.Busyif there is a write conflict,Status.Code.TimedOutif a lock could not be acquired,Status.Code.TryAgainif the memtable history size is not large enough. SeeColumnFamilyOptions.maxWriteBufferNumberToMaintain()- Parameters:
key- the specified key to be merged.value- the value associated with the specified key.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
delete
public void delete(ColumnFamilyHandle columnFamilyHandle, byte[] key, boolean assumeTracked) throws RocksDBException
Similar toRocksDB.delete(ColumnFamilyHandle, byte[]), but will also perform conflict checking on the keys be written. If this Transaction was created on anOptimisticTransactionDB, these functions should always succeed. If this Transaction was created on aTransactionDB, anRocksDBExceptionmay be thrown with an accompanyingStatuswhen:Status.Code.Busyif there is a write conflict,Status.Code.TimedOutif a lock could not be acquired,Status.Code.TryAgainif the memtable history size is not large enough. SeeColumnFamilyOptions.maxWriteBufferNumberToMaintain()- Parameters:
columnFamilyHandle- The column family to delete the key/value fromkey- the specified key to be deleted.assumeTracked- true when it is expected that the key is already tracked. More specifically, it means the the key was previous tracked in the same savepoint, with the same exclusive flag, and at a lower sequence number. If valid then it skips ValidateSnapshot, throws an error otherwise.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
delete
public void delete(ColumnFamilyHandle columnFamilyHandle, byte[] key) throws RocksDBException
Similar todelete(ColumnFamilyHandle, byte[], boolean)but withassumeTracked = false. Will also perform conflict checking on the keys be written. If this Transaction was created on anOptimisticTransactionDB, these functions should always succeed. If this Transaction was created on aTransactionDB, anRocksDBExceptionmay be thrown with an accompanyingStatuswhen:Status.Code.Busyif there is a write conflict,Status.Code.TimedOutif a lock could not be acquired,Status.Code.TryAgainif the memtable history size is not large enough. SeeColumnFamilyOptions.maxWriteBufferNumberToMaintain()- Parameters:
columnFamilyHandle- The column family to delete the key/value fromkey- the specified key to be deleted.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
delete
public void delete(byte[] key) throws RocksDBExceptionSimilar toRocksDB.delete(byte[]), but will also perform conflict checking on the keys be written. If this Transaction was created on anOptimisticTransactionDB, these functions should always succeed. If this Transaction was created on aTransactionDB, anRocksDBExceptionmay be thrown with an accompanyingStatuswhen:Status.Code.Busyif there is a write conflict,Status.Code.TimedOutif a lock could not be acquired,Status.Code.TryAgainif the memtable history size is not large enough. SeeColumnFamilyOptions.maxWriteBufferNumberToMaintain()- Parameters:
key- the specified key to be deleted.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
delete
public void delete(ColumnFamilyHandle columnFamilyHandle, byte[][] keyParts, boolean assumeTracked) throws RocksDBException
Similar todelete(ColumnFamilyHandle, byte[])but allows you to specify the key in several parts that will be concatenated together.- Parameters:
columnFamilyHandle- The column family to delete the key/value fromkeyParts- the specified key to be deleted.assumeTracked- true when it is expected that the key is already tracked. More specifically, it means the the key was previous tracked in the same savepoint, with the same exclusive flag, and at a lower sequence number. If valid then it skips ValidateSnapshot, throws an error otherwise.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
delete
public void delete(ColumnFamilyHandle columnFamilyHandle, byte[][] keyParts) throws RocksDBException
Similar todelete(ColumnFamilyHandle, byte[][], boolean)but withassumeTracked = false. Allows you to specify the key in several parts that will be concatenated together.- Parameters:
columnFamilyHandle- The column family to delete the key/value fromkeyParts- the specified key to be deleted.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
delete
public void delete(byte[][] keyParts) throws RocksDBExceptionSimilar todelete(byte[])but allows you to specify key the in several parts that will be concatenated together.- Parameters:
keyParts- the specified key to be deleted- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
singleDelete
@Experimental("Performance optimization for a very specific workload") public void singleDelete(ColumnFamilyHandle columnFamilyHandle, byte[] key, boolean assumeTracked) throws RocksDBException
Similar toRocksDB.singleDelete(ColumnFamilyHandle, byte[]), but will also perform conflict checking on the keys be written. If this Transaction was created on anOptimisticTransactionDB, these functions should always succeed. If this Transaction was created on aTransactionDB, anRocksDBExceptionmay be thrown with an accompanyingStatuswhen:Status.Code.Busyif there is a write conflict,Status.Code.TimedOutif a lock could not be acquired,Status.Code.TryAgainif the memtable history size is not large enough. SeeColumnFamilyOptions.maxWriteBufferNumberToMaintain()- Parameters:
columnFamilyHandle- The column family to delete the key/value fromkey- the specified key to be deleted.assumeTracked- true when it is expected that the key is already tracked. More specifically, it means the the key was previous tracked in the same savepoint, with the same exclusive flag, and at a lower sequence number. If valid then it skips ValidateSnapshot, throws an error otherwise.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
singleDelete
@Experimental("Performance optimization for a very specific workload") public void singleDelete(ColumnFamilyHandle columnFamilyHandle, byte[] key) throws RocksDBException
Similar tosingleDelete(ColumnFamilyHandle, byte[], boolean)but withassumeTracked = false. will also perform conflict checking on the keys be written. If this Transaction was created on anOptimisticTransactionDB, these functions should always succeed. If this Transaction was created on aTransactionDB, anRocksDBExceptionmay be thrown with an accompanyingStatuswhen:Status.Code.Busyif there is a write conflict,Status.Code.TimedOutif a lock could not be acquired,Status.Code.TryAgainif the memtable history size is not large enough. SeeColumnFamilyOptions.maxWriteBufferNumberToMaintain()- Parameters:
columnFamilyHandle- The column family to delete the key/value fromkey- the specified key to be deleted.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
singleDelete
@Experimental("Performance optimization for a very specific workload") public void singleDelete(byte[] key) throws RocksDBException
Similar toRocksDB.singleDelete(byte[]), but will also perform conflict checking on the keys be written. If this Transaction was created on anOptimisticTransactionDB, these functions should always succeed. If this Transaction was created on aTransactionDB, anRocksDBExceptionmay be thrown with an accompanyingStatuswhen:Status.Code.Busyif there is a write conflict,Status.Code.TimedOutif a lock could not be acquired,Status.Code.TryAgainif the memtable history size is not large enough. SeeColumnFamilyOptions.maxWriteBufferNumberToMaintain()- Parameters:
key- the specified key to be deleted.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
singleDelete
@Experimental("Performance optimization for a very specific workload") public void singleDelete(ColumnFamilyHandle columnFamilyHandle, byte[][] keyParts, boolean assumeTracked) throws RocksDBException
Similar tosingleDelete(ColumnFamilyHandle, byte[])but allows you to specify the key in several parts that will be concatenated together.- Parameters:
columnFamilyHandle- The column family to delete the key/value fromkeyParts- the specified key to be deleted.assumeTracked- true when it is expected that the key is already tracked. More specifically, it means the the key was previous tracked in the same savepoint, with the same exclusive flag, and at a lower sequence number. If valid then it skips ValidateSnapshot, throws an error otherwise.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
singleDelete
@Experimental("Performance optimization for a very specific workload") public void singleDelete(ColumnFamilyHandle columnFamilyHandle, byte[][] keyParts) throws RocksDBException
Similar tosingleDelete(ColumnFamilyHandle, byte[][], boolean)but withassumeTracked = false. Allows you to specify the key in several parts that will be concatenated together.- Parameters:
columnFamilyHandle- The column family to delete the key/value fromkeyParts- the specified key to be deleted.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
singleDelete
@Experimental("Performance optimization for a very specific workload") public void singleDelete(byte[][] keyParts) throws RocksDBException
Similar tosingleDelete(byte[])but allows you to specify the key in several parts that will be concatenated together.- Parameters:
keyParts- the specified key to be deleted.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
putUntracked
public void putUntracked(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value) throws RocksDBException
Similar toRocksDB.put(ColumnFamilyHandle, byte[], byte[]), but operates on the transactions write batch. This write will only happen if this transaction gets committed successfully. Unlikeput(ColumnFamilyHandle, byte[], byte[])no conflict checking will be performed for this key. If this Transaction was created on aTransactionDB, this function will still acquire locks necessary to make sure this write doesn't cause conflicts in other transactions; This may cause aRocksDBExceptionwith associatedStatus.Code.Busy.- Parameters:
columnFamilyHandle- The column family to put the key/value intokey- the specified key to be inserted.value- the value associated with the specified key.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
putUntracked
public void putUntracked(byte[] key, byte[] value) throws RocksDBExceptionSimilar toRocksDB.put(byte[], byte[]), but operates on the transactions write batch. This write will only happen if this transaction gets committed successfully. Unlikeput(byte[], byte[])no conflict checking will be performed for this key. If this Transaction was created on aTransactionDB, this function will still acquire locks necessary to make sure this write doesn't cause conflicts in other transactions; This may cause aRocksDBExceptionwith associatedStatus.Code.Busy.- Parameters:
key- the specified key to be inserted.value- the value associated with the specified key.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
putUntracked
public void putUntracked(ColumnFamilyHandle columnFamilyHandle, byte[][] keyParts, byte[][] valueParts) throws RocksDBException
Similar toputUntracked(ColumnFamilyHandle, byte[], byte[])but allows you to specify the key and value in several parts that will be concatenated together.- Parameters:
columnFamilyHandle- The column family to put the key/value intokeyParts- the specified key to be inserted.valueParts- the value associated with the specified key.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
putUntracked
public void putUntracked(byte[][] keyParts, byte[][] valueParts) throws RocksDBExceptionSimilar toputUntracked(byte[], byte[])but allows you to specify the key and value in several parts that will be concatenated together.- Parameters:
keyParts- the specified key to be inserted.valueParts- the value associated with the specified key.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
mergeUntracked
public void mergeUntracked(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value) throws RocksDBException
Similar toRocksDB.merge(ColumnFamilyHandle, byte[], byte[]), but operates on the transactions write batch. This write will only happen if this transaction gets committed successfully. Unlikemerge(ColumnFamilyHandle, byte[], byte[])no conflict checking will be performed for this key. If this Transaction was created on aTransactionDB, this function will still acquire locks necessary to make sure this write doesn't cause conflicts in other transactions; This may cause aRocksDBExceptionwith associatedStatus.Code.Busy.- Parameters:
columnFamilyHandle- The column family to merge the key/value intokey- the specified key to be merged.value- the value associated with the specified key.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
mergeUntracked
public void mergeUntracked(byte[] key, byte[] value) throws RocksDBExceptionSimilar toRocksDB.merge(byte[], byte[]), but operates on the transactions write batch. This write will only happen if this transaction gets committed successfully. Unlikemerge(byte[], byte[])no conflict checking will be performed for this key. If this Transaction was created on aTransactionDB, this function will still acquire locks necessary to make sure this write doesn't cause conflicts in other transactions; This may cause aRocksDBExceptionwith associatedStatus.Code.Busy.- Parameters:
key- the specified key to be merged.value- the value associated with the specified key.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
deleteUntracked
public void deleteUntracked(ColumnFamilyHandle columnFamilyHandle, byte[] key) throws RocksDBException
Similar toRocksDB.delete(ColumnFamilyHandle, byte[]), but operates on the transactions write batch. This write will only happen if this transaction gets committed successfully. Unlikedelete(ColumnFamilyHandle, byte[])no conflict checking will be performed for this key. If this Transaction was created on aTransactionDB, this function will still acquire locks necessary to make sure this write doesn't cause conflicts in other transactions; This may cause aRocksDBExceptionwith associatedStatus.Code.Busy.- Parameters:
columnFamilyHandle- The column family to delete the key/value fromkey- the specified key to be deleted.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
deleteUntracked
public void deleteUntracked(byte[] key) throws RocksDBExceptionSimilar toRocksDB.delete(byte[]), but operates on the transactions write batch. This write will only happen if this transaction gets committed successfully. Unlikedelete(byte[])no conflict checking will be performed for this key. If this Transaction was created on aTransactionDB, this function will still acquire locks necessary to make sure this write doesn't cause conflicts in other transactions; This may cause aRocksDBExceptionwith associatedStatus.Code.Busy.- Parameters:
key- the specified key to be deleted.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
deleteUntracked
public void deleteUntracked(ColumnFamilyHandle columnFamilyHandle, byte[][] keyParts) throws RocksDBException
Similar todeleteUntracked(ColumnFamilyHandle, byte[])but allows you to specify the key in several parts that will be concatenated together.- Parameters:
columnFamilyHandle- The column family to delete the key/value fromkeyParts- the specified key to be deleted.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
deleteUntracked
public void deleteUntracked(byte[][] keyParts) throws RocksDBExceptionSimilar todeleteUntracked(byte[])but allows you to specify the key in several parts that will be concatenated together.- Parameters:
keyParts- the specified key to be deleted.- Throws:
RocksDBException- when one of the TransactionalDB conditions described above occurs, or in the case of an unexpected error
-
putLogData
public void putLogData(byte[] blob)
Similar toAbstractWriteBatch.putLogData(byte[])- Parameters:
blob- binary object to be inserted
-
disableIndexing
public void disableIndexing()
By default, all put/merge/delete operations will be indexed in the transaction so that get/getForUpdate/getIterator can search for these keys. If the caller does not want to fetch the keys about to be written, they may want to avoid indexing as a performance optimization. CallingdisableIndexing()will turn off indexing for all future put/merge/delete operations untilenableIndexing()is called. If a key is put/merge/deleted afterdisableIndexing()is called and then is fetched via get/getForUpdate/getIterator, the result of the fetch is undefined.
-
enableIndexing
public void enableIndexing()
Re-enables indexing after a previous call todisableIndexing()
-
getNumKeys
public long getNumKeys()
Returns the number of distinct Keys being tracked by this transaction. If this transaction was created by aTransactionDB, this is the number of keys that are currently locked by this transaction. If this transaction was created by anOptimisticTransactionDB, this is the number of keys that need to be checked for conflicts at commit time.- Returns:
- the number of distinct Keys being tracked by this transaction
-
getNumPuts
public long getNumPuts()
Returns the number of puts that have been applied to this transaction so far.- Returns:
- the number of puts that have been applied to this transaction
-
getNumDeletes
public long getNumDeletes()
Returns the number of deletes that have been applied to this transaction so far.- Returns:
- the number of deletes that have been applied to this transaction
-
getNumMerges
public long getNumMerges()
Returns the number of merges that have been applied to this transaction so far.- Returns:
- the number of merges that have been applied to this transaction
-
getElapsedTime
public long getElapsedTime()
Returns the elapsed time in milliseconds since this Transaction began.- Returns:
- the elapsed time in milliseconds since this transaction began.
-
getWriteBatch
public WriteBatchWithIndex getWriteBatch()
Fetch the underlying write batch that contains all pending changes to be committed. Note: You should not write or delete anything from the batch directly and should only use the functions in theTransactionclass to write to this transaction.- Returns:
- The write batch
-
setLockTimeout
public void setLockTimeout(long lockTimeout)
Change the value ofTransactionOptions.getLockTimeout()(in milliseconds) for this transaction. Has no effect on OptimisticTransactions.- Parameters:
lockTimeout- the timeout (in milliseconds) for locks used by this transaction.
-
getWriteOptions
public WriteOptions getWriteOptions()
Return the WriteOptions that will be used duringcommit().- Returns:
- the WriteOptions that will be used
-
setWriteOptions
public void setWriteOptions(WriteOptions writeOptions)
Reset the WriteOptions that will be used duringcommit().- Parameters:
writeOptions- The new WriteOptions
-
undoGetForUpdate
public void undoGetForUpdate(ColumnFamilyHandle columnFamilyHandle, byte[] key)
If this key was previously fetched in this transaction usinggetForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean)/multiGetForUpdate(ReadOptions, List, byte[][]), callingundoGetForUpdate(ColumnFamilyHandle, byte[])will tell the transaction that it no longer needs to do any conflict checking for this key. If a key has been fetched N times viagetForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean)/multiGetForUpdate(ReadOptions, List, byte[][]), thenundoGetForUpdate(ColumnFamilyHandle, byte[])will only have an effect if it is also called N times. If this key has been written to in this transaction,undoGetForUpdate(ColumnFamilyHandle, byte[])will have no effect. IfsetSavePoint()has been called after thegetForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean),undoGetForUpdate(ColumnFamilyHandle, byte[])will not have any effect. If this Transaction was created by anOptimisticTransactionDB, callingundoGetForUpdate(ColumnFamilyHandle, byte[])can affect whether this key is conflict checked at commit time. If this Transaction was created by aTransactionDB, callingundoGetForUpdate(ColumnFamilyHandle, byte[])may release any held locks for this key.- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstancekey- the key to retrieve the value for.
-
undoGetForUpdate
public void undoGetForUpdate(byte[] key)
If this key was previously fetched in this transaction usinggetForUpdate(ReadOptions, byte[], boolean)/multiGetForUpdate(ReadOptions, List, byte[][]), callingundoGetForUpdate(byte[])will tell the transaction that it no longer needs to do any conflict checking for this key. If a key has been fetched N times viagetForUpdate(ReadOptions, byte[], boolean)/multiGetForUpdate(ReadOptions, List, byte[][]), thenundoGetForUpdate(byte[])will only have an effect if it is also called N times. If this key has been written to in this transaction,undoGetForUpdate(byte[])will have no effect. IfsetSavePoint()has been called after thegetForUpdate(ReadOptions, byte[], boolean),undoGetForUpdate(byte[])will not have any effect. If this Transaction was created by anOptimisticTransactionDB, callingundoGetForUpdate(byte[])can affect whether this key is conflict checked at commit time. If this Transaction was created by aTransactionDB, callingundoGetForUpdate(byte[])may release any held locks for this key.- Parameters:
key- the key to retrieve the value for.
-
rebuildFromWriteBatch
public void rebuildFromWriteBatch(WriteBatch writeBatch) throws RocksDBException
Adds the keys from the WriteBatch to the transaction- Parameters:
writeBatch- The write batch to read from- Throws:
RocksDBException- if an error occurs whilst rebuilding from the write batch.
-
getCommitTimeWriteBatch
public WriteBatch getCommitTimeWriteBatch()
Get the Commit time Write Batch.- Returns:
- the commit time write batch.
-
setLogNumber
public void setLogNumber(long logNumber)
Set the log number.- Parameters:
logNumber- the log number
-
getLogNumber
public long getLogNumber()
Get the log number.- Returns:
- the log number
-
setName
public void setName(java.lang.String transactionName) throws RocksDBExceptionSet the name of the transaction.- Parameters:
transactionName- the name of the transaction- Throws:
RocksDBException- if an error occurs when setting the transaction name.
-
getName
public java.lang.String getName()
Get the name of the transaction.- Returns:
- the name of the transaction
-
getID
public long getID()
Get the ID of the transaction.- Returns:
- the ID of the transaction.
-
isDeadlockDetect
public boolean isDeadlockDetect()
Determine if a deadlock has been detected.- Returns:
- true if a deadlock has been detected.
-
getWaitingTxns
public Transaction.WaitingTransactions getWaitingTxns()
Get the list of waiting transactions.- Returns:
- The list of waiting transactions.
-
getState
public Transaction.TransactionState getState()
Get the execution status of the transaction. NOTE: The execution status of an Optimistic Transaction never changes. This is only useful for non-optimistic transactions!- Returns:
- The execution status of the transaction
-
getId
@Experimental("NOTE: Experimental feature") public long getId()
The globally unique id with which the transaction is identified. This id might or might not be set depending on the implementation. Similarly the implementation decides the point in lifetime of a transaction at which it assigns the id. Although currently it is the case, the id is not guaranteed to remain the same across restarts.- Returns:
- the transaction id.
-
disposeInternal
protected final void disposeInternal(long handle)
- Specified by:
disposeInternalin classRocksObject
-
-