1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
11 * Provides BEGIN/COMMIT/ROLLBACK transactions.
13 * To use transactions, you must first create either an
14 * {@link OptimisticTransactionDB} or a {@link TransactionDB}
16 * To create a transaction, use
17 * {@link OptimisticTransactionDB#beginTransaction(org.rocksdb.WriteOptions)} or
18 * {@link TransactionDB#beginTransaction(org.rocksdb.WriteOptions)}
20 * It is up to the caller to synchronize access to this object.
22 * See samples/src/main/java/OptimisticTransactionSample.java and
23 * samples/src/main/java/TransactionSample.java for some simple
26 public class Transaction
extends RocksObject
{
28 private final RocksDB parent
;
31 * Intentionally package private
32 * as this is called from
33 * {@link OptimisticTransactionDB#beginTransaction(org.rocksdb.WriteOptions)}
34 * or {@link TransactionDB#beginTransaction(org.rocksdb.WriteOptions)}
36 * @param parent This must be either {@link TransactionDB} or
37 * {@link OptimisticTransactionDB}
38 * @param transactionHandle The native handle to the underlying C++
41 Transaction(final RocksDB parent
, final long transactionHandle
) {
42 super(transactionHandle
);
47 * If a transaction has a snapshot set, the transaction will ensure that
48 * any keys successfully written(or fetched via {@link #getForUpdate}) have
49 * not been modified outside of this transaction since the time the snapshot
52 * If a snapshot has not been set, the transaction guarantees that keys have
53 * not been modified since the time each key was first written (or fetched via
54 * {@link #getForUpdate}).
56 * Using {@link #setSnapshot()} will provide stricter isolation guarantees
57 * at the expense of potentially more transaction failures due to conflicts
60 * Calling {@link #setSnapshot()} has no effect on keys written before this
61 * function has been called.
63 * {@link #setSnapshot()} may be called multiple times if you would like to
64 * change the snapshot used for different operations in this transaction.
66 * Calling {@link #setSnapshot()} will not affect the version of Data returned
67 * by get(...) methods. See {@link #get} for more details.
69 public void setSnapshot() {
70 assert(isOwningHandle());
71 setSnapshot(nativeHandle_
);
75 * Similar to {@link #setSnapshot()}, but will not change the current snapshot
76 * until put/merge/delete/getForUpdate/multiGetForUpdate is called.
77 * By calling this function, the transaction will essentially call
78 * {@link #setSnapshot()} for you right before performing the next
81 * Calling {@link #setSnapshotOnNextOperation()} will not affect what
82 * snapshot is returned by {@link #getSnapshot} until the next
83 * write/getForUpdate is executed.
85 * When the snapshot is created the notifier's snapshotCreated method will
86 * be called so that the caller can get access to the snapshot.
88 * This is an optimization to reduce the likelihood of conflicts that
89 * could occur in between the time {@link #setSnapshot()} is called and the
90 * first write/getForUpdate operation. i.e. this prevents the following
93 * txn1->setSnapshot();
94 * txn2->put("A", ...);
96 * txn1->getForUpdate(opts, "A", ...); * FAIL!
98 public void setSnapshotOnNextOperation() {
99 assert(isOwningHandle());
100 setSnapshotOnNextOperation(nativeHandle_
);
104 * Similar to {@link #setSnapshot()}, but will not change the current snapshot
105 * until put/merge/delete/getForUpdate/multiGetForUpdate is called.
106 * By calling this function, the transaction will essentially call
107 * {@link #setSnapshot()} for you right before performing the next
108 * write/getForUpdate.
110 * Calling {@link #setSnapshotOnNextOperation()} will not affect what
111 * snapshot is returned by {@link #getSnapshot} until the next
112 * write/getForUpdate is executed.
114 * When the snapshot is created the
115 * {@link AbstractTransactionNotifier#snapshotCreated(Snapshot)} method will
116 * be called so that the caller can get access to the snapshot.
118 * This is an optimization to reduce the likelihood of conflicts that
119 * could occur in between the time {@link #setSnapshot()} is called and the
120 * first write/getForUpdate operation. i.e. this prevents the following
123 * txn1->setSnapshot();
124 * txn2->put("A", ...);
126 * txn1->getForUpdate(opts, "A", ...); * FAIL!
128 * @param transactionNotifier A handler for receiving snapshot notifications
129 * for the transaction
132 public void setSnapshotOnNextOperation(
133 final AbstractTransactionNotifier transactionNotifier
) {
134 assert(isOwningHandle());
135 setSnapshotOnNextOperation(nativeHandle_
, transactionNotifier
.nativeHandle_
);
139 * Returns the Snapshot created by the last call to {@link #setSnapshot()}.
141 * REQUIRED: The returned Snapshot is only valid up until the next time
142 * {@link #setSnapshot()}/{@link #setSnapshotOnNextOperation()} is called,
143 * {@link #clearSnapshot()} is called, or the Transaction is deleted.
145 * @return The snapshot or null if there is no snapshot
147 public Snapshot
getSnapshot() {
148 assert(isOwningHandle());
149 final long snapshotNativeHandle
= getSnapshot(nativeHandle_
);
150 if(snapshotNativeHandle
== 0) {
153 final Snapshot snapshot
= new Snapshot(snapshotNativeHandle
);
159 * Clears the current snapshot (i.e. no snapshot will be 'set')
161 * This removes any snapshot that currently exists or is set to be created
162 * on the next update operation ({@link #setSnapshotOnNextOperation()}).
164 * Calling {@link #clearSnapshot()} has no effect on keys written before this
165 * function has been called.
167 * If a reference to a snapshot was retrieved via {@link #getSnapshot()}, it
168 * will no longer be valid and should be discarded after a call to
169 * {@link #clearSnapshot()}.
171 public void clearSnapshot() {
172 assert(isOwningHandle());
173 clearSnapshot(nativeHandle_
);
177 * Prepare the current transaction for 2PC
179 void prepare() throws RocksDBException
{
180 //TODO(AR) consider a Java'ish version of this function, which returns an AutoCloseable (commit)
181 assert(isOwningHandle());
182 prepare(nativeHandle_
);
186 * Write all batched keys to the db atomically.
188 * Returns OK on success.
190 * May return any error status that could be returned by DB:Write().
192 * If this transaction was created by an {@link OptimisticTransactionDB}
193 * Status::Busy() may be returned if the transaction could not guarantee
194 * that there are no write conflicts. Status::TryAgain() may be returned
195 * if the memtable history size is not large enough
196 * (See max_write_buffer_number_to_maintain).
198 * If this transaction was created by a {@link TransactionDB},
199 * Status::Expired() may be returned if this transaction has lived for
200 * longer than {@link TransactionOptions#getExpiration()}.
202 * @throws RocksDBException if an error occurs when committing the transaction
204 public void commit() throws RocksDBException
{
205 assert(isOwningHandle());
206 commit(nativeHandle_
);
210 * Discard all batched writes in this transaction.
212 * @throws RocksDBException if an error occurs when rolling back the transaction
214 public void rollback() throws RocksDBException
{
215 assert(isOwningHandle());
216 rollback(nativeHandle_
);
220 * Records the state of the transaction for future calls to
221 * {@link #rollbackToSavePoint()}.
223 * May be called multiple times to set multiple save points.
225 * @throws RocksDBException if an error occurs whilst setting a save point
227 public void setSavePoint() throws RocksDBException
{
228 assert(isOwningHandle());
229 setSavePoint(nativeHandle_
);
233 * Undo all operations in this transaction (put, merge, delete, putLogData)
234 * since the most recent call to {@link #setSavePoint()} and removes the most
235 * recent {@link #setSavePoint()}.
237 * If there is no previous call to {@link #setSavePoint()},
238 * returns Status::NotFound()
240 * @throws RocksDBException if an error occurs when rolling back to a save point
242 public void rollbackToSavePoint() throws RocksDBException
{
243 assert(isOwningHandle());
244 rollbackToSavePoint(nativeHandle_
);
248 * This function is similar to
249 * {@link RocksDB#get(ColumnFamilyHandle, ReadOptions, byte[])} except it will
250 * also read pending changes in this transaction.
251 * Currently, this function will return Status::MergeInProgress if the most
252 * recent write to the queried key in this batch is a Merge.
254 * If {@link ReadOptions#snapshot()} is not set, the current version of the
255 * key will be read. Calling {@link #setSnapshot()} does not affect the
256 * version of the data returned.
258 * Note that setting {@link ReadOptions#setSnapshot(Snapshot)} will affect
259 * what is read from the DB but will NOT change which keys are read from this
260 * transaction (the keys in this transaction do not yet belong to any snapshot
261 * and will be fetched regardless).
263 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle} instance
264 * @param readOptions Read options.
265 * @param key the key to retrieve the value for.
267 * @return a byte array storing the value associated with the input key if
268 * any. null if it does not find the specified key.
270 * @throws RocksDBException thrown if error happens in underlying native
273 public byte[] get(final ColumnFamilyHandle columnFamilyHandle
,
274 final ReadOptions readOptions
, final byte[] key
) throws RocksDBException
{
275 assert(isOwningHandle());
276 return get(nativeHandle_
, readOptions
.nativeHandle_
, key
, key
.length
,
277 columnFamilyHandle
.nativeHandle_
);
281 * This function is similar to
282 * {@link RocksDB#get(ReadOptions, byte[])} except it will
283 * also read pending changes in this transaction.
284 * Currently, this function will return Status::MergeInProgress if the most
285 * recent write to the queried key in this batch is a Merge.
287 * If {@link ReadOptions#snapshot()} is not set, the current version of the
288 * key will be read. Calling {@link #setSnapshot()} does not affect the
289 * version of the data returned.
291 * Note that setting {@link ReadOptions#setSnapshot(Snapshot)} will affect
292 * what is read from the DB but will NOT change which keys are read from this
293 * transaction (the keys in this transaction do not yet belong to any snapshot
294 * and will be fetched regardless).
296 * @param readOptions Read options.
297 * @param key the key to retrieve the value for.
299 * @return a byte array storing the value associated with the input key if
300 * any. null if it does not find the specified key.
302 * @throws RocksDBException thrown if error happens in underlying native
305 public byte[] get(final ReadOptions readOptions
, final byte[] key
)
306 throws RocksDBException
{
307 assert(isOwningHandle());
308 return get(nativeHandle_
, readOptions
.nativeHandle_
, key
, key
.length
);
312 * This function is similar to
313 * {@link RocksDB#multiGet(ReadOptions, List, List)} except it will
314 * also read pending changes in this transaction.
315 * Currently, this function will return Status::MergeInProgress if the most
316 * recent write to the queried key in this batch is a Merge.
318 * If {@link ReadOptions#snapshot()} is not set, the current version of the
319 * key will be read. Calling {@link #setSnapshot()} does not affect the
320 * version of the data returned.
322 * Note that setting {@link ReadOptions#setSnapshot(Snapshot)} will affect
323 * what is read from the DB but will NOT change which keys are read from this
324 * transaction (the keys in this transaction do not yet belong to any snapshot
325 * and will be fetched regardless).
327 * @param readOptions Read options.
328 * @param columnFamilyHandles {@link java.util.List} containing
329 * {@link org.rocksdb.ColumnFamilyHandle} instances.
330 * @param keys of keys for which values need to be retrieved.
332 * @return Array of values, one for each key
334 * @throws RocksDBException thrown if error happens in underlying
336 * @throws IllegalArgumentException thrown if the size of passed keys is not
337 * equal to the amount of passed column family handles.
339 public byte[][] multiGet(final ReadOptions readOptions
,
340 final List
<ColumnFamilyHandle
> columnFamilyHandles
,
341 final byte[][] keys
) throws RocksDBException
{
342 assert(isOwningHandle());
343 // Check if key size equals cfList size. If not a exception must be
344 // thrown. If not a Segmentation fault happens.
345 if (keys
.length
!= columnFamilyHandles
.size()) {
346 throw new IllegalArgumentException(
347 "For each key there must be a ColumnFamilyHandle.");
349 if(keys
.length
== 0) {
350 return new byte[0][0];
352 final long[] cfHandles
= new long[columnFamilyHandles
.size()];
353 for (int i
= 0; i
< columnFamilyHandles
.size(); i
++) {
354 cfHandles
[i
] = columnFamilyHandles
.get(i
).nativeHandle_
;
357 return multiGet(nativeHandle_
, readOptions
.nativeHandle_
,
362 * This function is similar to
363 * {@link RocksDB#multiGet(ReadOptions, List)} except it will
364 * also read pending changes in this transaction.
365 * Currently, this function will return Status::MergeInProgress if the most
366 * recent write to the queried key in this batch is a Merge.
368 * If {@link ReadOptions#snapshot()} is not set, the current version of the
369 * key will be read. Calling {@link #setSnapshot()} does not affect the
370 * version of the data returned.
372 * Note that setting {@link ReadOptions#setSnapshot(Snapshot)} will affect
373 * what is read from the DB but will NOT change which keys are read from this
374 * transaction (the keys in this transaction do not yet belong to any snapshot
375 * and will be fetched regardless).
377 * @param readOptions Read options.=
378 * {@link org.rocksdb.ColumnFamilyHandle} instances.
379 * @param keys of keys for which values need to be retrieved.
381 * @return Array of values, one for each key
383 * @throws RocksDBException thrown if error happens in underlying
386 public byte[][] multiGet(final ReadOptions readOptions
,
387 final byte[][] keys
) throws RocksDBException
{
388 assert(isOwningHandle());
389 if(keys
.length
== 0) {
390 return new byte[0][0];
393 return multiGet(nativeHandle_
, readOptions
.nativeHandle_
,
398 * Read this key and ensure that this transaction will only
399 * be able to be committed if this key is not written outside this
400 * transaction after it has first been read (or after the snapshot if a
401 * snapshot is set in this transaction). The transaction behavior is the
402 * same regardless of whether the key exists or not.
404 * Note: Currently, this function will return Status::MergeInProgress
405 * if the most recent write to the queried key in this batch is a Merge.
407 * The values returned by this function are similar to
408 * {@link RocksDB#get(ColumnFamilyHandle, ReadOptions, byte[])}.
409 * If value==nullptr, then this function will not read any data, but will
410 * still ensure that this key cannot be written to by outside of this
413 * If this transaction was created by an {@link OptimisticTransactionDB},
414 * {@link #getForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean)}
415 * could cause {@link #commit()} to fail. Otherwise, it could return any error
416 * that could be returned by
417 * {@link RocksDB#get(ColumnFamilyHandle, ReadOptions, byte[])}.
419 * If this transaction was created on a {@link TransactionDB}, an
420 * {@link RocksDBException} may be thrown with an accompanying {@link Status}
422 * {@link Status.Code#Busy} if there is a write conflict,
423 * {@link Status.Code#TimedOut} if a lock could not be acquired,
424 * {@link Status.Code#TryAgain} if the memtable history size is not large
426 * {@link ColumnFamilyOptions#maxWriteBufferNumberToMaintain()}
427 * {@link Status.Code#MergeInProgress} if merge operations cannot be
430 * @param readOptions Read options.
431 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
433 * @param key the key to retrieve the value for.
434 * @param exclusive true if the transaction should have exclusive access to
435 * the key, otherwise false for shared access.
436 * @param do_validate true if it should validate the snapshot before doing the read
438 * @return a byte array storing the value associated with the input key if
439 * any. null if it does not find the specified key.
441 * @throws RocksDBException thrown if error happens in underlying
444 public byte[] getForUpdate(final ReadOptions readOptions
,
445 final ColumnFamilyHandle columnFamilyHandle
, final byte[] key
, final boolean exclusive
,
446 final boolean do_validate
) throws RocksDBException
{
447 assert (isOwningHandle());
448 return getForUpdate(nativeHandle_
, readOptions
.nativeHandle_
, key
, key
.length
,
449 columnFamilyHandle
.nativeHandle_
, exclusive
, do_validate
);
454 * {@link #getForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean, boolean)}
455 * with do_validate=true.
457 * @param readOptions Read options.
458 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
460 * @param key the key to retrieve the value for.
461 * @param exclusive true if the transaction should have exclusive access to
462 * the key, otherwise false for shared access.
464 * @return a byte array storing the value associated with the input key if
465 * any. null if it does not find the specified key.
467 * @throws RocksDBException thrown if error happens in underlying
470 public byte[] getForUpdate(final ReadOptions readOptions
,
471 final ColumnFamilyHandle columnFamilyHandle
, final byte[] key
,
472 final boolean exclusive
) throws RocksDBException
{
473 assert(isOwningHandle());
474 return getForUpdate(nativeHandle_
, readOptions
.nativeHandle_
, key
, key
.length
,
475 columnFamilyHandle
.nativeHandle_
, exclusive
, true /*do_validate*/);
479 * Read this key and ensure that this transaction will only
480 * be able to be committed if this key is not written outside this
481 * transaction after it has first been read (or after the snapshot if a
482 * snapshot is set in this transaction). The transaction behavior is the
483 * same regardless of whether the key exists or not.
485 * Note: Currently, this function will return Status::MergeInProgress
486 * if the most recent write to the queried key in this batch is a Merge.
488 * The values returned by this function are similar to
489 * {@link RocksDB#get(ReadOptions, byte[])}.
490 * If value==nullptr, then this function will not read any data, but will
491 * still ensure that this key cannot be written to by outside of this
494 * If this transaction was created on an {@link OptimisticTransactionDB},
495 * {@link #getForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean)}
496 * could cause {@link #commit()} to fail. Otherwise, it could return any error
497 * that could be returned by
498 * {@link RocksDB#get(ReadOptions, byte[])}.
500 * If this transaction was created on a {@link TransactionDB}, an
501 * {@link RocksDBException} may be thrown with an accompanying {@link Status}
503 * {@link Status.Code#Busy} if there is a write conflict,
504 * {@link Status.Code#TimedOut} if a lock could not be acquired,
505 * {@link Status.Code#TryAgain} if the memtable history size is not large
507 * {@link ColumnFamilyOptions#maxWriteBufferNumberToMaintain()}
508 * {@link Status.Code#MergeInProgress} if merge operations cannot be
511 * @param readOptions Read options.
512 * @param key the key to retrieve the value for.
513 * @param exclusive true if the transaction should have exclusive access to
514 * the key, otherwise false for shared access.
516 * @return a byte array storing the value associated with the input key if
517 * any. null if it does not find the specified key.
519 * @throws RocksDBException thrown if error happens in underlying
522 public byte[] getForUpdate(final ReadOptions readOptions
, final byte[] key
,
523 final boolean exclusive
) throws RocksDBException
{
524 assert(isOwningHandle());
526 nativeHandle_
, readOptions
.nativeHandle_
, key
, key
.length
, exclusive
, true /*do_validate*/);
530 * A multi-key version of
531 * {@link #getForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean)}.
534 * @param readOptions Read options.
535 * @param columnFamilyHandles {@link org.rocksdb.ColumnFamilyHandle}
537 * @param keys the keys to retrieve the values for.
539 * @return Array of values, one for each key
541 * @throws RocksDBException thrown if error happens in underlying
544 public byte[][] multiGetForUpdate(final ReadOptions readOptions
,
545 final List
<ColumnFamilyHandle
> columnFamilyHandles
,
546 final byte[][] keys
) throws RocksDBException
{
547 assert(isOwningHandle());
548 // Check if key size equals cfList size. If not a exception must be
549 // thrown. If not a Segmentation fault happens.
550 if (keys
.length
!= columnFamilyHandles
.size()){
551 throw new IllegalArgumentException(
552 "For each key there must be a ColumnFamilyHandle.");
554 if(keys
.length
== 0) {
555 return new byte[0][0];
557 final long[] cfHandles
= new long[columnFamilyHandles
.size()];
558 for (int i
= 0; i
< columnFamilyHandles
.size(); i
++) {
559 cfHandles
[i
] = columnFamilyHandles
.get(i
).nativeHandle_
;
561 return multiGetForUpdate(nativeHandle_
, readOptions
.nativeHandle_
,
566 * A multi-key version of {@link #getForUpdate(ReadOptions, byte[], boolean)}.
569 * @param readOptions Read options.
570 * @param keys the keys to retrieve the values for.
572 * @return Array of values, one for each key
574 * @throws RocksDBException thrown if error happens in underlying
577 public byte[][] multiGetForUpdate(final ReadOptions readOptions
,
578 final byte[][] keys
) throws RocksDBException
{
579 assert(isOwningHandle());
580 if(keys
.length
== 0) {
581 return new byte[0][0];
584 return multiGetForUpdate(nativeHandle_
,
585 readOptions
.nativeHandle_
, keys
);
589 * Returns an iterator that will iterate on all keys in the default
590 * column family including both keys in the DB and uncommitted keys in this
593 * Setting {@link ReadOptions#setSnapshot(Snapshot)} will affect what is read
594 * from the DB but will NOT change which keys are read from this transaction
595 * (the keys in this transaction do not yet belong to any snapshot and will be
596 * fetched regardless).
598 * Caller is responsible for deleting the returned Iterator.
600 * The returned iterator is only valid until {@link #commit()},
601 * {@link #rollback()}, or {@link #rollbackToSavePoint()} is called.
603 * @param readOptions Read options.
605 * @return instance of iterator object.
607 public RocksIterator
getIterator(final ReadOptions readOptions
) {
608 assert(isOwningHandle());
609 return new RocksIterator(parent
, getIterator(nativeHandle_
,
610 readOptions
.nativeHandle_
));
614 * Returns an iterator that will iterate on all keys in the default
615 * column family including both keys in the DB and uncommitted keys in this
618 * Setting {@link ReadOptions#setSnapshot(Snapshot)} will affect what is read
619 * from the DB but will NOT change which keys are read from this transaction
620 * (the keys in this transaction do not yet belong to any snapshot and will be
621 * fetched regardless).
623 * Caller is responsible for calling {@link RocksIterator#close()} on
624 * the returned Iterator.
626 * The returned iterator is only valid until {@link #commit()},
627 * {@link #rollback()}, or {@link #rollbackToSavePoint()} is called.
629 * @param readOptions Read options.
630 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
633 * @return instance of iterator object.
635 public RocksIterator
getIterator(final ReadOptions readOptions
,
636 final ColumnFamilyHandle columnFamilyHandle
) {
637 assert(isOwningHandle());
638 return new RocksIterator(parent
, getIterator(nativeHandle_
,
639 readOptions
.nativeHandle_
, columnFamilyHandle
.nativeHandle_
));
643 * Similar to {@link RocksDB#put(ColumnFamilyHandle, byte[], byte[])}, but
644 * will also perform conflict checking on the keys be written.
646 * If this Transaction was created on an {@link OptimisticTransactionDB},
647 * these functions should always succeed.
649 * If this Transaction was created on a {@link TransactionDB}, an
650 * {@link RocksDBException} may be thrown with an accompanying {@link Status}
652 * {@link Status.Code#Busy} if there is a write conflict,
653 * {@link Status.Code#TimedOut} if a lock could not be acquired,
654 * {@link Status.Code#TryAgain} if the memtable history size is not large
656 * {@link ColumnFamilyOptions#maxWriteBufferNumberToMaintain()}
658 * @param columnFamilyHandle The column family to put the key/value into
659 * @param key the specified key to be inserted.
660 * @param value the value associated with the specified key.
662 * @throws RocksDBException when one of the TransactionalDB conditions
663 * described above occurs, or in the case of an unexpected error
665 public void put(final ColumnFamilyHandle columnFamilyHandle
, final byte[] key
, final byte[] value
,
666 final boolean assume_tracked
) throws RocksDBException
{
667 assert (isOwningHandle());
668 put(nativeHandle_
, key
, key
.length
, value
, value
.length
, columnFamilyHandle
.nativeHandle_
,
674 * {@link #put(ColumnFamilyHandle, byte[], byte[], boolean)}
675 * with assume_tracked=false.
677 public void put(final ColumnFamilyHandle columnFamilyHandle
, final byte[] key
,
678 final byte[] value
) throws RocksDBException
{
679 assert(isOwningHandle());
680 put(nativeHandle_
, key
, key
.length
, value
, value
.length
, columnFamilyHandle
.nativeHandle_
,
681 /*assume_tracked*/ false);
685 * Similar to {@link RocksDB#put(byte[], byte[])}, but
686 * will also perform conflict checking on the keys be written.
688 * If this Transaction was created on an {@link OptimisticTransactionDB},
689 * these functions should always succeed.
691 * If this Transaction was created on a {@link TransactionDB}, an
692 * {@link RocksDBException} may be thrown with an accompanying {@link Status}
694 * {@link Status.Code#Busy} if there is a write conflict,
695 * {@link Status.Code#TimedOut} if a lock could not be acquired,
696 * {@link Status.Code#TryAgain} if the memtable history size is not large
698 * {@link ColumnFamilyOptions#maxWriteBufferNumberToMaintain()}
700 * @param key the specified key to be inserted.
701 * @param value the value associated with the specified key.
703 * @throws RocksDBException when one of the TransactionalDB conditions
704 * described above occurs, or in the case of an unexpected error
706 public void put(final byte[] key
, final byte[] value
)
707 throws RocksDBException
{
708 assert(isOwningHandle());
709 put(nativeHandle_
, key
, key
.length
, value
, value
.length
);
712 //TODO(AR) refactor if we implement org.rocksdb.SliceParts in future
714 * Similar to {@link #put(ColumnFamilyHandle, byte[], byte[])} but allows
715 * you to specify the key and value in several parts that will be
716 * concatenated together.
718 * @param columnFamilyHandle The column family to put the key/value into
719 * @param keyParts the specified key to be inserted.
720 * @param valueParts the value associated with the specified key.
722 * @throws RocksDBException when one of the TransactionalDB conditions
723 * described above occurs, or in the case of an unexpected error
725 public void put(final ColumnFamilyHandle columnFamilyHandle
, final byte[][] keyParts
,
726 final byte[][] valueParts
, final boolean assume_tracked
) throws RocksDBException
{
727 assert (isOwningHandle());
728 put(nativeHandle_
, keyParts
, keyParts
.length
, valueParts
, valueParts
.length
,
729 columnFamilyHandle
.nativeHandle_
, assume_tracked
);
734 * {@link #put(ColumnFamilyHandle, byte[][], byte[][], boolean)}
735 * with assume_tracked=false.
737 public void put(final ColumnFamilyHandle columnFamilyHandle
,
738 final byte[][] keyParts
, final byte[][] valueParts
)
739 throws RocksDBException
{
740 assert(isOwningHandle());
741 put(nativeHandle_
, keyParts
, keyParts
.length
, valueParts
, valueParts
.length
,
742 columnFamilyHandle
.nativeHandle_
, /*assume_tracked*/ false);
745 //TODO(AR) refactor if we implement org.rocksdb.SliceParts in future
747 * Similar to {@link #put(byte[], byte[])} but allows
748 * you to specify the key and value in several parts that will be
749 * concatenated together
751 * @param keyParts the specified key to be inserted.
752 * @param valueParts the value associated with the specified key.
754 * @throws RocksDBException when one of the TransactionalDB conditions
755 * described above occurs, or in the case of an unexpected error
757 public void put(final byte[][] keyParts
, final byte[][] valueParts
)
758 throws RocksDBException
{
759 assert(isOwningHandle());
760 put(nativeHandle_
, keyParts
, keyParts
.length
, valueParts
,
765 * Similar to {@link RocksDB#merge(ColumnFamilyHandle, byte[], byte[])}, but
766 * will also perform conflict checking on the keys be written.
768 * If this Transaction was created on an {@link OptimisticTransactionDB},
769 * these functions should always succeed.
771 * If this Transaction was created on a {@link TransactionDB}, an
772 * {@link RocksDBException} may be thrown with an accompanying {@link Status}
774 * {@link Status.Code#Busy} if there is a write conflict,
775 * {@link Status.Code#TimedOut} if a lock could not be acquired,
776 * {@link Status.Code#TryAgain} if the memtable history size is not large
778 * {@link ColumnFamilyOptions#maxWriteBufferNumberToMaintain()}
780 * @param columnFamilyHandle The column family to merge the key/value into
781 * @param key the specified key to be merged.
782 * @param value the value associated with the specified key.
784 * @throws RocksDBException when one of the TransactionalDB conditions
785 * described above occurs, or in the case of an unexpected error
787 public void merge(final ColumnFamilyHandle columnFamilyHandle
, final byte[] key
,
788 final byte[] value
, final boolean assume_tracked
) throws RocksDBException
{
789 assert (isOwningHandle());
790 merge(nativeHandle_
, key
, key
.length
, value
, value
.length
, columnFamilyHandle
.nativeHandle_
,
796 * {@link #merge(ColumnFamilyHandle, byte[], byte[], boolean)}
797 * with assume_tracked=false.
799 public void merge(final ColumnFamilyHandle columnFamilyHandle
,
800 final byte[] key
, final byte[] value
) throws RocksDBException
{
801 assert(isOwningHandle());
802 merge(nativeHandle_
, key
, key
.length
, value
, value
.length
, columnFamilyHandle
.nativeHandle_
,
803 /*assume_tracked*/ false);
807 * Similar to {@link RocksDB#merge(byte[], byte[])}, but
808 * will also perform conflict checking on the keys be written.
810 * If this Transaction was created on an {@link OptimisticTransactionDB},
811 * these functions should always succeed.
813 * If this Transaction was created on a {@link TransactionDB}, an
814 * {@link RocksDBException} may be thrown with an accompanying {@link Status}
816 * {@link Status.Code#Busy} if there is a write conflict,
817 * {@link Status.Code#TimedOut} if a lock could not be acquired,
818 * {@link Status.Code#TryAgain} if the memtable history size is not large
820 * {@link ColumnFamilyOptions#maxWriteBufferNumberToMaintain()}
822 * @param key the specified key to be merged.
823 * @param value the value associated with the specified key.
825 * @throws RocksDBException when one of the TransactionalDB conditions
826 * described above occurs, or in the case of an unexpected error
828 public void merge(final byte[] key
, final byte[] value
)
829 throws RocksDBException
{
830 assert(isOwningHandle());
831 merge(nativeHandle_
, key
, key
.length
, value
, value
.length
);
835 * Similar to {@link RocksDB#delete(ColumnFamilyHandle, byte[])}, but
836 * will also perform conflict checking on the keys be written.
838 * If this Transaction was created on an {@link OptimisticTransactionDB},
839 * these functions should always succeed.
841 * If this Transaction was created on a {@link TransactionDB}, an
842 * {@link RocksDBException} may be thrown with an accompanying {@link Status}
844 * {@link Status.Code#Busy} if there is a write conflict,
845 * {@link Status.Code#TimedOut} if a lock could not be acquired,
846 * {@link Status.Code#TryAgain} if the memtable history size is not large
848 * {@link ColumnFamilyOptions#maxWriteBufferNumberToMaintain()}
850 * @param columnFamilyHandle The column family to delete the key/value from
851 * @param key the specified key to be deleted.
853 * @throws RocksDBException when one of the TransactionalDB conditions
854 * described above occurs, or in the case of an unexpected error
856 public void delete(final ColumnFamilyHandle columnFamilyHandle
, final byte[] key
,
857 final boolean assume_tracked
) throws RocksDBException
{
858 assert (isOwningHandle());
859 delete(nativeHandle_
, key
, key
.length
, columnFamilyHandle
.nativeHandle_
, assume_tracked
);
864 * {@link #delete(ColumnFamilyHandle, byte[], boolean)}
865 * with assume_tracked=false.
867 public void delete(final ColumnFamilyHandle columnFamilyHandle
,
868 final byte[] key
) throws RocksDBException
{
869 assert(isOwningHandle());
870 delete(nativeHandle_
, key
, key
.length
, columnFamilyHandle
.nativeHandle_
,
871 /*assume_tracked*/ false);
875 * Similar to {@link RocksDB#delete(byte[])}, but
876 * will also perform conflict checking on the keys be written.
878 * If this Transaction was created on an {@link OptimisticTransactionDB},
879 * these functions should always succeed.
881 * If this Transaction was created on a {@link TransactionDB}, an
882 * {@link RocksDBException} may be thrown with an accompanying {@link Status}
884 * {@link Status.Code#Busy} if there is a write conflict,
885 * {@link Status.Code#TimedOut} if a lock could not be acquired,
886 * {@link Status.Code#TryAgain} if the memtable history size is not large
888 * {@link ColumnFamilyOptions#maxWriteBufferNumberToMaintain()}
890 * @param key the specified key to be deleted.
892 * @throws RocksDBException when one of the TransactionalDB conditions
893 * described above occurs, or in the case of an unexpected error
895 public void delete(final byte[] key
) throws RocksDBException
{
896 assert(isOwningHandle());
897 delete(nativeHandle_
, key
, key
.length
);
900 //TODO(AR) refactor if we implement org.rocksdb.SliceParts in future
902 * Similar to {@link #delete(ColumnFamilyHandle, byte[])} but allows
903 * you to specify the key in several parts that will be
904 * concatenated together.
906 * @param columnFamilyHandle The column family to delete the key/value from
907 * @param keyParts the specified key to be deleted.
909 * @throws RocksDBException when one of the TransactionalDB conditions
910 * described above occurs, or in the case of an unexpected error
912 public void delete(final ColumnFamilyHandle columnFamilyHandle
, final byte[][] keyParts
,
913 final boolean assume_tracked
) throws RocksDBException
{
914 assert (isOwningHandle());
916 nativeHandle_
, keyParts
, keyParts
.length
, columnFamilyHandle
.nativeHandle_
, assume_tracked
);
921 * {@link #delete(ColumnFamilyHandle, byte[][], boolean)}
922 * with assume_tracked=false.
924 public void delete(final ColumnFamilyHandle columnFamilyHandle
,
925 final byte[][] keyParts
) throws RocksDBException
{
926 assert(isOwningHandle());
927 delete(nativeHandle_
, keyParts
, keyParts
.length
, columnFamilyHandle
.nativeHandle_
,
928 /*assume_tracked*/ false);
931 //TODO(AR) refactor if we implement org.rocksdb.SliceParts in future
933 * Similar to {@link #delete(byte[])} but allows
934 * you to specify key the in several parts that will be
935 * concatenated together.
937 * @param keyParts the specified key to be deleted
939 * @throws RocksDBException when one of the TransactionalDB conditions
940 * described above occurs, or in the case of an unexpected error
942 public void delete(final byte[][] keyParts
) throws RocksDBException
{
943 assert(isOwningHandle());
944 delete(nativeHandle_
, keyParts
, keyParts
.length
);
948 * Similar to {@link RocksDB#singleDelete(ColumnFamilyHandle, byte[])}, but
949 * will also perform conflict checking on the keys be written.
951 * If this Transaction was created on an {@link OptimisticTransactionDB},
952 * these functions should always succeed.
954 * If this Transaction was created on a {@link TransactionDB}, an
955 * {@link RocksDBException} may be thrown with an accompanying {@link Status}
957 * {@link Status.Code#Busy} if there is a write conflict,
958 * {@link Status.Code#TimedOut} if a lock could not be acquired,
959 * {@link Status.Code#TryAgain} if the memtable history size is not large
961 * {@link ColumnFamilyOptions#maxWriteBufferNumberToMaintain()}
963 * @param columnFamilyHandle The column family to delete the key/value from
964 * @param key the specified key to be deleted.
966 * @throws RocksDBException when one of the TransactionalDB conditions
967 * described above occurs, or in the case of an unexpected error
969 @Experimental("Performance optimization for a very specific workload")
970 public void singleDelete(final ColumnFamilyHandle columnFamilyHandle
, final byte[] key
,
971 final boolean assume_tracked
) throws RocksDBException
{
972 assert (isOwningHandle());
973 singleDelete(nativeHandle_
, key
, key
.length
, columnFamilyHandle
.nativeHandle_
, assume_tracked
);
978 * {@link #singleDelete(ColumnFamilyHandle, byte[], boolean)}
979 * with assume_tracked=false.
981 @Experimental("Performance optimization for a very specific workload")
982 public void singleDelete(final ColumnFamilyHandle columnFamilyHandle
, final byte[] key
)
983 throws RocksDBException
{
984 assert(isOwningHandle());
985 singleDelete(nativeHandle_
, key
, key
.length
, columnFamilyHandle
.nativeHandle_
,
986 /*assume_tracked*/ false);
990 * Similar to {@link RocksDB#singleDelete(byte[])}, but
991 * will also perform conflict checking on the keys be written.
993 * If this Transaction was created on an {@link OptimisticTransactionDB},
994 * these functions should always succeed.
996 * If this Transaction was created on a {@link TransactionDB}, an
997 * {@link RocksDBException} may be thrown with an accompanying {@link Status}
999 * {@link Status.Code#Busy} if there is a write conflict,
1000 * {@link Status.Code#TimedOut} if a lock could not be acquired,
1001 * {@link Status.Code#TryAgain} if the memtable history size is not large
1003 * {@link ColumnFamilyOptions#maxWriteBufferNumberToMaintain()}
1005 * @param key the specified key to be deleted.
1007 * @throws RocksDBException when one of the TransactionalDB conditions
1008 * described above occurs, or in the case of an unexpected error
1010 @Experimental("Performance optimization for a very specific workload")
1011 public void singleDelete(final byte[] key
) throws RocksDBException
{
1012 assert(isOwningHandle());
1013 singleDelete(nativeHandle_
, key
, key
.length
);
1016 //TODO(AR) refactor if we implement org.rocksdb.SliceParts in future
1018 * Similar to {@link #singleDelete(ColumnFamilyHandle, byte[])} but allows
1019 * you to specify the key in several parts that will be
1020 * concatenated together.
1022 * @param columnFamilyHandle The column family to delete the key/value from
1023 * @param keyParts the specified key to be deleted.
1025 * @throws RocksDBException when one of the TransactionalDB conditions
1026 * described above occurs, or in the case of an unexpected error
1028 @Experimental("Performance optimization for a very specific workload")
1029 public void singleDelete(final ColumnFamilyHandle columnFamilyHandle
, final byte[][] keyParts
,
1030 final boolean assume_tracked
) throws RocksDBException
{
1031 assert (isOwningHandle());
1033 nativeHandle_
, keyParts
, keyParts
.length
, columnFamilyHandle
.nativeHandle_
, assume_tracked
);
1038 * {@link #singleDelete(ColumnFamilyHandle, byte[][], boolean)}
1039 * with assume_tracked=false.
1041 @Experimental("Performance optimization for a very specific workload")
1042 public void singleDelete(final ColumnFamilyHandle columnFamilyHandle
, final byte[][] keyParts
)
1043 throws RocksDBException
{
1044 assert(isOwningHandle());
1045 singleDelete(nativeHandle_
, keyParts
, keyParts
.length
, columnFamilyHandle
.nativeHandle_
,
1046 /*assume_tracked*/ false);
1049 //TODO(AR) refactor if we implement org.rocksdb.SliceParts in future
1051 * Similar to {@link #singleDelete(byte[])} but allows
1052 * you to specify the key in several parts that will be
1053 * concatenated together.
1055 * @param keyParts the specified key to be deleted.
1057 * @throws RocksDBException when one of the TransactionalDB conditions
1058 * described above occurs, or in the case of an unexpected error
1060 @Experimental("Performance optimization for a very specific workload")
1061 public void singleDelete(final byte[][] keyParts
) throws RocksDBException
{
1062 assert(isOwningHandle());
1063 singleDelete(nativeHandle_
, keyParts
, keyParts
.length
);
1067 * Similar to {@link RocksDB#put(ColumnFamilyHandle, byte[], byte[])},
1068 * but operates on the transactions write batch. This write will only happen
1069 * if this transaction gets committed successfully.
1071 * Unlike {@link #put(ColumnFamilyHandle, byte[], byte[])} no conflict
1072 * checking will be performed for this key.
1074 * If this Transaction was created on a {@link TransactionDB}, this function
1075 * will still acquire locks necessary to make sure this write doesn't cause
1076 * conflicts in other transactions; This may cause a {@link RocksDBException}
1077 * with associated {@link Status.Code#Busy}.
1079 * @param columnFamilyHandle The column family to put the key/value into
1080 * @param key the specified key to be inserted.
1081 * @param value the value associated with the specified key.
1083 * @throws RocksDBException when one of the TransactionalDB conditions
1084 * described above occurs, or in the case of an unexpected error
1086 public void putUntracked(final ColumnFamilyHandle columnFamilyHandle
,
1087 final byte[] key
, final byte[] value
) throws RocksDBException
{
1088 assert(isOwningHandle());
1089 putUntracked(nativeHandle_
, key
, key
.length
, value
, value
.length
,
1090 columnFamilyHandle
.nativeHandle_
);
1094 * Similar to {@link RocksDB#put(byte[], byte[])},
1095 * but operates on the transactions write batch. This write will only happen
1096 * if this transaction gets committed successfully.
1098 * Unlike {@link #put(byte[], byte[])} no conflict
1099 * checking will be performed for this key.
1101 * If this Transaction was created on a {@link TransactionDB}, this function
1102 * will still acquire locks necessary to make sure this write doesn't cause
1103 * conflicts in other transactions; This may cause a {@link RocksDBException}
1104 * with associated {@link Status.Code#Busy}.
1106 * @param key the specified key to be inserted.
1107 * @param value the value associated with the specified key.
1109 * @throws RocksDBException when one of the TransactionalDB conditions
1110 * described above occurs, or in the case of an unexpected error
1112 public void putUntracked(final byte[] key
, final byte[] value
)
1113 throws RocksDBException
{
1114 assert(isOwningHandle());
1115 putUntracked(nativeHandle_
, key
, key
.length
, value
, value
.length
);
1118 //TODO(AR) refactor if we implement org.rocksdb.SliceParts in future
1120 * Similar to {@link #putUntracked(ColumnFamilyHandle, byte[], byte[])} but
1121 * allows you to specify the key and value in several parts that will be
1122 * concatenated together.
1124 * @param columnFamilyHandle The column family to put the key/value into
1125 * @param keyParts the specified key to be inserted.
1126 * @param valueParts the value associated with the specified key.
1128 * @throws RocksDBException when one of the TransactionalDB conditions
1129 * described above occurs, or in the case of an unexpected error
1131 public void putUntracked(final ColumnFamilyHandle columnFamilyHandle
,
1132 final byte[][] keyParts
, final byte[][] valueParts
)
1133 throws RocksDBException
{
1134 assert(isOwningHandle());
1135 putUntracked(nativeHandle_
, keyParts
, keyParts
.length
, valueParts
,
1136 valueParts
.length
, columnFamilyHandle
.nativeHandle_
);
1139 //TODO(AR) refactor if we implement org.rocksdb.SliceParts in future
1141 * Similar to {@link #putUntracked(byte[], byte[])} but
1142 * allows you to specify the key and value in several parts that will be
1143 * concatenated together.
1145 * @param keyParts the specified key to be inserted.
1146 * @param valueParts the value associated with the specified key.
1148 * @throws RocksDBException when one of the TransactionalDB conditions
1149 * described above occurs, or in the case of an unexpected error
1151 public void putUntracked(final byte[][] keyParts
, final byte[][] valueParts
)
1152 throws RocksDBException
{
1153 assert(isOwningHandle());
1154 putUntracked(nativeHandle_
, keyParts
, keyParts
.length
, valueParts
,
1159 * Similar to {@link RocksDB#merge(ColumnFamilyHandle, byte[], byte[])},
1160 * but operates on the transactions write batch. This write will only happen
1161 * if this transaction gets committed successfully.
1163 * Unlike {@link #merge(ColumnFamilyHandle, byte[], byte[])} no conflict
1164 * checking will be performed for this key.
1166 * If this Transaction was created on a {@link TransactionDB}, this function
1167 * will still acquire locks necessary to make sure this write doesn't cause
1168 * conflicts in other transactions; This may cause a {@link RocksDBException}
1169 * with associated {@link Status.Code#Busy}.
1171 * @param columnFamilyHandle The column family to merge the key/value into
1172 * @param key the specified key to be merged.
1173 * @param value the value associated with the specified key.
1175 * @throws RocksDBException when one of the TransactionalDB conditions
1176 * described above occurs, or in the case of an unexpected error
1178 public void mergeUntracked(final ColumnFamilyHandle columnFamilyHandle
,
1179 final byte[] key
, final byte[] value
) throws RocksDBException
{
1180 mergeUntracked(nativeHandle_
, key
, key
.length
, value
, value
.length
,
1181 columnFamilyHandle
.nativeHandle_
);
1185 * Similar to {@link RocksDB#merge(byte[], byte[])},
1186 * but operates on the transactions write batch. This write will only happen
1187 * if this transaction gets committed successfully.
1189 * Unlike {@link #merge(byte[], byte[])} no conflict
1190 * checking will be performed for this key.
1192 * If this Transaction was created on a {@link TransactionDB}, this function
1193 * will still acquire locks necessary to make sure this write doesn't cause
1194 * conflicts in other transactions; This may cause a {@link RocksDBException}
1195 * with associated {@link Status.Code#Busy}.
1197 * @param key the specified key to be merged.
1198 * @param value the value associated with the specified key.
1200 * @throws RocksDBException when one of the TransactionalDB conditions
1201 * described above occurs, or in the case of an unexpected error
1203 public void mergeUntracked(final byte[] key
, final byte[] value
)
1204 throws RocksDBException
{
1205 assert(isOwningHandle());
1206 mergeUntracked(nativeHandle_
, key
, key
.length
, value
, value
.length
);
1210 * Similar to {@link RocksDB#delete(ColumnFamilyHandle, byte[])},
1211 * but operates on the transactions write batch. This write will only happen
1212 * if this transaction gets committed successfully.
1214 * Unlike {@link #delete(ColumnFamilyHandle, byte[])} no conflict
1215 * checking will be performed for this key.
1217 * If this Transaction was created on a {@link TransactionDB}, this function
1218 * will still acquire locks necessary to make sure this write doesn't cause
1219 * conflicts in other transactions; This may cause a {@link RocksDBException}
1220 * with associated {@link Status.Code#Busy}.
1222 * @param columnFamilyHandle The column family to delete the key/value from
1223 * @param key the specified key to be deleted.
1225 * @throws RocksDBException when one of the TransactionalDB conditions
1226 * described above occurs, or in the case of an unexpected error
1228 public void deleteUntracked(final ColumnFamilyHandle columnFamilyHandle
,
1229 final byte[] key
) throws RocksDBException
{
1230 assert(isOwningHandle());
1231 deleteUntracked(nativeHandle_
, key
, key
.length
,
1232 columnFamilyHandle
.nativeHandle_
);
1236 * Similar to {@link RocksDB#delete(byte[])},
1237 * but operates on the transactions write batch. This write will only happen
1238 * if this transaction gets committed successfully.
1240 * Unlike {@link #delete(byte[])} no conflict
1241 * checking will be performed for this key.
1243 * If this Transaction was created on a {@link TransactionDB}, this function
1244 * will still acquire locks necessary to make sure this write doesn't cause
1245 * conflicts in other transactions; This may cause a {@link RocksDBException}
1246 * with associated {@link Status.Code#Busy}.
1248 * @param key the specified key to be deleted.
1250 * @throws RocksDBException when one of the TransactionalDB conditions
1251 * described above occurs, or in the case of an unexpected error
1253 public void deleteUntracked(final byte[] key
) throws RocksDBException
{
1254 assert(isOwningHandle());
1255 deleteUntracked(nativeHandle_
, key
, key
.length
);
1258 //TODO(AR) refactor if we implement org.rocksdb.SliceParts in future
1260 * Similar to {@link #deleteUntracked(ColumnFamilyHandle, byte[])} but allows
1261 * you to specify the key in several parts that will be
1262 * concatenated together.
1264 * @param columnFamilyHandle The column family to delete the key/value from
1265 * @param keyParts the specified key to be deleted.
1267 * @throws RocksDBException when one of the TransactionalDB conditions
1268 * described above occurs, or in the case of an unexpected error
1270 public void deleteUntracked(final ColumnFamilyHandle columnFamilyHandle
,
1271 final byte[][] keyParts
) throws RocksDBException
{
1272 assert(isOwningHandle());
1273 deleteUntracked(nativeHandle_
, keyParts
, keyParts
.length
,
1274 columnFamilyHandle
.nativeHandle_
);
1277 //TODO(AR) refactor if we implement org.rocksdb.SliceParts in future
1279 * Similar to {@link #deleteUntracked(byte[])} but allows
1280 * you to specify the key in several parts that will be
1281 * concatenated together.
1283 * @param keyParts the specified key to be deleted.
1285 * @throws RocksDBException when one of the TransactionalDB conditions
1286 * described above occurs, or in the case of an unexpected error
1288 public void deleteUntracked(final byte[][] keyParts
) throws RocksDBException
{
1289 assert(isOwningHandle());
1290 deleteUntracked(nativeHandle_
, keyParts
, keyParts
.length
);
1294 * Similar to {@link WriteBatch#putLogData(byte[])}
1296 * @param blob binary object to be inserted
1298 public void putLogData(final byte[] blob
) {
1299 assert(isOwningHandle());
1300 putLogData(nativeHandle_
, blob
, blob
.length
);
1304 * By default, all put/merge/delete operations will be indexed in the
1305 * transaction so that get/getForUpdate/getIterator can search for these
1308 * If the caller does not want to fetch the keys about to be written,
1309 * they may want to avoid indexing as a performance optimization.
1310 * Calling {@link #disableIndexing()} will turn off indexing for all future
1311 * put/merge/delete operations until {@link #enableIndexing()} is called.
1313 * If a key is put/merge/deleted after {@link #disableIndexing()} is called
1314 * and then is fetched via get/getForUpdate/getIterator, the result of the
1315 * fetch is undefined.
1317 public void disableIndexing() {
1318 assert(isOwningHandle());
1319 disableIndexing(nativeHandle_
);
1323 * Re-enables indexing after a previous call to {@link #disableIndexing()}
1325 public void enableIndexing() {
1326 assert(isOwningHandle());
1327 enableIndexing(nativeHandle_
);
1331 * Returns the number of distinct Keys being tracked by this transaction.
1332 * If this transaction was created by a {@link TransactionDB}, this is the
1333 * number of keys that are currently locked by this transaction.
1334 * If this transaction was created by an {@link OptimisticTransactionDB},
1335 * this is the number of keys that need to be checked for conflicts at commit
1338 * @return the number of distinct Keys being tracked by this transaction
1340 public long getNumKeys() {
1341 assert(isOwningHandle());
1342 return getNumKeys(nativeHandle_
);
1346 * Returns the number of puts that have been applied to this
1347 * transaction so far.
1349 * @return the number of puts that have been applied to this transaction
1351 public long getNumPuts() {
1352 assert(isOwningHandle());
1353 return getNumPuts(nativeHandle_
);
1357 * Returns the number of deletes that have been applied to this
1358 * transaction so far.
1360 * @return the number of deletes that have been applied to this transaction
1362 public long getNumDeletes() {
1363 assert(isOwningHandle());
1364 return getNumDeletes(nativeHandle_
);
1368 * Returns the number of merges that have been applied to this
1369 * transaction so far.
1371 * @return the number of merges that have been applied to this transaction
1373 public long getNumMerges() {
1374 assert(isOwningHandle());
1375 return getNumMerges(nativeHandle_
);
1379 * Returns the elapsed time in milliseconds since this Transaction began.
1381 * @return the elapsed time in milliseconds since this transaction began.
1383 public long getElapsedTime() {
1384 assert(isOwningHandle());
1385 return getElapsedTime(nativeHandle_
);
1389 * Fetch the underlying write batch that contains all pending changes to be
1392 * Note: You should not write or delete anything from the batch directly and
1393 * should only use the functions in the {@link Transaction} class to
1394 * write to this transaction.
1396 * @return The write batch
1398 public WriteBatchWithIndex
getWriteBatch() {
1399 assert(isOwningHandle());
1400 final WriteBatchWithIndex writeBatchWithIndex
=
1401 new WriteBatchWithIndex(getWriteBatch(nativeHandle_
));
1402 return writeBatchWithIndex
;
1406 * Change the value of {@link TransactionOptions#getLockTimeout()}
1407 * (in milliseconds) for this transaction.
1409 * Has no effect on OptimisticTransactions.
1411 * @param lockTimeout the timeout (in milliseconds) for locks used by this
1414 public void setLockTimeout(final long lockTimeout
) {
1415 assert(isOwningHandle());
1416 setLockTimeout(nativeHandle_
, lockTimeout
);
1420 * Return the WriteOptions that will be used during {@link #commit()}.
1422 * @return the WriteOptions that will be used
1424 public WriteOptions
getWriteOptions() {
1425 assert(isOwningHandle());
1426 final WriteOptions writeOptions
=
1427 new WriteOptions(getWriteOptions(nativeHandle_
));
1428 return writeOptions
;
1432 * Reset the WriteOptions that will be used during {@link #commit()}.
1434 * @param writeOptions The new WriteOptions
1436 public void setWriteOptions(final WriteOptions writeOptions
) {
1437 assert(isOwningHandle());
1438 setWriteOptions(nativeHandle_
, writeOptions
.nativeHandle_
);
1442 * If this key was previously fetched in this transaction using
1443 * {@link #getForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean)}/
1444 * {@link #multiGetForUpdate(ReadOptions, List, byte[][])}, calling
1445 * {@link #undoGetForUpdate(ColumnFamilyHandle, byte[])} will tell
1446 * the transaction that it no longer needs to do any conflict checking
1449 * If a key has been fetched N times via
1450 * {@link #getForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean)}/
1451 * {@link #multiGetForUpdate(ReadOptions, List, byte[][])}, then
1452 * {@link #undoGetForUpdate(ColumnFamilyHandle, byte[])} will only have an
1453 * effect if it is also called N times. If this key has been written to in
1454 * this transaction, {@link #undoGetForUpdate(ColumnFamilyHandle, byte[])}
1455 * will have no effect.
1457 * If {@link #setSavePoint()} has been called after the
1458 * {@link #getForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean)},
1459 * {@link #undoGetForUpdate(ColumnFamilyHandle, byte[])} will not have any
1462 * If this Transaction was created by an {@link OptimisticTransactionDB},
1463 * calling {@link #undoGetForUpdate(ColumnFamilyHandle, byte[])} can affect
1464 * whether this key is conflict checked at commit time.
1465 * If this Transaction was created by a {@link TransactionDB},
1466 * calling {@link #undoGetForUpdate(ColumnFamilyHandle, byte[])} may release
1467 * any held locks for this key.
1469 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
1471 * @param key the key to retrieve the value for.
1473 public void undoGetForUpdate(final ColumnFamilyHandle columnFamilyHandle
,
1475 assert(isOwningHandle());
1476 undoGetForUpdate(nativeHandle_
, key
, key
.length
, columnFamilyHandle
.nativeHandle_
);
1480 * If this key was previously fetched in this transaction using
1481 * {@link #getForUpdate(ReadOptions, byte[], boolean)}/
1482 * {@link #multiGetForUpdate(ReadOptions, List, byte[][])}, calling
1483 * {@link #undoGetForUpdate(byte[])} will tell
1484 * the transaction that it no longer needs to do any conflict checking
1487 * If a key has been fetched N times via
1488 * {@link #getForUpdate(ReadOptions, byte[], boolean)}/
1489 * {@link #multiGetForUpdate(ReadOptions, List, byte[][])}, then
1490 * {@link #undoGetForUpdate(byte[])} will only have an
1491 * effect if it is also called N times. If this key has been written to in
1492 * this transaction, {@link #undoGetForUpdate(byte[])}
1493 * will have no effect.
1495 * If {@link #setSavePoint()} has been called after the
1496 * {@link #getForUpdate(ReadOptions, byte[], boolean)},
1497 * {@link #undoGetForUpdate(byte[])} will not have any
1500 * If this Transaction was created by an {@link OptimisticTransactionDB},
1501 * calling {@link #undoGetForUpdate(byte[])} can affect
1502 * whether this key is conflict checked at commit time.
1503 * If this Transaction was created by a {@link TransactionDB},
1504 * calling {@link #undoGetForUpdate(byte[])} may release
1505 * any held locks for this key.
1507 * @param key the key to retrieve the value for.
1509 public void undoGetForUpdate(final byte[] key
) {
1510 assert(isOwningHandle());
1511 undoGetForUpdate(nativeHandle_
, key
, key
.length
);
1515 * Adds the keys from the WriteBatch to the transaction
1517 * @param writeBatch The write batch to read from
1519 * @throws RocksDBException if an error occurs whilst rebuilding from the
1522 public void rebuildFromWriteBatch(final WriteBatch writeBatch
)
1523 throws RocksDBException
{
1524 assert(isOwningHandle());
1525 rebuildFromWriteBatch(nativeHandle_
, writeBatch
.nativeHandle_
);
1529 * Get the Commit time Write Batch.
1531 * @return the commit time write batch.
1533 public WriteBatch
getCommitTimeWriteBatch() {
1534 assert(isOwningHandle());
1535 final WriteBatch writeBatch
=
1536 new WriteBatch(getCommitTimeWriteBatch(nativeHandle_
));
1541 * Set the log number.
1543 * @param logNumber the log number
1545 public void setLogNumber(final long logNumber
) {
1546 assert(isOwningHandle());
1547 setLogNumber(nativeHandle_
, logNumber
);
1551 * Get the log number.
1553 * @return the log number
1555 public long getLogNumber() {
1556 assert(isOwningHandle());
1557 return getLogNumber(nativeHandle_
);
1561 * Set the name of the transaction.
1563 * @param transactionName the name of the transaction
1565 * @throws RocksDBException if an error occurs when setting the transaction
1568 public void setName(final String transactionName
) throws RocksDBException
{
1569 assert(isOwningHandle());
1570 setName(nativeHandle_
, transactionName
);
1574 * Get the name of the transaction.
1576 * @return the name of the transaction
1578 public String
getName() {
1579 assert(isOwningHandle());
1580 return getName(nativeHandle_
);
1584 * Get the ID of the transaction.
1586 * @return the ID of the transaction.
1588 public long getID() {
1589 assert(isOwningHandle());
1590 return getID(nativeHandle_
);
1594 * Determine if a deadlock has been detected.
1596 * @return true if a deadlock has been detected.
1598 public boolean isDeadlockDetect() {
1599 assert(isOwningHandle());
1600 return isDeadlockDetect(nativeHandle_
);
1604 * Get the list of waiting transactions.
1606 * @return The list of waiting transactions.
1608 public WaitingTransactions
getWaitingTxns() {
1609 assert(isOwningHandle());
1610 return getWaitingTxns(nativeHandle_
);
1614 * Get the execution status of the transaction.
1616 * NOTE: The execution status of an Optimistic Transaction
1617 * never changes. This is only useful for non-optimistic transactions!
1619 * @return The execution status of the transaction
1621 public TransactionState
getState() {
1622 assert(isOwningHandle());
1623 return TransactionState
.getTransactionState(
1624 getState(nativeHandle_
));
1628 * The globally unique id with which the transaction is identified. This id
1629 * might or might not be set depending on the implementation. Similarly the
1630 * implementation decides the point in lifetime of a transaction at which it
1631 * assigns the id. Although currently it is the case, the id is not guaranteed
1632 * to remain the same across restarts.
1634 * @return the transaction id.
1636 @Experimental("NOTE: Experimental feature")
1637 public long getId() {
1638 assert(isOwningHandle());
1639 return getId(nativeHandle_
);
1642 public enum TransactionState
{
1644 AWAITING_PREPARE((byte)1),
1646 AWAITING_COMMIT((byte)3),
1648 AWAITING_ROLLBACK((byte)5),
1649 ROLLEDBACK((byte)6),
1650 LOCKS_STOLEN((byte)7);
1652 private final byte value
;
1654 TransactionState(final byte value
) {
1659 * Get TransactionState by byte value.
1661 * @param value byte representation of TransactionState.
1663 * @return {@link org.rocksdb.Transaction.TransactionState} instance or null.
1664 * @throws java.lang.IllegalArgumentException if an invalid
1665 * value is provided.
1667 public static TransactionState
getTransactionState(final byte value
) {
1668 for (final TransactionState transactionState
: TransactionState
.values()) {
1669 if (transactionState
.value
== value
){
1670 return transactionState
;
1673 throw new IllegalArgumentException(
1674 "Illegal value provided for TransactionState.");
1679 * Called from C++ native method {@link #getWaitingTxns(long)}
1680 * to construct a WaitingTransactions object.
1682 * @param columnFamilyId The id of the {@link ColumnFamilyHandle}
1683 * @param key The key
1684 * @param transactionIds The transaction ids
1686 * @return The waiting transactions
1688 private WaitingTransactions
newWaitingTransactions(
1689 final long columnFamilyId
, final String key
,
1690 final long[] transactionIds
) {
1691 return new WaitingTransactions(columnFamilyId
, key
, transactionIds
);
1694 public static class WaitingTransactions
{
1695 private final long columnFamilyId
;
1696 private final String key
;
1697 private final long[] transactionIds
;
1699 private WaitingTransactions(final long columnFamilyId
, final String key
,
1700 final long[] transactionIds
) {
1701 this.columnFamilyId
= columnFamilyId
;
1703 this.transactionIds
= transactionIds
;
1707 * Get the Column Family ID.
1709 * @return The column family ID
1711 public long getColumnFamilyId() {
1712 return columnFamilyId
;
1716 * Get the key on which the transactions are waiting.
1720 public String
getKey() {
1725 * Get the IDs of the waiting transactions.
1727 * @return The IDs of the waiting transactions
1729 public long[] getTransactionIds() {
1730 return transactionIds
;
1734 private native void setSnapshot(final long handle
);
1735 private native void setSnapshotOnNextOperation(final long handle
);
1736 private native void setSnapshotOnNextOperation(final long handle
,
1737 final long transactionNotifierHandle
);
1738 private native long getSnapshot(final long handle
);
1739 private native void clearSnapshot(final long handle
);
1740 private native void prepare(final long handle
) throws RocksDBException
;
1741 private native void commit(final long handle
) throws RocksDBException
;
1742 private native void rollback(final long handle
) throws RocksDBException
;
1743 private native void setSavePoint(final long handle
) throws RocksDBException
;
1744 private native void rollbackToSavePoint(final long handle
)
1745 throws RocksDBException
;
1746 private native byte[] get(final long handle
, final long readOptionsHandle
,
1747 final byte key
[], final int keyLength
, final long columnFamilyHandle
)
1748 throws RocksDBException
;
1749 private native byte[] get(final long handle
, final long readOptionsHandle
,
1750 final byte key
[], final int keyLen
) throws RocksDBException
;
1751 private native byte[][] multiGet(final long handle
,
1752 final long readOptionsHandle
, final byte[][] keys
,
1753 final long[] columnFamilyHandles
) throws RocksDBException
;
1754 private native byte[][] multiGet(final long handle
,
1755 final long readOptionsHandle
, final byte[][] keys
)
1756 throws RocksDBException
;
1757 private native byte[] getForUpdate(final long handle
, final long readOptionsHandle
,
1758 final byte key
[], final int keyLength
, final long columnFamilyHandle
, final boolean exclusive
,
1759 final boolean do_validate
) throws RocksDBException
;
1760 private native byte[] getForUpdate(final long handle
, final long readOptionsHandle
,
1761 final byte key
[], final int keyLen
, final boolean exclusive
, final boolean do_validate
)
1762 throws RocksDBException
;
1763 private native byte[][] multiGetForUpdate(final long handle
,
1764 final long readOptionsHandle
, final byte[][] keys
,
1765 final long[] columnFamilyHandles
) throws RocksDBException
;
1766 private native byte[][] multiGetForUpdate(final long handle
,
1767 final long readOptionsHandle
, final byte[][] keys
)
1768 throws RocksDBException
;
1769 private native long getIterator(final long handle
,
1770 final long readOptionsHandle
);
1771 private native long getIterator(final long handle
,
1772 final long readOptionsHandle
, final long columnFamilyHandle
);
1773 private native void put(final long handle
, final byte[] key
, final int keyLength
,
1774 final byte[] value
, final int valueLength
, final long columnFamilyHandle
,
1775 final boolean assume_tracked
) throws RocksDBException
;
1776 private native void put(final long handle
, final byte[] key
,
1777 final int keyLength
, final byte[] value
, final int valueLength
)
1778 throws RocksDBException
;
1779 private native void put(final long handle
, final byte[][] keys
, final int keysLength
,
1780 final byte[][] values
, final int valuesLength
, final long columnFamilyHandle
,
1781 final boolean assume_tracked
) throws RocksDBException
;
1782 private native void put(final long handle
, final byte[][] keys
,
1783 final int keysLength
, final byte[][] values
, final int valuesLength
)
1784 throws RocksDBException
;
1785 private native void merge(final long handle
, final byte[] key
, final int keyLength
,
1786 final byte[] value
, final int valueLength
, final long columnFamilyHandle
,
1787 final boolean assume_tracked
) throws RocksDBException
;
1788 private native void merge(final long handle
, final byte[] key
,
1789 final int keyLength
, final byte[] value
, final int valueLength
)
1790 throws RocksDBException
;
1791 private native void delete(final long handle
, final byte[] key
, final int keyLength
,
1792 final long columnFamilyHandle
, final boolean assume_tracked
) throws RocksDBException
;
1793 private native void delete(final long handle
, final byte[] key
,
1794 final int keyLength
) throws RocksDBException
;
1795 private native void delete(final long handle
, final byte[][] keys
, final int keysLength
,
1796 final long columnFamilyHandle
, final boolean assume_tracked
) throws RocksDBException
;
1797 private native void delete(final long handle
, final byte[][] keys
,
1798 final int keysLength
) throws RocksDBException
;
1799 private native void singleDelete(final long handle
, final byte[] key
, final int keyLength
,
1800 final long columnFamilyHandle
, final boolean assume_tracked
) throws RocksDBException
;
1801 private native void singleDelete(final long handle
, final byte[] key
,
1802 final int keyLength
) throws RocksDBException
;
1803 private native void singleDelete(final long handle
, final byte[][] keys
, final int keysLength
,
1804 final long columnFamilyHandle
, final boolean assume_tracked
) throws RocksDBException
;
1805 private native void singleDelete(final long handle
, final byte[][] keys
,
1806 final int keysLength
) throws RocksDBException
;
1807 private native void putUntracked(final long handle
, final byte[] key
,
1808 final int keyLength
, final byte[] value
, final int valueLength
,
1809 final long columnFamilyHandle
) throws RocksDBException
;
1810 private native void putUntracked(final long handle
, final byte[] key
,
1811 final int keyLength
, final byte[] value
, final int valueLength
)
1812 throws RocksDBException
;
1813 private native void putUntracked(final long handle
, final byte[][] keys
,
1814 final int keysLength
, final byte[][] values
, final int valuesLength
,
1815 final long columnFamilyHandle
) throws RocksDBException
;
1816 private native void putUntracked(final long handle
, final byte[][] keys
,
1817 final int keysLength
, final byte[][] values
, final int valuesLength
)
1818 throws RocksDBException
;
1819 private native void mergeUntracked(final long handle
, final byte[] key
,
1820 final int keyLength
, final byte[] value
, final int valueLength
,
1821 final long columnFamilyHandle
) throws RocksDBException
;
1822 private native void mergeUntracked(final long handle
, final byte[] key
,
1823 final int keyLength
, final byte[] value
, final int valueLength
)
1824 throws RocksDBException
;
1825 private native void deleteUntracked(final long handle
, final byte[] key
,
1826 final int keyLength
, final long columnFamilyHandle
)
1827 throws RocksDBException
;
1828 private native void deleteUntracked(final long handle
, final byte[] key
,
1829 final int keyLength
) throws RocksDBException
;
1830 private native void deleteUntracked(final long handle
, final byte[][] keys
,
1831 final int keysLength
, final long columnFamilyHandle
)
1832 throws RocksDBException
;
1833 private native void deleteUntracked(final long handle
, final byte[][] keys
,
1834 final int keysLength
) throws RocksDBException
;
1835 private native void putLogData(final long handle
, final byte[] blob
,
1836 final int blobLength
);
1837 private native void disableIndexing(final long handle
);
1838 private native void enableIndexing(final long handle
);
1839 private native long getNumKeys(final long handle
);
1840 private native long getNumPuts(final long handle
);
1841 private native long getNumDeletes(final long handle
);
1842 private native long getNumMerges(final long handle
);
1843 private native long getElapsedTime(final long handle
);
1844 private native long getWriteBatch(final long handle
);
1845 private native void setLockTimeout(final long handle
, final long lockTimeout
);
1846 private native long getWriteOptions(final long handle
);
1847 private native void setWriteOptions(final long handle
,
1848 final long writeOptionsHandle
);
1849 private native void undoGetForUpdate(final long handle
, final byte[] key
,
1850 final int keyLength
, final long columnFamilyHandle
);
1851 private native void undoGetForUpdate(final long handle
, final byte[] key
,
1852 final int keyLength
);
1853 private native void rebuildFromWriteBatch(final long handle
,
1854 final long writeBatchHandle
) throws RocksDBException
;
1855 private native long getCommitTimeWriteBatch(final long handle
);
1856 private native void setLogNumber(final long handle
, final long logNumber
);
1857 private native long getLogNumber(final long handle
);
1858 private native void setName(final long handle
, final String name
)
1859 throws RocksDBException
;
1860 private native String
getName(final long handle
);
1861 private native long getID(final long handle
);
1862 private native boolean isDeadlockDetect(final long handle
);
1863 private native WaitingTransactions
getWaitingTxns(final long handle
);
1864 private native byte getState(final long handle
);
1865 private native long getId(final long handle
);
1867 @Override protected final native void disposeInternal(final long handle
);