]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/main/java/org/rocksdb/TransactionOptions.java
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).
8 public class TransactionOptions
extends RocksObject
9 implements TransactionalOptions
<TransactionOptions
> {
11 public TransactionOptions() {
12 super(newTransactionOptions());
16 public boolean isSetSnapshot() {
17 assert(isOwningHandle());
18 return isSetSnapshot(nativeHandle_
);
22 public TransactionOptions
setSetSnapshot(final boolean setSnapshot
) {
23 assert(isOwningHandle());
24 setSetSnapshot(nativeHandle_
, setSnapshot
);
29 * True means that before acquiring locks, this transaction will
30 * check if doing so will cause a deadlock. If so, it will return with
31 * {@link Status.Code#Busy}. The user should retry their transaction.
33 * @return true if a deadlock is detected.
35 public boolean isDeadlockDetect() {
36 assert(isOwningHandle());
37 return isDeadlockDetect(nativeHandle_
);
41 * Setting to true means that before acquiring locks, this transaction will
42 * check if doing so will cause a deadlock. If so, it will return with
43 * {@link Status.Code#Busy}. The user should retry their transaction.
45 * @param deadlockDetect true if we should detect deadlocks.
47 * @return this TransactionOptions instance
49 public TransactionOptions
setDeadlockDetect(final boolean deadlockDetect
) {
50 assert(isOwningHandle());
51 setDeadlockDetect(nativeHandle_
, deadlockDetect
);
56 * The wait timeout in milliseconds when a transaction attempts to lock a key.
58 * If 0, no waiting is done if a lock cannot instantly be acquired.
59 * If negative, {@link TransactionDBOptions#getTransactionLockTimeout(long)}
62 * @return the lock timeout in milliseconds
64 public long getLockTimeout() {
65 assert(isOwningHandle());
66 return getLockTimeout(nativeHandle_
);
70 * If positive, specifies the wait timeout in milliseconds when
71 * a transaction attempts to lock a key.
73 * If 0, no waiting is done if a lock cannot instantly be acquired.
74 * If negative, {@link TransactionDBOptions#getTransactionLockTimeout(long)}
79 * @param lockTimeout the lock timeout in milliseconds
81 * @return this TransactionOptions instance
83 public TransactionOptions
setLockTimeout(final long lockTimeout
) {
84 assert(isOwningHandle());
85 setLockTimeout(nativeHandle_
, lockTimeout
);
90 * Expiration duration in milliseconds.
92 * If non-negative, transactions that last longer than this many milliseconds
93 * will fail to commit. If not set, a forgotten transaction that is never
94 * committed, rolled back, or deleted will never relinquish any locks it
95 * holds. This could prevent keys from being written by other writers.
97 * @return expiration the expiration duration in milliseconds
99 public long getExpiration() {
100 assert(isOwningHandle());
101 return getExpiration(nativeHandle_
);
105 * Expiration duration in milliseconds.
107 * If non-negative, transactions that last longer than this many milliseconds
108 * will fail to commit. If not set, a forgotten transaction that is never
109 * committed, rolled back, or deleted will never relinquish any locks it
110 * holds. This could prevent keys from being written by other writers.
114 * @param expiration the expiration duration in milliseconds
116 * @return this TransactionOptions instance
118 public TransactionOptions
setExpiration(final long expiration
) {
119 assert(isOwningHandle());
120 setExpiration(nativeHandle_
, expiration
);
125 * Gets the number of traversals to make during deadlock detection.
127 * @return the number of traversals to make during
130 public long getDeadlockDetectDepth() {
131 return getDeadlockDetectDepth(nativeHandle_
);
135 * Sets the number of traversals to make during deadlock detection.
139 * @param deadlockDetectDepth the number of traversals to make during
142 * @return this TransactionOptions instance
144 public TransactionOptions
setDeadlockDetectDepth(
145 final long deadlockDetectDepth
) {
146 setDeadlockDetectDepth(nativeHandle_
, deadlockDetectDepth
);
151 * Get the maximum number of bytes that may be used for the write batch.
153 * @return the maximum number of bytes, 0 means no limit.
155 public long getMaxWriteBatchSize() {
156 return getMaxWriteBatchSize(nativeHandle_
);
160 * Set the maximum number of bytes that may be used for the write batch.
162 * @param maxWriteBatchSize the maximum number of bytes, 0 means no limit.
164 * @return this TransactionOptions instance
166 public TransactionOptions
setMaxWriteBatchSize(final long maxWriteBatchSize
) {
167 setMaxWriteBatchSize(nativeHandle_
, maxWriteBatchSize
);
171 private native static long newTransactionOptions();
172 private native boolean isSetSnapshot(final long handle
);
173 private native void setSetSnapshot(final long handle
,
174 final boolean setSnapshot
);
175 private native boolean isDeadlockDetect(final long handle
);
176 private native void setDeadlockDetect(final long handle
,
177 final boolean deadlockDetect
);
178 private native long getLockTimeout(final long handle
);
179 private native void setLockTimeout(final long handle
, final long lockTimeout
);
180 private native long getExpiration(final long handle
);
181 private native void setExpiration(final long handle
, final long expiration
);
182 private native long getDeadlockDetectDepth(final long handle
);
183 private native void setDeadlockDetectDepth(final long handle
,
184 final long deadlockDetectDepth
);
185 private native long getMaxWriteBatchSize(final long handle
);
186 private native void setMaxWriteBatchSize(final long handle
,
187 final long maxWriteBatchSize
);
188 @Override protected final native void disposeInternal(final long handle
);