@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,77 @@
|
|
|
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 DataCollection from "./data-collection.js"
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new instance of TableMetadata
|
|
22
|
+
* @classdesc Describes a table
|
|
23
|
+
* @param {String} name Name of the Table
|
|
24
|
+
* @augments {module:metadata~DataCollection}
|
|
25
|
+
* @alias module:metadata~TableMetadata
|
|
26
|
+
* @constructor
|
|
27
|
+
*/
|
|
28
|
+
function TableMetadata(name) {
|
|
29
|
+
DataCollection.call(this, name)
|
|
30
|
+
/**
|
|
31
|
+
* Applies only to counter tables.
|
|
32
|
+
* When set to true, replicates writes to all affected replicas regardless of the consistency level specified by
|
|
33
|
+
* the client for a write request. For counter tables, this should always be set to true.
|
|
34
|
+
* @type {Boolean}
|
|
35
|
+
*/
|
|
36
|
+
this.replicateOnWrite = true
|
|
37
|
+
/**
|
|
38
|
+
* Returns the memtable flush period (in milliseconds) option for this table.
|
|
39
|
+
* @type {Number}
|
|
40
|
+
*/
|
|
41
|
+
this.memtableFlushPeriod = 0
|
|
42
|
+
/**
|
|
43
|
+
* Returns the index interval option for this table.
|
|
44
|
+
* <p>
|
|
45
|
+
* Note: this option is only available in Apache Cassandra 2.0. It is deprecated in Apache Cassandra 2.1 and
|
|
46
|
+
* above, and will therefore return <code>null</code> for 2.1 nodes.
|
|
47
|
+
* </p>
|
|
48
|
+
* @type {Number|null}
|
|
49
|
+
*/
|
|
50
|
+
this.indexInterval = null
|
|
51
|
+
/**
|
|
52
|
+
* Determines whether the table uses the COMPACT STORAGE option.
|
|
53
|
+
* @type {Boolean}
|
|
54
|
+
*/
|
|
55
|
+
this.isCompact = false
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* @type {Array.<Index>}
|
|
59
|
+
*/
|
|
60
|
+
this.indexes = null
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Determines whether the Change Data Capture (CDC) flag is set for the table.
|
|
64
|
+
* @type {Boolean|null}
|
|
65
|
+
*/
|
|
66
|
+
this.cdc = null
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Determines whether the table is a virtual table or not.
|
|
70
|
+
* @type {Boolean}
|
|
71
|
+
*/
|
|
72
|
+
this.virtual = false
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
util.inherits(TableMetadata, DataCollection)
|
|
76
|
+
|
|
77
|
+
export default TableMetadata
|
|
@@ -0,0 +1,206 @@
|
|
|
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 utils from "./utils.js"
|
|
20
|
+
import errors from "./errors.js"
|
|
21
|
+
import { ExecuteRequest, QueryRequest } from "./requests.js"
|
|
22
|
+
|
|
23
|
+
const state = {
|
|
24
|
+
init: 0,
|
|
25
|
+
completed: 1,
|
|
26
|
+
timedOut: 2,
|
|
27
|
+
cancelled: 3,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Maintains the state information of a request inside a Connection.
|
|
32
|
+
*/
|
|
33
|
+
class OperationState {
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new instance of OperationState.
|
|
36
|
+
* @param {Request} request
|
|
37
|
+
* @param {Function} rowCallback
|
|
38
|
+
* @param {Function} callback
|
|
39
|
+
*/
|
|
40
|
+
constructor(request, rowCallback, callback) {
|
|
41
|
+
this.request = request
|
|
42
|
+
this._rowCallback = rowCallback
|
|
43
|
+
this._callback = callback
|
|
44
|
+
this._deadline = 0
|
|
45
|
+
this._state = state.init
|
|
46
|
+
this._rowIndex = 0
|
|
47
|
+
/**
|
|
48
|
+
* Stream id that is set right before being written.
|
|
49
|
+
* @type {number}
|
|
50
|
+
*/
|
|
51
|
+
this.streamId = -1
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Marks the operation as cancelled, clearing all callbacks.
|
|
56
|
+
*/
|
|
57
|
+
cancel() {
|
|
58
|
+
if (this._state !== state.init) {
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
this._state = state.cancelled
|
|
62
|
+
this._callback = utils.noop
|
|
63
|
+
this._deadline = 0
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Determines if the operation can be written to the wire (when it hasn't been cancelled or it hasn't timed out).
|
|
68
|
+
*/
|
|
69
|
+
canBeWritten() {
|
|
70
|
+
return this._state === state.init
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Determines if the response is going to be yielded by row.
|
|
75
|
+
* @return {boolean}
|
|
76
|
+
*/
|
|
77
|
+
isByRow() {
|
|
78
|
+
return (
|
|
79
|
+
this._rowCallback &&
|
|
80
|
+
(this.request instanceof ExecuteRequest ||
|
|
81
|
+
this.request instanceof QueryRequest)
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Stores the timeout deadline for this operation.
|
|
87
|
+
* The actual timer is managed by Connection to avoid per-operation setTimeout overhead.
|
|
88
|
+
* @param {ExecutionOptions} execOptions
|
|
89
|
+
* @param {Number} defaultReadTimeout
|
|
90
|
+
* @param {String} address
|
|
91
|
+
* @param {Function} onTimeout The callback to be invoked when it times out.
|
|
92
|
+
* @param {Function} onResponse The callback to be invoked if a response is obtained after it timed out.
|
|
93
|
+
*/
|
|
94
|
+
setRequestTimeout(
|
|
95
|
+
execOptions,
|
|
96
|
+
defaultReadTimeout,
|
|
97
|
+
address,
|
|
98
|
+
onTimeout,
|
|
99
|
+
onResponse,
|
|
100
|
+
) {
|
|
101
|
+
if (this._state !== state.init) {
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
const millis =
|
|
105
|
+
execOptions.getReadTimeout() !== undefined
|
|
106
|
+
? execOptions.getReadTimeout()
|
|
107
|
+
: defaultReadTimeout
|
|
108
|
+
if (!(millis > 0)) {
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
this._deadline = Date.now() + millis
|
|
113
|
+
this._timeoutMillis = millis
|
|
114
|
+
this._onTimeoutCb = onTimeout
|
|
115
|
+
this._onResponseCb = onResponse
|
|
116
|
+
this._address = address
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Checks if this operation has timed out.
|
|
121
|
+
* Called by the Connection's shared timeout timer.
|
|
122
|
+
* @param {Number} now current timestamp
|
|
123
|
+
* @returns {boolean} true if the operation timed out
|
|
124
|
+
*/
|
|
125
|
+
checkTimeout(now) {
|
|
126
|
+
if (
|
|
127
|
+
this._state !== state.init ||
|
|
128
|
+
!this._deadline ||
|
|
129
|
+
this._deadline > now
|
|
130
|
+
) {
|
|
131
|
+
return false
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
this._onTimeoutCb()
|
|
135
|
+
const message = util.format(
|
|
136
|
+
"The host %s did not reply before timeout %d ms",
|
|
137
|
+
this._address,
|
|
138
|
+
this._timeoutMillis,
|
|
139
|
+
)
|
|
140
|
+
this._markAsTimedOut(
|
|
141
|
+
new errors.OperationTimedOutError(message, this._address),
|
|
142
|
+
this._onResponseCb,
|
|
143
|
+
)
|
|
144
|
+
return true
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
setResultRow(row, meta, rowLength, flags, header) {
|
|
148
|
+
this._markAsCompleted()
|
|
149
|
+
if (!this._rowCallback) {
|
|
150
|
+
return this.setResult(
|
|
151
|
+
new errors.DriverInternalError(
|
|
152
|
+
"RowCallback not found for streaming frame handler",
|
|
153
|
+
),
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
this._rowCallback(this._rowIndex++, row, rowLength)
|
|
157
|
+
if (this._rowIndex === rowLength) {
|
|
158
|
+
this._swapCallbackAndInvoke(
|
|
159
|
+
null,
|
|
160
|
+
{ rowLength: rowLength, meta: meta, flags: flags },
|
|
161
|
+
header.bodyLength,
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Marks the current operation as timed out.
|
|
168
|
+
* @param {Error} err
|
|
169
|
+
* @param {Function} onResponse
|
|
170
|
+
* @private
|
|
171
|
+
*/
|
|
172
|
+
_markAsTimedOut(err, onResponse) {
|
|
173
|
+
if (this._state !== state.init) {
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
this._state = state.timedOut
|
|
177
|
+
this._swapCallbackAndInvoke(err, null, null, onResponse)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
_markAsCompleted() {
|
|
181
|
+
if (this._state !== state.init) {
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
this._state = state.completed
|
|
185
|
+
this._deadline = 0
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Sets the result of this operation, declaring that no further input will be processed for this operation.
|
|
190
|
+
* @param {Error} err
|
|
191
|
+
* @param {Object} [result]
|
|
192
|
+
* @param {Number} [length]
|
|
193
|
+
*/
|
|
194
|
+
setResult(err, result, length) {
|
|
195
|
+
this._markAsCompleted()
|
|
196
|
+
this._swapCallbackAndInvoke(err, result, length)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
_swapCallbackAndInvoke(err, result, length, newCallback) {
|
|
200
|
+
const callback = this._callback
|
|
201
|
+
this._callback = newCallback || utils.noop
|
|
202
|
+
callback(err, result, length)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export default OperationState
|
|
@@ -0,0 +1,145 @@
|
|
|
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 dns from "dns"
|
|
19
|
+
import util from "util"
|
|
20
|
+
import utils from "../utils.js"
|
|
21
|
+
/** @module policies/addressResolution */
|
|
22
|
+
/**
|
|
23
|
+
* @class
|
|
24
|
+
* @classdesc
|
|
25
|
+
* Translates IP addresses received from Cassandra nodes into locally queryable
|
|
26
|
+
* addresses.
|
|
27
|
+
* <p>
|
|
28
|
+
* The driver auto-detects new Cassandra nodes added to the cluster through server
|
|
29
|
+
* side pushed notifications and through checking the system tables. For each
|
|
30
|
+
* node, the address received will correspond to the address set as
|
|
31
|
+
* <code>rpc_address</code> in the node yaml file. In most case, this is the correct
|
|
32
|
+
* address to use by the driver and that is what is used by default. However,
|
|
33
|
+
* sometimes the addresses received through this mechanism will either not be
|
|
34
|
+
* reachable directly by the driver or should not be the preferred address to use
|
|
35
|
+
* to reach the node (for instance, the <code>rpc_address</code> set on Cassandra nodes
|
|
36
|
+
* might be a private IP, but some clients may have to use a public IP, or
|
|
37
|
+
* pass by a router to reach that node). This interface allows to deal with
|
|
38
|
+
* such cases, by allowing to translate an address as sent by a Cassandra node
|
|
39
|
+
* to another address to be used by the driver for connection.
|
|
40
|
+
* <p>
|
|
41
|
+
* Please note that the contact points addresses provided while creating the
|
|
42
|
+
* {@link Client} instance are not "translated", only IP address retrieve from or sent
|
|
43
|
+
* by Cassandra nodes to the driver are.
|
|
44
|
+
* @constructor
|
|
45
|
+
*/
|
|
46
|
+
function AddressTranslator() {}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Translates a Cassandra <code>rpc_address</code> to another address if necessary.
|
|
50
|
+
* @param {String} address the address of a node as returned by Cassandra.
|
|
51
|
+
* <p>
|
|
52
|
+
* Note that if the <code>rpc_address</code> of a node has been configured to <code>0.0.0.0</code>
|
|
53
|
+
* server side, then the provided address will be the node <code>listen_address</code>,
|
|
54
|
+
* *not* <code>0.0.0.0</code>.
|
|
55
|
+
* </p>
|
|
56
|
+
* @param {Number} port The port number, as specified in the [protocolOptions]{@link ClientOptions} at Client instance creation (9042 by default).
|
|
57
|
+
* @param {Function} callback Callback to invoke with endpoint as first parameter.
|
|
58
|
+
* The endpoint is an string composed of the IP address and the port number in the format <code>ipAddress:port</code>.
|
|
59
|
+
*/
|
|
60
|
+
AddressTranslator.prototype.translate = function (address, port, callback) {
|
|
61
|
+
callback(address + ":" + port)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @class
|
|
66
|
+
* @classdesc
|
|
67
|
+
* {@link AddressTranslator} implementation for multi-region EC2 deployments <strong>where clients are also deployed in EC2</strong>.
|
|
68
|
+
* <p>
|
|
69
|
+
* Its distinctive feature is that it translates addresses according to the location of the Cassandra host:
|
|
70
|
+
* </p>
|
|
71
|
+
* <ul>
|
|
72
|
+
* <li>addresses in different EC2 regions (than the client) are unchanged</li>
|
|
73
|
+
* <li>addresses in the same EC2 region are <strong>translated to private IPs</strong></li>
|
|
74
|
+
* </ul>
|
|
75
|
+
* <p>
|
|
76
|
+
* This optimizes network costs, because Amazon charges more for communication over public IPs.
|
|
77
|
+
* </p>
|
|
78
|
+
* @constructor
|
|
79
|
+
*/
|
|
80
|
+
function EC2MultiRegionTranslator() {}
|
|
81
|
+
|
|
82
|
+
util.inherits(EC2MultiRegionTranslator, AddressTranslator)
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Addresses in the same EC2 region are translated to private IPs and addresses in
|
|
86
|
+
* different EC2 regions (than the client) are unchanged
|
|
87
|
+
*/
|
|
88
|
+
EC2MultiRegionTranslator.prototype.translate = function (
|
|
89
|
+
address,
|
|
90
|
+
port,
|
|
91
|
+
callback,
|
|
92
|
+
) {
|
|
93
|
+
let newAddress = address
|
|
94
|
+
const self = this
|
|
95
|
+
let name
|
|
96
|
+
utils.series(
|
|
97
|
+
[
|
|
98
|
+
function resolve(next) {
|
|
99
|
+
dns.reverse(address, function (err, hostNames) {
|
|
100
|
+
if (err) {
|
|
101
|
+
return next(err)
|
|
102
|
+
}
|
|
103
|
+
if (!hostNames) {
|
|
104
|
+
return next()
|
|
105
|
+
}
|
|
106
|
+
name = hostNames[0]
|
|
107
|
+
next()
|
|
108
|
+
})
|
|
109
|
+
},
|
|
110
|
+
function lookup(next) {
|
|
111
|
+
if (!name) {
|
|
112
|
+
return next()
|
|
113
|
+
}
|
|
114
|
+
dns.lookup(name, function (err, lookupAddress) {
|
|
115
|
+
if (err) {
|
|
116
|
+
return next(err)
|
|
117
|
+
}
|
|
118
|
+
newAddress = lookupAddress
|
|
119
|
+
next()
|
|
120
|
+
})
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
function (err) {
|
|
124
|
+
if (err) {
|
|
125
|
+
//there was an issue while doing dns resolution
|
|
126
|
+
self.logError(address, err)
|
|
127
|
+
}
|
|
128
|
+
callback(newAddress + ":" + port)
|
|
129
|
+
},
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Log method called to log errors that occurred while performing dns resolution.
|
|
135
|
+
* You can assign your own method to the class instance to do proper logging.
|
|
136
|
+
* @param {String} address
|
|
137
|
+
* @param {Error} err
|
|
138
|
+
*/
|
|
139
|
+
EC2MultiRegionTranslator.prototype.logError = function (address, err) {
|
|
140
|
+
//Do nothing by default
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export { AddressTranslator, EC2MultiRegionTranslator }
|
|
144
|
+
|
|
145
|
+
export default { AddressTranslator, EC2MultiRegionTranslator }
|
|
@@ -0,0 +1,241 @@
|
|
|
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
|
+
|
|
19
|
+
import { Client, EmptyCallback, ExecutionOptions, Host, HostMap } from ".."
|
|
20
|
+
import { types } from "../types"
|
|
21
|
+
|
|
22
|
+
export namespace policies {
|
|
23
|
+
function defaultAddressTranslator(): addressResolution.AddressTranslator
|
|
24
|
+
|
|
25
|
+
function defaultLoadBalancingPolicy(
|
|
26
|
+
localDc?: string,
|
|
27
|
+
): loadBalancing.LoadBalancingPolicy
|
|
28
|
+
|
|
29
|
+
function defaultReconnectionPolicy(): reconnection.ReconnectionPolicy
|
|
30
|
+
|
|
31
|
+
function defaultRetryPolicy(): retry.RetryPolicy
|
|
32
|
+
|
|
33
|
+
function defaultSpeculativeExecutionPolicy(): speculativeExecution.SpeculativeExecutionPolicy
|
|
34
|
+
|
|
35
|
+
function defaultTimestampGenerator(): timestampGeneration.TimestampGenerator
|
|
36
|
+
|
|
37
|
+
namespace addressResolution {
|
|
38
|
+
interface AddressTranslator {
|
|
39
|
+
translate(address: string, port: number, callback: Function): void
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
class EC2MultiRegionTranslator implements AddressTranslator {
|
|
43
|
+
translate(address: string, port: number, callback: Function): void
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
namespace loadBalancing {
|
|
48
|
+
abstract class LoadBalancingPolicy {
|
|
49
|
+
init(client: Client, hosts: HostMap, callback: EmptyCallback): void
|
|
50
|
+
|
|
51
|
+
getDistance(host: Host): types.distance
|
|
52
|
+
|
|
53
|
+
newQueryPlan(
|
|
54
|
+
keyspace: string,
|
|
55
|
+
executionOptions: ExecutionOptions,
|
|
56
|
+
callback: (error: Error, iterator: Iterator<Host>) => void,
|
|
57
|
+
): void
|
|
58
|
+
|
|
59
|
+
getOptions(): Map<string, object>
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
class DCAwareRoundRobinPolicy extends LoadBalancingPolicy {
|
|
63
|
+
constructor(localDc: string)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
class TokenAwarePolicy extends LoadBalancingPolicy {
|
|
67
|
+
constructor(childPolicy: LoadBalancingPolicy)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
class AllowListPolicy extends LoadBalancingPolicy {
|
|
71
|
+
constructor(childPolicy: LoadBalancingPolicy, allowList: string[])
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
class WhiteListPolicy extends AllowListPolicy {}
|
|
75
|
+
|
|
76
|
+
class RoundRobinPolicy extends LoadBalancingPolicy {
|
|
77
|
+
constructor()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
class DefaultLoadBalancingPolicy extends LoadBalancingPolicy {
|
|
81
|
+
constructor(options?: {
|
|
82
|
+
localDc?: string
|
|
83
|
+
filter?: (host: Host) => boolean
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
namespace reconnection {
|
|
89
|
+
class ConstantReconnectionPolicy implements ReconnectionPolicy {
|
|
90
|
+
constructor(delay: number)
|
|
91
|
+
|
|
92
|
+
getOptions(): Map<string, object>
|
|
93
|
+
|
|
94
|
+
newSchedule(): Iterator<number>
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
class ExponentialReconnectionPolicy implements ReconnectionPolicy {
|
|
98
|
+
constructor(
|
|
99
|
+
baseDelay: number,
|
|
100
|
+
maxDelay: number,
|
|
101
|
+
startWithNoDelay?: boolean,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
getOptions(): Map<string, object>
|
|
105
|
+
|
|
106
|
+
newSchedule(): Iterator<number>
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface ReconnectionPolicy {
|
|
110
|
+
getOptions(): Map<string, object>
|
|
111
|
+
|
|
112
|
+
newSchedule(): Iterator<number>
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
namespace retry {
|
|
117
|
+
class DecisionInfo {
|
|
118
|
+
decision: number
|
|
119
|
+
consistency: types.consistencies
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
class OperationInfo {
|
|
123
|
+
query: string
|
|
124
|
+
executionOptions: ExecutionOptions
|
|
125
|
+
nbRetry: number
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
class IdempotenceAwareRetryPolicy extends RetryPolicy {
|
|
129
|
+
constructor(childPolicy: RetryPolicy)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
class FallthroughRetryPolicy extends RetryPolicy {
|
|
133
|
+
constructor()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
class RetryPolicy {
|
|
137
|
+
onReadTimeout(
|
|
138
|
+
info: OperationInfo,
|
|
139
|
+
consistency: types.consistencies,
|
|
140
|
+
received: number,
|
|
141
|
+
blockFor: number,
|
|
142
|
+
isDataPresent: boolean,
|
|
143
|
+
): DecisionInfo
|
|
144
|
+
|
|
145
|
+
onRequestError(
|
|
146
|
+
info: OperationInfo,
|
|
147
|
+
consistency: types.consistencies,
|
|
148
|
+
err: Error,
|
|
149
|
+
): DecisionInfo
|
|
150
|
+
|
|
151
|
+
onUnavailable(
|
|
152
|
+
info: OperationInfo,
|
|
153
|
+
consistency: types.consistencies,
|
|
154
|
+
required: number,
|
|
155
|
+
alive: boolean,
|
|
156
|
+
): DecisionInfo
|
|
157
|
+
|
|
158
|
+
onWriteTimeout(
|
|
159
|
+
info: OperationInfo,
|
|
160
|
+
consistency: types.consistencies,
|
|
161
|
+
received: number,
|
|
162
|
+
blockFor: number,
|
|
163
|
+
writeType: string,
|
|
164
|
+
): DecisionInfo
|
|
165
|
+
|
|
166
|
+
rethrowResult(): DecisionInfo
|
|
167
|
+
|
|
168
|
+
retryResult(
|
|
169
|
+
consistency: types.consistencies,
|
|
170
|
+
useCurrentHost?: boolean,
|
|
171
|
+
): DecisionInfo
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
namespace RetryDecision {
|
|
175
|
+
enum retryDecision {
|
|
176
|
+
ignore,
|
|
177
|
+
rethrow,
|
|
178
|
+
retry,
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
namespace speculativeExecution {
|
|
184
|
+
class ConstantSpeculativeExecutionPolicy implements SpeculativeExecutionPolicy {
|
|
185
|
+
constructor(delay: number, maxSpeculativeExecutions: number)
|
|
186
|
+
|
|
187
|
+
getOptions(): Map<string, object>
|
|
188
|
+
|
|
189
|
+
init(client: Client): void
|
|
190
|
+
|
|
191
|
+
newPlan(
|
|
192
|
+
keyspace: string,
|
|
193
|
+
queryInfo: string | Array<object>,
|
|
194
|
+
): { nextExecution: Function }
|
|
195
|
+
|
|
196
|
+
shutdown(): void
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
class NoSpeculativeExecutionPolicy implements SpeculativeExecutionPolicy {
|
|
200
|
+
constructor()
|
|
201
|
+
|
|
202
|
+
getOptions(): Map<string, object>
|
|
203
|
+
|
|
204
|
+
init(client: Client): void
|
|
205
|
+
|
|
206
|
+
newPlan(
|
|
207
|
+
keyspace: string,
|
|
208
|
+
queryInfo: string | Array<object>,
|
|
209
|
+
): { nextExecution: Function }
|
|
210
|
+
|
|
211
|
+
shutdown(): void
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
interface SpeculativeExecutionPolicy {
|
|
215
|
+
getOptions(): Map<string, object>
|
|
216
|
+
|
|
217
|
+
init(client: Client): void
|
|
218
|
+
|
|
219
|
+
newPlan(
|
|
220
|
+
keyspace: string,
|
|
221
|
+
queryInfo: string | Array<object>,
|
|
222
|
+
): { nextExecution: Function }
|
|
223
|
+
|
|
224
|
+
shutdown(): void
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
namespace timestampGeneration {
|
|
229
|
+
class MonotonicTimestampGenerator implements TimestampGenerator {
|
|
230
|
+
constructor(warningThreshold: number, minLogInterval: number)
|
|
231
|
+
|
|
232
|
+
getDate(): number
|
|
233
|
+
|
|
234
|
+
next(client: Client): types.Long | number
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
interface TimestampGenerator {
|
|
238
|
+
next(client: Client): types.Long | number
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|