@ragestudio/scylla-odm 0.22.2 → 0.22.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/batch/index.d.ts +3 -3
- package/batch/index.d.ts.map +1 -1
- package/client.d.ts +6 -5
- package/client.d.ts.map +1 -1
- package/client.js +11 -12
- package/client.js.map +1 -1
- package/cql_gen/create_table.d.ts +1 -1
- package/cql_gen/create_table.d.ts.map +1 -1
- package/document/index.d.ts +3 -3
- package/document/index.d.ts.map +1 -1
- package/driver/LICENSE.txt +177 -0
- package/driver/NOTICE.txt +67 -0
- package/driver/auth/index.d.ts +37 -0
- package/driver/auth/index.js +37 -0
- package/driver/auth/no-auth-provider.js +73 -0
- package/driver/auth/plain-text-auth-provider.js +81 -0
- package/driver/auth/provider.js +77 -0
- package/driver/client-options.js +442 -0
- package/driver/client.js +1267 -0
- package/driver/concurrent/index.d.ts +49 -0
- package/driver/concurrent/index.js +366 -0
- package/driver/connection.js +1034 -0
- package/driver/control-connection.js +1282 -0
- package/driver/encoder.js +2316 -0
- package/driver/errors.js +223 -0
- package/driver/execution-options.js +612 -0
- package/driver/execution-profile.js +274 -0
- package/driver/host-connection-pool.js +587 -0
- package/driver/host.js +699 -0
- package/driver/index.d.ts +387 -0
- package/driver/index.js +81 -0
- package/driver/mapping/cache.js +214 -0
- package/driver/mapping/doc-info-adapter.js +171 -0
- package/driver/mapping/index.d.ts +219 -0
- package/driver/mapping/index.js +57 -0
- package/driver/mapping/mapper.js +225 -0
- package/driver/mapping/mapping-handler.js +641 -0
- package/driver/mapping/model-batch-item.js +215 -0
- package/driver/mapping/model-batch-mapper.js +141 -0
- package/driver/mapping/model-mapper.js +315 -0
- package/driver/mapping/model-mapping-info.js +225 -0
- package/driver/mapping/object-selector.js +417 -0
- package/driver/mapping/q.js +156 -0
- package/driver/mapping/query-generator.js +556 -0
- package/driver/mapping/result-mapper.js +123 -0
- package/driver/mapping/result.js +139 -0
- package/driver/mapping/table-mappings.js +133 -0
- package/driver/mapping/tree.js +160 -0
- package/driver/metadata/aggregate.js +79 -0
- package/driver/metadata/client-state.js +119 -0
- package/driver/metadata/data-collection.js +182 -0
- package/driver/metadata/event-debouncer.js +174 -0
- package/driver/metadata/index.d.ts +276 -0
- package/driver/metadata/index.js +1156 -0
- package/driver/metadata/materialized-view.js +49 -0
- package/driver/metadata/schema-function.js +98 -0
- package/driver/metadata/schema-index.js +166 -0
- package/driver/metadata/schema-parser.js +1399 -0
- package/driver/metadata/table-metadata.js +77 -0
- package/driver/operation-state.js +206 -0
- package/driver/policies/address-resolution.js +145 -0
- package/driver/policies/index.d.ts +241 -0
- package/driver/policies/index.js +110 -0
- package/driver/policies/load-balancing.js +970 -0
- package/driver/policies/reconnection.js +166 -0
- package/driver/policies/retry.js +326 -0
- package/driver/policies/speculative-execution.js +150 -0
- package/driver/policies/timestamp-generation.js +176 -0
- package/driver/prepare-handler.js +347 -0
- package/driver/promise-utils.js +191 -0
- package/driver/readers.js +624 -0
- package/driver/request-execution.js +644 -0
- package/driver/request-handler.js +332 -0
- package/driver/requests.js +618 -0
- package/driver/stream-id-stack.js +209 -0
- package/driver/streams.js +745 -0
- package/driver/token.js +325 -0
- package/driver/tokenizer.js +631 -0
- package/driver/types/big-decimal.js +282 -0
- package/driver/types/duration.js +576 -0
- package/driver/types/index.d.ts +486 -0
- package/driver/types/index.js +733 -0
- package/driver/types/inet-address.js +262 -0
- package/driver/types/integer.js +818 -0
- package/driver/types/local-date.js +280 -0
- package/driver/types/local-time.js +299 -0
- package/driver/types/mutable-long.js +385 -0
- package/driver/types/protocol-version.js +391 -0
- package/driver/types/result-set.js +287 -0
- package/driver/types/result-stream.js +164 -0
- package/driver/types/row.js +85 -0
- package/driver/types/time-uuid.js +414 -0
- package/driver/types/tuple.js +103 -0
- package/driver/types/uuid.js +160 -0
- package/driver/types/vector.js +130 -0
- package/driver/types/version-number.js +153 -0
- package/driver/utils.js +1485 -0
- package/driver/writers.js +350 -0
- package/global.d.ts +1 -1
- package/global.d.ts.map +1 -1
- package/index.d.ts +6 -6
- package/index.d.ts.map +1 -1
- package/index.js +6 -6
- package/index.js.map +1 -1
- package/migrate/index.d.ts +1 -1
- package/migrate/index.d.ts.map +1 -1
- package/migrate/index.js +1 -1
- package/migrate/index.js.map +1 -1
- package/model/index.d.ts +6 -6
- package/model/index.d.ts.map +1 -1
- package/model/index.js +10 -10
- package/model/index.js.map +1 -1
- package/operations/countAll.d.ts +1 -1
- package/operations/countAll.d.ts.map +1 -1
- package/operations/delete.d.ts +3 -4
- package/operations/delete.d.ts.map +1 -1
- package/operations/delete.js +1 -1
- package/operations/delete.js.map +1 -1
- package/operations/find.d.ts +2 -2
- package/operations/find.d.ts.map +1 -1
- package/operations/find.js +1 -1
- package/operations/find.js.map +1 -1
- package/operations/findOne.d.ts +2 -2
- package/operations/findOne.d.ts.map +1 -1
- package/operations/findOne.js +1 -1
- package/operations/findOne.js.map +1 -1
- package/operations/insert.d.ts +3 -3
- package/operations/insert.d.ts.map +1 -1
- package/operations/insert.js +2 -2
- package/operations/insert.js.map +1 -1
- package/operations/sync.d.ts +1 -1
- package/operations/sync.d.ts.map +1 -1
- package/operations/sync.js +1 -1
- package/operations/sync.js.map +1 -1
- package/operations/tableExists.d.ts +1 -1
- package/operations/tableExists.d.ts.map +1 -1
- package/operations/update.d.ts +3 -3
- package/operations/update.d.ts.map +1 -1
- package/operations/update.js +2 -2
- package/operations/update.js.map +1 -1
- package/package.json +4 -12
- package/schema/index.d.ts +1 -1
- package/schema/index.d.ts.map +1 -1
- package/types.d.ts +4 -4
- package/types.d.ts.map +1 -1
- package/utils/queryParser.d.ts +1 -1
- package/utils/queryParser.d.ts.map +1 -1
- package/utils/queryParser.js +1 -1
- package/utils/queryParser.js.map +1 -1
- package/utils/typeChecker.d.ts +1 -1
- package/utils/typeChecker.d.ts.map +1 -1
- package/utils/typeChecker.js +1 -1
- package/utils/typeChecker.js.map +1 -1
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
import util from "util"
|
|
19
|
+
|
|
20
|
+
/** @module policies/reconnection */
|
|
21
|
+
/**
|
|
22
|
+
* Base class for Reconnection Policies
|
|
23
|
+
* @constructor
|
|
24
|
+
*/
|
|
25
|
+
function ReconnectionPolicy() {}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A new reconnection schedule.
|
|
29
|
+
* @returns {{next: function}} An infinite iterator
|
|
30
|
+
*/
|
|
31
|
+
ReconnectionPolicy.prototype.newSchedule = function () {
|
|
32
|
+
throw new Error(
|
|
33
|
+
"You must implement a new schedule for the Reconnection class",
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Gets an associative array containing the policy options.
|
|
39
|
+
*/
|
|
40
|
+
ReconnectionPolicy.prototype.getOptions = function () {
|
|
41
|
+
return new Map()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A reconnection policy that waits a constant time between each reconnection attempt.
|
|
46
|
+
* @param {Number} delay Delay in ms
|
|
47
|
+
* @constructor
|
|
48
|
+
*/
|
|
49
|
+
function ConstantReconnectionPolicy(delay) {
|
|
50
|
+
this.delay = delay
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
util.inherits(ConstantReconnectionPolicy, ReconnectionPolicy)
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A new reconnection schedule that returns the same next delay value
|
|
57
|
+
* @returns {{next: Function}} An infinite iterator
|
|
58
|
+
*/
|
|
59
|
+
ConstantReconnectionPolicy.prototype.newSchedule = function () {
|
|
60
|
+
const self = this
|
|
61
|
+
return {
|
|
62
|
+
next: function () {
|
|
63
|
+
return { value: self.delay, done: false }
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Gets an associative array containing the policy options.
|
|
70
|
+
*/
|
|
71
|
+
ConstantReconnectionPolicy.prototype.getOptions = function () {
|
|
72
|
+
return new Map([["delay", this.delay]])
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A reconnection policy that waits exponentially longer between each
|
|
77
|
+
* reconnection attempt (but keeps a constant delay once a maximum delay is reached).
|
|
78
|
+
* <p>
|
|
79
|
+
* A random amount of jitter (+/- 15%) will be added to the pure exponential delay value to avoid situations
|
|
80
|
+
* where many clients are in the reconnection process at exactly the same time. The jitter will never cause the
|
|
81
|
+
* delay to be less than the base delay, or more than the max delay.
|
|
82
|
+
* </p>
|
|
83
|
+
* @param {Number} baseDelay The base delay in milliseconds to use for the schedules created by this policy.
|
|
84
|
+
* @param {Number} maxDelay The maximum delay in milliseconds to wait between two reconnection attempt.
|
|
85
|
+
* @param {Boolean} startWithNoDelay Determines if the first attempt should be zero delay
|
|
86
|
+
* @constructor
|
|
87
|
+
*/
|
|
88
|
+
function ExponentialReconnectionPolicy(baseDelay, maxDelay, startWithNoDelay) {
|
|
89
|
+
this.baseDelay = baseDelay
|
|
90
|
+
this.maxDelay = maxDelay
|
|
91
|
+
this.startWithNoDelay = startWithNoDelay
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
util.inherits(ExponentialReconnectionPolicy, ReconnectionPolicy)
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A new schedule that uses an exponentially growing delay between reconnection attempts.
|
|
98
|
+
* @returns {{next: Function}} An infinite iterator.
|
|
99
|
+
*/
|
|
100
|
+
ExponentialReconnectionPolicy.prototype.newSchedule = function* () {
|
|
101
|
+
let index = this.startWithNoDelay ? -1 : 0
|
|
102
|
+
|
|
103
|
+
while (true) {
|
|
104
|
+
let delay = 0
|
|
105
|
+
|
|
106
|
+
if (index >= 64) {
|
|
107
|
+
delay = this.maxDelay
|
|
108
|
+
} else if (index !== -1) {
|
|
109
|
+
delay = Math.min(Math.pow(2, index) * this.baseDelay, this.maxDelay)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
index++
|
|
113
|
+
|
|
114
|
+
yield this._addJitter(delay)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Adds a random portion of +-15% to the delay provided.
|
|
120
|
+
* Initially, its adds a random value of 15% to avoid reconnection before reaching the base delay.
|
|
121
|
+
* When the schedule reaches max delay, only subtracts a random portion of 15%.
|
|
122
|
+
*/
|
|
123
|
+
ExponentialReconnectionPolicy.prototype._addJitter = function (value) {
|
|
124
|
+
if (value === 0) {
|
|
125
|
+
// Instant reconnection without jitter
|
|
126
|
+
return value
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Use the formula: 85% + rnd() * 30% to calculate the percentage of the original delay
|
|
130
|
+
let minPercentage = 0.85
|
|
131
|
+
let range = 0.3
|
|
132
|
+
|
|
133
|
+
if (!this.startWithNoDelay && value === this.baseDelay) {
|
|
134
|
+
// Between 100% to 115% of the original value
|
|
135
|
+
minPercentage = 1
|
|
136
|
+
range = 0.15
|
|
137
|
+
} else if (value === this.maxDelay) {
|
|
138
|
+
// Between 85% to 100% of the original value
|
|
139
|
+
range = 0.15
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return Math.floor(value * (Math.random() * range + minPercentage))
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Gets an associative array containing the policy options.
|
|
147
|
+
*/
|
|
148
|
+
ExponentialReconnectionPolicy.prototype.getOptions = function () {
|
|
149
|
+
return new Map([
|
|
150
|
+
["baseDelay", this.baseDelay],
|
|
151
|
+
["maxDelay", this.maxDelay],
|
|
152
|
+
["startWithNoDelay", this.startWithNoDelay],
|
|
153
|
+
])
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export {
|
|
157
|
+
ReconnectionPolicy,
|
|
158
|
+
ConstantReconnectionPolicy,
|
|
159
|
+
ExponentialReconnectionPolicy,
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export default {
|
|
163
|
+
ReconnectionPolicy,
|
|
164
|
+
ConstantReconnectionPolicy,
|
|
165
|
+
ExponentialReconnectionPolicy,
|
|
166
|
+
}
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
import util from "util"
|
|
19
|
+
|
|
20
|
+
/** @module policies/retry */
|
|
21
|
+
/**
|
|
22
|
+
* Base and default RetryPolicy.
|
|
23
|
+
* Determines what to do when the drivers runs into an specific Cassandra exception
|
|
24
|
+
* @constructor
|
|
25
|
+
*/
|
|
26
|
+
function RetryPolicy() {}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Determines what to do when the driver gets an UnavailableException response from a Cassandra node.
|
|
30
|
+
* @param {OperationInfo} info
|
|
31
|
+
* @param {Number} consistency The [consistency]{@link module:types~consistencies} level of the query that triggered
|
|
32
|
+
* the exception.
|
|
33
|
+
* @param {Number} required The number of replicas whose response is required to achieve the
|
|
34
|
+
* required [consistency]{@link module:types~consistencies}.
|
|
35
|
+
* @param {Number} alive The number of replicas that were known to be alive when the request had been processed
|
|
36
|
+
* (since an unavailable exception has been triggered, there will be alive < required)
|
|
37
|
+
* @returns {DecisionInfo}
|
|
38
|
+
*/
|
|
39
|
+
RetryPolicy.prototype.onUnavailable = function (
|
|
40
|
+
info,
|
|
41
|
+
consistency,
|
|
42
|
+
required,
|
|
43
|
+
alive,
|
|
44
|
+
) {
|
|
45
|
+
if (info.nbRetry > 0) {
|
|
46
|
+
return this.rethrowResult()
|
|
47
|
+
}
|
|
48
|
+
return this.retryResult(undefined, false)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Determines what to do when the driver gets a ReadTimeoutException response from a Cassandra node.
|
|
53
|
+
* @param {OperationInfo} info
|
|
54
|
+
* @param {Number} consistency The [consistency]{@link module:types~consistencies} level of the query that triggered
|
|
55
|
+
* the exception.
|
|
56
|
+
* @param {Number} received The number of nodes having answered the request.
|
|
57
|
+
* @param {Number} blockFor The number of replicas whose response is required to achieve the
|
|
58
|
+
* required [consistency]{@link module:types~consistencies}.
|
|
59
|
+
* @param {Boolean} isDataPresent When <code>false</code>, it means the replica that was asked for data has not responded.
|
|
60
|
+
* @returns {DecisionInfo}
|
|
61
|
+
*/
|
|
62
|
+
RetryPolicy.prototype.onReadTimeout = function (
|
|
63
|
+
info,
|
|
64
|
+
consistency,
|
|
65
|
+
received,
|
|
66
|
+
blockFor,
|
|
67
|
+
isDataPresent,
|
|
68
|
+
) {
|
|
69
|
+
if (info.nbRetry > 0) {
|
|
70
|
+
return this.rethrowResult()
|
|
71
|
+
}
|
|
72
|
+
return received >= blockFor && !isDataPresent
|
|
73
|
+
? this.retryResult()
|
|
74
|
+
: this.rethrowResult()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Determines what to do when the driver gets a WriteTimeoutException response from a Cassandra node.
|
|
79
|
+
* @param {OperationInfo} info
|
|
80
|
+
* @param {Number} consistency The [consistency]{@link module:types~consistencies} level of the query that triggered
|
|
81
|
+
* the exception.
|
|
82
|
+
* @param {Number} received The number of nodes having acknowledged the request.
|
|
83
|
+
* @param {Number} blockFor The number of replicas whose acknowledgement is required to achieve the required
|
|
84
|
+
* [consistency]{@link module:types~consistencies}.
|
|
85
|
+
* @param {String} writeType A <code>string</code> that describes the type of the write that timed out ("SIMPLE"
|
|
86
|
+
* / "BATCH" / "BATCH_LOG" / "UNLOGGED_BATCH" / "COUNTER").
|
|
87
|
+
* @returns {DecisionInfo}
|
|
88
|
+
*/
|
|
89
|
+
RetryPolicy.prototype.onWriteTimeout = function (
|
|
90
|
+
info,
|
|
91
|
+
consistency,
|
|
92
|
+
received,
|
|
93
|
+
blockFor,
|
|
94
|
+
writeType,
|
|
95
|
+
) {
|
|
96
|
+
if (info.nbRetry > 0) {
|
|
97
|
+
return this.rethrowResult()
|
|
98
|
+
}
|
|
99
|
+
// If the batch log write failed, retry the operation as this might just be we were unlucky at picking candidates
|
|
100
|
+
return writeType === "BATCH_LOG" ? this.retryResult() : this.rethrowResult()
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Defines whether to retry and at which consistency level on an unexpected error.
|
|
105
|
+
* <p>
|
|
106
|
+
* This method might be invoked in the following situations:
|
|
107
|
+
* </p>
|
|
108
|
+
* <ol>
|
|
109
|
+
* <li>On a client timeout, while waiting for the server response
|
|
110
|
+
* (see [socketOptions.readTimeout]{@link ClientOptions}), being the error an instance of
|
|
111
|
+
* [OperationTimedOutError]{@link module:errors~OperationTimedOutError}.</li>
|
|
112
|
+
* <li>On a connection error (socket closed, etc.).</li>
|
|
113
|
+
* <li>When the contacted host replies with an error, such as <code>overloaded</code>, <code>isBootstrapping</code>,
|
|
114
|
+
* </code>serverError, etc. In this case, the error is instance of [ResponseError]{@link module:errors~ResponseError}.
|
|
115
|
+
* </li>
|
|
116
|
+
* </ol>
|
|
117
|
+
* <p>
|
|
118
|
+
* Note that when this method is invoked, <em>the driver cannot guarantee that the mutation has been effectively
|
|
119
|
+
* applied server-side</em>; a retry should only be attempted if the request is known to be idempotent.
|
|
120
|
+
* </p>
|
|
121
|
+
* @param {OperationInfo} info
|
|
122
|
+
* @param {Number|undefined} consistency The [consistency]{@link module:types~consistencies} level of the query that triggered
|
|
123
|
+
* the exception.
|
|
124
|
+
* @param {Error} err The error that caused this request to fail.
|
|
125
|
+
* @returns {DecisionInfo}
|
|
126
|
+
*/
|
|
127
|
+
RetryPolicy.prototype.onRequestError = function (info, consistency, err) {
|
|
128
|
+
// The default implementation triggers a retry on the next host in the query plan with the same consistency level,
|
|
129
|
+
// regardless of the statement's idempotence, for historical reasons.
|
|
130
|
+
return this.retryResult(undefined, false)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Returns a {@link DecisionInfo} to retry the request with the given [consistency]{@link module:types~consistencies}.
|
|
135
|
+
* @param {Number|undefined} [consistency] When specified, it retries the request with the given consistency.
|
|
136
|
+
* @param {Boolean} [useCurrentHost] When specified, determines if the retry should be made using the same coordinator.
|
|
137
|
+
* Default: true.
|
|
138
|
+
* @returns {DecisionInfo}
|
|
139
|
+
*/
|
|
140
|
+
RetryPolicy.prototype.retryResult = function (consistency, useCurrentHost) {
|
|
141
|
+
return {
|
|
142
|
+
decision: RetryPolicy.retryDecision.retry,
|
|
143
|
+
consistency: consistency,
|
|
144
|
+
useCurrentHost: useCurrentHost !== false,
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Returns a {@link DecisionInfo} to callback in error when a err is obtained for a given request.
|
|
150
|
+
* @returns {DecisionInfo}
|
|
151
|
+
*/
|
|
152
|
+
RetryPolicy.prototype.rethrowResult = function () {
|
|
153
|
+
return { decision: RetryPolicy.retryDecision.rethrow }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Determines the retry decision for the retry policies.
|
|
158
|
+
* @type {Object}
|
|
159
|
+
* @property {Number} rethrow
|
|
160
|
+
* @property {Number} retry
|
|
161
|
+
* @property {Number} ignore
|
|
162
|
+
* @static
|
|
163
|
+
*/
|
|
164
|
+
RetryPolicy.retryDecision = {
|
|
165
|
+
rethrow: 0,
|
|
166
|
+
retry: 1,
|
|
167
|
+
ignore: 2,
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Creates a new instance of <code>IdempotenceAwareRetryPolicy</code>.
|
|
172
|
+
* @classdesc
|
|
173
|
+
* A retry policy that avoids retrying non-idempotent statements.
|
|
174
|
+
* <p>
|
|
175
|
+
* In case of write timeouts or unexpected errors, this policy will always return
|
|
176
|
+
* [rethrowResult()]{@link module:policies/retry~RetryPolicy#rethrowResult} if the statement is deemed non-idempotent
|
|
177
|
+
* (see [QueryOptions.isIdempotent]{@link QueryOptions}).
|
|
178
|
+
* <p/>
|
|
179
|
+
* For all other cases, this policy delegates the decision to the child policy.
|
|
180
|
+
* @param {RetryPolicy} [childPolicy] The child retry policy to wrap. When not defined, it will use an instance of
|
|
181
|
+
* [RetryPolicy]{@link module:policies/retry~RetryPolicy} as child policy.
|
|
182
|
+
* @extends module:policies/retry~RetryPolicy
|
|
183
|
+
* @constructor
|
|
184
|
+
* @deprecated Since version 4.0 non-idempotent operations are never tried for write timeout or request error, use the
|
|
185
|
+
* default retry policy instead.
|
|
186
|
+
*/
|
|
187
|
+
function IdempotenceAwareRetryPolicy(childPolicy) {
|
|
188
|
+
this._childPolicy = childPolicy || new RetryPolicy()
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
util.inherits(IdempotenceAwareRetryPolicy, RetryPolicy)
|
|
192
|
+
|
|
193
|
+
IdempotenceAwareRetryPolicy.prototype.onReadTimeout = function (
|
|
194
|
+
info,
|
|
195
|
+
consistency,
|
|
196
|
+
received,
|
|
197
|
+
blockFor,
|
|
198
|
+
isDataPresent,
|
|
199
|
+
) {
|
|
200
|
+
return this._childPolicy.onReadTimeout(
|
|
201
|
+
info,
|
|
202
|
+
consistency,
|
|
203
|
+
received,
|
|
204
|
+
blockFor,
|
|
205
|
+
isDataPresent,
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* If the query is not idempotent, it returns a rethrow decision. Otherwise, it relies on the child policy to decide.
|
|
211
|
+
*/
|
|
212
|
+
IdempotenceAwareRetryPolicy.prototype.onRequestError = function (
|
|
213
|
+
info,
|
|
214
|
+
consistency,
|
|
215
|
+
err,
|
|
216
|
+
) {
|
|
217
|
+
if (info.executionOptions.isIdempotent()) {
|
|
218
|
+
return this._childPolicy.onRequestError(info, consistency, err)
|
|
219
|
+
}
|
|
220
|
+
return this.rethrowResult()
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
IdempotenceAwareRetryPolicy.prototype.onUnavailable = function (
|
|
224
|
+
info,
|
|
225
|
+
consistency,
|
|
226
|
+
required,
|
|
227
|
+
alive,
|
|
228
|
+
) {
|
|
229
|
+
return this._childPolicy.onUnavailable(info, consistency, required, alive)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* If the query is not idempotent, it return a rethrow decision. Otherwise, it relies on the child policy to decide.
|
|
234
|
+
*/
|
|
235
|
+
IdempotenceAwareRetryPolicy.prototype.onWriteTimeout = function (
|
|
236
|
+
info,
|
|
237
|
+
consistency,
|
|
238
|
+
received,
|
|
239
|
+
blockFor,
|
|
240
|
+
writeType,
|
|
241
|
+
) {
|
|
242
|
+
if (info.executionOptions.isIdempotent()) {
|
|
243
|
+
return this._childPolicy.onWriteTimeout(
|
|
244
|
+
info,
|
|
245
|
+
consistency,
|
|
246
|
+
received,
|
|
247
|
+
blockFor,
|
|
248
|
+
writeType,
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
return this.rethrowResult()
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Creates a new instance of FallthroughRetryPolicy.
|
|
256
|
+
* @classdesc
|
|
257
|
+
* A retry policy that never retries nor ignores.
|
|
258
|
+
* <p>
|
|
259
|
+
* All of the methods of this retry policy unconditionally return
|
|
260
|
+
* [rethrow]{@link module:policies/retry~Retry#rethrowResult()}. If this policy is used, retry logic will have to be
|
|
261
|
+
* implemented in business code.
|
|
262
|
+
* </p>
|
|
263
|
+
* @alias module:policies/retry~FallthroughRetryPolicy
|
|
264
|
+
* @extends RetryPolicy
|
|
265
|
+
* @constructor
|
|
266
|
+
*/
|
|
267
|
+
function FallthroughRetryPolicy() {}
|
|
268
|
+
|
|
269
|
+
util.inherits(FallthroughRetryPolicy, RetryPolicy)
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Implementation of RetryPolicy method that returns [rethrow]{@link module:policies/retry~Retry#rethrowResult()}.
|
|
273
|
+
*/
|
|
274
|
+
FallthroughRetryPolicy.prototype.onReadTimeout = function () {
|
|
275
|
+
return this.rethrowResult()
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Implementation of RetryPolicy method that returns [rethrow]{@link module:policies/retry~Retry#rethrowResult()}.
|
|
280
|
+
*/
|
|
281
|
+
FallthroughRetryPolicy.prototype.onRequestError = function () {
|
|
282
|
+
return this.rethrowResult()
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Implementation of RetryPolicy method that returns [rethrow]{@link module:policies/retry~Retry#rethrowResult()}.
|
|
287
|
+
*/
|
|
288
|
+
FallthroughRetryPolicy.prototype.onUnavailable = function () {
|
|
289
|
+
return this.rethrowResult()
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Implementation of RetryPolicy method that returns [rethrow]{@link module:policies/retry~Retry#rethrowResult()}.
|
|
294
|
+
*/
|
|
295
|
+
FallthroughRetryPolicy.prototype.onWriteTimeout = function () {
|
|
296
|
+
return this.rethrowResult()
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Decision information
|
|
301
|
+
* @typedef {Object} DecisionInfo
|
|
302
|
+
* @property {Number} decision The decision as specified in
|
|
303
|
+
* [retryDecision]{@link module:policies/retry~RetryPolicy.retryDecision}.
|
|
304
|
+
* @property {Number} [consistency] The [consistency level]{@link module:types~consistencies}.
|
|
305
|
+
* @property {useCurrentHost} [useCurrentHost] Determines if it should use the same host to retry the request.
|
|
306
|
+
* <p>
|
|
307
|
+
* In the case that the current host is not available anymore, it will be retried on the next host even when
|
|
308
|
+
* <code>useCurrentHost</code> is set to <code>true</code>.
|
|
309
|
+
* </p>
|
|
310
|
+
*/
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Information of the execution to be used to determine whether the operation should be retried.
|
|
314
|
+
* @typedef {Object} OperationInfo
|
|
315
|
+
* @property {String} query The query that was executed.
|
|
316
|
+
* @param {ExecutionOptions} executionOptions The options related to the execution of the request.
|
|
317
|
+
* @property {Number} nbRetry The number of retries already performed for this operation.
|
|
318
|
+
*/
|
|
319
|
+
|
|
320
|
+
export { IdempotenceAwareRetryPolicy, FallthroughRetryPolicy, RetryPolicy }
|
|
321
|
+
|
|
322
|
+
export default {
|
|
323
|
+
IdempotenceAwareRetryPolicy,
|
|
324
|
+
FallthroughRetryPolicy,
|
|
325
|
+
RetryPolicy,
|
|
326
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
import util from "util"
|
|
19
|
+
import errors from "../errors.js"
|
|
20
|
+
|
|
21
|
+
/** @module policies/speculativeExecution */
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @classdesc
|
|
25
|
+
* The policy that decides if the driver will send speculative queries to the next hosts when the current host takes too
|
|
26
|
+
* long to respond.
|
|
27
|
+
* <p>Note that only idempotent statements will be speculatively retried.</p>
|
|
28
|
+
* @constructor
|
|
29
|
+
* @abstract
|
|
30
|
+
*/
|
|
31
|
+
function SpeculativeExecutionPolicy() {}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Initialization method that gets invoked on Client startup.
|
|
35
|
+
* @param {Client} client
|
|
36
|
+
* @abstract
|
|
37
|
+
*/
|
|
38
|
+
SpeculativeExecutionPolicy.prototype.init = function (client) {}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Gets invoked at client shutdown, giving the opportunity to the implementor to perform cleanup.
|
|
42
|
+
* @abstract
|
|
43
|
+
*/
|
|
44
|
+
SpeculativeExecutionPolicy.prototype.shutdown = function () {}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Gets the plan to use for a new query.
|
|
48
|
+
* Returns an object with a <code>nextExecution()</code> method, which returns a positive number representing the
|
|
49
|
+
* amount of milliseconds to delay the next execution or a non-negative number to avoid further executions.
|
|
50
|
+
* @param {String} keyspace The currently logged keyspace.
|
|
51
|
+
* @param {String|Array<String>} queryInfo The query, or queries in the case of batches, for which to build a plan.
|
|
52
|
+
* @return {{nextExecution: function}}
|
|
53
|
+
* @abstract
|
|
54
|
+
*/
|
|
55
|
+
SpeculativeExecutionPolicy.prototype.newPlan = function (keyspace, queryInfo) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
"You must implement newPlan() method in the SpeculativeExecutionPolicy",
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Gets an associative array containing the policy options.
|
|
63
|
+
*/
|
|
64
|
+
SpeculativeExecutionPolicy.prototype.getOptions = function () {
|
|
65
|
+
return new Map()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Creates a new instance of NoSpeculativeExecutionPolicy.
|
|
70
|
+
* @classdesc
|
|
71
|
+
* A {@link SpeculativeExecutionPolicy} that never schedules speculative executions.
|
|
72
|
+
* @constructor
|
|
73
|
+
* @extends {SpeculativeExecutionPolicy}
|
|
74
|
+
*/
|
|
75
|
+
function NoSpeculativeExecutionPolicy() {
|
|
76
|
+
this._plan = {
|
|
77
|
+
nextExecution: function () {
|
|
78
|
+
return -1
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
util.inherits(NoSpeculativeExecutionPolicy, SpeculativeExecutionPolicy)
|
|
84
|
+
|
|
85
|
+
NoSpeculativeExecutionPolicy.prototype.newPlan = function () {
|
|
86
|
+
return this._plan
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Creates a new instance of ConstantSpeculativeExecutionPolicy.
|
|
91
|
+
* @classdesc
|
|
92
|
+
* A {@link SpeculativeExecutionPolicy} that schedules a given number of speculative executions,
|
|
93
|
+
* separated by a fixed delay.
|
|
94
|
+
* @constructor
|
|
95
|
+
* @param {Number} delay The delay between each speculative execution.
|
|
96
|
+
* @param {Number} maxSpeculativeExecutions The amount of speculative executions that should be scheduled after the
|
|
97
|
+
* initial execution. Must be strictly positive.
|
|
98
|
+
* @extends {SpeculativeExecutionPolicy}
|
|
99
|
+
*/
|
|
100
|
+
function ConstantSpeculativeExecutionPolicy(delay, maxSpeculativeExecutions) {
|
|
101
|
+
if (!(delay >= 0)) {
|
|
102
|
+
throw new errors.ArgumentError(
|
|
103
|
+
"delay must be a positive number or zero",
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
if (!(maxSpeculativeExecutions > 0)) {
|
|
107
|
+
throw new errors.ArgumentError(
|
|
108
|
+
"maxSpeculativeExecutions must be a positive number",
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
this._delay = delay
|
|
112
|
+
this._maxSpeculativeExecutions = maxSpeculativeExecutions
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
util.inherits(ConstantSpeculativeExecutionPolicy, SpeculativeExecutionPolicy)
|
|
116
|
+
|
|
117
|
+
ConstantSpeculativeExecutionPolicy.prototype.newPlan = function () {
|
|
118
|
+
let executions = 0
|
|
119
|
+
const self = this
|
|
120
|
+
return {
|
|
121
|
+
nextExecution: function () {
|
|
122
|
+
if (executions++ < self._maxSpeculativeExecutions) {
|
|
123
|
+
return self._delay
|
|
124
|
+
}
|
|
125
|
+
return -1
|
|
126
|
+
},
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Gets an associative array containing the policy options.
|
|
132
|
+
*/
|
|
133
|
+
ConstantSpeculativeExecutionPolicy.prototype.getOptions = function () {
|
|
134
|
+
return new Map([
|
|
135
|
+
["delay", this._delay],
|
|
136
|
+
["maxSpeculativeExecutions", this._maxSpeculativeExecutions],
|
|
137
|
+
])
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
NoSpeculativeExecutionPolicy,
|
|
142
|
+
SpeculativeExecutionPolicy,
|
|
143
|
+
ConstantSpeculativeExecutionPolicy,
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export default {
|
|
147
|
+
NoSpeculativeExecutionPolicy,
|
|
148
|
+
SpeculativeExecutionPolicy,
|
|
149
|
+
ConstantSpeculativeExecutionPolicy,
|
|
150
|
+
}
|