kuzzle 2.61.0-beta.4 → 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.
Files changed (39) hide show
  1. package/dist/lib/api/controllers/serverController.js +1 -1
  2. package/dist/lib/cluster/idCardHandler.d.ts +41 -19
  3. package/dist/lib/cluster/idCardHandler.js +73 -45
  4. package/dist/lib/cluster/node.d.ts +8 -2
  5. package/dist/lib/cluster/node.js +9 -11
  6. package/dist/lib/cluster/storageDriverCheck.d.ts +31 -0
  7. package/dist/lib/cluster/storageDriverCheck.js +142 -0
  8. package/dist/lib/config/default.config.js +1 -0
  9. package/dist/lib/core/backend/backendStorage.d.ts +9 -0
  10. package/dist/lib/core/backend/backendStorage.js +48 -0
  11. package/dist/lib/core/plugin/pluginContext.d.ts +10 -0
  12. package/dist/lib/core/plugin/pluginContext.js +1 -0
  13. package/dist/lib/core/storage/clientAdapter.d.ts +13 -0
  14. package/dist/lib/core/storage/clientAdapter.js +26 -2
  15. package/dist/lib/core/storage/conformance/capabilityCases.js +41 -0
  16. package/dist/lib/core/storage/conformance/conformanceContext.d.ts +11 -1
  17. package/dist/lib/core/storage/conformance/conformanceContext.js +7 -1
  18. package/dist/lib/core/storage/conformance/coreCases.js +136 -0
  19. package/dist/lib/core/storage/conformance/storageDriverConformance.js +19 -3
  20. package/dist/lib/core/storage/indexCache.d.ts +9 -0
  21. package/dist/lib/core/storage/indexCache.js +20 -1
  22. package/dist/lib/core/storage/storageDriverLoader.d.ts +24 -5
  23. package/dist/lib/core/storage/storageDriverLoader.js +177 -25
  24. package/dist/lib/core/storage/storageEngine.d.ts +11 -0
  25. package/dist/lib/core/storage/storageEngine.js +47 -5
  26. package/dist/lib/kerror/codes/1-services.json +18 -12
  27. package/dist/lib/kerror/codes/2-api.json +1 -1
  28. package/dist/lib/kerror/codes/8-cluster.json +1 -1
  29. package/dist/lib/kuzzle/kuzzle.d.ts +2 -0
  30. package/dist/lib/kuzzle/kuzzle.js +14 -1
  31. package/dist/lib/service/storage/builtInDrivers.d.ts +7 -0
  32. package/dist/lib/service/storage/builtInDrivers.js +18 -35
  33. package/dist/lib/service/storage/driverPackage.d.ts +20 -0
  34. package/dist/lib/service/storage/driverPackage.js +101 -0
  35. package/dist/lib/service/storage/storageService.js +3 -3
  36. package/dist/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +12 -0
  37. package/dist/lib/types/storage/StorageDriver.d.ts +24 -2
  38. package/dist/package.json +21 -21
  39. package/package.json +21 -21
@@ -53,10 +53,11 @@ var __importStar = (this && this.__importStar) || (function () {
53
53
  };
54
54
  })();
55
55
  Object.defineProperty(exports, "__esModule", { value: true });
56
- exports.CAPABILITY_METHODS = void 0;
56
+ exports.CAPABILITY_METHODS = exports.CORE_METHODS = void 0;
57
57
  exports.selectStorageDriver = selectStorageDriver;
58
58
  exports.createNativeStorageClient = createNativeStorageClient;
59
- exports.assertDeclaredCapabilities = assertDeclaredCapabilities;
59
+ exports.getStorageEngineInfo = getStorageEngineInfo;
60
+ exports.assertDriverContract = assertDriverContract;
60
61
  // The storage driver loader (ADR-0003 step 03): selects the driver class the
61
62
  // storage layer runs on. `services.storageEngine.driver` names an npm package,
62
63
  // whose manifest is checked before its code is loaded; without it, the
@@ -66,9 +67,57 @@ const path = __importStar(require("node:path"));
66
67
  const semver = __importStar(require("semver"));
67
68
  const kerror = __importStar(require("../../kerror"));
68
69
  const builtInDrivers_1 = require("../../service/storage/builtInDrivers");
70
+ const driverPackage_1 = require("../../service/storage/driverPackage");
69
71
  const StorageDriver_1 = require("../../types/storage/StorageDriver");
70
72
  require("../../types/Global");
71
73
  const driverError = kerror.wrap("services", "storage_driver");
74
+ /**
75
+ * Every method of the core contract, checked off against `StorageDriverCore`
76
+ * by the compiler: a method missing here or unknown to it does not build.
77
+ */
78
+ const CORE_METHOD_SET = {
79
+ count: true,
80
+ create: true,
81
+ createCollection: true,
82
+ createIndex: true,
83
+ createOrReplace: true,
84
+ delete: true,
85
+ deleteByQuery: true,
86
+ deleteCollection: true,
87
+ deleteFields: true,
88
+ deleteIndex: true,
89
+ deleteIndexes: true,
90
+ exists: true,
91
+ get: true,
92
+ getMapping: true,
93
+ getSchema: true,
94
+ getSettings: true,
95
+ import: true,
96
+ info: true,
97
+ init: true,
98
+ mCreate: true,
99
+ mCreateOrReplace: true,
100
+ mDelete: true,
101
+ mExecute: true,
102
+ mExists: true,
103
+ mGet: true,
104
+ mReplace: true,
105
+ mUpdate: true,
106
+ mUpsert: true,
107
+ refreshCollection: true,
108
+ replace: true,
109
+ scroll: true,
110
+ search: true,
111
+ translateKoncordeFilters: true,
112
+ truncateCollection: true,
113
+ update: true,
114
+ upsert: true,
115
+ };
116
+ /** The methods every driver must have */
117
+ exports.CORE_METHODS = Object.freeze(Object.keys(CORE_METHOD_SET).filter(isCoreMethod));
118
+ function isCoreMethod(key) {
119
+ return Object.hasOwn(CORE_METHOD_SET, key);
120
+ }
72
121
  /** The methods a driver declaring a capability must have */
73
122
  exports.CAPABILITY_METHODS = Object.freeze({
74
123
  // A search body option, not a method
@@ -110,13 +159,28 @@ function createNativeStorageClient(config, clientConfig) {
110
159
  return selectStorageDriver(config).Driver.createNativeClient(clientConfig);
111
160
  }
112
161
  /**
113
- * Checks that a driver instance has the methods of the capabilities its
114
- * driver declares. Done on the instance rather than on the class: a method
115
- * can be an instance property.
162
+ * The storage engine Kuzzle runs on: the driver's package, and the engine
163
+ * family and server version its `info()` reports. Asks the engine, so only
164
+ * once the storage is initialized.
165
+ */
166
+ async function getStorageEngineInfo() {
167
+ const { packageName } = selectStorageDriver(global.kuzzle.config.services.storageEngine);
168
+ const { type, version } = await global.kuzzle.ask("core:storage:public:info:get");
169
+ return { driver: packageName, engine: type, version };
170
+ }
171
+ /**
172
+ * Checks that a driver instance has the methods of the core contract, and
173
+ * those of the capabilities its driver declares: at startup, rather than
174
+ * with a `TypeError` on the first request needing a missing one. Done on the
175
+ * instance rather than on the class: a method can be an instance property.
116
176
  *
117
177
  * @throws {services.storage_driver.invalid_driver}
118
178
  */
119
- function assertDeclaredCapabilities(driver, { capabilities, description }) {
179
+ function assertDriverContract(driver, { capabilities, description }) {
180
+ const missing = exports.CORE_METHODS.filter((method) => typeof driver[method] !== "function");
181
+ if (missing.length > 0) {
182
+ throw driverError.get("invalid_driver", description, `it lacks ${missing.length === 1 ? "a method" : "methods"} of the core contract: ${missing.join(", ")}`);
183
+ }
120
184
  for (const capability of capabilities) {
121
185
  for (const method of exports.CAPABILITY_METHODS[capability]) {
122
186
  if (typeof driver[method] !== "function") {
@@ -129,21 +193,33 @@ function selectBuiltInDriver(config) {
129
193
  // Without a `majorVersion`, the raw client surfaces have always built an
130
194
  // Elasticsearch 7 client.
131
195
  const majorVersion = config.majorVersion ?? "7";
196
+ // Throws first if no built-in driver supports `majorVersion`
197
+ const Driver = (0, builtInDrivers_1.builtInStorageDriver)(majorVersion);
198
+ const packageName = (0, builtInDrivers_1.builtInStorageDriverPackage)(majorVersion);
132
199
  return {
133
- Driver: (0, builtInDrivers_1.builtInStorageDriver)(majorVersion),
200
+ Driver,
201
+ builtIn: packageName,
134
202
  capabilities: BUILT_IN_CAPABILITIES,
135
203
  description: `the built-in Elasticsearch ${majorVersion} driver`,
136
204
  identity: null,
205
+ location: null,
206
+ packageName,
137
207
  };
138
208
  }
209
+ /**
210
+ * An npm package name, scoped or not: no path, no version, no subpath
211
+ * (rules of validate-npm-package-name, upper case allowed for older packages)
212
+ */
213
+ const PACKAGE_NAME = /^(?:@[a-z0-9~-][a-z0-9._~-]*\/)?[a-z0-9~-][a-z0-9._~-]*$/i;
139
214
  function loadExternalDriver(name) {
140
- if (typeof name !== "string" || name.length === 0) {
141
- throw driverError.get("not_found", String(name), "services.storageEngine.driver must be an npm package name");
142
- }
143
- const entry = resolveDriver(name);
144
- const { root, version } = findPackageRoot(name, entry);
215
+ assertPackageName(name);
216
+ const lookup = [process.cwd(), __dirname];
217
+ const entry = resolveDriver(name, lookup);
218
+ const { packageName, root, version } = findPackageRoot(name, entry);
145
219
  const capabilities = readManifest(name, root);
146
- const identity = `${name}@${version}`;
220
+ const identity = `${packageName}@${version}`;
221
+ // Before the driver's code requires `kuzzle`
222
+ (0, driverPackage_1.provideRunningKuzzle)(entry);
147
223
  let exported;
148
224
  try {
149
225
  // The package the configuration names: only known at runtime.
@@ -155,38 +231,92 @@ function loadExternalDriver(name) {
155
231
  }
156
232
  return {
157
233
  Driver: driverClass(identity, exported),
234
+ builtIn: null,
158
235
  capabilities,
159
- description: identity,
236
+ // An npm alias (`npm install <alias>@npm:<package>`) shows both names
237
+ description: name === packageName ? identity : `${name} (${identity})`,
160
238
  identity,
239
+ location: root,
240
+ packageName,
161
241
  };
162
242
  }
243
+ /** @throws {services.storage_driver.not_found} */
244
+ function assertPackageName(name) {
245
+ if (typeof name !== "string" || name.length === 0) {
246
+ throw driverError.get("not_found", String(name), "services.storageEngine.driver must be an npm package name");
247
+ }
248
+ if (PACKAGE_NAME.test(name)) {
249
+ return;
250
+ }
251
+ throw driverError.get("not_found", name, name.startsWith(".") || path.isAbsolute(name) || name.includes("\\")
252
+ ? `services.storageEngine.driver must be an npm package name, not a path: install the driver (npm install ${name}), then set its package name`
253
+ : "services.storageEngine.driver must be an npm package name, without a version or a subpath");
254
+ }
163
255
  /**
164
- * Looked up from the application first, then from Kuzzle itself: the
165
- * application is what installs the driver, next to `kuzzle`.
256
+ * Looked up from the current directory first, as the `.kuzzlerc` file is,
257
+ * then from Kuzzle itself: the application installs the driver next to
258
+ * `kuzzle`, which Kuzzle's own location finds whatever the current
259
+ * directory.
260
+ *
261
+ * @throws {services.storage_driver.not_found}
166
262
  */
167
- function resolveDriver(name) {
263
+ function resolveDriver(name, lookup) {
168
264
  try {
169
- return require.resolve(name, { paths: [process.cwd(), __dirname] });
265
+ return require.resolve(name, { paths: lookup });
170
266
  }
171
267
  catch (error) {
172
- throw driverError.get("not_found", name, messageOf(error));
268
+ const installed = findInstalledVersion(name, lookup);
269
+ throw driverError.get("not_found", name, installed === null
270
+ ? (0, driverPackage_1.notFoundDetail)(name, error)
271
+ : `installed ${name}@${installed} has no entry point`);
272
+ }
273
+ }
274
+ /**
275
+ * The version of a package installed in a `node_modules` directory Node
276
+ * looks into from `lookup`, which `require.resolve` could not load anyway: a
277
+ * package without an entry point, like a name-reservation placeholder.
278
+ */
279
+ function findInstalledVersion(name, lookup) {
280
+ for (const start of lookup) {
281
+ let dir = start;
282
+ while (true) {
283
+ const pkg = readJsonQuietly(path.join(dir, "node_modules", name, "package.json"));
284
+ if (pkg !== null) {
285
+ return String(pkg.version);
286
+ }
287
+ const parent = path.dirname(dir);
288
+ if (parent === dir) {
289
+ break;
290
+ }
291
+ dir = parent;
292
+ }
173
293
  }
294
+ return null;
174
295
  }
175
296
  /**
176
297
  * The directory of the driver's own `package.json`, found from its entry
177
298
  * point: `<name>/package.json` cannot be resolved when the package's
178
- * `exports` does not list it.
299
+ * `exports` does not list it. Under an npm alias, that `package.json` names
300
+ * the aliased package, and the directory is `node_modules/<alias>`.
301
+ *
302
+ * @throws {services.storage_driver.not_found}
179
303
  */
180
304
  function findPackageRoot(name, entry) {
305
+ const aliasDir = path.sep + path.join("node_modules", name);
181
306
  let dir = path.dirname(entry);
182
307
  while (true) {
183
308
  const pkg = readJson(path.join(dir, "package.json"));
184
- if (pkg?.name === name) {
185
- return { root: dir, version: String(pkg.version) };
309
+ if (typeof pkg?.name === "string" &&
310
+ (pkg.name === name || dir.endsWith(aliasDir))) {
311
+ return {
312
+ packageName: pkg.name,
313
+ root: dir,
314
+ version: String(pkg.version),
315
+ };
186
316
  }
187
317
  const parent = path.dirname(dir);
188
318
  if (parent === dir) {
189
- throw driverError.get("not_found", name, `no package.json named "${name}" above ${entry}`);
319
+ throw driverError.get("not_found", name, `${entry} belongs to no package named "${name}"`);
190
320
  }
191
321
  dir = parent;
192
322
  }
@@ -203,7 +333,7 @@ function readManifest(name, root) {
203
333
  manifest = readJson(manifestPath, { required: true });
204
334
  }
205
335
  catch (error) {
206
- throw driverError.get("invalid_manifest", name, `cannot read ${manifestPath}: ${messageOf(error)}`);
336
+ throw driverError.get("invalid_manifest", name, manifestError(manifestPath, error));
207
337
  }
208
338
  const { capabilities, kuzzleVersion } = manifest ?? {};
209
339
  if (typeof kuzzleVersion !== "string" ||
@@ -226,6 +356,19 @@ function readManifest(name, root) {
226
356
  }
227
357
  return declared;
228
358
  }
359
+ /** The path once: Node's file system errors repeat it */
360
+ function manifestError(manifestPath, error) {
361
+ if (error instanceof SyntaxError) {
362
+ return `${manifestPath} is not valid JSON: ${error.message}`;
363
+ }
364
+ const code = error instanceof Error && "code" in error ? String(error.code) : null;
365
+ if (code === "ENOENT") {
366
+ return `${manifestPath} does not exist`;
367
+ }
368
+ return code === null
369
+ ? `cannot read ${manifestPath}: ${messageOf(error)}`
370
+ : `cannot read ${manifestPath} (${code})`;
371
+ }
229
372
  /** Typed for a lookup of any manifest value */
230
373
  const KNOWN_CAPABILITIES = new Set(StorageDriver_1.STORAGE_CAPABILITIES);
231
374
  function isStorageCapability(value) {
@@ -243,7 +386,7 @@ function driverClass(identity, exported) {
243
386
  }
244
387
  /**
245
388
  * What can be checked of a class before building it: the contract of its
246
- * instances is checked once they exist (`assertDeclaredCapabilities`).
389
+ * instances is checked once they exist (`assertDriverContract`).
247
390
  */
248
391
  function isDriverClass(value) {
249
392
  return (typeof value === "function" &&
@@ -270,6 +413,15 @@ function readJson(file, { required = false } = {}) {
270
413
  }
271
414
  return JSON.parse(content);
272
415
  }
416
+ /** The parsed file, or `null` when it cannot be read or parsed */
417
+ function readJsonQuietly(file) {
418
+ try {
419
+ return readJson(file);
420
+ }
421
+ catch {
422
+ return null;
423
+ }
424
+ }
273
425
  function messageOf(error) {
274
426
  return error instanceof Error ? error.message : String(error);
275
427
  }
@@ -5,10 +5,21 @@ declare class StorageEngine {
5
5
  public: ClientAdapter;
6
6
  private: ClientAdapter;
7
7
  logger: Logger;
8
+ /** The running close, shared by every `close()` call */
9
+ private closing;
8
10
  constructor();
9
11
  /**
10
12
  * Initialize storage clients and perform integrity checks
11
13
  */
12
14
  init(): Promise<void>;
15
+ /**
16
+ * Closes the driver instances of both scopes on shutdown, once the requests
17
+ * in flight are done: calls their `close()` hook, when they have one, once.
18
+ *
19
+ * Never rejects, nor waits longer than `timeout` for a driver: a failure or
20
+ * a timeout is logged, and the shutdown goes on.
21
+ */
22
+ close(timeout?: number): Promise<void>;
23
+ private closeDriver;
13
24
  }
14
25
  export = StorageEngine;
@@ -22,26 +22,36 @@
22
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
24
  };
25
+ const node_util_1 = require("node:util");
25
26
  const kerror_1 = require("../../kerror");
26
27
  const clientAdapter_1 = __importDefault(require("./clientAdapter"));
27
28
  const storageDriverLoader_1 = require("./storageDriverLoader");
28
29
  const storeScopeEnum_1 = require("./storeScopeEnum");
29
30
  require("../../types/Global");
30
31
  const kerror = (0, kerror_1.wrap)("services", "storage");
32
+ /**
33
+ * How long the shutdown waits for a driver's `close()` hook: a requested
34
+ * shutdown has no other time limit, and a hook that never settles must not
35
+ * keep the node up
36
+ */
37
+ const DRIVER_CLOSE_TIMEOUT = 5000;
31
38
  class StorageEngine {
32
39
  constructor() {
40
+ /** The running close, shared by every `close()` call */
41
+ this.closing = null;
33
42
  // Storage client for public indexes only
34
43
  this.public = new clientAdapter_1.default(storeScopeEnum_1.storeScopeEnum.PUBLIC);
35
44
  // Storage client for private indexes only
36
45
  this.private = new clientAdapter_1.default(storeScopeEnum_1.storeScopeEnum.PRIVATE);
37
46
  this.logger = global.kuzzle.log.child("core:storage:storageEngine");
38
- const { description, identity } = (0, storageDriverLoader_1.selectStorageDriver)(global.kuzzle.config.services.storageEngine);
47
+ const { description, identity, location } = (0, storageDriverLoader_1.selectStorageDriver)(global.kuzzle.config.services.storageEngine);
39
48
  this.logger.info(identity === null
40
49
  ? `[ℹ] Elasticsearch configuration is set to major version : ${global.kuzzle.config.services.storageEngine.majorVersion}`
41
- : `[ℹ] Storage driver: ${description}`);
42
- const ignored = global.kuzzle.config.internal?.ignoredSettings;
43
- if (ignored?.length) {
44
- this.logger.warn(`[⚠] Ignored, since "services.storageEngine.driver" selects the storage driver: ${ignored.join(", ")}. Remove it from your configuration.`);
50
+ : // Where from: the application and Kuzzle may each have a copy
51
+ `[ℹ] Storage driver: ${description} (${location})`);
52
+ for (const setting of global.kuzzle.config.internal?.ignoredSettings ??
53
+ []) {
54
+ this.logger.warn(`[⚠] ${setting} is ignored because services.storageEngine.driver is set: remove ${setting.split(".").pop()}.`);
45
55
  }
46
56
  }
47
57
  /**
@@ -58,6 +68,38 @@ class StorageEngine {
58
68
  }
59
69
  this.logger.info("[✔] Storage initialized");
60
70
  }
71
+ /**
72
+ * Closes the driver instances of both scopes on shutdown, once the requests
73
+ * in flight are done: calls their `close()` hook, when they have one, once.
74
+ *
75
+ * Never rejects, nor waits longer than `timeout` for a driver: a failure or
76
+ * a timeout is logged, and the shutdown goes on.
77
+ */
78
+ close(timeout = DRIVER_CLOSE_TIMEOUT) {
79
+ this.closing ?? (this.closing = Promise.all([this.public, this.private].map((adapter) => this.closeDriver(adapter, timeout))).then(() => undefined));
80
+ return this.closing;
81
+ }
82
+ async closeDriver({ driver, scope }, timeout) {
83
+ if (typeof driver.close !== "function") {
84
+ return;
85
+ }
86
+ let timer;
87
+ try {
88
+ await Promise.race([
89
+ // A hook throwing synchronously is reported as one that rejects
90
+ (async () => driver.close?.())(),
91
+ new Promise((_resolve, reject) => {
92
+ timer = setTimeout(() => reject(new Error(`not closed after ${timeout}ms`)), timeout);
93
+ }),
94
+ ]);
95
+ }
96
+ catch (error) {
97
+ this.logger.warn(`[⚠] Unable to close the ${scope} storage driver: ${error instanceof Error ? error.message : (0, node_util_1.inspect)(error)}`);
98
+ }
99
+ finally {
100
+ clearTimeout(timer);
101
+ }
102
+ }
61
103
  }
62
104
  module.exports = StorageEngine;
63
105
  //# sourceMappingURL=storageEngine.js.map
@@ -65,9 +65,9 @@
65
65
  "class": "InternalError"
66
66
  },
67
67
  "version_mismatch": {
68
- "description": "The version of the target Elasticsearch is not compatible with this version of Kuzzle",
68
+ "description": "The version of the target storage engine is not compatible with this version of Kuzzle",
69
69
  "code": 13,
70
- "message": "Your elasticsearch version is %s: this version is not compatible with this version of Kuzzle",
70
+ "message": "Your storage engine version is %s: this version is not compatible with this version of Kuzzle",
71
71
  "class": "InternalError"
72
72
  },
73
73
  "unknown_scroll_id": {
@@ -134,7 +134,7 @@
134
134
  "not_connected": {
135
135
  "description": "Unable to connect to the storage instance",
136
136
  "code": 24,
137
- "message": "Elasticsearch service is not connected.",
137
+ "message": "Storage engine is not connected.",
138
138
  "class": "ExternalServiceError"
139
139
  },
140
140
  "too_many_operations": {
@@ -186,19 +186,19 @@
186
186
  "class": "ExternalServiceError"
187
187
  },
188
188
  "unexpected_bad_request": {
189
- "description": "Embeds an unexpected bad request error from Elasticsearch",
189
+ "description": "Embeds an unexpected bad request error from the storage engine",
190
190
  "code": 33,
191
191
  "message": "%s",
192
192
  "class": "BadRequestError"
193
193
  },
194
194
  "unexpected_not_found": {
195
- "description": "Embeds an unexpected notfound error from Elasticsearch",
195
+ "description": "Embeds an unexpected notfound error from the storage engine",
196
196
  "code": 34,
197
197
  "message": "%s",
198
198
  "class": "NotFoundError"
199
199
  },
200
200
  "unexpected_error": {
201
- "description": "Embeds an unexpected error from Elasticsearch",
201
+ "description": "Embeds an unexpected error from the storage engine",
202
202
  "code": 35,
203
203
  "message": "%s",
204
204
  "class": "ExternalServiceError"
@@ -255,7 +255,7 @@
255
255
  "unknown_query_keyword": {
256
256
  "description": "An unknown keyword has been provided in the search query",
257
257
  "code": 45,
258
- "message": "The keyword \"%s\" is not part of Elasticsearch Query DSL. Are you trying to use a Koncorde query?",
258
+ "message": "The keyword \"%s\" is not part of the storage engine Query DSL. Are you trying to use a Koncorde query?",
259
259
  "class": "BadRequestError"
260
260
  },
261
261
  "incomplete_update": {
@@ -273,7 +273,7 @@
273
273
  "multiple_indice_alias": {
274
274
  "description": "The unique association between an indice and its alias has not been respected",
275
275
  "code": 48,
276
- "message": "An %s is not allowed to be associated with multiple %s. This is probably not linked to this request but rather the consequence of previous actions on ElasticSearch.",
276
+ "message": "An %s is not allowed to be associated with multiple %s. This is probably not linked to this request but rather the consequence of previous actions on the storage engine.",
277
277
  "class": "PreconditionError"
278
278
  },
279
279
  "invalid_multi_index_collection_usage": {
@@ -346,9 +346,9 @@
346
346
  "code": 5,
347
347
  "errors": {
348
348
  "elastic_translation_error": {
349
- "description": "An error occured while translating a Koncorde filter to an Elasticsearch query",
349
+ "description": "An error occured while translating a Koncorde filter to a storage engine query",
350
350
  "code": 1,
351
- "message": "An error occured while translating a Koncorde filter to an Elasticsearch query: %s",
351
+ "message": "An error occured while translating a Koncorde filter to a storage engine query: %s",
352
352
  "class": "BadRequestError"
353
353
  }
354
354
  }
@@ -357,7 +357,7 @@
357
357
  "code": 6,
358
358
  "errors": {
359
359
  "not_found": {
360
- "description": "The storage driver package cannot be found: the one named by services.storageEngine.driver, or the built-in kuzzle-storage-es-7 / kuzzle-storage-es-8 package of the configured majorVersion. Kuzzle does not start.",
360
+ "description": "The storage driver package cannot be found: the one named by services.storageEngine.driver (an npm package name, not a path), or the built-in kuzzle-storage-es-7 / kuzzle-storage-es-8 package of the configured majorVersion; or the installed package has no entry point. Kuzzle does not start.",
361
361
  "code": 1,
362
362
  "message": "Cannot find the storage driver \"%s\": %s.",
363
363
  "class": "InternalError"
@@ -375,7 +375,7 @@
375
375
  "class": "InternalError"
376
376
  },
377
377
  "invalid_driver": {
378
- "description": "The storage driver named by services.storageEngine.driver does not export a storage driver class, or lacks a method of a capability its manifest declares. Kuzzle does not start.",
378
+ "description": "The storage driver named by services.storageEngine.driver does not export a storage driver class, lacks a method of the core contract, or lacks a method of a capability its manifest declares. Kuzzle does not start.",
379
379
  "code": 4,
380
380
  "message": "Invalid storage driver \"%s\": %s.",
381
381
  "class": "InternalError"
@@ -385,6 +385,12 @@
385
385
  "code": 5,
386
386
  "message": "The storage engine does not support this request: its driver does not declare the \"%s\" capability.",
387
387
  "class": "BadRequestError"
388
+ },
389
+ "unsupported_major_version": {
390
+ "description": "No built-in storage driver supports the configured services.storageEngine.majorVersion (built-in: Elasticsearch 7 and 8). Another engine, such as Elasticsearch 9 or OpenSearch, runs through an installable driver named by services.storageEngine.driver. Kuzzle does not start.",
391
+ "code": 6,
392
+ "message": "Unsupported services.storageEngine.majorVersion \"%s\" (supported: %s): for Elasticsearch 9 or OpenSearch, set services.storageEngine.driver instead (e.g. \"kuzzle-storage-es-9\").",
393
+ "class": "InternalError"
388
394
  }
389
395
  }
390
396
  }
@@ -73,7 +73,7 @@
73
73
  "koncorde_unknown_keyword": {
74
74
  "description": "An unknown keyword has been provided in filters",
75
75
  "code": 12,
76
- "message": "The keyword \"%s\" is not part of Koncorde filters DSL keywords. Are you trying to use an Elasticsearch query?",
76
+ "message": "The keyword \"%s\" is not part of Koncorde filters DSL keywords. Are you trying to use a storage engine query?",
77
77
  "class": "BadRequestError"
78
78
  },
79
79
  "koncorde_restricted_keyword": {
@@ -34,7 +34,7 @@
34
34
  "class": "InternalError"
35
35
  },
36
36
  "storage_driver_mismatch": {
37
- "description": "The joining node runs another storage driver (package name or version) than a node of the cluster: every node must run the same one. The joining node does not start.",
37
+ "description": "The joining node runs another storage driver than a node of the cluster: an external driver differs by package name or version, a built-in one by Elasticsearch major version, and a node older than 2.61.0 counts as a built-in one. Checked before the joining node connects to the storage: it does not start.",
38
38
  "code": 4,
39
39
  "message": "This node runs %s, but the cluster node %s runs %s: every cluster node must run the same storage driver.",
40
40
  "class": "InternalError"
@@ -23,6 +23,8 @@ declare class Kuzzle extends KuzzleEventEmitter {
23
23
  private shutdownExitCode;
24
24
  /** Ends a failure's shutdown that does not finish in time */
25
25
  private shutdownWatchdog;
26
+ /** Built by `start()`; its storage drivers are closed on shutdown */
27
+ private storageEngine;
26
28
  log: Logger;
27
29
  /** Read by `PluginsManager` to locate the plugins directories. */
28
30
  rootPath: string;
@@ -68,6 +68,7 @@ const package_json_1 = require("../../package.json");
68
68
  const funnel_1 = __importDefault(require("../api/funnel"));
69
69
  const openapi_1 = require("../api/openapi");
70
70
  const cluster_1 = __importDefault(require("../cluster"));
71
+ const storageDriverCheck_1 = require("../cluster/storageDriverCheck");
71
72
  const passportWrapper_1 = __importDefault(require("../core/auth/passportWrapper"));
72
73
  const tokenManager_1 = require("../core/auth/tokenManager");
73
74
  const cacheEngine_1 = __importDefault(require("../core/cache/cacheEngine"));
@@ -136,6 +137,8 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
136
137
  this.shutdownExitCode = 0;
137
138
  /** Ends a failure's shutdown that does not finish in time */
138
139
  this.shutdownWatchdog = null;
140
+ /** Built by `start()`; its storage drivers are closed on shutdown */
141
+ this.storageEngine = null;
139
142
  global.kuzzle = this;
140
143
  this._state = kuzzleStateEnum_1.default.STARTING;
141
144
  this.config = config;
@@ -184,7 +187,14 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
184
187
  seed: this.config.internal.hash.seed,
185
188
  });
186
189
  await new cacheEngine_1.default().init();
187
- await new storageEngine_1.default().init();
190
+ // Before the storage, so that a node refused by the cluster has
191
+ // written nothing to it (#3139)
192
+ if (this.config.cluster.enabled) {
193
+ await (0, storageDriverCheck_1.assertClusterStorageDriver)(this.config);
194
+ this.stopIfShuttingDown();
195
+ }
196
+ this.storageEngine = new storageEngine_1.default();
197
+ await this.storageEngine.init();
188
198
  await new realtime_1.default().init();
189
199
  this.stopIfShuttingDown();
190
200
  await this.internalIndex.init();
@@ -349,6 +359,9 @@ class Kuzzle extends KuzzleEventEmitter_1.default {
349
359
  (0, distributedLock_1.releaseAllLocksBeforeExit)(),
350
360
  mutex_1.Mutex.releaseAllBeforeExit(), // NOSONAR: frees locks taken through the deprecated API
351
361
  ]);
362
+ // Nothing reads or writes the storage anymore: its drivers may release
363
+ // their connections (bounded, never rejects)
364
+ await this.storageEngine?.close();
352
365
  this.log.info("Halted.");
353
366
  // flush both application and Kuzzle core loggers before leaving (Could happen even if some core/application components are not initialized)
354
367
  await this?.log?.flush?.();
@@ -2,9 +2,16 @@ import type { Client as ClientES7 } from "sdk-es7";
2
2
  import type { Client as ClientES8 } from "sdk-es8";
3
3
  import type { StorageEngineElasticsearch } from "../../types/config/storageEngine/StorageEngineElasticsearchConfiguration";
4
4
  import type { StorageDriverClass } from "../../types/storage/StorageDriver";
5
+ /**
6
+ * The package of the built-in driver of an Elasticsearch major version,
7
+ * `undefined` for an unknown one
8
+ */
9
+ export declare function builtInStorageDriverPackage(majorVersion: StorageEngineElasticsearch["majorVersion"]): string | undefined;
5
10
  /**
6
11
  * The built-in driver of an Elasticsearch major version
7
12
  *
13
+ * @throws {services.storage_driver.unsupported_major_version} if no built-in
14
+ * driver supports it: Kuzzle does not start
8
15
  * @throws {services.storage_driver.not_found} if its package is not
9
16
  * installed: Kuzzle does not start
10
17
  */