Skip to main content

TransactionOptions

Struct TransactionOptions 

Source
pub struct TransactionOptions { /* private fields */ }

Implementations§

Source§

impl TransactionOptions

Source

pub fn new() -> TransactionOptions

Source

pub fn set_skip_prepare(&mut self, skip_prepare: bool)

Source

pub fn set_snapshot(&mut self, snapshot: bool)

Specifies use snapshot or not.

Default: false.

If a transaction has a snapshot set, the transaction will ensure that any keys successfully written(or fetched via get_for_update) have not been modified outside 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 via get_for_update).

Using snapshot will provide stricter isolation guarantees at the expense of potentially more transaction failures due to conflicts with other writes.

Calling set_snapshot will not affect the version of Data returned by get methods.

Source

pub fn set_deadlock_detect(&mut self, deadlock_detect: bool)

Specifies whether detect deadlock or not.

Setting to true means that before acquiring locks, this transaction will check if doing so will cause a deadlock. If so, it will return with Status::Busy. The user should retry their transaction.

Default: false.

Source

pub fn set_lock_timeout(&mut self, lock_timeout: i64)

Specifies the wait timeout in milliseconds when a transaction attempts to lock a key.

If 0, no waiting is done if a lock cannot instantly be acquired. If negative, transaction lock timeout in TransactionDBOptions will be used.

Default: -1.

Source

pub fn set_expiration(&mut self, expiration: i64)

Specifies expiration duration in milliseconds.

If non-negative, transactions that last longer than this many milliseconds will fail to commit. If not set, a forgotten transaction that is never committed, rolled back, or deleted will never relinquish any locks it holds. This could prevent keys from being accessed by other writers.

Default: -1.

Source

pub fn set_deadlock_detect_depth(&mut self, depth: i64)

Specifies the number of traversals to make during deadlock detection.

Default: 50.

Source

pub fn set_max_write_batch_size(&mut self, size: usize)

Specifies the maximum number of bytes used for the write batch. 0 means no limit.

Default: 0.

Source

pub fn set_commit_bypass_memtable(&mut self, val: bool)

The following three options enable optimizations for large transaction commit to bypass memtable write.

  • If any transaction’s commit should bybass memtable write, set commit_bypass_memtable to true.
  • If only bypass memtable write for transactions with >= n operations, set commit_bypass_memtable to false, large_txn_commit_optimize_threshold to n, and large_txn_commit_optimize_byte_threshold to 0. Similarly for only optimize when a transaction’s write batch size is >= n.
  • If bypass memtable write for transactions with >= n operations or >= x bytes, set commit_bypass_memtable to false, large_txn_commit_optimize_threshold to n, and large_txn_commit_optimize_byte_threshold to x.

EXPERIMENTAL, SUBJECT TO CHANGE Only supports write-committed policy. If set to true, the transaction will skip memtable write and ingest into the DB directly during Commit(). This makes Commit() much faster for transactions with many operations. Transaction neeeds to call Prepare() before Commit() for this option to take effect. Transactions with Merge() or PutEntity() is not supported yet.

Note that the transaction will be ingested as an immutable memtable for CFs it updates, and the current memtable will be switched to a new one. So ingesting many transactions in a short period of time may cause stall due to too many memtables. Note that the ingestion relies on the transaction’s underlying index, (WriteBatchWithIndex), so updates that are added to the transaction without indexing (i.e. added directly to the transaction underlying write batch through Transaction::GetWriteBatch()->GetWriteBatch()) are not supported, and the optimization will not apply in that case.

NOTE: since WBWI keep track of the most recent update per key, a Put followed by a SingleDelete will be written to DB as a SingleDelete. This can cause flush/compaction to report num_single_del_mismatch due to consecutive SingleDeletes.

Source

pub fn get_commit_bypass_memtable(&self) -> bool

Returns the value of the commit_bypass_memtable option.

Source

pub fn get_deadlock_detect(&self) -> bool

Setting to true means that before acquiring locks, this transaction will check if doing so will cause a deadlock. If so, it will return with Status::Busy. The user should retry their transaction.

Source

pub fn set_large_txn_commit_optimize_byte_threshold(&mut self, val: u64)

EXPERIMENTAL, SUBJECT TO CHANGE When the size of a transaction’s write batch is at least this threshold, we will enable optimizations for commiting a large transaction. See comment for commit_bypass_memtable for more optimization detail.

Default: 0 (disabled).

Source

pub fn get_large_txn_commit_optimize_byte_threshold(&self) -> u64

Returns the value of the large_txn_commit_optimize_byte_threshold option.

Source

pub fn set_large_txn_commit_optimize_threshold(&mut self, val: u32)

EXPERIMENTAL, SUBJECT TO CHANGE When the number of updates in a transaction is at least this threshold, we will enable optimizations for commiting a large transaction. See comment for commit_bypass_memtable for more optimization detail.

Default: 0 (disabled).

Source

pub fn get_large_txn_commit_optimize_threshold(&self) -> u32

Returns the value of the large_txn_commit_optimize_threshold option.

Source

pub fn get_max_write_batch_size(&self) -> usize

The maximum number of bytes used for the write batch. 0 means no limit.

Source

pub fn get_set_snapshot(&self) -> bool

Setting set_snapshot=true is the same as calling Transaction::SetSnapshot().

Source

pub fn set_skip_concurrency_control(&mut self, val: bool)

If true, the TransactionDB implementation might skip concurrency control unless it is overridden by TransactionOptions or TransactionDBWriteOptimizations. This can be used in conjunction with DBOptions::unordered_write when the TransactionDB is used solely for write ordering rather than concurrency control.

Source

pub fn get_skip_concurrency_control(&self) -> bool

Returns the value of the skip_concurrency_control option.

Source

pub fn get_skip_prepare(&self) -> bool

In pessimistic transaction, if this is true, then you can skip Prepare before Commit, otherwise, you must Prepare before Commit.

Source

pub fn set_use_only_the_last_commit_time_batch_for_recovery( &mut self, val: bool, )

If set, it states that the CommitTimeWriteBatch represents the latest state of the application, has only one sub-batch, i.e., no duplicate keys, and meant to be used later during recovery. It enables an optimization to postpone updating the memtable with CommitTimeWriteBatch to only SwitchMemtable or recovery. This option does not affect write-committed. Only write-prepared/write-unprepared transactions will be affected.

Source

pub fn get_use_only_the_last_commit_time_batch_for_recovery(&self) -> bool

Returns the value of the use_only_the_last_commit_time_batch_for_recovery option.

Source

pub fn set_write_batch_track_timestamp_size(&mut self, val: bool)

DO NOT USE. This is only a temporary option dedicated for MyRocks that will soon be removed. In normal use cases, meta info like column family’s timestamp size is tracked at the transaction layer, so it’s not necessary and even detrimental to track such info inside the internal WriteBatch because it may let anti-patterns like bypassing Transaction write APIs and directly write to its internal WriteBatch retrieved like this: https://github.com/facebook/mysql-5.6/blob/fb-mysql-8.0.32/storage/rocksdb/ha_rocksdb.cc#L4949-L4950 Setting this option to true will keep aforementioned use case continue to work before it’s refactored out. When this flag is enabled, we also intentionally only track the timestamp size in APIs that MyRocks currently are using, including Put, Merge, Delete DeleteRange, SingleDelete.

Source

pub fn get_write_batch_track_timestamp_size(&self) -> bool

Returns the value of the write_batch_track_timestamp_size option.

Source

pub fn get_deadlock_detect_depth(&self) -> i64

Returns the current deadlock_detect_depth setting.

See Self::set_deadlock_detect_depth for what this controls.

Source

pub fn get_deadlock_timeout_us(&self) -> i64

Returns the current deadlock_timeout_us setting.

See Self::set_deadlock_timeout_us for what this controls.

Source

pub fn get_expiration(&self) -> i64

Returns the current expiration setting.

See Self::set_expiration for what this controls.

Source

pub fn get_lock_timeout(&self) -> i64

Returns the current lock_timeout setting.

See Self::set_lock_timeout for what this controls.

Source

pub fn get_write_batch_flush_threshold(&self) -> i64

Returns the current write_batch_flush_threshold setting.

See Self::set_write_batch_flush_threshold for what this controls.

Source

pub fn set_deadlock_timeout_us(&mut self, val: i64)

Timeout in microseconds before perform dead lock detection. If 0, deadlock detection will be performed immediately.

To optimize performance, this parameter could be tuned.

When deadlock happens very frequently, deadlock timeout should be set to 0, so deadlock will be detected immediately.

When deadlock happen very rarely, this timeout could be turned to be slightly longer than the typical transaction execution time, so that transaction will be waked up to take the lock before this timeout, which will allow the transaction to save the CPU time on deadlock detection.

Deadlock timeout is always smaller than lock_timeout.

Source

pub fn set_write_batch_flush_threshold(&mut self, val: i64)

See TransactionDBOptions::default_write_batch_flush_threshold for description. If a negative value is specified, then the default value from TransactionDBOptions is used.

Trait Implementations§

Source§

impl Default for TransactionOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for TransactionOptions

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for TransactionOptions

Source§

impl Sync for TransactionOptions

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.