@tachybase/module-multi-app 1.6.0 → 1.6.2
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/README.md +34 -34
- package/README.zh-CN.md +34 -34
- package/client.d.ts +1 -1
- package/client.js +1 -1
- package/dist/externalVersion.js +5 -5
- package/dist/locale/en-US.json +48 -48
- package/dist/locale/es-ES.json +9 -9
- package/dist/locale/ko_KR.json +11 -11
- package/dist/locale/pt-BR.json +9 -9
- package/dist/locale/zh-CN.json +58 -58
- package/dist/node_modules/mariadb/callback.js +43 -8
- package/dist/node_modules/mariadb/check-node.js +30 -0
- package/dist/node_modules/mariadb/lib/cluster-callback.js +84 -0
- package/dist/node_modules/mariadb/lib/cluster.js +446 -0
- package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +576 -177
- package/dist/node_modules/mariadb/lib/cmd/change-user.js +54 -44
- package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +3 -2
- package/dist/node_modules/mariadb/lib/cmd/class/prepare-cache-wrapper.js +46 -0
- package/dist/node_modules/mariadb/lib/cmd/class/prepare-result-packet.js +141 -0
- package/dist/node_modules/mariadb/lib/cmd/class/prepare-wrapper.js +70 -0
- package/dist/node_modules/mariadb/lib/cmd/close-prepare.js +38 -0
- package/dist/node_modules/mariadb/lib/cmd/column-definition.js +145 -47
- package/dist/node_modules/mariadb/lib/cmd/command.js +41 -75
- package/dist/node_modules/mariadb/lib/cmd/decoder/binary-decoder.js +282 -0
- package/dist/node_modules/mariadb/lib/cmd/decoder/text-decoder.js +210 -0
- package/dist/node_modules/mariadb/lib/cmd/{common-binary-cmd.js → encoder/binary-encoder.js} +34 -77
- package/dist/node_modules/mariadb/lib/cmd/encoder/text-encoder.js +311 -0
- package/dist/node_modules/mariadb/lib/cmd/execute-stream.js +61 -0
- package/dist/node_modules/mariadb/lib/cmd/execute.js +338 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +25 -62
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +39 -6
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +48 -16
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/handshake.js +198 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/{initial-handshake.js → auth/initial-handshake.js} +10 -8
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +22 -9
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +9 -4
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/parsec-auth.js +115 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +12 -5
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +44 -33
- package/dist/node_modules/mariadb/lib/cmd/handshake/authentication.js +335 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +20 -19
- package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +6 -3
- package/dist/node_modules/mariadb/lib/cmd/parser.js +861 -0
- package/dist/node_modules/mariadb/lib/cmd/ping.js +17 -18
- package/dist/node_modules/mariadb/lib/cmd/prepare.js +170 -0
- package/dist/node_modules/mariadb/lib/cmd/query.js +281 -144
- package/dist/node_modules/mariadb/lib/cmd/quit.js +9 -6
- package/dist/node_modules/mariadb/lib/cmd/reset.js +15 -19
- package/dist/node_modules/mariadb/lib/cmd/stream.js +21 -6
- package/dist/node_modules/mariadb/lib/config/cluster-options.js +23 -0
- package/dist/node_modules/mariadb/lib/config/connection-options.js +196 -132
- package/dist/node_modules/mariadb/lib/config/pool-options.js +27 -19
- package/dist/node_modules/mariadb/lib/connection-callback.js +492 -120
- package/dist/node_modules/mariadb/lib/connection-promise.js +372 -0
- package/dist/node_modules/mariadb/lib/connection.js +1739 -1016
- package/dist/node_modules/mariadb/lib/const/capabilities.js +36 -30
- package/dist/node_modules/mariadb/lib/const/collations.js +972 -36
- package/dist/node_modules/mariadb/lib/const/connection_status.js +3 -0
- package/dist/node_modules/mariadb/lib/const/error-code.js +35 -11
- package/dist/node_modules/mariadb/lib/const/field-detail.js +3 -0
- package/dist/node_modules/mariadb/lib/const/field-type.js +7 -4
- package/dist/node_modules/mariadb/lib/const/server-status.js +4 -1
- package/dist/node_modules/mariadb/lib/const/state-change.js +3 -0
- package/dist/node_modules/mariadb/lib/filtered-cluster-callback.js +136 -0
- package/dist/node_modules/mariadb/lib/filtered-cluster.js +118 -0
- package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +14 -13
- package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +21 -18
- package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +75 -64
- package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +13 -9
- package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +12 -10
- package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +402 -134
- package/dist/node_modules/mariadb/lib/io/packet.js +287 -202
- package/dist/node_modules/mariadb/lib/lru-prepare-cache.js +84 -0
- package/dist/node_modules/mariadb/lib/misc/connection-information.js +15 -32
- package/dist/node_modules/mariadb/lib/misc/errors.js +68 -25
- package/dist/node_modules/mariadb/lib/misc/parse.js +207 -711
- package/dist/node_modules/mariadb/lib/misc/utils.js +34 -62
- package/dist/node_modules/mariadb/lib/pool-callback.js +213 -174
- package/dist/node_modules/mariadb/lib/pool-promise.js +228 -94
- package/dist/node_modules/mariadb/lib/pool.js +951 -0
- package/dist/node_modules/mariadb/package.json +1 -1
- package/dist/node_modules/mariadb/promise.js +1 -34
- package/dist/node_modules/mariadb/types/callback.d.ts +207 -0
- package/dist/node_modules/mariadb/types/index.d.ts +94 -674
- package/dist/node_modules/mariadb/types/share.d.ts +804 -0
- package/dist/node_modules/qs/package.json +1 -1
- package/dist/server/actions/apps.js +2 -2
- package/dist/server/app-lifecycle.d.ts +1 -1
- package/dist/server/app-lifecycle.js +4 -4
- package/dist/server/models/application.d.ts +1 -1
- package/package.json +7 -7
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +0 -372
- package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +0 -427
- package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +0 -126
- package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +0 -292
- package/dist/node_modules/mariadb/lib/cmd/resultset.js +0 -607
- package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +0 -19
- package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +0 -81
- package/dist/node_modules/mariadb/lib/io/bulk-packet.js +0 -590
- package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +0 -481
- package/dist/node_modules/mariadb/lib/pool-base.js +0 -611
- package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +0 -66
- package/dist/node_modules/mariadb/lib/pool-cluster.js +0 -407
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const PoolClusterOptions = require('./config/pool-cluster-options');
|
|
4
|
-
const PoolOptions = require('./config/pool-options');
|
|
5
|
-
const Pool = require('./pool-promise');
|
|
6
|
-
const PoolCallback = require('./pool-callback');
|
|
7
|
-
const FilteredPoolCluster = require('./filtered-pool-cluster');
|
|
8
|
-
const EventEmitter = require('events');
|
|
9
|
-
const util = require('util');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Create a new Cluster.
|
|
13
|
-
* Cluster handle pools with patterns and handle failover / distributed load
|
|
14
|
-
* according to selectors (round robin / random / ordered )
|
|
15
|
-
*
|
|
16
|
-
* @param args cluster argurments. see pool-cluster-options.
|
|
17
|
-
* @constructor
|
|
18
|
-
*/
|
|
19
|
-
function PoolCluster(args) {
|
|
20
|
-
const opts = new PoolClusterOptions(args);
|
|
21
|
-
const nodes = {};
|
|
22
|
-
let cachedPatterns = {};
|
|
23
|
-
let nodeCounter = 0;
|
|
24
|
-
EventEmitter.call(this);
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Add a new pool node to cluster.
|
|
28
|
-
*
|
|
29
|
-
* @param id identifier
|
|
30
|
-
* @param config pool configuration
|
|
31
|
-
*/
|
|
32
|
-
this.add = (id, config) => {
|
|
33
|
-
let identifier;
|
|
34
|
-
if (typeof id === 'string' || id instanceof String) {
|
|
35
|
-
identifier = id;
|
|
36
|
-
if (nodes[identifier])
|
|
37
|
-
throw new Error("Node identifier '" + identifier + "' already exist !");
|
|
38
|
-
} else {
|
|
39
|
-
identifier = 'PoolNode-' + nodeCounter++;
|
|
40
|
-
config = id;
|
|
41
|
-
}
|
|
42
|
-
const options = new PoolOptions(config);
|
|
43
|
-
const pool = _createPool(options);
|
|
44
|
-
pool.initialize();
|
|
45
|
-
nodes[identifier] = pool;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* End cluster (and underlying pools).
|
|
50
|
-
*
|
|
51
|
-
* @return {Promise<any[]>}
|
|
52
|
-
*/
|
|
53
|
-
this.end = () => {
|
|
54
|
-
cachedPatterns = {};
|
|
55
|
-
const poolEndPromise = [];
|
|
56
|
-
Object.keys(nodes).forEach((pool) => {
|
|
57
|
-
poolEndPromise.push(nodes[pool].end());
|
|
58
|
-
delete nodes[pool];
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
return Promise.all(poolEndPromise);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
this.of = (pattern, selector) => {
|
|
65
|
-
return new FilteredPoolCluster(this, pattern, selector);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Remove nodes according to pattern.
|
|
70
|
-
*
|
|
71
|
-
* @param pattern pattern
|
|
72
|
-
*/
|
|
73
|
-
this.remove = (pattern) => {
|
|
74
|
-
if (!pattern) throw new Error('pattern parameter in Cluster.remove(pattern) is mandatory');
|
|
75
|
-
|
|
76
|
-
const regex = RegExp(pattern);
|
|
77
|
-
Object.keys(nodes).forEach((key) => {
|
|
78
|
-
if (regex.test(key)) {
|
|
79
|
-
nodes[key].end();
|
|
80
|
-
delete nodes[key];
|
|
81
|
-
cachedPatterns = {};
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Get connection from available pools matching pattern, according to selector
|
|
88
|
-
*
|
|
89
|
-
* @param pattern pattern filter (not mandatory)
|
|
90
|
-
* @param selector node selector ('RR','RANDOM' or 'ORDER')
|
|
91
|
-
* @return {Promise}
|
|
92
|
-
*/
|
|
93
|
-
this.getConnection = (pattern, selector) => {
|
|
94
|
-
return _getConnection(this, pattern, selector);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Force using callback methods.
|
|
99
|
-
*/
|
|
100
|
-
this.setCallback = () => {
|
|
101
|
-
this.getConnection = _getConnectionCallback.bind(this, this);
|
|
102
|
-
_createPool = _createPoolCallback;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Get connection from available pools matching pattern, according to selector
|
|
107
|
-
* with additional parameter to avoid reusing failing node
|
|
108
|
-
*
|
|
109
|
-
* @param pattern pattern filter (not mandatory)
|
|
110
|
-
* @param selector node selector ('RR','RANDOM' or 'ORDER')
|
|
111
|
-
* @param avoidNodeKey failing node
|
|
112
|
-
* @param lastError last error
|
|
113
|
-
* @return {Promise}
|
|
114
|
-
* @private
|
|
115
|
-
*/
|
|
116
|
-
const _getConnection = (cluster, pattern, selector, avoidNodeKey, lastError) => {
|
|
117
|
-
const matchingNodeList = _matchingNodes(pattern || /^/);
|
|
118
|
-
|
|
119
|
-
if (matchingNodeList.length === 0) {
|
|
120
|
-
if (Object.keys(nodes).length === 0 && !lastError) {
|
|
121
|
-
return Promise.reject(
|
|
122
|
-
new Error(
|
|
123
|
-
'No node have been added to cluster ' +
|
|
124
|
-
'or nodes have been removed due to too much connection error'
|
|
125
|
-
)
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
if (avoidNodeKey === undefined)
|
|
129
|
-
return Promise.reject(new Error("No node found for pattern '" + pattern + "'"));
|
|
130
|
-
const errMsg =
|
|
131
|
-
"No Connection available for '" +
|
|
132
|
-
pattern +
|
|
133
|
-
"'" +
|
|
134
|
-
(lastError ? '. Last connection error was: ' + lastError.message : '');
|
|
135
|
-
return Promise.reject(new Error(errMsg));
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const retry = _getConnection.bind(this, this, pattern, selector);
|
|
139
|
-
try {
|
|
140
|
-
const nodeKey = _selectPool(matchingNodeList, selector, avoidNodeKey);
|
|
141
|
-
return _handleConnectionError(cluster, matchingNodeList, nodeKey, retry);
|
|
142
|
-
} catch (e) {
|
|
143
|
-
return Promise.reject(e);
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
let _createPool = (options) => {
|
|
148
|
-
return new Pool(options, false);
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
const _createPoolCallback = (options) => {
|
|
152
|
-
return new PoolCallback(options, false);
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Get connection from available pools matching pattern, according to selector
|
|
157
|
-
* with additional parameter to avoid reusing failing node
|
|
158
|
-
*
|
|
159
|
-
* @param pattern pattern filter (not mandatory)
|
|
160
|
-
* @param selector node selector ('RR','RANDOM' or 'ORDER')
|
|
161
|
-
* @param callback callback function
|
|
162
|
-
* @param avoidNodeKey failing node
|
|
163
|
-
* @param lastError last error
|
|
164
|
-
* @private
|
|
165
|
-
*/
|
|
166
|
-
const _getConnectionCallback = (
|
|
167
|
-
cluster,
|
|
168
|
-
pattern,
|
|
169
|
-
selector,
|
|
170
|
-
callback,
|
|
171
|
-
avoidNodeKey,
|
|
172
|
-
lastError
|
|
173
|
-
) => {
|
|
174
|
-
const matchingNodeList = _matchingNodes(pattern || /^/);
|
|
175
|
-
|
|
176
|
-
if (matchingNodeList.length === 0) {
|
|
177
|
-
if (Object.keys(nodes).length === 0 && !lastError) {
|
|
178
|
-
callback(
|
|
179
|
-
new Error(
|
|
180
|
-
'No node have been added to cluster ' +
|
|
181
|
-
'or nodes have been removed due to too much connection error'
|
|
182
|
-
)
|
|
183
|
-
);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (avoidNodeKey === undefined)
|
|
188
|
-
callback(new Error("No node found for pattern '" + pattern + "'"));
|
|
189
|
-
const errMsg =
|
|
190
|
-
"No Connection available for '" +
|
|
191
|
-
pattern +
|
|
192
|
-
"'" +
|
|
193
|
-
(lastError ? '. Last connection error was: ' + lastError.message : '');
|
|
194
|
-
callback(new Error(errMsg));
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const retry = _getConnectionCallback.bind(this, this, pattern, selector, callback);
|
|
199
|
-
try {
|
|
200
|
-
const nodeKey = _selectPool(matchingNodeList, selector, avoidNodeKey);
|
|
201
|
-
_handleConnectionCallbackError(this, matchingNodeList, nodeKey, retry, callback);
|
|
202
|
-
} catch (e) {
|
|
203
|
-
callback(e);
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Selecting nodes according to pattern.
|
|
209
|
-
*
|
|
210
|
-
* @param pattern pattern
|
|
211
|
-
* @return {*}
|
|
212
|
-
* @private
|
|
213
|
-
*/
|
|
214
|
-
const _matchingNodes = (pattern) => {
|
|
215
|
-
if (cachedPatterns[pattern]) return cachedPatterns[pattern];
|
|
216
|
-
|
|
217
|
-
const regex = RegExp(pattern);
|
|
218
|
-
const matchingNodeList = [];
|
|
219
|
-
Object.keys(nodes).forEach((key) => {
|
|
220
|
-
if (regex.test(key)) {
|
|
221
|
-
matchingNodeList.push(key);
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
cachedPatterns[pattern] = matchingNodeList;
|
|
226
|
-
return matchingNodeList;
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Select next node to be chosen in nodeList according to selector and failed nodes.
|
|
231
|
-
*
|
|
232
|
-
* @param nodeList current node list
|
|
233
|
-
* @param selectorParam selector
|
|
234
|
-
* @param avoidNodeKey last failing node to avoid selecting this one.
|
|
235
|
-
* @return {Promise}
|
|
236
|
-
* @private
|
|
237
|
-
*/
|
|
238
|
-
const _selectPool = (nodeList, selectorParam, avoidNodeKey) => {
|
|
239
|
-
const selector = selectorParam || opts.defaultSelector;
|
|
240
|
-
let retry = 0;
|
|
241
|
-
let selectorFct;
|
|
242
|
-
let nodeKey;
|
|
243
|
-
switch (selector) {
|
|
244
|
-
case 'RR':
|
|
245
|
-
selectorFct = roundRobinSelector;
|
|
246
|
-
break;
|
|
247
|
-
|
|
248
|
-
case 'RANDOM':
|
|
249
|
-
selectorFct = randomSelector;
|
|
250
|
-
break;
|
|
251
|
-
|
|
252
|
-
case 'ORDER':
|
|
253
|
-
selectorFct = orderedSelector;
|
|
254
|
-
break;
|
|
255
|
-
|
|
256
|
-
default:
|
|
257
|
-
throw new Error(
|
|
258
|
-
"Wrong selector value '" + selector + "'. Possible values are 'RR','RANDOM' or 'ORDER'"
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
nodeKey = selectorFct(nodeList, retry);
|
|
263
|
-
while (
|
|
264
|
-
(avoidNodeKey === nodeKey || nodes[nodeKey].blacklistedUntil > Date.now()) &&
|
|
265
|
-
retry < nodeList.length - 1
|
|
266
|
-
) {
|
|
267
|
-
retry++;
|
|
268
|
-
nodeKey = selectorFct(nodeList, retry);
|
|
269
|
-
}
|
|
270
|
-
return nodeKey;
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Round robin selector: using nodes one after the other.
|
|
275
|
-
*
|
|
276
|
-
* @param nodeList node list
|
|
277
|
-
* @return {String}
|
|
278
|
-
*/
|
|
279
|
-
const roundRobinSelector = (nodeList) => {
|
|
280
|
-
let lastRoundRobin = nodeList.lastRrIdx;
|
|
281
|
-
if (lastRoundRobin === undefined) lastRoundRobin = -1;
|
|
282
|
-
if (++lastRoundRobin >= nodeList.length) lastRoundRobin = 0;
|
|
283
|
-
nodeList.lastRrIdx = lastRoundRobin;
|
|
284
|
-
return nodeList[lastRoundRobin];
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Random selector: use a random node.
|
|
289
|
-
*
|
|
290
|
-
* @param nodeList node list
|
|
291
|
-
* @return {String}
|
|
292
|
-
*/
|
|
293
|
-
const randomSelector = (nodeList) => {
|
|
294
|
-
let randomIdx = Math.floor(Math.random() * nodeList.length);
|
|
295
|
-
return nodeList[randomIdx];
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Ordered selector: always use the nodes in sequence, unless failing.
|
|
300
|
-
*
|
|
301
|
-
* @param nodeList node list
|
|
302
|
-
* @param retry sequence number if last node is tagged has failing
|
|
303
|
-
* @return {String}
|
|
304
|
-
*/
|
|
305
|
-
const orderedSelector = (nodeList, retry) => {
|
|
306
|
-
return nodeList[retry];
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Connect, or if fail handle retry / set timeout error
|
|
311
|
-
*
|
|
312
|
-
* @param cluster current cluster
|
|
313
|
-
* @param nodeList current node list
|
|
314
|
-
* @param nodeKey node name to connect
|
|
315
|
-
* @param retryFct retry function
|
|
316
|
-
* @return {Promise}
|
|
317
|
-
* @private
|
|
318
|
-
*/
|
|
319
|
-
const _handleConnectionError = (cluster, nodeList, nodeKey, retryFct) => {
|
|
320
|
-
const node = nodes[nodeKey];
|
|
321
|
-
return node
|
|
322
|
-
.getConnection()
|
|
323
|
-
.then((conn) => {
|
|
324
|
-
node.errorCount = 0;
|
|
325
|
-
return Promise.resolve(conn);
|
|
326
|
-
})
|
|
327
|
-
.catch((err) => {
|
|
328
|
-
node.errorCount = node.errorCount ? node.errorCount + 1 : 1;
|
|
329
|
-
node.blacklistedUntil = Date.now() + opts.restoreNodeTimeout;
|
|
330
|
-
if (
|
|
331
|
-
opts.removeNodeErrorCount &&
|
|
332
|
-
node.errorCount >= opts.removeNodeErrorCount &&
|
|
333
|
-
nodes[nodeKey]
|
|
334
|
-
) {
|
|
335
|
-
delete nodes[nodeKey];
|
|
336
|
-
cachedPatterns = {};
|
|
337
|
-
delete nodeList.lastRrIdx;
|
|
338
|
-
process.nextTick(() => cluster.emit('remove', nodeKey));
|
|
339
|
-
//remove node from configuration if not already removed
|
|
340
|
-
node.end().catch((err) => {
|
|
341
|
-
// dismiss error
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
if (nodeList.length !== 0 && opts.canRetry) {
|
|
346
|
-
return retryFct(nodeKey, err);
|
|
347
|
-
}
|
|
348
|
-
return Promise.reject(err);
|
|
349
|
-
});
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Connect, or if fail handle retry / set timeout error
|
|
354
|
-
*
|
|
355
|
-
* @param cluster current cluster
|
|
356
|
-
* @param nodeList current node list
|
|
357
|
-
* @param nodeKey node name to connect
|
|
358
|
-
* @param retryFct retry function
|
|
359
|
-
* @param callback callback function
|
|
360
|
-
* @private
|
|
361
|
-
*/
|
|
362
|
-
const _handleConnectionCallbackError = (cluster, nodeList, nodeKey, retryFct, callback) => {
|
|
363
|
-
const node = nodes[nodeKey];
|
|
364
|
-
node.getConnection((err, conn) => {
|
|
365
|
-
if (err) {
|
|
366
|
-
node.errorCount = node.errorCount ? node.errorCount + 1 : 1;
|
|
367
|
-
node.blacklistedUntil = Date.now() + opts.restoreNodeTimeout;
|
|
368
|
-
if (
|
|
369
|
-
opts.removeNodeErrorCount &&
|
|
370
|
-
node.errorCount >= opts.removeNodeErrorCount &&
|
|
371
|
-
nodes[nodeKey]
|
|
372
|
-
) {
|
|
373
|
-
delete nodes[nodeKey];
|
|
374
|
-
cachedPatterns = {};
|
|
375
|
-
delete nodeList.lastRrIdx;
|
|
376
|
-
process.nextTick(() => cluster.emit('remove', nodeKey));
|
|
377
|
-
//remove node from configuration if not already removed
|
|
378
|
-
node.end(() => {
|
|
379
|
-
//dismiss error
|
|
380
|
-
});
|
|
381
|
-
if (nodeList.length === 0) return Promise.reject(err);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
if (opts.canRetry) return retryFct(nodeKey, err);
|
|
385
|
-
callback(err);
|
|
386
|
-
} else {
|
|
387
|
-
node.errorCount = 0;
|
|
388
|
-
callback(null, conn);
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
};
|
|
392
|
-
|
|
393
|
-
//*****************************************************************
|
|
394
|
-
// internal public testing methods
|
|
395
|
-
//*****************************************************************
|
|
396
|
-
|
|
397
|
-
function TestMethods() {}
|
|
398
|
-
TestMethods.prototype.getNodes = () => {
|
|
399
|
-
return nodes;
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
this.__tests = new TestMethods();
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
util.inherits(PoolCluster, EventEmitter);
|
|
406
|
-
|
|
407
|
-
module.exports = PoolCluster;
|