kuzzle 2.61.0-beta.5 → 2.61.0-beta.6
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/dist/lib/api/controllers/serverController.js +1 -1
- package/dist/lib/cluster/idCardHandler.d.ts +41 -19
- package/dist/lib/cluster/idCardHandler.js +73 -45
- package/dist/lib/cluster/node.d.ts +8 -2
- package/dist/lib/cluster/node.js +9 -11
- package/dist/lib/cluster/storageDriverCheck.d.ts +31 -0
- package/dist/lib/cluster/storageDriverCheck.js +142 -0
- package/dist/lib/config/default.config.js +1 -0
- package/dist/lib/core/backend/backendStorage.d.ts +9 -0
- package/dist/lib/core/backend/backendStorage.js +48 -0
- package/dist/lib/core/plugin/pluginContext.d.ts +10 -0
- package/dist/lib/core/plugin/pluginContext.js +1 -0
- package/dist/lib/core/storage/clientAdapter.d.ts +13 -0
- package/dist/lib/core/storage/clientAdapter.js +26 -2
- package/dist/lib/core/storage/conformance/capabilityCases.js +41 -0
- package/dist/lib/core/storage/conformance/conformanceContext.d.ts +11 -1
- package/dist/lib/core/storage/conformance/conformanceContext.js +7 -1
- package/dist/lib/core/storage/conformance/coreCases.js +136 -0
- package/dist/lib/core/storage/conformance/storageDriverConformance.js +19 -3
- package/dist/lib/core/storage/indexCache.d.ts +9 -0
- package/dist/lib/core/storage/indexCache.js +20 -1
- package/dist/lib/core/storage/storageDriverLoader.d.ts +24 -5
- package/dist/lib/core/storage/storageDriverLoader.js +177 -25
- package/dist/lib/core/storage/storageEngine.d.ts +11 -0
- package/dist/lib/core/storage/storageEngine.js +47 -5
- package/dist/lib/kerror/codes/1-services.json +18 -12
- package/dist/lib/kerror/codes/2-api.json +1 -1
- package/dist/lib/kerror/codes/8-cluster.json +1 -1
- package/dist/lib/kuzzle/kuzzle.d.ts +2 -0
- package/dist/lib/kuzzle/kuzzle.js +14 -1
- package/dist/lib/service/storage/builtInDrivers.d.ts +7 -0
- package/dist/lib/service/storage/builtInDrivers.js +18 -35
- package/dist/lib/service/storage/driverPackage.d.ts +20 -0
- package/dist/lib/service/storage/driverPackage.js +101 -0
- package/dist/lib/service/storage/storageService.js +3 -3
- package/dist/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +12 -0
- package/dist/lib/types/storage/StorageDriver.d.ts +24 -2
- package/dist/package.json +21 -21
- package/package.json +21 -21
|
@@ -238,7 +238,7 @@ class ServerController extends baseController_1.NativeController {
|
|
|
238
238
|
try {
|
|
239
239
|
const response = await global.kuzzle.ask("core:storage:public:info:get");
|
|
240
240
|
if (response.status !== "yellow" && response.status !== "green") {
|
|
241
|
-
throw new Error(`
|
|
241
|
+
throw new Error(`Storage engine is down: ${JSON.stringify(response)}`);
|
|
242
242
|
}
|
|
243
243
|
result.services.storageEngine = "green";
|
|
244
244
|
}
|
|
@@ -10,7 +10,18 @@ export type SerializedIdCard = {
|
|
|
10
10
|
* set with a built-in driver, as on the nodes that predate the drivers.
|
|
11
11
|
*/
|
|
12
12
|
storageDriver?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Package of the node's built-in storage driver (e.g.
|
|
15
|
+
* `kuzzle-storage-es-7`), without its version. Not set with an external
|
|
16
|
+
* driver, nor on the nodes that predate 2.61.0: a card with neither field
|
|
17
|
+
* is a built-in node of unknown major version.
|
|
18
|
+
*/
|
|
19
|
+
builtInStorageDriver?: string;
|
|
13
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* How long an ID card outlives the last renewal of its node, in ms
|
|
23
|
+
*/
|
|
24
|
+
export declare function idCardTtl(heartbeat: number): number;
|
|
14
25
|
export declare class IdCard {
|
|
15
26
|
/**
|
|
16
27
|
* Node unique identifier
|
|
@@ -41,10 +52,35 @@ export declare class IdCard {
|
|
|
41
52
|
* `undefined` with a built-in one
|
|
42
53
|
*/
|
|
43
54
|
readonly storageDriver?: string;
|
|
44
|
-
|
|
55
|
+
/**
|
|
56
|
+
* The package of the node's built-in storage driver; `undefined` with an
|
|
57
|
+
* external one, or on a node older than 2.61.0
|
|
58
|
+
*/
|
|
59
|
+
readonly builtInStorageDriver?: string;
|
|
60
|
+
constructor({ id, ip, birthdate, topology, storageDriver, builtInStorageDriver, }: SerializedIdCard);
|
|
45
61
|
serialize(): SerializedIdCard;
|
|
46
62
|
static unserialize(serialized: SerializedIdCard): IdCard;
|
|
47
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Retrieves the ID cards of the cluster nodes, but the one stored under
|
|
66
|
+
* `ownKey`
|
|
67
|
+
*
|
|
68
|
+
* Each node store it's ID Card under a specific key name. When Redis database
|
|
69
|
+
* is growing, searching for those keys can be quite expensive and can slow down
|
|
70
|
+
* the handshake process.
|
|
71
|
+
*
|
|
72
|
+
* We are storing a set containing ID Card's keys under a set so when a new node
|
|
73
|
+
* is started, it can directly get the other nodes ID Cards with SMEMBERS and
|
|
74
|
+
* then MGET instead of using SCAN.
|
|
75
|
+
*
|
|
76
|
+
* When a new node retrieve the ID Card's keys from the set, it try to get them
|
|
77
|
+
* with MGET, those who cannot be retrieved are expired ID Cards so the node update
|
|
78
|
+
* the set accordingly.
|
|
79
|
+
*
|
|
80
|
+
* A function rather than a method: a starting node reads the cards before it
|
|
81
|
+
* has a card, or a `ClusterNode`, of its own (storage driver check).
|
|
82
|
+
*/
|
|
83
|
+
export declare function getIdCards(ownKey: string | null): Promise<IdCard[]>;
|
|
48
84
|
/**
|
|
49
85
|
* Handles the ID Key stored in Redis, holding node information
|
|
50
86
|
*/
|
|
@@ -60,17 +96,17 @@ export declare class ClusterIdCardHandler {
|
|
|
60
96
|
/**
|
|
61
97
|
* Local node IP address
|
|
62
98
|
*/
|
|
63
|
-
private ip;
|
|
99
|
+
private readonly ip;
|
|
64
100
|
/**
|
|
65
101
|
* Delay for refreshing the ID Card. The heartbeat timer is run on this delay
|
|
66
102
|
* and the node ID Card should be available on Redis otherwise it will be evicted.
|
|
67
103
|
*/
|
|
68
|
-
private refreshDelay;
|
|
104
|
+
private readonly refreshDelay;
|
|
69
105
|
/**
|
|
70
106
|
* Multiplier used to ensure the node has enough time to refresh it's ID Card
|
|
71
107
|
* before the ID Card refresh delay
|
|
72
108
|
*/
|
|
73
|
-
private refreshMultiplier;
|
|
109
|
+
private readonly refreshMultiplier;
|
|
74
110
|
/**
|
|
75
111
|
* Worker thread in charge of refreshing the ID Card once the node has started
|
|
76
112
|
*/
|
|
@@ -129,21 +165,7 @@ export declare class ClusterIdCardHandler {
|
|
|
129
165
|
private startTemporaryRefresh;
|
|
130
166
|
dispose(): Promise<void>;
|
|
131
167
|
/**
|
|
132
|
-
* Retrieves the ID cards from other nodes
|
|
133
|
-
*
|
|
134
|
-
* Each node store it's ID Card under a specific key name. When Redis database
|
|
135
|
-
* is growing, searching for those keys can be quite expensive and can slow down
|
|
136
|
-
* the handshake process.
|
|
137
|
-
*
|
|
138
|
-
* We are storing a set containing ID Card's keys under a set so when a new node
|
|
139
|
-
* is started, it can directly get the other nodes ID Cards with SMEMBERS and
|
|
140
|
-
* then MGET instead of using SCAN.
|
|
141
|
-
*
|
|
142
|
-
* When a new node retrieve the ID Card's keys from the set, it try to get them
|
|
143
|
-
* with MGET, those who cannot be retrieved are expired ID Cards so the node update
|
|
144
|
-
* the set accordingly.
|
|
145
|
-
*
|
|
146
|
-
* @return {Array.<IdCard>}
|
|
168
|
+
* Retrieves the ID cards from other nodes: see `getIdCards()`
|
|
147
169
|
*/
|
|
148
170
|
getRemoteIdCards(): Promise<IdCard[]>;
|
|
149
171
|
/**
|
|
@@ -24,6 +24,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.ClusterIdCardHandler = exports.IdCard = void 0;
|
|
27
|
+
exports.idCardTtl = idCardTtl;
|
|
28
|
+
exports.getIdCards = getIdCards;
|
|
27
29
|
const name_generator_1 = require("../util/name-generator");
|
|
28
30
|
const node_child_process_1 = require("node:child_process");
|
|
29
31
|
const node_path_1 = require("node:path");
|
|
@@ -31,13 +33,24 @@ const bluebird_1 = __importDefault(require("bluebird"));
|
|
|
31
33
|
require("../types");
|
|
32
34
|
const REDIS_PREFIX = "{cluster/node}/";
|
|
33
35
|
const REDIS_ID_CARDS_INDEX = REDIS_PREFIX + "id-cards-index";
|
|
36
|
+
/**
|
|
37
|
+
* How many heartbeats an ID card outlives the last renewal of its node
|
|
38
|
+
*/
|
|
39
|
+
const REFRESH_MULTIPLIER = 2;
|
|
40
|
+
/**
|
|
41
|
+
* How long an ID card outlives the last renewal of its node, in ms
|
|
42
|
+
*/
|
|
43
|
+
function idCardTtl(heartbeat) {
|
|
44
|
+
return heartbeat * REFRESH_MULTIPLIER;
|
|
45
|
+
}
|
|
34
46
|
class IdCard {
|
|
35
|
-
constructor({ id, ip, birthdate, topology, storageDriver, }) {
|
|
47
|
+
constructor({ id, ip, birthdate, topology, storageDriver, builtInStorageDriver, }) {
|
|
36
48
|
this.id = id;
|
|
37
49
|
this.ip = ip;
|
|
38
50
|
this.birthdate = birthdate;
|
|
39
51
|
this.topology = new Set(topology);
|
|
40
52
|
this.storageDriver = storageDriver;
|
|
53
|
+
this.builtInStorageDriver = builtInStorageDriver;
|
|
41
54
|
}
|
|
42
55
|
serialize() {
|
|
43
56
|
const serialized = {
|
|
@@ -51,6 +64,12 @@ class IdCard {
|
|
|
51
64
|
if (this.storageDriver !== undefined) {
|
|
52
65
|
serialized.storageDriver = this.storageDriver;
|
|
53
66
|
}
|
|
67
|
+
// A field of its own rather than a value of `storageDriver`: a
|
|
68
|
+
// 2.61.0-beta node reads a card without `storageDriver` as a built-in
|
|
69
|
+
// node, and must keep joining these
|
|
70
|
+
if (this.builtInStorageDriver !== undefined) {
|
|
71
|
+
serialized.builtInStorageDriver = this.builtInStorageDriver;
|
|
72
|
+
}
|
|
54
73
|
return serialized;
|
|
55
74
|
}
|
|
56
75
|
static unserialize(serialized) {
|
|
@@ -58,6 +77,53 @@ class IdCard {
|
|
|
58
77
|
}
|
|
59
78
|
}
|
|
60
79
|
exports.IdCard = IdCard;
|
|
80
|
+
/**
|
|
81
|
+
* Retrieves the ID cards of the cluster nodes, but the one stored under
|
|
82
|
+
* `ownKey`
|
|
83
|
+
*
|
|
84
|
+
* Each node store it's ID Card under a specific key name. When Redis database
|
|
85
|
+
* is growing, searching for those keys can be quite expensive and can slow down
|
|
86
|
+
* the handshake process.
|
|
87
|
+
*
|
|
88
|
+
* We are storing a set containing ID Card's keys under a set so when a new node
|
|
89
|
+
* is started, it can directly get the other nodes ID Cards with SMEMBERS and
|
|
90
|
+
* then MGET instead of using SCAN.
|
|
91
|
+
*
|
|
92
|
+
* When a new node retrieve the ID Card's keys from the set, it try to get them
|
|
93
|
+
* with MGET, those who cannot be retrieved are expired ID Cards so the node update
|
|
94
|
+
* the set accordingly.
|
|
95
|
+
*
|
|
96
|
+
* A function rather than a method: a starting node reads the cards before it
|
|
97
|
+
* has a card, or a `ClusterNode`, of its own (storage driver check).
|
|
98
|
+
*/
|
|
99
|
+
async function getIdCards(ownKey) {
|
|
100
|
+
const idCards = [];
|
|
101
|
+
let keys = await global.kuzzle.ask("core:cache:internal:execute", "smembers", REDIS_ID_CARDS_INDEX);
|
|
102
|
+
keys = keys.filter((nodeIdKey) => nodeIdKey !== ownKey);
|
|
103
|
+
if (keys.length === 0) {
|
|
104
|
+
return idCards;
|
|
105
|
+
}
|
|
106
|
+
const rawIdCards = await global.kuzzle.ask("core:cache:internal:mget", keys);
|
|
107
|
+
const expiredIdCards = [];
|
|
108
|
+
// `entries()` over the keys: `rawIdCards` is the answer to a mget over
|
|
109
|
+
// exactly these keys, so the pair is what the loop is really walking.
|
|
110
|
+
for (const [i, key] of keys.entries()) {
|
|
111
|
+
// filter keys that might have expired between the key search and their
|
|
112
|
+
// values retrieval
|
|
113
|
+
const raw = rawIdCards[i];
|
|
114
|
+
if (raw !== null && raw !== undefined) {
|
|
115
|
+
idCards.push(IdCard.unserialize(JSON.parse(raw)));
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
expiredIdCards.push(key);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Clean expired ID Card's keys in the index
|
|
122
|
+
await bluebird_1.default.map(expiredIdCards, (idCardKey) => {
|
|
123
|
+
return global.kuzzle.ask("core:cache:internal:execute", "srem", REDIS_ID_CARDS_INDEX, idCardKey);
|
|
124
|
+
});
|
|
125
|
+
return idCards;
|
|
126
|
+
}
|
|
61
127
|
/**
|
|
62
128
|
* Handles the ID Key stored in Redis, holding node information
|
|
63
129
|
*/
|
|
@@ -71,7 +137,7 @@ class ClusterIdCardHandler {
|
|
|
71
137
|
* Multiplier used to ensure the node has enough time to refresh it's ID Card
|
|
72
138
|
* before the ID Card refresh delay
|
|
73
139
|
*/
|
|
74
|
-
this.refreshMultiplier =
|
|
140
|
+
this.refreshMultiplier = REFRESH_MULTIPLIER;
|
|
75
141
|
/**
|
|
76
142
|
* Worker thread in charge of refreshing the ID Card once the node has started
|
|
77
143
|
*/
|
|
@@ -105,7 +171,7 @@ class ClusterIdCardHandler {
|
|
|
105
171
|
* How long an ID card outlives the last renewal of its node, in ms
|
|
106
172
|
*/
|
|
107
173
|
get ttl() {
|
|
108
|
-
return this.refreshDelay
|
|
174
|
+
return idCardTtl(this.refreshDelay);
|
|
109
175
|
}
|
|
110
176
|
/**
|
|
111
177
|
* Generates and reserves a unique ID for this node instance.
|
|
@@ -133,6 +199,7 @@ class ClusterIdCardHandler {
|
|
|
133
199
|
this.nodeIdKey = `${REDIS_PREFIX}${this.nodeId}`;
|
|
134
200
|
this.idCard = new IdCard({
|
|
135
201
|
birthdate: Date.now(),
|
|
202
|
+
builtInStorageDriver: this.node.builtInStorageDriver,
|
|
136
203
|
id: this.nodeId,
|
|
137
204
|
ip: this.ip,
|
|
138
205
|
storageDriver: this.node.storageDriver,
|
|
@@ -259,49 +326,10 @@ class ClusterIdCardHandler {
|
|
|
259
326
|
}
|
|
260
327
|
}
|
|
261
328
|
/**
|
|
262
|
-
* Retrieves the ID cards from other nodes
|
|
263
|
-
*
|
|
264
|
-
* Each node store it's ID Card under a specific key name. When Redis database
|
|
265
|
-
* is growing, searching for those keys can be quite expensive and can slow down
|
|
266
|
-
* the handshake process.
|
|
267
|
-
*
|
|
268
|
-
* We are storing a set containing ID Card's keys under a set so when a new node
|
|
269
|
-
* is started, it can directly get the other nodes ID Cards with SMEMBERS and
|
|
270
|
-
* then MGET instead of using SCAN.
|
|
271
|
-
*
|
|
272
|
-
* When a new node retrieve the ID Card's keys from the set, it try to get them
|
|
273
|
-
* with MGET, those who cannot be retrieved are expired ID Cards so the node update
|
|
274
|
-
* the set accordingly.
|
|
275
|
-
*
|
|
276
|
-
* @return {Array.<IdCard>}
|
|
329
|
+
* Retrieves the ID cards from other nodes: see `getIdCards()`
|
|
277
330
|
*/
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
let keys = await global.kuzzle.ask("core:cache:internal:execute", "smembers", REDIS_ID_CARDS_INDEX);
|
|
281
|
-
keys = keys.filter((nodeIdKey) => nodeIdKey !== this.nodeIdKey);
|
|
282
|
-
if (keys.length === 0) {
|
|
283
|
-
return idCards;
|
|
284
|
-
}
|
|
285
|
-
const rawIdCards = await global.kuzzle.ask("core:cache:internal:mget", keys);
|
|
286
|
-
const expiredIdCards = [];
|
|
287
|
-
// `entries()` over the keys: `rawIdCards` is the answer to a mget over
|
|
288
|
-
// exactly these keys, so the pair is what the loop is really walking.
|
|
289
|
-
for (const [i, key] of keys.entries()) {
|
|
290
|
-
// filter keys that might have expired between the key search and their
|
|
291
|
-
// values retrieval
|
|
292
|
-
const raw = rawIdCards[i];
|
|
293
|
-
if (raw !== null && raw !== undefined) {
|
|
294
|
-
idCards.push(IdCard.unserialize(JSON.parse(raw)));
|
|
295
|
-
}
|
|
296
|
-
else {
|
|
297
|
-
expiredIdCards.push(key);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
// Clean expired ID Card's keys in the index
|
|
301
|
-
await bluebird_1.default.map(expiredIdCards, (idCardKey) => {
|
|
302
|
-
return global.kuzzle.ask("core:cache:internal:execute", "srem", REDIS_ID_CARDS_INDEX, idCardKey);
|
|
303
|
-
});
|
|
304
|
-
return idCards;
|
|
331
|
+
getRemoteIdCards() {
|
|
332
|
+
return getIdCards(this.nodeIdKey);
|
|
305
333
|
}
|
|
306
334
|
/**
|
|
307
335
|
* Adds a remote node IdCard to the node known topology
|
|
@@ -77,6 +77,11 @@ declare class ClusterNode {
|
|
|
77
77
|
* same
|
|
78
78
|
*/
|
|
79
79
|
readonly storageDriver?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Package of this node's built-in storage driver, `undefined` with an
|
|
82
|
+
* external one
|
|
83
|
+
*/
|
|
84
|
+
readonly builtInStorageDriver?: string;
|
|
80
85
|
constructor();
|
|
81
86
|
get syncAddress(): string;
|
|
82
87
|
init(): Promise<string>;
|
|
@@ -175,8 +180,9 @@ declare class ClusterNode {
|
|
|
175
180
|
*/
|
|
176
181
|
private discoverNodes;
|
|
177
182
|
/**
|
|
178
|
-
*
|
|
179
|
-
*
|
|
183
|
+
* Already compared before the storage initialized
|
|
184
|
+
* (`assertClusterStorageDriver`): checked again for a node that started at
|
|
185
|
+
* the same time as this one, too late for that first check to see it.
|
|
180
186
|
*
|
|
181
187
|
* @throws {cluster.join.storage_driver_mismatch} if a node runs another
|
|
182
188
|
* storage driver than this one
|
package/dist/lib/cluster/node.js
CHANGED
|
@@ -70,7 +70,6 @@ const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
|
70
70
|
const intersection_1 = __importDefault(require("lodash/intersection"));
|
|
71
71
|
const xor_1 = __importDefault(require("lodash/xor"));
|
|
72
72
|
const long_1 = __importDefault(require("long"));
|
|
73
|
-
const storageDriverLoader_1 = require("../core/storage/storageDriverLoader");
|
|
74
73
|
const kerror = __importStar(require("../kerror"));
|
|
75
74
|
const kuzzleError_1 = require("../kerror/errors/kuzzleError");
|
|
76
75
|
const kuzzleStateEnum_1 = __importDefault(require("../kuzzle/kuzzleStateEnum"));
|
|
@@ -81,6 +80,7 @@ const command_1 = __importDefault(require("./command"));
|
|
|
81
80
|
const idCardHandler_1 = require("./idCardHandler");
|
|
82
81
|
const publisher_1 = __importDefault(require("./publisher"));
|
|
83
82
|
const state_1 = __importDefault(require("./state"));
|
|
83
|
+
const storageDriverCheck_1 = require("./storageDriverCheck");
|
|
84
84
|
const subscriber_1 = __importDefault(require("./subscriber"));
|
|
85
85
|
const debug = (0, debug_1.default)("kuzzle:cluster:sync");
|
|
86
86
|
const joinError = kerror.wrap("cluster", "join");
|
|
@@ -229,9 +229,10 @@ class ClusterNode {
|
|
|
229
229
|
constructor() {
|
|
230
230
|
this._nodeId = null;
|
|
231
231
|
this.config = global.kuzzle.config.cluster;
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
232
|
+
({
|
|
233
|
+
storageDriver: this.storageDriver,
|
|
234
|
+
builtInStorageDriver: this.builtInStorageDriver,
|
|
235
|
+
} = (0, storageDriverCheck_1.localStorageDriver)(global.kuzzle.config.services.storageEngine));
|
|
235
236
|
this.logger = global.kuzzle.log.child("cluster:node");
|
|
236
237
|
this.heartbeatDelay = this.config.heartbeat;
|
|
237
238
|
const family = this.config.ipv6 ? "IPv6" : "IPv4";
|
|
@@ -628,18 +629,15 @@ class ClusterNode {
|
|
|
628
629
|
return remaining;
|
|
629
630
|
}
|
|
630
631
|
/**
|
|
631
|
-
*
|
|
632
|
-
*
|
|
632
|
+
* Already compared before the storage initialized
|
|
633
|
+
* (`assertClusterStorageDriver`): checked again for a node that started at
|
|
634
|
+
* the same time as this one, too late for that first check to see it.
|
|
633
635
|
*
|
|
634
636
|
* @throws {cluster.join.storage_driver_mismatch} if a node runs another
|
|
635
637
|
* storage driver than this one
|
|
636
638
|
*/
|
|
637
639
|
assertSameStorageDriver(nodes) {
|
|
638
|
-
|
|
639
|
-
if (other) {
|
|
640
|
-
const describe = (driver) => driver ?? "a built-in Elasticsearch driver";
|
|
641
|
-
throw joinError.get("storage_driver_mismatch", describe(this.storageDriver), other.id, describe(other.storageDriver));
|
|
642
|
-
}
|
|
640
|
+
(0, storageDriverCheck_1.assertSameStorageDriver)(this, nodes);
|
|
643
641
|
}
|
|
644
642
|
/**
|
|
645
643
|
* Discovers other active nodes from the cluster and, if other nodes exist,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { IKuzzleConfiguration } from "../types/config/KuzzleConfiguration";
|
|
2
|
+
import { type IdCard } from "./idCardHandler";
|
|
3
|
+
/**
|
|
4
|
+
* The storage driver a node runs, as its ID card carries it: one of the two
|
|
5
|
+
* fields is set, or neither on a node older than 2.61.0.
|
|
6
|
+
*/
|
|
7
|
+
export type StorageDriverIdentity = Pick<IdCard, "storageDriver" | "builtInStorageDriver">;
|
|
8
|
+
/**
|
|
9
|
+
* The storage driver this node's configuration selects
|
|
10
|
+
*
|
|
11
|
+
* @throws {services.storage_driver.*} if it cannot be loaded
|
|
12
|
+
*/
|
|
13
|
+
export declare function localStorageDriver(config: IKuzzleConfiguration["services"]["storageEngine"]): StorageDriverIdentity;
|
|
14
|
+
/**
|
|
15
|
+
* @throws {cluster.join.storage_driver_mismatch} if a node runs another
|
|
16
|
+
* storage driver than `local`
|
|
17
|
+
*/
|
|
18
|
+
export declare function assertSameStorageDriver(local: StorageDriverIdentity, nodes: IdCard[]): void;
|
|
19
|
+
/**
|
|
20
|
+
* Compares this node's storage driver with the ID cards of the cluster
|
|
21
|
+
* nodes, before this node touches the storage: a node refused here has
|
|
22
|
+
* written nothing.
|
|
23
|
+
*
|
|
24
|
+
* A mismatching card can be a stale one, left by a node stopped without
|
|
25
|
+
* cleaning up, as in the full cluster restart a driver change requires: it
|
|
26
|
+
* is read again once it would have expired, and only a card still there
|
|
27
|
+
* refuses this node.
|
|
28
|
+
*
|
|
29
|
+
* @throws {cluster.join.storage_driver_mismatch}
|
|
30
|
+
*/
|
|
31
|
+
export declare function assertClusterStorageDriver(config: IKuzzleConfiguration): Promise<void>;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Kuzzle, a backend software, self-hostable and ready to use
|
|
4
|
+
* to power modern apps
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2015-2026 Kuzzle
|
|
7
|
+
* mailto: support AT kuzzle.io
|
|
8
|
+
* website: http://kuzzle.io
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License.
|
|
12
|
+
* You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
25
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
26
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
27
|
+
}
|
|
28
|
+
Object.defineProperty(o, k2, desc);
|
|
29
|
+
}) : (function(o, m, k, k2) {
|
|
30
|
+
if (k2 === undefined) k2 = k;
|
|
31
|
+
o[k2] = m[k];
|
|
32
|
+
}));
|
|
33
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
34
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
35
|
+
}) : function(o, v) {
|
|
36
|
+
o["default"] = v;
|
|
37
|
+
});
|
|
38
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
39
|
+
var ownKeys = function(o) {
|
|
40
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
41
|
+
var ar = [];
|
|
42
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
43
|
+
return ar;
|
|
44
|
+
};
|
|
45
|
+
return ownKeys(o);
|
|
46
|
+
};
|
|
47
|
+
return function (mod) {
|
|
48
|
+
if (mod && mod.__esModule) return mod;
|
|
49
|
+
var result = {};
|
|
50
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
51
|
+
__setModuleDefault(result, mod);
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
})();
|
|
55
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
56
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
57
|
+
};
|
|
58
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
+
exports.localStorageDriver = localStorageDriver;
|
|
60
|
+
exports.assertSameStorageDriver = assertSameStorageDriver;
|
|
61
|
+
exports.assertClusterStorageDriver = assertClusterStorageDriver;
|
|
62
|
+
// Every cluster node runs the same storage driver (ADR-0003, decision 9).
|
|
63
|
+
// The driver is known from the configuration and the driver's manifest, before
|
|
64
|
+
// any connection: a starting node compares it with the ID cards of the cluster
|
|
65
|
+
// before its storage initializes (#3139), and again at its handshake.
|
|
66
|
+
const bluebird_1 = __importDefault(require("bluebird"));
|
|
67
|
+
const kerror = __importStar(require("../kerror"));
|
|
68
|
+
const storageDriverLoader_1 = require("../core/storage/storageDriverLoader");
|
|
69
|
+
const idCardHandler_1 = require("./idCardHandler");
|
|
70
|
+
const joinError = kerror.wrap("cluster", "join");
|
|
71
|
+
/**
|
|
72
|
+
* The storage driver this node's configuration selects
|
|
73
|
+
*
|
|
74
|
+
* @throws {services.storage_driver.*} if it cannot be loaded
|
|
75
|
+
*/
|
|
76
|
+
function localStorageDriver(config) {
|
|
77
|
+
const { identity, builtIn } = (0, storageDriverLoader_1.selectStorageDriver)(config);
|
|
78
|
+
return identity === null
|
|
79
|
+
? { builtInStorageDriver: builtIn ?? undefined }
|
|
80
|
+
: { storageDriver: identity };
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Whether a node running `local` can join a node whose card says `remote`.
|
|
84
|
+
*
|
|
85
|
+
* - external drivers: same package, same version;
|
|
86
|
+
* - built-in drivers: same package (the Elasticsearch major version), its
|
|
87
|
+
* version being Kuzzle's own, so that a rolling upgrade of Kuzzle goes on;
|
|
88
|
+
* - a card with no driver at all is a node older than 2.61.0, which could
|
|
89
|
+
* only run a built-in driver of a major version it does not say: it is
|
|
90
|
+
* accepted by a built-in node, as before 2.61.0, and refused by an
|
|
91
|
+
* external one.
|
|
92
|
+
*/
|
|
93
|
+
function sameDriver(local, remote) {
|
|
94
|
+
if (local.storageDriver !== undefined || remote.storageDriver !== undefined) {
|
|
95
|
+
return local.storageDriver === remote.storageDriver;
|
|
96
|
+
}
|
|
97
|
+
return (remote.builtInStorageDriver === undefined ||
|
|
98
|
+
remote.builtInStorageDriver === local.builtInStorageDriver);
|
|
99
|
+
}
|
|
100
|
+
function describe({ storageDriver, builtInStorageDriver, }) {
|
|
101
|
+
if (storageDriver !== undefined) {
|
|
102
|
+
return storageDriver;
|
|
103
|
+
}
|
|
104
|
+
return builtInStorageDriver === undefined
|
|
105
|
+
? "a built-in Elasticsearch driver"
|
|
106
|
+
: `the built-in driver ${builtInStorageDriver}`;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* @throws {cluster.join.storage_driver_mismatch} if a node runs another
|
|
110
|
+
* storage driver than `local`
|
|
111
|
+
*/
|
|
112
|
+
function assertSameStorageDriver(local, nodes) {
|
|
113
|
+
const other = nodes.find((node) => !sameDriver(local, node));
|
|
114
|
+
if (other) {
|
|
115
|
+
throw joinError.get("storage_driver_mismatch", describe(local), other.id, describe(other));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Compares this node's storage driver with the ID cards of the cluster
|
|
120
|
+
* nodes, before this node touches the storage: a node refused here has
|
|
121
|
+
* written nothing.
|
|
122
|
+
*
|
|
123
|
+
* A mismatching card can be a stale one, left by a node stopped without
|
|
124
|
+
* cleaning up, as in the full cluster restart a driver change requires: it
|
|
125
|
+
* is read again once it would have expired, and only a card still there
|
|
126
|
+
* refuses this node.
|
|
127
|
+
*
|
|
128
|
+
* @throws {cluster.join.storage_driver_mismatch}
|
|
129
|
+
*/
|
|
130
|
+
async function assertClusterStorageDriver(config) {
|
|
131
|
+
const local = localStorageDriver(config.services.storageEngine);
|
|
132
|
+
const other = (await (0, idCardHandler_1.getIdCards)(null)).find((node) => !sameDriver(local, node));
|
|
133
|
+
if (other === undefined) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
// A heartbeat more than the TTL: the card's last renewal may be in flight
|
|
137
|
+
const delay = (0, idCardHandler_1.idCardTtl)(config.cluster.heartbeat) + config.cluster.heartbeat;
|
|
138
|
+
global.kuzzle.log.warn(`[CLUSTER] This node runs ${describe(local)}, but the cluster node ${other.id} runs ${describe(other)}. Waiting ${delay}ms for its ID card to expire, in case it is a stale one...`);
|
|
139
|
+
await bluebird_1.default.delay(delay);
|
|
140
|
+
assertSameStorageDriver(local, await (0, idCardHandler_1.getIdCards)(null));
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=storageDriverCheck.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StorageEngineInfo } from "../../types/storage/StorageDriver";
|
|
1
2
|
import { ApplicationManager } from "./index";
|
|
2
3
|
export declare class BackendStorage extends ApplicationManager {
|
|
3
4
|
private _client;
|
|
@@ -14,4 +15,12 @@ export declare class BackendStorage extends ApplicationManager {
|
|
|
14
15
|
* (Currently Elasticsearch)
|
|
15
16
|
*/
|
|
16
17
|
get storageClient(): any;
|
|
18
|
+
/**
|
|
19
|
+
* The storage engine Kuzzle runs on: its driver's package, the engine
|
|
20
|
+
* family and the engine server's version. What the raw client's API
|
|
21
|
+
* follows, unlike `services.storageEngine.majorVersion`.
|
|
22
|
+
*
|
|
23
|
+
* Asks the engine: call it once, not on every request.
|
|
24
|
+
*/
|
|
25
|
+
getEngine(): Promise<StorageEngineInfo>;
|
|
17
26
|
}
|
|
@@ -19,10 +19,45 @@
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
25
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
26
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
27
|
+
}
|
|
28
|
+
Object.defineProperty(o, k2, desc);
|
|
29
|
+
}) : (function(o, m, k, k2) {
|
|
30
|
+
if (k2 === undefined) k2 = k;
|
|
31
|
+
o[k2] = m[k];
|
|
32
|
+
}));
|
|
33
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
34
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
35
|
+
}) : function(o, v) {
|
|
36
|
+
o["default"] = v;
|
|
37
|
+
});
|
|
38
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
39
|
+
var ownKeys = function(o) {
|
|
40
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
41
|
+
var ar = [];
|
|
42
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
43
|
+
return ar;
|
|
44
|
+
};
|
|
45
|
+
return ownKeys(o);
|
|
46
|
+
};
|
|
47
|
+
return function (mod) {
|
|
48
|
+
if (mod && mod.__esModule) return mod;
|
|
49
|
+
var result = {};
|
|
50
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
51
|
+
__setModuleDefault(result, mod);
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
})();
|
|
22
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
56
|
exports.BackendStorage = void 0;
|
|
57
|
+
const kerror = __importStar(require("../../kerror"));
|
|
24
58
|
const storageDriverLoader_1 = require("../storage/storageDriverLoader");
|
|
25
59
|
const index_1 = require("./index");
|
|
60
|
+
const runtimeError = kerror.wrap("plugin", "runtime");
|
|
26
61
|
class BackendStorage extends index_1.ApplicationManager {
|
|
27
62
|
constructor() {
|
|
28
63
|
super(...arguments);
|
|
@@ -56,6 +91,19 @@ class BackendStorage extends index_1.ApplicationManager {
|
|
|
56
91
|
this._client ?? (this._client = (0, storageDriverLoader_1.createNativeStorageClient)(kuzzle.config.services.storageEngine, kuzzle.config.services.storageEngine.client));
|
|
57
92
|
return this._client;
|
|
58
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* The storage engine Kuzzle runs on: its driver's package, the engine
|
|
96
|
+
* family and the engine server's version. What the raw client's API
|
|
97
|
+
* follows, unlike `services.storageEngine.majorVersion`.
|
|
98
|
+
*
|
|
99
|
+
* Asks the engine: call it once, not on every request.
|
|
100
|
+
*/
|
|
101
|
+
async getEngine() {
|
|
102
|
+
if (!this._application.started) {
|
|
103
|
+
throw runtimeError.get("unavailable_before_start", "storage.getEngine");
|
|
104
|
+
}
|
|
105
|
+
return (0, storageDriverLoader_1.getStorageEngineInfo)();
|
|
106
|
+
}
|
|
59
107
|
}
|
|
60
108
|
exports.BackendStorage = BackendStorage;
|
|
61
109
|
//# sourceMappingURL=backendStorage.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Koncorde } from "../shared/KoncordeWrapper";
|
|
2
2
|
import type { JSONObject } from "../../types/JSONObject";
|
|
3
3
|
import { KuzzleRequest, RequestContext, RequestInput } from "../../api/request";
|
|
4
|
+
import type { StorageEngineInfo } from "../../types/storage/StorageDriver";
|
|
4
5
|
import { Mutex } from "../../util/mutex";
|
|
5
6
|
import { BackendCluster } from "../backend/backendCluster";
|
|
6
7
|
import { EmbeddedSDK } from "../shared/sdk/embeddedSdk";
|
|
@@ -95,6 +96,15 @@ export declare class PluginContext {
|
|
|
95
96
|
*/
|
|
96
97
|
createCollection(collection: string, mappings: unknown): Promise<void>;
|
|
97
98
|
};
|
|
99
|
+
/**
|
|
100
|
+
* The storage engine Kuzzle runs on: its driver's package, the engine
|
|
101
|
+
* family and the engine server's version. What `constructors.ESClient`'s
|
|
102
|
+
* API follows, unlike `services.storageEngine.majorVersion`.
|
|
103
|
+
*
|
|
104
|
+
* Asks the engine: call it once (e.g. in the plugin's `init()`), not on
|
|
105
|
+
* every request.
|
|
106
|
+
*/
|
|
107
|
+
getStorageEngine(): Promise<StorageEngineInfo>;
|
|
98
108
|
/**
|
|
99
109
|
* Cluster accessor
|
|
100
110
|
* @type {BackendCluster}
|
|
@@ -160,6 +160,7 @@ class PluginContext {
|
|
|
160
160
|
this.accessors = {
|
|
161
161
|
cluster: new backendCluster_1.BackendCluster(),
|
|
162
162
|
execute,
|
|
163
|
+
getStorageEngine: storageDriverLoader_1.getStorageEngineInfo,
|
|
163
164
|
nodeId: global.nodeId,
|
|
164
165
|
sdk: new embeddedSdk_1.EmbeddedSDK(),
|
|
165
166
|
storage: {
|