/
transactions_configs.go
159 lines (127 loc) · 5.41 KB
/
transactions_configs.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package gocb
import (
"time"
)
// TransactionsCleanupConfig specifies various tunable options related to transactions cleanup.
type TransactionsCleanupConfig struct {
// CleanupWindow specifies how often to the cleanup process runs
// attempting to garbage collection transactions that have failed but
// were not cleaned up by the previous client.
CleanupWindow time.Duration
// DisableClientAttemptCleanup controls where any transaction attempts made
// by this client are automatically removed.
DisableClientAttemptCleanup bool
// DisableLostAttemptCleanup controls where a background process is created
// to cleanup any ‘lost’ transaction attempts.
DisableLostAttemptCleanup bool
// CleanupQueueSize controls the maximum queue size for the cleanup thread.
CleanupQueueSize uint32
// CleanupCollections is a set of extra collections that should be monitored
// by the cleanup thread.
CleanupCollections []TransactionKeyspace
}
// TransactionsConfig specifies various tunable options related to transactions.
type TransactionsConfig struct {
// MetadataCollection specifies a specific location to place meta-data.
MetadataCollection *TransactionKeyspace
// ExpirationTimout sets the maximum time that transactions created
// by this Transactions object can run for, before expiring.
Timeout time.Duration
// DurabilityLevel specifies the durability level that should be used
// for all write operations performed by this Transactions object.
DurabilityLevel DurabilityLevel
// QueryConfig specifies any query configuration to use in transactions.
QueryConfig TransactionsQueryConfig
// CleanupConfig specifies cleanup configuration to use in transactions.
CleanupConfig TransactionsCleanupConfig
// Internal specifies a set of options for internal use.
// Internal: This should never be used and is not supported.
Internal struct {
Hooks TransactionHooks
CleanupHooks TransactionCleanupHooks
ClientRecordHooks TransactionClientRecordHooks
NumATRs int
}
}
// TransactionOptions specifies options which can be overridden on a per transaction basis.
type TransactionOptions struct {
// DurabilityLevel specifies the durability level that should be used
// for all write operations performed by this transaction.
DurabilityLevel DurabilityLevel
// Timeout sets the maximum time that this transaction can run for, before expiring.
Timeout time.Duration
// MetadataCollection specifies a specific Collection to place meta-data.
MetadataCollection *Collection
// Internal specifies a set of options for internal use.
// Internal: This should never be used and is not supported.
Internal struct {
Hooks TransactionHooks
}
}
// TransactionsQueryConfig specifies various tunable query options related to transactions.
type TransactionsQueryConfig struct {
ScanConsistency QueryScanConsistency
}
// SingleQueryTransactionOptions specifies various tunable query options related to single query transactions.
type SingleQueryTransactionOptions struct {
DurabilityLevel DurabilityLevel
// Internal specifies a set of options for internal use.
// Internal: This should never be used and is not supported.
Internal struct {
Hooks TransactionHooks
}
}
// TransactionKeyspace specifies a specific location where ATR entries should be
// placed when performing transactions.
type TransactionKeyspace struct {
BucketName string
ScopeName string
CollectionName string
}
// TransactionQueryOptions specifies the set of options available when running queries as a part of a transaction.
// This is a subset of QueryOptions.
type TransactionQueryOptions struct {
ScanConsistency QueryScanConsistency
Profile QueryProfileMode
// ScanCap is the maximum buffered channel size between the indexer connectionManager and the query service for index scans.
ScanCap uint32
// PipelineBatch controls the number of items execution operators can batch for Fetch from the KV.
PipelineBatch uint32
// PipelineCap controls the maximum number of items each execution operator can buffer between various operators.
PipelineCap uint32
// ScanWait is how long the indexer is allowed to wait until it can satisfy ScanConsistency/ConsistentWith criteria.
ScanWait time.Duration
Readonly bool
// ClientContextID provides a unique ID for this query which can be used matching up requests between connectionManager and
// server. If not provided will be assigned a uuid value.
ClientContextID string
PositionalParameters []interface{}
NamedParameters map[string]interface{}
// FlexIndex tells the query engine to use a flex index (utilizing the search service).
FlexIndex bool
// Raw provides a way to provide extra parameters in the request body for the query.
Raw map[string]interface{}
Prepared bool
Scope *Scope
}
func (qo *TransactionQueryOptions) toSDKOptions() QueryOptions {
scanc := qo.ScanConsistency
if scanc == 0 {
scanc = QueryScanConsistencyRequestPlus
}
return QueryOptions{
ScanConsistency: scanc,
Profile: qo.Profile,
ScanCap: qo.ScanCap,
PipelineBatch: qo.PipelineBatch,
PipelineCap: qo.PipelineCap,
ScanWait: qo.ScanWait,
Readonly: qo.Readonly,
ClientContextID: qo.ClientContextID,
PositionalParameters: qo.PositionalParameters,
NamedParameters: qo.NamedParameters,
Raw: qo.Raw,
Adhoc: !qo.Prepared,
FlexIndex: qo.FlexIndex,
}
}