forked from linxGnu/grocksdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_transaction.go
99 lines (82 loc) · 4.04 KB
/
options_transaction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package grocksdb
// #include "rocksdb/c.h"
import "C"
// TransactionOptions represent all of the available options options for
// a transaction on the database.
type TransactionOptions struct {
c *C.rocksdb_transaction_options_t
}
// NewDefaultTransactionOptions creates a default TransactionOptions object.
func NewDefaultTransactionOptions() *TransactionOptions {
return newNativeTransactionOptions(C.rocksdb_transaction_options_create())
}
// NewNativeTransactionOptions creates a TransactionOptions object.
func newNativeTransactionOptions(c *C.rocksdb_transaction_options_t) *TransactionOptions {
return &TransactionOptions{c: c}
}
// SetSetSnapshot to true is the same as calling
// Transaction::SetSnapshot().
func (opts *TransactionOptions) SetSetSnapshot(value bool) {
C.rocksdb_transaction_options_set_set_snapshot(opts.c, boolToChar(value))
}
// SetDeadlockDetect 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.
func (opts *TransactionOptions) SetDeadlockDetect(value bool) {
C.rocksdb_transaction_options_set_deadlock_detect(opts.c, boolToChar(value))
}
// SetLockTimeout positive, 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, TransactionDBOptions::transaction_lock_timeout will be used
func (opts *TransactionOptions) SetLockTimeout(lockTimeout int64) {
C.rocksdb_transaction_options_set_lock_timeout(opts.c, C.int64_t(lockTimeout))
}
// SetExpiration sets the 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 written by other writers.
func (opts *TransactionOptions) SetExpiration(expiration int64) {
C.rocksdb_transaction_options_set_expiration(opts.c, C.int64_t(expiration))
}
// SetDeadlockDetectDepth sets the number of traversals to make during deadlock detection.
func (opts *TransactionOptions) SetDeadlockDetectDepth(depth int64) {
C.rocksdb_transaction_options_set_deadlock_detect_depth(opts.c, C.int64_t(depth))
}
// SetMaxWriteBatchSize sets the maximum number of bytes used for the write batch. 0 means no limit.
func (opts *TransactionOptions) SetMaxWriteBatchSize(size uint64) {
C.rocksdb_transaction_options_set_max_write_batch_size(opts.c, C.size_t(size))
}
// SetSkipPrepare skips prepare phase.
func (opts *TransactionOptions) SetSkipPrepare(skip bool) {
C.rocksdb_transaction_options_set_skip_prepare(opts.c, boolToChar(skip))
}
// Destroy deallocates the TransactionOptions object.
func (opts *TransactionOptions) Destroy() {
C.rocksdb_transaction_options_destroy(opts.c)
opts.c = nil
}
// OptimisticTransactionOptions represent all of the available options options for
// a optimistic transaction on the database.
type OptimisticTransactionOptions struct {
c *C.rocksdb_optimistictransaction_options_t
}
// NewDefaultOptimisticTransactionOptions creates a default TransactionOptions object.
func NewDefaultOptimisticTransactionOptions() *OptimisticTransactionOptions {
return newNativeOptimisticTransactionOptions(C.rocksdb_optimistictransaction_options_create())
}
// NewNativeOptimisticTransactionOptions creates a OptimisticTransactionOptions object.
func newNativeOptimisticTransactionOptions(c *C.rocksdb_optimistictransaction_options_t) *OptimisticTransactionOptions {
return &OptimisticTransactionOptions{c: c}
}
// SetSetSnapshot to true is the same as calling
// Transaction::SetSnapshot().
func (opts *OptimisticTransactionOptions) SetSetSnapshot(value bool) {
C.rocksdb_optimistictransaction_options_set_set_snapshot(opts.c, boolToChar(value))
}
// Destroy deallocates the TransactionOptions object.
func (opts *OptimisticTransactionOptions) Destroy() {
C.rocksdb_optimistictransaction_options_destroy(opts.c)
opts.c = nil
}