kuzzle 2.49.1 → 2.50.0-beta.3
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/bin/check-node-version.js +11 -0
- package/dist/bin/copy-protobuf.js +17 -0
- package/dist/lib/api/controllers/adminController.d.ts +51 -0
- package/dist/lib/api/controllers/adminController.js +191 -0
- package/{lib → dist/lib}/api/controllers/authController.d.ts +20 -40
- package/{lib → dist/lib}/api/controllers/authController.js +23 -24
- package/dist/lib/api/controllers/bulkController.d.ts +46 -0
- package/dist/lib/api/controllers/bulkController.js +132 -0
- package/dist/lib/api/controllers/clusterController.d.ts +6 -0
- package/{lib → dist/lib}/api/controllers/clusterController.js +7 -11
- package/dist/lib/api/controllers/collectionController.d.ts +136 -0
- package/dist/lib/api/controllers/collectionController.js +356 -0
- package/dist/lib/api/controllers/documentController.d.ts +181 -0
- package/dist/lib/api/controllers/documentController.js +768 -0
- package/dist/lib/api/controllers/index.d.ts +12 -0
- package/{lib → dist/lib}/api/controllers/index.js +13 -14
- package/dist/lib/api/controllers/indexController.d.ts +65 -0
- package/dist/lib/api/controllers/indexController.js +139 -0
- package/dist/lib/api/controllers/memoryStorageController.d.ts +8 -0
- package/dist/lib/api/controllers/memoryStorageController.js +867 -0
- package/dist/lib/api/controllers/realtimeController.d.ts +47 -0
- package/dist/lib/api/controllers/realtimeController.js +128 -0
- package/dist/lib/api/controllers/securityController.d.ts +423 -0
- package/dist/lib/api/controllers/securityController.js +1139 -0
- package/dist/lib/api/controllers/serverController.d.ts +82 -0
- package/dist/lib/api/controllers/serverController.js +321 -0
- package/dist/lib/api/documentExtractor.d.ts +9 -0
- package/dist/lib/api/documentExtractor.js +274 -0
- package/dist/lib/api/funnel.d.ts +183 -0
- package/dist/lib/api/funnel.js +821 -0
- package/dist/lib/api/httpRoutes.d.ts +17 -0
- package/dist/lib/api/httpRoutes.js +1496 -0
- package/dist/lib/api/rateLimiter.d.ts +18 -0
- package/dist/lib/api/rateLimiter.js +74 -0
- package/{lib → dist/lib}/api/request/kuzzleRequest.d.ts +2 -2
- package/{lib → dist/lib}/api/request/requestContext.d.ts +2 -1
- package/dist/lib/cluster/command.d.ts +73 -0
- package/dist/lib/cluster/command.js +236 -0
- package/dist/lib/cluster/index.d.ts +2 -0
- package/{lib → dist/lib}/cluster/index.js +1 -2
- package/dist/lib/cluster/node.d.ts +278 -0
- package/dist/lib/cluster/node.js +876 -0
- package/dist/lib/cluster/publisher.d.ts +188 -0
- package/dist/lib/cluster/publisher.js +347 -0
- package/dist/lib/cluster/subscriber.d.ts +269 -0
- package/dist/lib/cluster/subscriber.js +555 -0
- package/dist/lib/cluster/workers/IDCardRenewer.d.ts +13 -0
- package/dist/lib/cluster/workers/IDCardRenewer.js +120 -0
- package/{lib → dist/lib}/config/documentEventAliases.d.ts +1 -2
- package/dist/lib/config/index.d.ts +5 -0
- package/dist/lib/config/index.js +244 -0
- package/dist/lib/config/sdkCompatibility.json +9 -0
- package/dist/lib/core/auth/formatProcessing.d.ts +30 -0
- package/dist/lib/core/auth/formatProcessing.js +55 -0
- package/dist/lib/core/auth/passportResponse.d.ts +15 -0
- package/{lib → dist/lib}/core/auth/passportResponse.js +24 -30
- package/dist/lib/core/auth/passportWrapper.d.ts +28 -0
- package/dist/lib/core/auth/passportWrapper.js +126 -0
- package/{lib → dist/lib}/core/backend/backendConfig.js +2 -2
- package/{lib → dist/lib}/core/backend/backendErrors.js +9 -12
- package/dist/lib/core/cache/cacheEngine.d.ts +15 -0
- package/dist/lib/core/cache/cacheEngine.js +205 -0
- package/dist/lib/core/network/accessLogger.d.ts +29 -0
- package/dist/lib/core/network/accessLogger.js +250 -0
- package/dist/lib/core/network/clientConnection.d.ts +15 -0
- package/{lib → dist/lib}/core/network/clientConnection.js +17 -24
- package/dist/lib/core/network/context.d.ts +42 -0
- package/dist/lib/core/network/context.js +57 -0
- package/dist/lib/core/network/entryPoint.d.ts +62 -0
- package/dist/lib/core/network/entryPoint.js +261 -0
- package/dist/lib/core/network/httpRouter/index.d.ts +85 -0
- package/dist/lib/core/network/httpRouter/index.js +258 -0
- package/dist/lib/core/network/httpRouter/routeHandler.d.ts +46 -0
- package/dist/lib/core/network/httpRouter/routeHandler.js +101 -0
- package/dist/lib/core/network/httpRouter/routePart.d.ts +35 -0
- package/dist/lib/core/network/httpRouter/routePart.js +117 -0
- package/dist/lib/core/network/protocolManifest.d.ts +6 -0
- package/{lib → dist/lib}/core/network/protocolManifest.js +5 -9
- package/dist/lib/core/network/protocols/httpMessage.d.ts +22 -0
- package/dist/lib/core/network/protocols/httpMessage.js +62 -0
- package/dist/lib/core/network/protocols/httpwsProtocol.d.ts +171 -0
- package/dist/lib/core/network/protocols/httpwsProtocol.js +921 -0
- package/dist/lib/core/network/protocols/internalProtocol.d.ts +27 -0
- package/dist/lib/core/network/protocols/internalProtocol.js +82 -0
- package/dist/lib/core/network/protocols/mqttProtocol.d.ts +39 -0
- package/dist/lib/core/network/protocols/mqttProtocol.js +219 -0
- package/dist/lib/core/network/protocols/protocol.d.ts +26 -0
- package/dist/lib/core/network/protocols/protocol.js +74 -0
- package/dist/lib/core/network/router.d.ts +49 -0
- package/dist/lib/core/network/router.js +193 -0
- package/dist/lib/core/plugin/plugin.d.ts +56 -0
- package/dist/lib/core/plugin/plugin.js +282 -0
- package/{lib → dist/lib}/core/plugin/pluginContext.js +2 -2
- package/dist/lib/core/plugin/pluginManifest.d.ts +5 -0
- package/{lib → dist/lib}/core/plugin/pluginManifest.js +16 -27
- package/dist/lib/core/plugin/pluginRepository.d.ts +53 -0
- package/dist/lib/core/plugin/pluginRepository.js +112 -0
- package/dist/lib/core/plugin/pluginsManager.d.ts +190 -0
- package/dist/lib/core/plugin/pluginsManager.js +817 -0
- package/dist/lib/core/plugin/privilegedContext.d.ts +14 -0
- package/{lib → dist/lib}/core/plugin/privilegedContext.js +10 -14
- package/dist/lib/core/realtime/actionEnum.d.ts +25 -0
- package/{lib → dist/lib}/core/realtime/actionEnum.js +7 -10
- package/dist/lib/core/realtime/index.d.ts +8 -0
- package/{lib → dist/lib}/core/realtime/index.js +9 -13
- package/dist/lib/core/realtime/notification/document.d.ts +34 -0
- package/dist/lib/core/realtime/notification/document.js +98 -0
- package/dist/lib/core/realtime/notification/index.d.ts +3 -0
- package/{lib → dist/lib}/core/realtime/notification/index.js +4 -5
- package/dist/lib/core/realtime/notification/server.d.ts +17 -0
- package/{lib → dist/lib}/core/realtime/notification/server.js +8 -10
- package/dist/lib/core/realtime/notification/user.d.ts +29 -0
- package/dist/lib/core/realtime/notification/user.js +66 -0
- package/dist/lib/core/realtime/notifier.d.ts +171 -0
- package/dist/lib/core/realtime/notifier.js +405 -0
- package/dist/lib/core/security/index.d.ts +14 -0
- package/{lib → dist/lib}/core/security/index.js +15 -19
- package/dist/lib/core/security/roleRepository.d.ts +143 -0
- package/dist/lib/core/security/roleRepository.js +445 -0
- package/dist/lib/core/security/securityLoader.d.ts +24 -0
- package/dist/lib/core/security/securityLoader.js +125 -0
- package/{lib → dist/lib}/core/security/tokenRepository.js +1 -1
- package/dist/lib/core/security/userRepository.d.ts +81 -0
- package/dist/lib/core/security/userRepository.js +346 -0
- package/dist/lib/core/shared/abstractManifest.d.ts +27 -0
- package/dist/lib/core/shared/abstractManifest.js +85 -0
- package/dist/lib/core/shared/sdk/impersonatedSdk.d.ts +7 -0
- package/dist/lib/core/shared/sdk/impersonatedSdk.js +80 -0
- package/{lib → dist/lib}/core/shared/store.d.ts +2 -2
- package/dist/lib/core/statistics/statistics.d.ts +94 -0
- package/dist/lib/core/statistics/statistics.js +287 -0
- package/dist/lib/core/storage/clientAdapter.d.ts +62 -0
- package/dist/lib/core/storage/clientAdapter.js +756 -0
- package/dist/lib/core/storage/storageEngine.d.ts +13 -0
- package/dist/lib/core/storage/storageEngine.js +52 -0
- package/dist/lib/core/validation/baseType.d.ts +35 -0
- package/dist/lib/core/validation/baseType.js +70 -0
- package/dist/lib/core/validation/types/anything.d.ts +10 -0
- package/{lib → dist/lib}/core/validation/types/anything.js +7 -10
- package/dist/lib/core/validation/types/boolean.d.ts +16 -0
- package/{lib → dist/lib}/core/validation/types/boolean.js +18 -23
- package/dist/lib/core/validation/types/date.d.ts +17 -0
- package/dist/lib/core/validation/types/date.js +215 -0
- package/dist/lib/core/validation/types/email.d.ts +17 -0
- package/dist/lib/core/validation/types/email.js +80 -0
- package/dist/lib/core/validation/types/enum.d.ts +17 -0
- package/dist/lib/core/validation/types/enum.js +70 -0
- package/dist/lib/core/validation/types/geoPoint.d.ts +17 -0
- package/{lib → dist/lib}/core/validation/types/geoPoint.js +19 -24
- package/dist/lib/core/validation/types/geoShape.d.ts +31 -0
- package/dist/lib/core/validation/types/geoShape.js +280 -0
- package/dist/lib/core/validation/types/integer.d.ts +7 -0
- package/{lib → dist/lib}/core/validation/types/integer.js +21 -27
- package/dist/lib/core/validation/types/ipAddress.d.ts +17 -0
- package/dist/lib/core/validation/types/ipAddress.js +73 -0
- package/dist/lib/core/validation/types/numeric.d.ts +17 -0
- package/dist/lib/core/validation/types/numeric.js +84 -0
- package/dist/lib/core/validation/types/object.d.ts +24 -0
- package/dist/lib/core/validation/types/object.js +74 -0
- package/dist/lib/core/validation/types/string.d.ts +17 -0
- package/dist/lib/core/validation/types/string.js +85 -0
- package/dist/lib/core/validation/types/url.d.ts +17 -0
- package/dist/lib/core/validation/types/url.js +73 -0
- package/dist/lib/core/validation/validation.d.ts +113 -0
- package/dist/lib/core/validation/validation.js +692 -0
- package/dist/lib/kerror/codes/0-core.json +194 -0
- package/dist/lib/kerror/codes/1-services.json +351 -0
- package/dist/lib/kerror/codes/2-api.json +195 -0
- package/dist/lib/kerror/codes/3-network.json +151 -0
- package/dist/lib/kerror/codes/4-plugin.json +498 -0
- package/dist/lib/kerror/codes/5-validation.json +158 -0
- package/dist/lib/kerror/codes/6-protocol.json +28 -0
- package/dist/lib/kerror/codes/7-security.json +283 -0
- package/dist/lib/kerror/codes/8-cluster.json +16 -0
- package/dist/lib/kerror/codes/index.d.ts +24 -0
- package/dist/lib/kerror/codes/index.js +140 -0
- package/{lib → dist/lib}/kerror/index.d.ts +5 -5
- package/{lib → dist/lib}/kuzzle/Logger.d.ts +6 -0
- package/{lib → dist/lib}/kuzzle/Logger.js +26 -5
- package/dist/lib/kuzzle/dumpGenerator.d.ts +14 -0
- package/dist/lib/kuzzle/dumpGenerator.js +180 -0
- package/dist/lib/kuzzle/event/pipeRunner.d.ts +30 -0
- package/dist/lib/kuzzle/event/pipeRunner.js +119 -0
- package/dist/lib/kuzzle/event/waterfall.d.ts +2 -0
- package/dist/lib/kuzzle/event/waterfall.js +90 -0
- package/dist/lib/kuzzle/internalIndexHandler.d.ts +186 -0
- package/dist/lib/kuzzle/internalIndexHandler.js +174 -0
- package/{lib → dist/lib}/kuzzle/kuzzle.d.ts +6 -7
- package/{lib → dist/lib}/kuzzle/kuzzle.js +5 -2
- package/dist/lib/kuzzle/kuzzleStateEnum.d.ts +20 -0
- package/{lib → dist/lib}/kuzzle/kuzzleStateEnum.js +5 -8
- package/dist/lib/kuzzle/vault.d.ts +2 -0
- package/dist/lib/kuzzle/vault.js +63 -0
- package/dist/lib/model/security/rights.d.ts +8 -0
- package/{lib → dist/lib}/model/security/rights.js +4 -8
- package/{lib → dist/lib}/model/security/role.d.ts +1 -1
- package/{lib → dist/lib}/model/security/user.d.ts +1 -0
- package/dist/lib/model/storage/apiKey.d.ts +49 -0
- package/dist/lib/model/storage/apiKey.js +126 -0
- package/dist/lib/model/storage/baseModel.d.ts +100 -0
- package/dist/lib/model/storage/baseModel.js +211 -0
- package/dist/lib/service/cache/redis.d.ts +74 -0
- package/dist/lib/service/cache/redis.js +237 -0
- package/dist/lib/service/service.d.ts +30 -0
- package/dist/lib/service/service.js +74 -0
- package/{lib → dist/lib}/service/storage/7/elasticsearch.d.ts +2 -2
- package/{lib → dist/lib}/service/storage/7/elasticsearch.js +23 -25
- package/dist/lib/service/storage/7/esWrapper.d.ts +19 -0
- package/dist/lib/service/storage/7/esWrapper.js +245 -0
- package/{lib → dist/lib}/service/storage/8/elasticsearch.js +23 -25
- package/dist/lib/service/storage/8/esWrapper.d.ts +19 -0
- package/dist/lib/service/storage/8/esWrapper.js +245 -0
- package/{lib → dist/lib}/types/Plugin.d.ts +1 -1
- package/{lib/types → dist/lib/types/controllers}/Controller.d.ts +2 -2
- package/{lib/types → dist/lib/types/controllers}/ControllerDefinition.d.ts +1 -1
- package/dist/lib/types/controllers/adminControlller.type.d.ts +5 -0
- package/dist/lib/types/controllers/adminControlller.type.js +3 -0
- package/dist/lib/types/controllers/authController.type.d.ts +5 -0
- package/dist/lib/types/controllers/authController.type.js +3 -0
- package/dist/lib/types/core/auth/formatProcessing.type.d.ts +7 -0
- package/dist/lib/types/core/auth/formatProcessing.type.js +3 -0
- package/{lib → dist/lib}/types/index.d.ts +3 -3
- package/{lib → dist/lib}/types/index.js +3 -3
- package/dist/lib/util/assertType.d.ts +41 -0
- package/{lib → dist/lib}/util/assertType.js +38 -56
- package/dist/lib/util/asyncStore.d.ts +38 -0
- package/dist/lib/util/asyncStore.js +70 -0
- package/dist/lib/util/bytes.d.ts +2 -0
- package/dist/lib/util/bytes.js +33 -0
- package/dist/lib/util/debug.d.ts +2 -0
- package/{lib → dist/lib}/util/debug.js +15 -23
- package/dist/lib/util/deprecate.d.ts +1 -0
- package/dist/lib/util/deprecate.js +64 -0
- package/dist/lib/util/didYouMean.d.ts +2 -0
- package/{lib → dist/lib}/util/didYouMean.js +9 -15
- package/dist/lib/util/extractFields.d.ts +17 -0
- package/{lib → dist/lib}/util/extractFields.js +18 -32
- package/dist/lib/util/memoize.d.ts +7 -0
- package/{lib → dist/lib}/util/memoize.js +14 -21
- package/dist/lib/util/promback.d.ts +13 -0
- package/dist/lib/util/promback.js +60 -0
- package/dist/lib/util/requestAssertions.d.ts +10 -0
- package/dist/lib/util/requestAssertions.js +143 -0
- package/dist/lib/util/safeObject.d.ts +3 -0
- package/{lib → dist/lib}/util/safeObject.js +7 -13
- package/dist/lib/util/stackTrace.d.ts +19 -0
- package/{lib → dist/lib}/util/stackTrace.js +35 -41
- package/dist/lib/util/wildcard.d.ts +1 -0
- package/{lib → dist/lib}/util/wildcard.js +21 -30
- package/dist/package.json +120 -0
- package/package.json +45 -58
- package/bin/start-kuzzle-server +0 -126
- package/check-node-version.js +0 -17
- package/lib/api/controllers/adminController.js +0 -229
- package/lib/api/controllers/bulkController.js +0 -210
- package/lib/api/controllers/collectionController.js +0 -502
- package/lib/api/controllers/documentController.js +0 -1156
- package/lib/api/controllers/indexController.js +0 -179
- package/lib/api/controllers/memoryStorageController.js +0 -1023
- package/lib/api/controllers/realtimeController.js +0 -155
- package/lib/api/controllers/securityController.js +0 -1571
- package/lib/api/controllers/serverController.js +0 -381
- package/lib/api/documentExtractor.js +0 -309
- package/lib/api/funnel.js +0 -1143
- package/lib/api/httpRoutes.js +0 -1547
- package/lib/api/rateLimiter.js +0 -87
- package/lib/cluster/command.js +0 -284
- package/lib/cluster/node.js +0 -1203
- package/lib/cluster/publisher.js +0 -386
- package/lib/cluster/subscriber.js +0 -776
- package/lib/cluster/workers/IDCardRenewer.js +0 -144
- package/lib/config/index.js +0 -351
- package/lib/config/sdkCompatibility.json +0 -9
- package/lib/core/auth/formatProcessing.js +0 -66
- package/lib/core/auth/passportWrapper.js +0 -126
- package/lib/core/cache/cacheEngine.js +0 -278
- package/lib/core/network/accessLogger.js +0 -322
- package/lib/core/network/context.js +0 -80
- package/lib/core/network/entryPoint.js +0 -358
- package/lib/core/network/httpRouter/index.js +0 -316
- package/lib/core/network/httpRouter/routeHandler.js +0 -111
- package/lib/core/network/httpRouter/routePart.js +0 -147
- package/lib/core/network/protocols/httpMessage.js +0 -69
- package/lib/core/network/protocols/httpwsProtocol.js +0 -1254
- package/lib/core/network/protocols/internalProtocol.js +0 -109
- package/lib/core/network/protocols/mqttProtocol.js +0 -291
- package/lib/core/network/protocols/protocol.js +0 -102
- package/lib/core/network/router.js +0 -255
- package/lib/core/plugin/plugin.js +0 -436
- package/lib/core/plugin/pluginRepository.js +0 -132
- package/lib/core/plugin/pluginsManager.js +0 -1244
- package/lib/core/realtime/notification/document.js +0 -108
- package/lib/core/realtime/notification/user.js +0 -70
- package/lib/core/realtime/notifier.js +0 -541
- package/lib/core/security/README.md +0 -223
- package/lib/core/security/roleRepository.js +0 -569
- package/lib/core/security/securityLoader.js +0 -174
- package/lib/core/security/userRepository.js +0 -446
- package/lib/core/shared/README.md +0 -3
- package/lib/core/shared/abstractManifest.js +0 -102
- package/lib/core/shared/sdk/impersonatedSdk.js +0 -94
- package/lib/core/statistics/index.js +0 -24
- package/lib/core/statistics/statistics.js +0 -373
- package/lib/core/storage/clientAdapter.js +0 -1045
- package/lib/core/storage/storageEngine.js +0 -63
- package/lib/core/validation/baseType.js +0 -80
- package/lib/core/validation/index.js +0 -24
- package/lib/core/validation/types/date.js +0 -284
- package/lib/core/validation/types/email.js +0 -92
- package/lib/core/validation/types/enum.js +0 -100
- package/lib/core/validation/types/geoShape.js +0 -370
- package/lib/core/validation/types/ipAddress.js +0 -83
- package/lib/core/validation/types/numeric.js +0 -108
- package/lib/core/validation/types/object.js +0 -88
- package/lib/core/validation/types/string.js +0 -110
- package/lib/core/validation/types/url.js +0 -83
- package/lib/core/validation/validation.js +0 -1180
- package/lib/kerror/codes/0-core.json +0 -194
- package/lib/kerror/codes/1-services.json +0 -351
- package/lib/kerror/codes/2-api.json +0 -195
- package/lib/kerror/codes/3-network.json +0 -151
- package/lib/kerror/codes/4-plugin.json +0 -498
- package/lib/kerror/codes/5-validation.json +0 -158
- package/lib/kerror/codes/6-protocol.json +0 -28
- package/lib/kerror/codes/7-security.json +0 -283
- package/lib/kerror/codes/8-cluster.json +0 -16
- package/lib/kerror/codes/index.js +0 -208
- package/lib/kuzzle/dumpGenerator.js +0 -259
- package/lib/kuzzle/event/pipeRunner.js +0 -144
- package/lib/kuzzle/event/waterfall.js +0 -101
- package/lib/kuzzle/internalIndexHandler.js +0 -234
- package/lib/kuzzle/vault.js +0 -89
- package/lib/model/storage/apiKey.js +0 -158
- package/lib/model/storage/baseModel.js +0 -275
- package/lib/service/cache/redis.js +0 -282
- package/lib/service/service.js +0 -84
- package/lib/service/storage/7/esWrapper.js +0 -303
- package/lib/service/storage/8/esWrapper.js +0 -303
- package/lib/util/asyncStore.js +0 -112
- package/lib/util/bytes.js +0 -36
- package/lib/util/deprecate.js +0 -82
- package/lib/util/promback.js +0 -66
- package/lib/util/readYamlFile.d.ts +0 -2
- package/lib/util/readYamlFile.js +0 -10
- package/lib/util/requestAssertions.js +0 -157
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{lib → dist/lib}/api/controllers/baseController.d.ts +0 -0
- /package/{lib → dist/lib}/api/controllers/baseController.js +0 -0
- /package/{lib → dist/lib}/api/controllers/debugController.d.ts +0 -0
- /package/{lib → dist/lib}/api/controllers/debugController.js +0 -0
- /package/{lib → dist/lib}/api/openapi/OpenApiManager.d.ts +0 -0
- /package/{lib → dist/lib}/api/openapi/OpenApiManager.js +0 -0
- /package/{lib → dist/lib}/api/openapi/index.d.ts +0 -0
- /package/{lib → dist/lib}/api/openapi/index.js +0 -0
- /package/{lib → dist/lib}/api/openapi/openApiGenerator.d.ts +0 -0
- /package/{lib → dist/lib}/api/openapi/openApiGenerator.js +0 -0
- /package/{lib → dist/lib}/api/request/index.d.ts +0 -0
- /package/{lib → dist/lib}/api/request/index.js +0 -0
- /package/{lib → dist/lib}/api/request/kuzzleRequest.js +0 -0
- /package/{lib → dist/lib}/api/request/requestContext.js +0 -0
- /package/{lib → dist/lib}/api/request/requestInput.d.ts +0 -0
- /package/{lib → dist/lib}/api/request/requestInput.js +0 -0
- /package/{lib → dist/lib}/api/request/requestResponse.d.ts +0 -0
- /package/{lib → dist/lib}/api/request/requestResponse.js +0 -0
- /package/{lib → dist/lib}/cluster/idCardHandler.d.ts +0 -0
- /package/{lib → dist/lib}/cluster/idCardHandler.js +0 -0
- /package/{lib → dist/lib}/cluster/protobuf/command.proto +0 -0
- /package/{lib → dist/lib}/cluster/protobuf/sync.proto +0 -0
- /package/{lib → dist/lib}/cluster/state.d.ts +0 -0
- /package/{lib → dist/lib}/cluster/state.js +0 -0
- /package/{lib → dist/lib}/config/default.config.d.ts +0 -0
- /package/{lib → dist/lib}/config/default.config.js +0 -0
- /package/{lib → dist/lib}/config/documentEventAliases.js +0 -0
- /package/{lib → dist/lib}/core/auth/tokenManager.d.ts +0 -0
- /package/{lib → dist/lib}/core/auth/tokenManager.js +0 -0
- /package/{lib → dist/lib}/core/backend/applicationManager.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/applicationManager.js +0 -0
- /package/{lib → dist/lib}/core/backend/backend.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backend.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendCluster.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendCluster.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendConfig.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendController.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendController.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendErrors.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendHook.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendHook.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendImport.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendImport.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendOpenApi.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendOpenApi.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendPipe.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendPipe.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendPlugin.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendPlugin.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendStorage.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendStorage.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendSubscription.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendSubscription.js +0 -0
- /package/{lib → dist/lib}/core/backend/backendVault.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/backendVault.js +0 -0
- /package/{lib → dist/lib}/core/backend/index.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/index.js +0 -0
- /package/{lib → dist/lib}/core/backend/internalLogger.d.ts +0 -0
- /package/{lib → dist/lib}/core/backend/internalLogger.js +0 -0
- /package/{lib → dist/lib}/core/cache/cacheDbEnum.d.ts +0 -0
- /package/{lib → dist/lib}/core/cache/cacheDbEnum.js +0 -0
- /package/{lib → dist/lib}/core/debug/kuzzleDebugger.d.ts +0 -0
- /package/{lib → dist/lib}/core/debug/kuzzleDebugger.js +0 -0
- /package/{lib → dist/lib}/core/plugin/pluginContext.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/channel.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/channel.js +0 -0
- /package/{lib → dist/lib}/core/realtime/connectionRooms.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/connectionRooms.js +0 -0
- /package/{lib → dist/lib}/core/realtime/hotelClerk.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/hotelClerk.js +0 -0
- /package/{lib → dist/lib}/core/realtime/room.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/room.js +0 -0
- /package/{lib → dist/lib}/core/realtime/subscription.d.ts +0 -0
- /package/{lib → dist/lib}/core/realtime/subscription.js +0 -0
- /package/{lib → dist/lib}/core/security/profileRepository.d.ts +0 -0
- /package/{lib → dist/lib}/core/security/profileRepository.js +0 -0
- /package/{lib → dist/lib}/core/security/tokenRepository.d.ts +0 -0
- /package/{lib → dist/lib}/core/shared/KoncordeWrapper.d.ts +0 -0
- /package/{lib → dist/lib}/core/shared/KoncordeWrapper.js +0 -0
- /package/{lib → dist/lib}/core/shared/ObjectRepository.d.ts +0 -0
- /package/{lib → dist/lib}/core/shared/ObjectRepository.js +0 -0
- /package/{lib → dist/lib}/core/shared/sdk/embeddedSdk.d.ts +0 -0
- /package/{lib → dist/lib}/core/shared/sdk/embeddedSdk.js +0 -0
- /package/{lib → dist/lib}/core/shared/sdk/funnelProtocol.d.ts +0 -0
- /package/{lib → dist/lib}/core/shared/sdk/funnelProtocol.js +0 -0
- /package/{lib → dist/lib}/core/shared/store.js +0 -0
- /package/{lib → dist/lib}/core/storage/indexCache.d.ts +0 -0
- /package/{lib → dist/lib}/core/storage/indexCache.js +0 -0
- /package/{lib → dist/lib}/core/storage/storeScopeEnum.d.ts +0 -0
- /package/{lib → dist/lib}/core/storage/storeScopeEnum.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/badRequestError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/badRequestError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/externalServiceError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/externalServiceError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/forbiddenError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/forbiddenError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/gatewayTimeoutError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/gatewayTimeoutError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/index.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/index.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/internalError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/internalError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/kuzzleError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/kuzzleError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/multipleErrorsError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/multipleErrorsError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/notFoundError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/notFoundError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/partialError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/partialError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/pluginImplementationError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/pluginImplementationError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/preconditionError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/preconditionError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/serviceUnavailableError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/serviceUnavailableError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/sizeLimitError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/sizeLimitError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/tooManyRequestsError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/tooManyRequestsError.js +0 -0
- /package/{lib → dist/lib}/kerror/errors/unauthorizedError.d.ts +0 -0
- /package/{lib → dist/lib}/kerror/errors/unauthorizedError.js +0 -0
- /package/{lib → dist/lib}/kerror/index.js +0 -0
- /package/{lib → dist/lib}/kuzzle/event/KuzzleEventEmitter.d.ts +0 -0
- /package/{lib → dist/lib}/kuzzle/event/KuzzleEventEmitter.js +0 -0
- /package/{lib → dist/lib}/kuzzle/index.d.ts +0 -0
- /package/{lib → dist/lib}/kuzzle/index.js +0 -0
- /package/{lib → dist/lib}/model/security/profile.d.ts +0 -0
- /package/{lib → dist/lib}/model/security/profile.js +0 -0
- /package/{lib → dist/lib}/model/security/role.js +0 -0
- /package/{lib → dist/lib}/model/security/token.d.ts +0 -0
- /package/{lib → dist/lib}/model/security/token.js +0 -0
- /package/{lib → dist/lib}/model/security/user.js +0 -0
- /package/{lib → dist/lib}/service/storage/8/elasticsearch.d.ts +0 -0
- /package/{lib → dist/lib}/service/storage/Elasticsearch.d.ts +0 -0
- /package/{lib → dist/lib}/service/storage/Elasticsearch.js +0 -0
- /package/{lib → dist/lib}/service/storage/commons/queryTranslator.d.ts +0 -0
- /package/{lib → dist/lib}/service/storage/commons/queryTranslator.js +0 -0
- /package/{lib → dist/lib}/types/ClientConnection.d.ts +0 -0
- /package/{lib → dist/lib}/types/ClientConnection.js +0 -0
- /package/{lib → dist/lib}/types/Deprecation.d.ts +0 -0
- /package/{lib → dist/lib}/types/Deprecation.js +0 -0
- /package/{lib → dist/lib}/types/EventHandler.d.ts +0 -0
- /package/{lib → dist/lib}/types/EventHandler.js +0 -0
- /package/{lib → dist/lib}/types/Global.d.ts +0 -0
- /package/{lib → dist/lib}/types/Global.js +0 -0
- /package/{lib → dist/lib}/types/HttpMessage.d.ts +0 -0
- /package/{lib → dist/lib}/types/HttpMessage.js +0 -0
- /package/{lib → dist/lib}/types/HttpStream.d.ts +0 -0
- /package/{lib → dist/lib}/types/HttpStream.js +0 -0
- /package/{lib → dist/lib}/types/Kuzzle.d.ts +0 -0
- /package/{lib → dist/lib}/types/Kuzzle.js +0 -0
- /package/{lib → dist/lib}/types/KuzzleDocument.d.ts +0 -0
- /package/{lib → dist/lib}/types/KuzzleDocument.js +0 -0
- /package/{lib → dist/lib}/types/OpenApiDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/OpenApiDefinition.js +0 -0
- /package/{lib → dist/lib}/types/PasswordPolicy.d.ts +0 -0
- /package/{lib → dist/lib}/types/PasswordPolicy.js +0 -0
- /package/{lib → dist/lib}/types/Plugin.js +0 -0
- /package/{lib → dist/lib}/types/PluginManifest.d.ts +0 -0
- /package/{lib → dist/lib}/types/PluginManifest.js +0 -0
- /package/{lib → dist/lib}/types/Policy.d.ts +0 -0
- /package/{lib → dist/lib}/types/Policy.js +0 -0
- /package/{lib → dist/lib}/types/PolicyRestrictions.d.ts +0 -0
- /package/{lib → dist/lib}/types/PolicyRestrictions.js +0 -0
- /package/{lib → dist/lib}/types/ProfileDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/ProfileDefinition.js +0 -0
- /package/{lib → dist/lib}/types/RoleDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/RoleDefinition.js +0 -0
- /package/{lib → dist/lib}/types/StrategyDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/StrategyDefinition.js +0 -0
- /package/{lib → dist/lib}/types/Target.d.ts +0 -0
- /package/{lib → dist/lib}/types/Target.js +0 -0
- /package/{lib → dist/lib}/types/Token.d.ts +0 -0
- /package/{lib → dist/lib}/types/Token.js +0 -0
- /package/{lib → dist/lib}/types/User.d.ts +0 -0
- /package/{lib → dist/lib}/types/User.js +0 -0
- /package/{lib → dist/lib}/types/config/DumpConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/DumpConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/HttpConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/HttpConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/KuzzleConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/KuzzleConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/LimitsConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/LimitsConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/PluginsConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/PluginsConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/SecurityConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/SecurityConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/ServerConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/ServerConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/ServicesConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/ServicesConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/internalCache/InternalCacheRedisConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/internalCache/InternalCacheRedisConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/publicCache/PublicCacheRedisConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/publicCache/PublicCacheRedisConfiguration.js +0 -0
- /package/{lib → dist/lib}/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +0 -0
- /package/{lib → dist/lib}/types/config/storageEngine/StorageEngineElasticsearchConfiguration.js +0 -0
- /package/{lib/types → dist/lib/types/controllers}/Controller.js +0 -0
- /package/{lib/types → dist/lib/types/controllers}/ControllerDefinition.js +0 -0
- /package/{lib/types → dist/lib/types/controllers}/ControllerRights.d.ts +0 -0
- /package/{lib/types → dist/lib/types/controllers}/ControllerRights.js +0 -0
- /package/{lib → dist/lib}/types/errors/ErrorDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/errors/ErrorDefinition.js +0 -0
- /package/{lib → dist/lib}/types/errors/ErrorDomains.d.ts +0 -0
- /package/{lib → dist/lib}/types/errors/ErrorDomains.js +0 -0
- /package/{lib → dist/lib}/types/events/EventGenericDocument.d.ts +0 -0
- /package/{lib → dist/lib}/types/events/EventGenericDocument.js +0 -0
- /package/{lib → dist/lib}/types/events/EventProtocol.d.ts +0 -0
- /package/{lib → dist/lib}/types/events/EventProtocol.js +0 -0
- /package/{lib → dist/lib}/types/realtime/RealtimeScope.d.ts +0 -0
- /package/{lib → dist/lib}/types/realtime/RealtimeScope.js +0 -0
- /package/{lib → dist/lib}/types/realtime/RealtimeUsers.d.ts +0 -0
- /package/{lib → dist/lib}/types/realtime/RealtimeUsers.js +0 -0
- /package/{lib → dist/lib}/types/realtime/RoomList.d.ts +0 -0
- /package/{lib → dist/lib}/types/realtime/RoomList.js +0 -0
- /package/{lib → dist/lib}/types/shared/StoreCollectionsDefinition.d.ts +0 -0
- /package/{lib → dist/lib}/types/shared/StoreCollectionsDefinition.js +0 -0
- /package/{lib → dist/lib}/types/storage/7/Elasticsearch.d.ts +0 -0
- /package/{lib → dist/lib}/types/storage/7/Elasticsearch.js +0 -0
- /package/{lib → dist/lib}/types/storage/8/Elasticsearch.d.ts +0 -0
- /package/{lib → dist/lib}/types/storage/8/Elasticsearch.js +0 -0
- /package/{lib → dist/lib}/util/Inflector.d.ts +0 -0
- /package/{lib → dist/lib}/util/Inflector.js +0 -0
- /package/{lib → dist/lib}/util/array.d.ts +0 -0
- /package/{lib → dist/lib}/util/array.js +0 -0
- /package/{lib → dist/lib}/util/async.d.ts +0 -0
- /package/{lib → dist/lib}/util/async.js +0 -0
- /package/{lib → dist/lib}/util/bufferedPassThrough.d.ts +0 -0
- /package/{lib → dist/lib}/util/bufferedPassThrough.js +0 -0
- /package/{lib → dist/lib}/util/crypto.d.ts +0 -0
- /package/{lib → dist/lib}/util/crypto.js +0 -0
- /package/{lib → dist/lib}/util/dump-collection.d.ts +0 -0
- /package/{lib → dist/lib}/util/dump-collection.js +0 -0
- /package/{lib → dist/lib}/util/esRequest.d.ts +0 -0
- /package/{lib → dist/lib}/util/esRequest.js +0 -0
- /package/{lib → dist/lib}/util/koncordeCompat.d.ts +0 -0
- /package/{lib → dist/lib}/util/koncordeCompat.js +0 -0
- /package/{lib → dist/lib}/util/mutex.d.ts +0 -0
- /package/{lib → dist/lib}/util/mutex.js +0 -0
- /package/{lib → dist/lib}/util/name-generator.d.ts +0 -0
- /package/{lib → dist/lib}/util/name-generator.js +0 -0
- /package/{lib → dist/lib}/util/time.d.ts +0 -0
- /package/{lib → dist/lib}/util/time.js +0 -0
|
@@ -1,776 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Kuzzle, a backend software, self-hostable and ready to use
|
|
3
|
-
* to power modern apps
|
|
4
|
-
*
|
|
5
|
-
* Copyright 2015-2022 Kuzzle
|
|
6
|
-
* mailto: support AT kuzzle.io
|
|
7
|
-
* website: http://kuzzle.io
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
"use strict";
|
|
23
|
-
|
|
24
|
-
const { Subscriber } = require("zeromq");
|
|
25
|
-
const protobuf = require("protobufjs");
|
|
26
|
-
const Long = require("long");
|
|
27
|
-
|
|
28
|
-
const debug = require("../util/debug")("kuzzle:cluster:sync");
|
|
29
|
-
const DocumentNotification = require("../core/realtime/notification/document");
|
|
30
|
-
const UserNotification = require("../core/realtime/notification/user");
|
|
31
|
-
const { has } = require("../util/safeObject");
|
|
32
|
-
const { fromKoncordeIndex } = require("../util/koncordeCompat");
|
|
33
|
-
|
|
34
|
-
/* eslint-disable sort-keys */
|
|
35
|
-
const stateEnum = Object.freeze({
|
|
36
|
-
BUFFERING: 1,
|
|
37
|
-
SANE: 2,
|
|
38
|
-
MISSING_HEARTBEAT: 3,
|
|
39
|
-
EVICTED: 4,
|
|
40
|
-
});
|
|
41
|
-
/* eslint-enable sort-keys */
|
|
42
|
-
|
|
43
|
-
// Handles messages received from other nodes
|
|
44
|
-
class ClusterSubscriber {
|
|
45
|
-
/**
|
|
46
|
-
* @constructor
|
|
47
|
-
* @param {ClusterNode} localNode
|
|
48
|
-
* @param {string} remoteNodeId - Remote node unique ID
|
|
49
|
-
* @param {string} remoteNodeIP - address of the distant node
|
|
50
|
-
*/
|
|
51
|
-
constructor(localNode, remoteNodeId, remoteNodeIP) {
|
|
52
|
-
// not to be confused with remote nodes
|
|
53
|
-
this.localNode = localNode;
|
|
54
|
-
|
|
55
|
-
this.remoteNodeIP = remoteNodeIP;
|
|
56
|
-
this.remoteNodeAddress = `tcp://${remoteNodeIP}:${this.localNode.config.ports.sync}`;
|
|
57
|
-
this.remoteNodeId = remoteNodeId;
|
|
58
|
-
// Used in debug mode when the node might be slower
|
|
59
|
-
this.remoteNodeEvictionPrevented = false;
|
|
60
|
-
this.socket = null;
|
|
61
|
-
this.protoroot = null;
|
|
62
|
-
|
|
63
|
-
// keeps track of received message ids from the remote node
|
|
64
|
-
this.lastMessageId = new Long(0, 0, true);
|
|
65
|
-
|
|
66
|
-
// A subscriber starts in the BUFFERING state, meaning it stores incoming
|
|
67
|
-
// sync messages without processing them, until it enters the SANE state
|
|
68
|
-
// This delays applying sync messages while the local node initializes
|
|
69
|
-
this.state = stateEnum.BUFFERING;
|
|
70
|
-
this.buffer = [];
|
|
71
|
-
|
|
72
|
-
// keeps track of the remote node heartbeats, and evicts it if no
|
|
73
|
-
// heartbeats have been received after some time
|
|
74
|
-
this.heartbeatTimer = null;
|
|
75
|
-
this.lastHeartbeat = Date.now();
|
|
76
|
-
this.heartbeatDelay = this.localNode.heartbeatDelay * 1.5;
|
|
77
|
-
|
|
78
|
-
// Messages handlers (quick translation between a topic name and its
|
|
79
|
-
// associated handler)
|
|
80
|
-
this.handlers = Object.freeze({
|
|
81
|
-
AddCollection: this.handleCollectionAddition,
|
|
82
|
-
AddIndex: this.handleIndexAddition,
|
|
83
|
-
ClusterWideEvent: this.handleClusterWideEvent,
|
|
84
|
-
DocumentNotification: this.handleDocumentNotification,
|
|
85
|
-
DumpRequest: this.handleDumpRequest,
|
|
86
|
-
Heartbeat: this.handleHeartbeat,
|
|
87
|
-
InvalidateProfile: this.handleProfileInvalidation,
|
|
88
|
-
InvalidateRole: this.handleRoleInvalidation,
|
|
89
|
-
NewAuthStrategy: this.handleNewAuthStrategy,
|
|
90
|
-
NewRealtimeRoom: this.handleNewRealtimeRoom,
|
|
91
|
-
NodeEvicted: this.handleNodeEviction,
|
|
92
|
-
NodePreventEviction: this.handleNodePreventEviction,
|
|
93
|
-
NodeShutdown: this.handleNodeShutdown,
|
|
94
|
-
RefreshIndexCache: this.handleRefreshIndexCache,
|
|
95
|
-
RefreshValidators: this.handleRefreshValidators,
|
|
96
|
-
RemoveAuthStrategy: this.handleAuthStrategyRemoval,
|
|
97
|
-
RemoveCollection: this.handleCollectionRemoval,
|
|
98
|
-
RemoveIndexes: this.handleIndexesRemoval,
|
|
99
|
-
RemoveRealtimeRoom: this.handleRealtimeRoomRemoval,
|
|
100
|
-
ResetSecurity: this.handleResetSecurity,
|
|
101
|
-
Shutdown: this.handleShutdown,
|
|
102
|
-
Subscription: this.handleSubscription,
|
|
103
|
-
Unsubscription: this.handleUnsubscription,
|
|
104
|
-
UserNotification: this.handleUserNotification,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
this.logger = global.kuzzle.log.child("cluster:subscriber");
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Initializes this class, establishes a connection to the remote node and
|
|
112
|
-
* starts listening to it.
|
|
113
|
-
*/
|
|
114
|
-
async init() {
|
|
115
|
-
this.protoroot = await protobuf.load(`${__dirname}/protobuf/sync.proto`);
|
|
116
|
-
this.socket = new Subscriber();
|
|
117
|
-
this.socket.connect(this.remoteNodeAddress);
|
|
118
|
-
this.socket.subscribe();
|
|
119
|
-
this.heartbeatTimer = setInterval(
|
|
120
|
-
() => this.checkHeartbeat(),
|
|
121
|
-
this.heartbeatDelay,
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
this.listen();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Starts subscribing to other nodes
|
|
129
|
-
* Do NOT wait this method: it's an infinite loop, it's not meant to ever
|
|
130
|
-
* return (unless the remote node has been evicted)
|
|
131
|
-
*/
|
|
132
|
-
async listen() {
|
|
133
|
-
while (this.state !== stateEnum.EVICTED) {
|
|
134
|
-
let topic;
|
|
135
|
-
let data;
|
|
136
|
-
|
|
137
|
-
try {
|
|
138
|
-
[topic, data] = await this.socket.receive();
|
|
139
|
-
} catch (e) {
|
|
140
|
-
if (this.state !== stateEnum.EVICTED) {
|
|
141
|
-
await this.evictNode({
|
|
142
|
-
broadcast: true,
|
|
143
|
-
reason: e.message,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// do nothing is the node was evicted even if we already check
|
|
151
|
-
// for this in processData()
|
|
152
|
-
if (this.state === stateEnum.EVICTED) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (this.state !== stateEnum.BUFFERING) {
|
|
157
|
-
await this.processData(topic.toString(), data);
|
|
158
|
-
} else {
|
|
159
|
-
this.buffer.push([topic.toString(), data]);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Plays all buffered sync messages, and switches this subscriber state from
|
|
166
|
-
* BUFFERING to SANE.
|
|
167
|
-
*
|
|
168
|
-
* @param {Long} lastMessageId
|
|
169
|
-
* @return {void}
|
|
170
|
-
*/
|
|
171
|
-
async sync(lastMessageId) {
|
|
172
|
-
this.lastMessageId = lastMessageId;
|
|
173
|
-
|
|
174
|
-
// copy the buffer for processing: new sync messages might be buffered
|
|
175
|
-
// while we apply older messages with async functions
|
|
176
|
-
while (this.buffer.length > 0) {
|
|
177
|
-
const _buffer = this.buffer;
|
|
178
|
-
this.buffer = [];
|
|
179
|
-
|
|
180
|
-
for (let i = 0; i < _buffer.length; i++) {
|
|
181
|
-
await this.processData(_buffer[i][0], _buffer[i][1]);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
this.state = stateEnum.SANE;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Decodes an incoming message, and dispatches it.
|
|
190
|
-
* The topic name must match a protobuf message.
|
|
191
|
-
*
|
|
192
|
-
* /!\ This method MUST NEVER THROW
|
|
193
|
-
* It's awaited by this.listen(), which cannot be awaited (infinite loop),
|
|
194
|
-
* and it also cannot afford to attach a rejection handler everytime a message
|
|
195
|
-
* is received to prevent clogging the event loop with unnecessary promises
|
|
196
|
-
*
|
|
197
|
-
* @param {string} topic
|
|
198
|
-
* @param {Buffer} data
|
|
199
|
-
* @return {void}
|
|
200
|
-
*/
|
|
201
|
-
async processData(topic, data) {
|
|
202
|
-
if (this.state === stateEnum.EVICTED) {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const decoder = this.protoroot.lookup(topic);
|
|
207
|
-
|
|
208
|
-
if (decoder === null) {
|
|
209
|
-
await this.evictNode({
|
|
210
|
-
broadcast: true,
|
|
211
|
-
reason: `received an invalid message from ${this.remoteNodeId} (unknown topic "${topic}")`,
|
|
212
|
-
});
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const message = decoder.toObject(decoder.decode(data));
|
|
217
|
-
|
|
218
|
-
if (!(await this.validateMessage(message))) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
try {
|
|
223
|
-
// If we are receiving messages from a node,
|
|
224
|
-
// it means the node is alive so it should counts as an heartbeat
|
|
225
|
-
this.handleHeartbeat();
|
|
226
|
-
await this.handlers[topic].call(this, message);
|
|
227
|
-
} catch (e) {
|
|
228
|
-
this.localNode.evictSelf(
|
|
229
|
-
`Unable to process sync message (topic: ${topic}, message: ${JSON.stringify(
|
|
230
|
-
message,
|
|
231
|
-
)}`,
|
|
232
|
-
e,
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
async handleNodePreventEviction(message) {
|
|
238
|
-
this.remoteNodeEvictionPrevented = message.evictionPrevented;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Handles a heartbeat from the remote node
|
|
243
|
-
*
|
|
244
|
-
* @return {void}
|
|
245
|
-
*/
|
|
246
|
-
handleHeartbeat() {
|
|
247
|
-
this.lastHeartbeat = Date.now();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Handles a node eviction message.
|
|
252
|
-
*
|
|
253
|
-
* @param {Object} message - decoded NodeEvicted protobuf message
|
|
254
|
-
* @return {void}
|
|
255
|
-
*/
|
|
256
|
-
async handleNodeEviction(message) {
|
|
257
|
-
if (message.nodeId === this.localNode.nodeId) {
|
|
258
|
-
this.logger.error(
|
|
259
|
-
`[CLUSTER] Node evicted by ${message.evictor}. Reason: ${message.reason}`,
|
|
260
|
-
);
|
|
261
|
-
global.kuzzle.shutdown();
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
await this.localNode.evictNode(message.nodeId, {
|
|
266
|
-
broadcast: false,
|
|
267
|
-
reason: message.reason,
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Handles a node shutdown.
|
|
273
|
-
*
|
|
274
|
-
* @param {Object} message - decoded NodeShutdown protobuf message
|
|
275
|
-
* @return {void}
|
|
276
|
-
*/
|
|
277
|
-
async handleNodeShutdown(message) {
|
|
278
|
-
await this.localNode.evictNode(message.nodeId, {
|
|
279
|
-
broadcast: false,
|
|
280
|
-
reason: "Node is shutting down",
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Handles messages about realtime room creations
|
|
286
|
-
*
|
|
287
|
-
* @param {Object} message - decoded NewRealtimeRoom protobuf message
|
|
288
|
-
* @return {void}
|
|
289
|
-
*/
|
|
290
|
-
handleNewRealtimeRoom(message) {
|
|
291
|
-
const { id, index, filter, messageId } = message;
|
|
292
|
-
const icpair = fromKoncordeIndex(index);
|
|
293
|
-
|
|
294
|
-
debug(
|
|
295
|
-
"New realtime room created by node %s (message: %d, room: %s, index: %s, collection: %s)",
|
|
296
|
-
this.remoteNodeId,
|
|
297
|
-
messageId,
|
|
298
|
-
id,
|
|
299
|
-
icpair.index,
|
|
300
|
-
icpair.collection,
|
|
301
|
-
);
|
|
302
|
-
|
|
303
|
-
this.localNode.fullState.addRealtimeRoom(
|
|
304
|
-
id,
|
|
305
|
-
icpair.index,
|
|
306
|
-
icpair.collection,
|
|
307
|
-
JSON.parse(filter),
|
|
308
|
-
{
|
|
309
|
-
messageId,
|
|
310
|
-
nodeId: this.remoteNodeId,
|
|
311
|
-
subscribers: 0,
|
|
312
|
-
},
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Handles messages about realtime subscriptions
|
|
318
|
-
*
|
|
319
|
-
* @param {Object} message - decoded Subscription protobuf message
|
|
320
|
-
* @return {void}
|
|
321
|
-
*/
|
|
322
|
-
handleSubscription(message) {
|
|
323
|
-
debug(
|
|
324
|
-
"New realtime subscription received from node %s (message: %d, room: %s)",
|
|
325
|
-
this.remoteNodeId,
|
|
326
|
-
message.messageId,
|
|
327
|
-
message.roomId,
|
|
328
|
-
);
|
|
329
|
-
|
|
330
|
-
this.localNode.fullState.addRealtimeSubscription(
|
|
331
|
-
message.roomId,
|
|
332
|
-
this.remoteNodeId,
|
|
333
|
-
message.messageId,
|
|
334
|
-
);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Handles messages about realtime room removal
|
|
339
|
-
*
|
|
340
|
-
* @param {Object} message - decoded RemoveRealtimeRoom protobuf message
|
|
341
|
-
* @return {void}
|
|
342
|
-
*/
|
|
343
|
-
handleRealtimeRoomRemoval(message) {
|
|
344
|
-
debug(
|
|
345
|
-
"Realtime room removal received from node %s (message: %d, room: %s)",
|
|
346
|
-
this.remoteNodeId,
|
|
347
|
-
message.messageId,
|
|
348
|
-
message.roomId,
|
|
349
|
-
);
|
|
350
|
-
|
|
351
|
-
this.localNode.fullState.removeRealtimeRoom(
|
|
352
|
-
message.roomId,
|
|
353
|
-
this.remoteNodeId,
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Handles messages about user unsubscriptions
|
|
359
|
-
*
|
|
360
|
-
* @param {Object} message - decoded Unscription protobuf message
|
|
361
|
-
* @return {void}
|
|
362
|
-
*/
|
|
363
|
-
handleUnsubscription(message) {
|
|
364
|
-
debug(
|
|
365
|
-
"Realtime unsubscription received from node %s (message: %d, room: %s)",
|
|
366
|
-
this.remoteNodeId,
|
|
367
|
-
message.messageId,
|
|
368
|
-
message.roomId,
|
|
369
|
-
);
|
|
370
|
-
|
|
371
|
-
this.localNode.fullState.removeRealtimeSubscription(
|
|
372
|
-
message.roomId,
|
|
373
|
-
this.remoteNodeId,
|
|
374
|
-
message.messageId,
|
|
375
|
-
);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Handles messages about cluster-wide events
|
|
380
|
-
*
|
|
381
|
-
* @param {Object} message - decoded ClusterWideEvent protobuf message
|
|
382
|
-
* @return {void}
|
|
383
|
-
*/
|
|
384
|
-
handleClusterWideEvent(message) {
|
|
385
|
-
const payload = JSON.parse(message.payload);
|
|
386
|
-
|
|
387
|
-
this.localNode.eventEmitter.emit(message.event, payload);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Handles messages about document notifications
|
|
392
|
-
*
|
|
393
|
-
* @param {Object} message - decoded DocumentNotification protobuf message
|
|
394
|
-
* @return {void}
|
|
395
|
-
*/
|
|
396
|
-
async handleDocumentNotification(message) {
|
|
397
|
-
const notification = new DocumentNotification({
|
|
398
|
-
action: message.action,
|
|
399
|
-
collection: message.collection,
|
|
400
|
-
controller: message.controller,
|
|
401
|
-
index: message.index,
|
|
402
|
-
node: this.remoteNodeId,
|
|
403
|
-
protocol: message.protocol,
|
|
404
|
-
requestId: message.requestId,
|
|
405
|
-
result: JSON.parse(message.result),
|
|
406
|
-
scope: message.scope,
|
|
407
|
-
status: message.status,
|
|
408
|
-
timestamp: message.timestamp.toNumber(),
|
|
409
|
-
volatile: JSON.parse(message.volatile),
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
return global.kuzzle.ask(
|
|
413
|
-
"core:realtime:document:dispatch",
|
|
414
|
-
message.rooms,
|
|
415
|
-
notification,
|
|
416
|
-
);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* Handles messages about user notifications
|
|
421
|
-
*
|
|
422
|
-
* @param {Object} message - decoded UserNotification protobuf message
|
|
423
|
-
* @return {void}
|
|
424
|
-
*/
|
|
425
|
-
async handleUserNotification(message) {
|
|
426
|
-
const notification = new UserNotification({
|
|
427
|
-
action: message.action,
|
|
428
|
-
collection: message.collection,
|
|
429
|
-
controller: message.controller,
|
|
430
|
-
index: message.index,
|
|
431
|
-
node: this.remoteNodeId,
|
|
432
|
-
protocol: message.protocol,
|
|
433
|
-
result: JSON.parse(message.result),
|
|
434
|
-
status: message.status,
|
|
435
|
-
timestamp: message.timestamp.toNumber(),
|
|
436
|
-
user: message.user,
|
|
437
|
-
volatile: JSON.parse(message.volatile),
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
return global.kuzzle.ask(
|
|
441
|
-
"core:realtime:user:sendMessage",
|
|
442
|
-
message.room,
|
|
443
|
-
notification,
|
|
444
|
-
);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* Handles messages about new authentication strategies
|
|
449
|
-
*
|
|
450
|
-
* @param {Object} message - decoded NewAuthStrategy protobuf message
|
|
451
|
-
* @return {void}
|
|
452
|
-
*/
|
|
453
|
-
handleNewAuthStrategy(message) {
|
|
454
|
-
const { pluginName, strategy, strategyName } = message;
|
|
455
|
-
|
|
456
|
-
debug(
|
|
457
|
-
"New authentication strategy added by node %s (plugin: %s, strategy: %s)",
|
|
458
|
-
this.remoteNodeId,
|
|
459
|
-
pluginName,
|
|
460
|
-
strategyName,
|
|
461
|
-
);
|
|
462
|
-
|
|
463
|
-
this.localNode.fullState.addAuthStrategy(message);
|
|
464
|
-
|
|
465
|
-
global.kuzzle.pluginsManager.registerStrategy(
|
|
466
|
-
pluginName,
|
|
467
|
-
strategyName,
|
|
468
|
-
strategy,
|
|
469
|
-
);
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
/**
|
|
473
|
-
* Handles messages about authentication strategy removals
|
|
474
|
-
*
|
|
475
|
-
* @param {Object} message - decoded RemoveAuthStrategy protobuf message
|
|
476
|
-
* @return {void}
|
|
477
|
-
*/
|
|
478
|
-
handleAuthStrategyRemoval(message) {
|
|
479
|
-
const { pluginName, strategyName } = message;
|
|
480
|
-
|
|
481
|
-
debug(
|
|
482
|
-
"Authentication strategy removed by node %s (plugin: %s, strategy: %s)",
|
|
483
|
-
this.remoteNodeId,
|
|
484
|
-
pluginName,
|
|
485
|
-
strategyName,
|
|
486
|
-
);
|
|
487
|
-
|
|
488
|
-
global.kuzzle.pluginsManager.unregisterStrategy(pluginName, strategyName);
|
|
489
|
-
this.localNode.fullState.removeAuthStrategy(strategyName);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* Handles messages about security resets
|
|
494
|
-
*
|
|
495
|
-
* @return {void}
|
|
496
|
-
*/
|
|
497
|
-
async handleResetSecurity() {
|
|
498
|
-
debug("Security reset received from node %s", this.remoteNodeId);
|
|
499
|
-
await global.kuzzle.ask("core:security:profile:invalidate");
|
|
500
|
-
await global.kuzzle.ask("core:security:role:invalidate");
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
/**
|
|
504
|
-
* Handles a cross-nodes dump request
|
|
505
|
-
*
|
|
506
|
-
* @param {Object} message - decoded DumpRequest protobuf message
|
|
507
|
-
* @return {void}
|
|
508
|
-
*/
|
|
509
|
-
handleDumpRequest(message) {
|
|
510
|
-
debug("Dump generation request received from node %s", this.remoteNodeId);
|
|
511
|
-
global.kuzzle.dump(message.suffix);
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* Handles cluster-wide shutdown
|
|
516
|
-
* @return {void}
|
|
517
|
-
*/
|
|
518
|
-
handleShutdown() {
|
|
519
|
-
debug(
|
|
520
|
-
"Cluster-wide shutdown request received from node %s",
|
|
521
|
-
this.remoteNodeId,
|
|
522
|
-
);
|
|
523
|
-
this.logger.error(
|
|
524
|
-
`[CLUSTER] Cluster wide shutdown from ${this.remoteNodeId}`,
|
|
525
|
-
);
|
|
526
|
-
global.kuzzle.shutdown();
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* Handles changes on document validators
|
|
531
|
-
*
|
|
532
|
-
* @return {void}
|
|
533
|
-
*/
|
|
534
|
-
async handleRefreshValidators() {
|
|
535
|
-
debug(
|
|
536
|
-
"Validators changed notification received from node %s",
|
|
537
|
-
this.remoteNodeId,
|
|
538
|
-
);
|
|
539
|
-
await global.kuzzle.validation.curateSpecification();
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* Handles manual refresh of the index cache
|
|
544
|
-
*/
|
|
545
|
-
async handleRefreshIndexCache() {
|
|
546
|
-
debug(
|
|
547
|
-
"Index cache manually refresh received from node %s",
|
|
548
|
-
this.remoteNodeId,
|
|
549
|
-
);
|
|
550
|
-
await global.kuzzle.ask("core:storage:public:cache:refresh", {
|
|
551
|
-
from: "cluster",
|
|
552
|
-
});
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
/**
|
|
556
|
-
* Invalidates a profile to force reloading it from the storage space
|
|
557
|
-
*
|
|
558
|
-
* @param {Object} message - decoded DumpRequest protobuf message
|
|
559
|
-
* @return {void}
|
|
560
|
-
*/
|
|
561
|
-
async handleProfileInvalidation(message) {
|
|
562
|
-
debug(
|
|
563
|
-
"Profile invalidation request received from node %s (profile: %s)",
|
|
564
|
-
this.remoteNodeId,
|
|
565
|
-
message.profileId,
|
|
566
|
-
);
|
|
567
|
-
|
|
568
|
-
await global.kuzzle.ask(
|
|
569
|
-
"core:security:profile:invalidate",
|
|
570
|
-
message.profileId,
|
|
571
|
-
);
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
/**
|
|
575
|
-
* Invalidates a role to force reloading it from the storage space
|
|
576
|
-
*
|
|
577
|
-
* @param {Object} message - decoded DumpRequest protobuf message
|
|
578
|
-
* @return {void}
|
|
579
|
-
*/
|
|
580
|
-
async handleRoleInvalidation(message) {
|
|
581
|
-
debug(
|
|
582
|
-
"Role invalidation request received from node %s (role: %s)",
|
|
583
|
-
this.remoteNodeId,
|
|
584
|
-
message.roleId,
|
|
585
|
-
);
|
|
586
|
-
|
|
587
|
-
await global.kuzzle.ask("core:security:role:invalidate", message.roleId);
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* Adds a new index to the index cache
|
|
592
|
-
*
|
|
593
|
-
* @param {Object} message - decoded IndexCacheAdd protobuf message
|
|
594
|
-
* @return {void}
|
|
595
|
-
*/
|
|
596
|
-
async handleIndexAddition(message) {
|
|
597
|
-
const { index, scope } = message;
|
|
598
|
-
|
|
599
|
-
debug(
|
|
600
|
-
"New index added by node %s (scope: %s, index: %s)",
|
|
601
|
-
this.remoteNodeId,
|
|
602
|
-
scope,
|
|
603
|
-
index,
|
|
604
|
-
);
|
|
605
|
-
|
|
606
|
-
await global.kuzzle.ask(`core:storage:${scope}:cache:addIndex`, index);
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
/**
|
|
610
|
-
* Removes indexes from the index cache
|
|
611
|
-
*
|
|
612
|
-
* @param {Object} message - decoded IndexCacheAdd protobuf message
|
|
613
|
-
* @return {void}
|
|
614
|
-
*/
|
|
615
|
-
async handleIndexesRemoval(message) {
|
|
616
|
-
const { indexes, scope } = message;
|
|
617
|
-
|
|
618
|
-
debug(
|
|
619
|
-
"Indexes removed by node %s (scope: %s, indexes: %s)",
|
|
620
|
-
this.remoteNodeId,
|
|
621
|
-
scope,
|
|
622
|
-
indexes,
|
|
623
|
-
);
|
|
624
|
-
|
|
625
|
-
await global.kuzzle.ask(
|
|
626
|
-
`core:storage:${scope}:cache:removeIndexes`,
|
|
627
|
-
indexes,
|
|
628
|
-
);
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
/**
|
|
632
|
-
* Adds a new collection to the index cache
|
|
633
|
-
*
|
|
634
|
-
* @param {Object} message - decoded IndexCacheAdd protobuf message
|
|
635
|
-
* @return {void}
|
|
636
|
-
*/
|
|
637
|
-
async handleCollectionAddition(message) {
|
|
638
|
-
const { collection, index, scope } = message;
|
|
639
|
-
|
|
640
|
-
debug(
|
|
641
|
-
"New collection added by node %s (scope: %s, index: %s, collection: %s)",
|
|
642
|
-
this.remoteNodeId,
|
|
643
|
-
scope,
|
|
644
|
-
index,
|
|
645
|
-
collection,
|
|
646
|
-
);
|
|
647
|
-
|
|
648
|
-
await global.kuzzle.ask(
|
|
649
|
-
`core:storage:${scope}:cache:addCollection`,
|
|
650
|
-
index,
|
|
651
|
-
collection,
|
|
652
|
-
);
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
/**
|
|
656
|
-
* Removes a collection from the index cache
|
|
657
|
-
*
|
|
658
|
-
* @param {Object} message - decoded IndexCacheAdd protobuf message
|
|
659
|
-
* @return {void}
|
|
660
|
-
*/
|
|
661
|
-
async handleCollectionRemoval(message) {
|
|
662
|
-
const { collection, index, scope } = message;
|
|
663
|
-
|
|
664
|
-
debug(
|
|
665
|
-
"Indexes removed by node %s (scope: %s, index: %s, collection: %s)",
|
|
666
|
-
this.remoteNodeId,
|
|
667
|
-
scope,
|
|
668
|
-
index,
|
|
669
|
-
collection,
|
|
670
|
-
);
|
|
671
|
-
|
|
672
|
-
await global.kuzzle.ask(
|
|
673
|
-
`core:storage:${scope}:cache:removeCollection`,
|
|
674
|
-
index,
|
|
675
|
-
collection,
|
|
676
|
-
);
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
/**
|
|
680
|
-
* Checks that we did receive a heartbeat from the remote node
|
|
681
|
-
* If a heartbeat is missing, we allow 1 heartbeat round for the remote node
|
|
682
|
-
* to recover, otherwise we evict it from the cluster.
|
|
683
|
-
*/
|
|
684
|
-
async checkHeartbeat() {
|
|
685
|
-
if (this.remoteNodeEvictionPrevented) {
|
|
686
|
-
// Fake the heartbeat while the node eviction prevention is enabled
|
|
687
|
-
// otherwise when the node eviction prevention is disabled
|
|
688
|
-
// the node will be evicted if it did not send a heartbeat before disabling the protection.
|
|
689
|
-
this.lastHeartbeat = Date.now();
|
|
690
|
-
return;
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
if (this.state === stateEnum.EVICTED) {
|
|
694
|
-
return;
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
const now = Date.now();
|
|
698
|
-
|
|
699
|
-
if (now - this.lastHeartbeat > this.heartbeatDelay) {
|
|
700
|
-
if (this.state === stateEnum.MISSING_HEARTBEAT) {
|
|
701
|
-
await this.evictNode({
|
|
702
|
-
broadcast: true,
|
|
703
|
-
reason: "heartbeat timeout",
|
|
704
|
-
});
|
|
705
|
-
} else {
|
|
706
|
-
this.state = stateEnum.MISSING_HEARTBEAT;
|
|
707
|
-
}
|
|
708
|
-
} else {
|
|
709
|
-
this.state = stateEnum.SANE;
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
/**
|
|
714
|
-
* Disconnects from the remote node, and frees all allocated resources.
|
|
715
|
-
*/
|
|
716
|
-
dispose() {
|
|
717
|
-
if (this.state === stateEnum.EVICTED) {
|
|
718
|
-
return;
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
this.state = stateEnum.EVICTED;
|
|
722
|
-
this.socket.close();
|
|
723
|
-
this.socket = null;
|
|
724
|
-
clearInterval(this.heartbeatTimer);
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
/**
|
|
728
|
-
* Checks that the received message is the one we expect.
|
|
729
|
-
* @param {Object} message - decoded protobuf message
|
|
730
|
-
* @return {boolean} false: the message must be discarded, true otherwise
|
|
731
|
-
*/
|
|
732
|
-
async validateMessage(message) {
|
|
733
|
-
if (!has(message, "messageId")) {
|
|
734
|
-
this.logger.warn(
|
|
735
|
-
`Invalid message received from node ${this.remoteNodeId}. Evicting it.`,
|
|
736
|
-
);
|
|
737
|
-
|
|
738
|
-
await this.evictNode({
|
|
739
|
-
broadcast: true,
|
|
740
|
-
reason: 'invalid message received (missing "messageId" field)',
|
|
741
|
-
});
|
|
742
|
-
|
|
743
|
-
return false;
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
if (
|
|
747
|
-
this.state === stateEnum.BUFFERING &&
|
|
748
|
-
this.lastMessageId.greaterThanOrEqual(message.messageId)
|
|
749
|
-
) {
|
|
750
|
-
return false;
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
this.lastMessageId = this.lastMessageId.add(1);
|
|
754
|
-
|
|
755
|
-
if (this.lastMessageId.notEquals(message.messageId)) {
|
|
756
|
-
await this.localNode.evictSelf(
|
|
757
|
-
`Node out-of-sync: ${
|
|
758
|
-
message.messageId - this.lastMessageId - 1
|
|
759
|
-
} messages lost from node ${this.remoteNodeId}`,
|
|
760
|
-
);
|
|
761
|
-
return false;
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
return true;
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
async evictNode({ broadcast, reason }) {
|
|
768
|
-
this.state = stateEnum.EVICTED;
|
|
769
|
-
|
|
770
|
-
await this.localNode.evictNode(this.remoteNodeId, { broadcast, reason });
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
ClusterSubscriber.stateEnum = stateEnum;
|
|
775
|
-
|
|
776
|
-
module.exports = ClusterSubscriber;
|