@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,119 @@
|
|
|
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
|
+
/**
|
|
22
|
+
* Represents the state of a {@link Client}.
|
|
23
|
+
* <p>
|
|
24
|
+
* Exposes information on the connections maintained by a Client at a specific time.
|
|
25
|
+
* </p>
|
|
26
|
+
* @alias module:metadata~ClientState
|
|
27
|
+
* @constructor
|
|
28
|
+
*/
|
|
29
|
+
class ClientState {
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new instance of <code>ClientState</code>.
|
|
32
|
+
* @param {Array<Host>} hosts
|
|
33
|
+
* @param {Object.<String, Number>} openConnections
|
|
34
|
+
* @param {Object.<String, Number>} inFlightQueries
|
|
35
|
+
*/
|
|
36
|
+
constructor(hosts, openConnections, inFlightQueries) {
|
|
37
|
+
this._hosts = hosts
|
|
38
|
+
this._openConnections = openConnections
|
|
39
|
+
this._inFlightQueries = inFlightQueries
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get an array of hosts to which the client is connected to.
|
|
44
|
+
* @return {Array<Host>}
|
|
45
|
+
*/
|
|
46
|
+
getConnectedHosts() {
|
|
47
|
+
return this._hosts
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Gets the amount of open connections to a given host.
|
|
52
|
+
* @param {Host} host
|
|
53
|
+
* @return {Number}
|
|
54
|
+
*/
|
|
55
|
+
getOpenConnections(host) {
|
|
56
|
+
if (!host) {
|
|
57
|
+
throw new errors.ArgumentError("Host is not defined")
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return this._openConnections[host.address] || 0
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Gets the amount of queries that are currently being executed through a given host.
|
|
65
|
+
* <p>
|
|
66
|
+
* This corresponds to the number of queries that have been sent by the Client to server Host on one of its connections
|
|
67
|
+
* but haven't yet obtained a response.
|
|
68
|
+
* </p>
|
|
69
|
+
* @param {Host} host
|
|
70
|
+
* @return {Number}
|
|
71
|
+
*/
|
|
72
|
+
getInFlightQueries(host) {
|
|
73
|
+
if (!host) {
|
|
74
|
+
throw new errors.ArgumentError("Host is not defined")
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return this._inFlightQueries[host.address] || 0
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Returns the string representation of the instance.
|
|
82
|
+
*/
|
|
83
|
+
toString() {
|
|
84
|
+
return util.format(
|
|
85
|
+
'{"hosts": %j, "openConnections": %j, "inFlightQueries": %j}',
|
|
86
|
+
this._hosts.map(function (h) {
|
|
87
|
+
return h.address
|
|
88
|
+
}),
|
|
89
|
+
this._openConnections,
|
|
90
|
+
this._inFlightQueries,
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Creates a new instance from the provided client.
|
|
96
|
+
* @param {Client} client
|
|
97
|
+
* @internal
|
|
98
|
+
* @ignore
|
|
99
|
+
*/
|
|
100
|
+
static from(client) {
|
|
101
|
+
const openConnections = {}
|
|
102
|
+
const inFlightQueries = {}
|
|
103
|
+
const hostArray = []
|
|
104
|
+
|
|
105
|
+
client.hosts.forEach((host) => {
|
|
106
|
+
if (host.pool.connections.length === 0) {
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
hostArray.push(host)
|
|
111
|
+
openConnections[host.address] = host.pool.connections.length
|
|
112
|
+
inFlightQueries[host.address] = host.getInFlight()
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
return new ClientState(hostArray, openConnections, inFlightQueries)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export default ClientState
|
|
@@ -0,0 +1,182 @@
|
|
|
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 events from "events"
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new instance of DataCollection
|
|
22
|
+
* @param {String} name Name of the data object.
|
|
23
|
+
* @classdesc Describes a table or a view
|
|
24
|
+
* @alias module:metadata~DataCollection
|
|
25
|
+
* @constructor
|
|
26
|
+
* @abstract
|
|
27
|
+
*/
|
|
28
|
+
function DataCollection(name) {
|
|
29
|
+
events.EventEmitter.call(this)
|
|
30
|
+
this.setMaxListeners(0)
|
|
31
|
+
//private
|
|
32
|
+
Object.defineProperty(this, "loading", {
|
|
33
|
+
value: false,
|
|
34
|
+
enumerable: false,
|
|
35
|
+
writable: true,
|
|
36
|
+
})
|
|
37
|
+
Object.defineProperty(this, "loaded", {
|
|
38
|
+
value: false,
|
|
39
|
+
enumerable: false,
|
|
40
|
+
writable: true,
|
|
41
|
+
})
|
|
42
|
+
/**
|
|
43
|
+
* Name of the object
|
|
44
|
+
* @type {String}
|
|
45
|
+
*/
|
|
46
|
+
this.name = name
|
|
47
|
+
/**
|
|
48
|
+
* False-positive probability for SSTable Bloom filters.
|
|
49
|
+
* @type {number}
|
|
50
|
+
*/
|
|
51
|
+
this.bloomFilterFalsePositiveChance = 0
|
|
52
|
+
/**
|
|
53
|
+
* Level of caching: all, keys_only, rows_only, none
|
|
54
|
+
* @type {String}
|
|
55
|
+
*/
|
|
56
|
+
this.caching = null
|
|
57
|
+
/**
|
|
58
|
+
* A human readable comment describing the table.
|
|
59
|
+
* @type {String}
|
|
60
|
+
*/
|
|
61
|
+
this.comment = null
|
|
62
|
+
/**
|
|
63
|
+
* Specifies the time to wait before garbage collecting tombstones (deletion markers)
|
|
64
|
+
* @type {number}
|
|
65
|
+
*/
|
|
66
|
+
this.gcGraceSeconds = 0
|
|
67
|
+
/**
|
|
68
|
+
* Compaction strategy class used for the table.
|
|
69
|
+
* @type {String}
|
|
70
|
+
*/
|
|
71
|
+
this.compactionClass = null
|
|
72
|
+
/**
|
|
73
|
+
* Associative-array containing the compaction options keys and values.
|
|
74
|
+
* @type {Object}
|
|
75
|
+
*/
|
|
76
|
+
this.compactionOptions = null
|
|
77
|
+
/**
|
|
78
|
+
* Associative-array containing the compression options.
|
|
79
|
+
* @type {Object}
|
|
80
|
+
*/
|
|
81
|
+
this.compression = null
|
|
82
|
+
/**
|
|
83
|
+
* Specifies the probability of read repairs being invoked over all replicas in the current data center.
|
|
84
|
+
* @type {number}
|
|
85
|
+
*/
|
|
86
|
+
this.localReadRepairChance = 0
|
|
87
|
+
/**
|
|
88
|
+
* Specifies the probability with which read repairs should be invoked on non-quorum reads. The value must be
|
|
89
|
+
* between 0 and 1.
|
|
90
|
+
* @type {number}
|
|
91
|
+
*/
|
|
92
|
+
this.readRepairChance = 0
|
|
93
|
+
/**
|
|
94
|
+
* An associative Array containing extra metadata for the table.
|
|
95
|
+
* <p>
|
|
96
|
+
* For Apache Cassandra versions prior to 3.0.0, this method always returns <code>null</code>.
|
|
97
|
+
* </p>
|
|
98
|
+
* @type {Object}
|
|
99
|
+
*/
|
|
100
|
+
this.extensions = null
|
|
101
|
+
/**
|
|
102
|
+
* When compression is enabled, this option defines the probability
|
|
103
|
+
* with which checksums for compressed blocks are checked during reads.
|
|
104
|
+
* The default value for this options is 1.0 (always check).
|
|
105
|
+
* <p>
|
|
106
|
+
* For Apache Cassandra versions prior to 3.0.0, this method always returns <code>null</code>.
|
|
107
|
+
* </p>
|
|
108
|
+
* @type {Number|null}
|
|
109
|
+
*/
|
|
110
|
+
this.crcCheckChance = null
|
|
111
|
+
/**
|
|
112
|
+
* Whether the populate I/O cache on flush is set on this table.
|
|
113
|
+
* @type {Boolean}
|
|
114
|
+
*/
|
|
115
|
+
this.populateCacheOnFlush = false
|
|
116
|
+
/**
|
|
117
|
+
* Returns the default TTL for this table.
|
|
118
|
+
* @type {Number}
|
|
119
|
+
*/
|
|
120
|
+
this.defaultTtl = 0
|
|
121
|
+
/**
|
|
122
|
+
* * Returns the speculative retry option for this table.
|
|
123
|
+
* @type {String}
|
|
124
|
+
*/
|
|
125
|
+
this.speculativeRetry = "NONE"
|
|
126
|
+
/**
|
|
127
|
+
* Returns the minimum index interval option for this table.
|
|
128
|
+
* <p>
|
|
129
|
+
* Note: this option is available in Apache Cassandra 2.1 and above, and will return <code>null</code> for
|
|
130
|
+
* earlier versions.
|
|
131
|
+
* </p>
|
|
132
|
+
* @type {Number|null}
|
|
133
|
+
*/
|
|
134
|
+
this.minIndexInterval = 128
|
|
135
|
+
/**
|
|
136
|
+
* Returns the maximum index interval option for this table.
|
|
137
|
+
* <p>
|
|
138
|
+
* Note: this option is available in Apache Cassandra 2.1 and above, and will return <code>null</code> for
|
|
139
|
+
* earlier versions.
|
|
140
|
+
* </p>
|
|
141
|
+
* @type {Number|null}
|
|
142
|
+
*/
|
|
143
|
+
this.maxIndexInterval = 2048
|
|
144
|
+
/**
|
|
145
|
+
* Array describing the table columns.
|
|
146
|
+
* @type {Array}
|
|
147
|
+
*/
|
|
148
|
+
this.columns = null
|
|
149
|
+
/**
|
|
150
|
+
* An associative Array of columns by name.
|
|
151
|
+
* @type {Object}
|
|
152
|
+
*/
|
|
153
|
+
this.columnsByName = null
|
|
154
|
+
/**
|
|
155
|
+
* Array describing the columns that are part of the partition key.
|
|
156
|
+
* @type {Array}
|
|
157
|
+
*/
|
|
158
|
+
this.partitionKeys = []
|
|
159
|
+
/**
|
|
160
|
+
* Array describing the columns that form the clustering key.
|
|
161
|
+
* @type {Array}
|
|
162
|
+
*/
|
|
163
|
+
this.clusteringKeys = []
|
|
164
|
+
/**
|
|
165
|
+
* Array describing the clustering order of the columns in the same order as the clusteringKeys.
|
|
166
|
+
* @type {Array}
|
|
167
|
+
*/
|
|
168
|
+
this.clusteringOrder = []
|
|
169
|
+
/**
|
|
170
|
+
* An associative Array containing nodesync options for this table.
|
|
171
|
+
* <p>
|
|
172
|
+
* For DSE versions prior to 6.0.0, this method always returns {@code null}. If nodesync
|
|
173
|
+
* was not explicitly configured for this table this method will also return {@code null}.
|
|
174
|
+
* </p>
|
|
175
|
+
* @type {Object}
|
|
176
|
+
*/
|
|
177
|
+
this.nodesync = null
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
util.inherits(DataCollection, events.EventEmitter)
|
|
181
|
+
|
|
182
|
+
export default DataCollection
|
|
@@ -0,0 +1,174 @@
|
|
|
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 promiseUtils from "../promise-utils.js"
|
|
21
|
+
|
|
22
|
+
const _queueOverflowThreshold = 1000
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Debounce protocol events by acting on those events with a sliding delay.
|
|
26
|
+
* @ignore
|
|
27
|
+
* @constructor
|
|
28
|
+
*/
|
|
29
|
+
class EventDebouncer {
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new instance of the event debouncer.
|
|
32
|
+
* @param {Number} delay
|
|
33
|
+
* @param {Function} logger
|
|
34
|
+
*/
|
|
35
|
+
constructor(delay, logger) {
|
|
36
|
+
this._delay = delay
|
|
37
|
+
this._logger = logger
|
|
38
|
+
this._queue = null
|
|
39
|
+
this._timeout = null
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Adds a new event to the queue and moves the delay.
|
|
44
|
+
* @param {{ handler: Function, all: boolean|undefined, keyspace: String|undefined,
|
|
45
|
+
* cqlObject: String|null|undefined }} event
|
|
46
|
+
* @param {Boolean} processNow
|
|
47
|
+
* @returns {Promise}
|
|
48
|
+
*/
|
|
49
|
+
eventReceived(event, processNow) {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
event.callback = promiseUtils.getCallback(resolve, reject)
|
|
52
|
+
this._queue = this._queue || { callbacks: [], keyspaces: {} }
|
|
53
|
+
const delay = !processNow ? this._delay : 0
|
|
54
|
+
if (event.all) {
|
|
55
|
+
// when an event marked with all is received, it supersedes all the rest of events
|
|
56
|
+
// a full update (hosts + keyspaces + tokens) is going to be made
|
|
57
|
+
this._queue.mainEvent = event
|
|
58
|
+
}
|
|
59
|
+
if (this._queue.callbacks.length === _queueOverflowThreshold) {
|
|
60
|
+
// warn once
|
|
61
|
+
this._logger(
|
|
62
|
+
"warn",
|
|
63
|
+
util.format(
|
|
64
|
+
"Event debouncer queue exceeded %d events",
|
|
65
|
+
_queueOverflowThreshold,
|
|
66
|
+
),
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
this._queue.callbacks.push(event.callback)
|
|
70
|
+
if (this._queue.mainEvent) {
|
|
71
|
+
// a full refresh is scheduled and the callback was added, nothing else to do.
|
|
72
|
+
return this._slideDelay(delay)
|
|
73
|
+
}
|
|
74
|
+
// Insert at keyspace level
|
|
75
|
+
let keyspaceEvents = this._queue.keyspaces[event.keyspace]
|
|
76
|
+
if (!keyspaceEvents) {
|
|
77
|
+
keyspaceEvents = this._queue.keyspaces[event.keyspace] = {
|
|
78
|
+
events: [],
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (event.cqlObject === undefined) {
|
|
82
|
+
// a full refresh of the keyspace, supersedes all child keyspace events
|
|
83
|
+
keyspaceEvents.mainEvent = event
|
|
84
|
+
}
|
|
85
|
+
keyspaceEvents.events.push(event)
|
|
86
|
+
this._slideDelay(delay)
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param {Number} delay
|
|
92
|
+
* @private
|
|
93
|
+
* */
|
|
94
|
+
_slideDelay(delay) {
|
|
95
|
+
const self = this
|
|
96
|
+
function process() {
|
|
97
|
+
const q = self._queue
|
|
98
|
+
self._queue = null
|
|
99
|
+
self._timeout = null
|
|
100
|
+
processQueue(q)
|
|
101
|
+
}
|
|
102
|
+
if (delay === 0) {
|
|
103
|
+
// no delay, process immediately
|
|
104
|
+
if (this._timeout) {
|
|
105
|
+
clearTimeout(this._timeout)
|
|
106
|
+
}
|
|
107
|
+
return process()
|
|
108
|
+
}
|
|
109
|
+
const previousTimeout = this._timeout
|
|
110
|
+
// Add the new timeout before removing the previous one performs better
|
|
111
|
+
this._timeout = setTimeout(process, delay)
|
|
112
|
+
if (previousTimeout) {
|
|
113
|
+
clearTimeout(previousTimeout)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Clears the timeout and invokes all pending callback.
|
|
119
|
+
*/
|
|
120
|
+
shutdown() {
|
|
121
|
+
if (!this._queue) {
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
this._queue.callbacks.forEach(function (cb) {
|
|
125
|
+
cb()
|
|
126
|
+
})
|
|
127
|
+
this._queue = null
|
|
128
|
+
clearTimeout(this._timeout)
|
|
129
|
+
this._timeout = null
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @param {{callbacks: Array, keyspaces: Object, mainEvent: Object}} q
|
|
135
|
+
* @private
|
|
136
|
+
*/
|
|
137
|
+
function processQueue(q) {
|
|
138
|
+
if (q.mainEvent) {
|
|
139
|
+
// refresh all by invoking 1 handler and invoke all pending callbacks
|
|
140
|
+
return promiseUtils.toCallback(q.mainEvent.handler(), (err) => {
|
|
141
|
+
for (let i = 0; i < q.callbacks.length; i++) {
|
|
142
|
+
q.callbacks[i](err)
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
utils.each(Object.keys(q.keyspaces), function eachKeyspace(name, next) {
|
|
148
|
+
const keyspaceEvents = q.keyspaces[name]
|
|
149
|
+
if (keyspaceEvents.mainEvent) {
|
|
150
|
+
// refresh a keyspace
|
|
151
|
+
return promiseUtils.toCallback(
|
|
152
|
+
keyspaceEvents.mainEvent.handler(),
|
|
153
|
+
function mainEventCallback(err) {
|
|
154
|
+
for (let i = 0; i < keyspaceEvents.events.length; i++) {
|
|
155
|
+
keyspaceEvents.events[i].callback(err)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
next()
|
|
159
|
+
},
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// deal with individual handlers and callbacks
|
|
164
|
+
keyspaceEvents.events.forEach((event) => {
|
|
165
|
+
// sync handlers
|
|
166
|
+
event.handler()
|
|
167
|
+
event.callback()
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
next()
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export default EventDebouncer
|