@zlink-systems/framework 0.10.0
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/LICENSE +105 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/contracts/Actors/ZLinkActor.d.ts +7 -0
- package/dist/contracts/Actors/ZLinkActor.js +2 -0
- package/dist/contracts/Actors/ZLinkActorClient.d.ts +15 -0
- package/dist/contracts/Actors/ZLinkActorClient.js +2 -0
- package/dist/contracts/Actors/ZLinkActorContext.d.ts +14 -0
- package/dist/contracts/Actors/ZLinkActorContext.js +2 -0
- package/dist/contracts/Actors/ZLinkActorFactory.d.ts +34 -0
- package/dist/contracts/Actors/ZLinkActorFactory.js +2 -0
- package/dist/contracts/Actors/ZLinkActorManager.d.ts +34 -0
- package/dist/contracts/Actors/ZLinkActorManager.js +2 -0
- package/dist/contracts/Actors/index.d.ts +5 -0
- package/dist/contracts/Actors/index.js +21 -0
- package/dist/contracts/Channels/Calls.d.ts +28 -0
- package/dist/contracts/Channels/Calls.js +2 -0
- package/dist/contracts/Channels/IZLinkChannelClient.d.ts +5 -0
- package/dist/contracts/Channels/IZLinkChannelClient.js +2 -0
- package/dist/contracts/Channels/IZLinkFanoutClient.d.ts +11 -0
- package/dist/contracts/Channels/IZLinkFanoutClient.js +2 -0
- package/dist/contracts/Channels/RouteCalls.d.ts +11 -0
- package/dist/contracts/Channels/RouteCalls.js +2 -0
- package/dist/contracts/Channels/index.d.ts +4 -0
- package/dist/contracts/Channels/index.js +20 -0
- package/dist/contracts/Codecs/IZLinkCodecRegistryBuilder.d.ts +14 -0
- package/dist/contracts/Codecs/IZLinkCodecRegistryBuilder.js +2 -0
- package/dist/contracts/Codecs/ZLinkMessageSerializer.d.ts +5 -0
- package/dist/contracts/Codecs/ZLinkMessageSerializer.js +2 -0
- package/dist/contracts/Codecs/index.d.ts +2 -0
- package/dist/contracts/Codecs/index.js +18 -0
- package/dist/contracts/Common/ActorRef.d.ts +7 -0
- package/dist/contracts/Common/ActorRef.js +2 -0
- package/dist/contracts/Common/CoreTypes.d.ts +6 -0
- package/dist/contracts/Common/CoreTypes.js +2 -0
- package/dist/contracts/Common/Message.d.ts +9 -0
- package/dist/contracts/Common/Message.js +2 -0
- package/dist/contracts/Common/ZLinkEncodedPayload.d.ts +12 -0
- package/dist/contracts/Common/ZLinkEncodedPayload.js +41 -0
- package/dist/contracts/Common/ZLinkMessage.d.ts +25 -0
- package/dist/contracts/Common/ZLinkMessage.js +127 -0
- package/dist/contracts/Common/ZLinkMessageMetadata.d.ts +10 -0
- package/dist/contracts/Common/ZLinkMessageMetadata.js +49 -0
- package/dist/contracts/Common/ZLinkProviderResolver.d.ts +5 -0
- package/dist/contracts/Common/ZLinkProviderResolver.js +2 -0
- package/dist/contracts/Common/encoded-payload-storage.d.ts +3 -0
- package/dist/contracts/Common/encoded-payload-storage.js +18 -0
- package/dist/contracts/Common/index.d.ts +5 -0
- package/dist/contracts/Common/index.js +24 -0
- package/dist/contracts/Configuration/Builders.d.ts +153 -0
- package/dist/contracts/Configuration/Builders.js +2 -0
- package/dist/contracts/Configuration/CodecContentType.d.ts +2 -0
- package/dist/contracts/Configuration/CodecContentType.js +68 -0
- package/dist/contracts/Configuration/CodecSerializerSelection.d.ts +9 -0
- package/dist/contracts/Configuration/CodecSerializerSelection.js +15 -0
- package/dist/contracts/Configuration/Configs.d.ts +23 -0
- package/dist/contracts/Configuration/Configs.js +2 -0
- package/dist/contracts/Configuration/ConfigurationException.d.ts +3 -0
- package/dist/contracts/Configuration/ConfigurationException.js +10 -0
- package/dist/contracts/Configuration/Connections.d.ts +5 -0
- package/dist/contracts/Configuration/Connections.js +2 -0
- package/dist/contracts/Configuration/DiagnosticsValidation.d.ts +3 -0
- package/dist/contracts/Configuration/DiagnosticsValidation.js +23 -0
- package/dist/contracts/Configuration/EndpointNotation.d.ts +77 -0
- package/dist/contracts/Configuration/EndpointNotation.js +218 -0
- package/dist/contracts/Configuration/InternalDefaults.d.ts +7 -0
- package/dist/contracts/Configuration/InternalDefaults.js +47 -0
- package/dist/contracts/Configuration/ObjectRoles.d.ts +38 -0
- package/dist/contracts/Configuration/ObjectRoles.js +13 -0
- package/dist/contracts/Configuration/Registration.d.ts +11 -0
- package/dist/contracts/Configuration/Registration.js +162 -0
- package/dist/contracts/Configuration/RegistrationBuilderPolicy.d.ts +14 -0
- package/dist/contracts/Configuration/RegistrationBuilderPolicy.js +61 -0
- package/dist/contracts/Configuration/RegistrationBuilders.d.ts +61 -0
- package/dist/contracts/Configuration/RegistrationBuilders.js +1181 -0
- package/dist/contracts/Configuration/RegistrationCodecRegistry.d.ts +19 -0
- package/dist/contracts/Configuration/RegistrationCodecRegistry.js +79 -0
- package/dist/contracts/Configuration/RegistrationNormalizers.d.ts +23 -0
- package/dist/contracts/Configuration/RegistrationNormalizers.js +319 -0
- package/dist/contracts/Configuration/RegistrationTypes.d.ts +414 -0
- package/dist/contracts/Configuration/RegistrationTypes.js +2 -0
- package/dist/contracts/Configuration/RegistrationValidators.d.ts +2 -0
- package/dist/contracts/Configuration/RegistrationValidators.js +461 -0
- package/dist/contracts/Configuration/RouteChannelInternalState.d.ts +10 -0
- package/dist/contracts/Configuration/RouteChannelInternalState.js +39 -0
- package/dist/contracts/Configuration/RuntimeEndpointConnections.d.ts +9 -0
- package/dist/contracts/Configuration/RuntimeEndpointConnections.js +80 -0
- package/dist/contracts/Configuration/SendTimeoutValidation.d.ts +2 -0
- package/dist/contracts/Configuration/SendTimeoutValidation.js +16 -0
- package/dist/contracts/Configuration/TimerRegistrationValidator.d.ts +2 -0
- package/dist/contracts/Configuration/TimerRegistrationValidator.js +24 -0
- package/dist/contracts/Configuration/index.d.ts +5 -0
- package/dist/contracts/Configuration/index.js +18 -0
- package/dist/contracts/Dispatch/ZLinkDispatchOptions.d.ts +181 -0
- package/dist/contracts/Dispatch/ZLinkDispatchOptions.js +89 -0
- package/dist/contracts/Dispatch/ZLinkFlowOrigin.d.ts +1 -0
- package/dist/contracts/Dispatch/ZLinkFlowOrigin.js +2 -0
- package/dist/contracts/Dispatch/index.d.ts +2 -0
- package/dist/contracts/Dispatch/index.js +18 -0
- package/dist/contracts/Errors/ZLinkFrameworkException.d.ts +20 -0
- package/dist/contracts/Errors/ZLinkFrameworkException.js +29 -0
- package/dist/contracts/Errors/index.d.ts +1 -0
- package/dist/contracts/Errors/index.js +6 -0
- package/dist/contracts/Eventing/Metrics.d.ts +29 -0
- package/dist/contracts/Eventing/Metrics.js +4 -0
- package/dist/contracts/Eventing/index.d.ts +1 -0
- package/dist/contracts/Eventing/index.js +17 -0
- package/dist/contracts/Handlers/Attributes.d.ts +24 -0
- package/dist/contracts/Handlers/Attributes.js +84 -0
- package/dist/contracts/Handlers/Contexts.d.ts +18 -0
- package/dist/contracts/Handlers/Contexts.js +2 -0
- package/dist/contracts/Handlers/IZLinkChannelHandlers.d.ts +43 -0
- package/dist/contracts/Handlers/IZLinkChannelHandlers.js +2 -0
- package/dist/contracts/Handlers/IZLinkHandlerFilter.d.ts +15 -0
- package/dist/contracts/Handlers/IZLinkHandlerFilter.js +11 -0
- package/dist/contracts/Handlers/JsonContract.d.ts +46 -0
- package/dist/contracts/Handlers/JsonContract.js +137 -0
- package/dist/contracts/Handlers/ZLinkHandlerFilterNext.d.ts +1 -0
- package/dist/contracts/Handlers/ZLinkHandlerFilterNext.js +2 -0
- package/dist/contracts/Handlers/index.d.ts +5 -0
- package/dist/contracts/Handlers/index.js +33 -0
- package/dist/contracts/Locations/ActorTransfer.d.ts +41 -0
- package/dist/contracts/Locations/ActorTransfer.js +2 -0
- package/dist/contracts/Locations/Authority.d.ts +296 -0
- package/dist/contracts/Locations/Authority.js +17 -0
- package/dist/contracts/Locations/Diagnostics.d.ts +42 -0
- package/dist/contracts/Locations/Diagnostics.js +12 -0
- package/dist/contracts/Locations/Keys.d.ts +86 -0
- package/dist/contracts/Locations/Keys.js +2 -0
- package/dist/contracts/Locations/Models.d.ts +7 -0
- package/dist/contracts/Locations/Models.js +23 -0
- package/dist/contracts/Locations/Options.d.ts +23 -0
- package/dist/contracts/Locations/Options.js +20 -0
- package/dist/contracts/Locations/Readiness.d.ts +5 -0
- package/dist/contracts/Locations/Readiness.js +2 -0
- package/dist/contracts/Locations/RelocationStore.d.ts +38 -0
- package/dist/contracts/Locations/RelocationStore.js +2 -0
- package/dist/contracts/Locations/Resolvers.d.ts +4 -0
- package/dist/contracts/Locations/Resolvers.js +2 -0
- package/dist/contracts/Locations/Rows.d.ts +152 -0
- package/dist/contracts/Locations/Rows.js +19 -0
- package/dist/contracts/Locations/RuntimeQuery.d.ts +25 -0
- package/dist/contracts/Locations/RuntimeQuery.js +2 -0
- package/dist/contracts/Locations/Stores.d.ts +88 -0
- package/dist/contracts/Locations/Stores.js +2 -0
- package/dist/contracts/Locations/Values.d.ts +27 -0
- package/dist/contracts/Locations/Values.js +36 -0
- package/dist/contracts/Locations/Watch.d.ts +14 -0
- package/dist/contracts/Locations/Watch.js +12 -0
- package/dist/contracts/Locations/Writes.d.ts +48 -0
- package/dist/contracts/Locations/Writes.js +15 -0
- package/dist/contracts/Locations/index.d.ts +12 -0
- package/dist/contracts/Locations/index.js +30 -0
- package/dist/contracts/RouteMesh/Contracts.d.ts +102 -0
- package/dist/contracts/RouteMesh/Contracts.js +39 -0
- package/dist/contracts/RouteMesh/RuntimeTopology.d.ts +165 -0
- package/dist/contracts/RouteMesh/RuntimeTopology.js +38 -0
- package/dist/contracts/RouteMesh/index.d.ts +2 -0
- package/dist/contracts/RouteMesh/index.js +18 -0
- package/dist/contracts/Spots/Builders.d.ts +10 -0
- package/dist/contracts/Spots/Builders.js +2 -0
- package/dist/contracts/Spots/Contracts.d.ts +110 -0
- package/dist/contracts/Spots/Contracts.js +9 -0
- package/dist/contracts/Spots/SpotKind.d.ts +8 -0
- package/dist/contracts/Spots/SpotKind.js +28 -0
- package/dist/contracts/Spots/ZLinkSpot.d.ts +62 -0
- package/dist/contracts/Spots/ZLinkSpot.js +15 -0
- package/dist/contracts/Spots/index.d.ts +3 -0
- package/dist/contracts/Spots/index.js +19 -0
- package/dist/contracts/Streams/BoundSessionContracts.d.ts +8 -0
- package/dist/contracts/Streams/BoundSessionContracts.js +2 -0
- package/dist/contracts/Streams/IZLinkSession.d.ts +44 -0
- package/dist/contracts/Streams/IZLinkSession.js +2 -0
- package/dist/contracts/Streams/IZLinkSessionActor.d.ts +15 -0
- package/dist/contracts/Streams/IZLinkSessionActor.js +2 -0
- package/dist/contracts/Streams/IZLinkSessionPacketHandler.d.ts +9 -0
- package/dist/contracts/Streams/IZLinkSessionPacketHandler.js +2 -0
- package/dist/contracts/Streams/IZLinkStream.d.ts +9 -0
- package/dist/contracts/Streams/IZLinkStream.js +2 -0
- package/dist/contracts/Streams/ZLinkMessageMetadata.d.ts +1 -0
- package/dist/contracts/Streams/ZLinkMessageMetadata.js +2 -0
- package/dist/contracts/Streams/ZLinkStreamCompression.d.ts +8 -0
- package/dist/contracts/Streams/ZLinkStreamCompression.js +2 -0
- package/dist/contracts/Streams/ZLinkStreamError.d.ts +8 -0
- package/dist/contracts/Streams/ZLinkStreamError.js +8 -0
- package/dist/contracts/Streams/index.d.ts +8 -0
- package/dist/contracts/Streams/index.js +24 -0
- package/dist/contracts/Timers/IZLinkTimer.d.ts +5 -0
- package/dist/contracts/Timers/IZLinkTimer.js +2 -0
- package/dist/contracts/Timers/ZLinkTimerOptions.d.ts +10 -0
- package/dist/contracts/Timers/ZLinkTimerOptions.js +9 -0
- package/dist/contracts/Timers/ZLinkTimerTick.d.ts +12 -0
- package/dist/contracts/Timers/ZLinkTimerTick.js +2 -0
- package/dist/contracts/Timers/index.d.ts +3 -0
- package/dist/contracts/Timers/index.js +19 -0
- package/dist/contracts/index.d.ts +25 -0
- package/dist/contracts/index.js +45 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/internal.d.ts +26 -0
- package/dist/internal.js +48 -0
- package/dist/location-store-integration.d.ts +5 -0
- package/dist/location-store-integration.js +31 -0
- package/dist/nest-integration.d.ts +49 -0
- package/dist/nest-integration.js +143 -0
- package/dist/runtime/abort.d.ts +13 -0
- package/dist/runtime/abort.js +71 -0
- package/dist/runtime/actors/actor-authority-payload-codec.d.ts +33 -0
- package/dist/runtime/actors/actor-authority-payload-codec.js +366 -0
- package/dist/runtime/actors/actor-authority-publication.d.ts +28 -0
- package/dist/runtime/actors/actor-authority-publication.js +207 -0
- package/dist/runtime/actors/actor-client.d.ts +36 -0
- package/dist/runtime/actors/actor-client.js +612 -0
- package/dist/runtime/actors/actor-context.d.ts +26 -0
- package/dist/runtime/actors/actor-context.js +433 -0
- package/dist/runtime/actors/actor-creation.d.ts +19 -0
- package/dist/runtime/actors/actor-creation.js +158 -0
- package/dist/runtime/actors/actor-execution-context.d.ts +6 -0
- package/dist/runtime/actors/actor-execution-context.js +27 -0
- package/dist/runtime/actors/actor-handoff.d.ts +191 -0
- package/dist/runtime/actors/actor-handoff.js +1252 -0
- package/dist/runtime/actors/actor-join-deferred-scope.d.ts +11 -0
- package/dist/runtime/actors/actor-join-deferred-scope.js +144 -0
- package/dist/runtime/actors/actor-join-relocation.d.ts +38 -0
- package/dist/runtime/actors/actor-join-relocation.js +2 -0
- package/dist/runtime/actors/actor-lifecycle-snapshot.d.ts +21 -0
- package/dist/runtime/actors/actor-lifecycle-snapshot.js +58 -0
- package/dist/runtime/actors/actor-local-native-join.d.ts +27 -0
- package/dist/runtime/actors/actor-local-native-join.js +409 -0
- package/dist/runtime/actors/actor-mailbox.d.ts +10 -0
- package/dist/runtime/actors/actor-mailbox.js +53 -0
- package/dist/runtime/actors/actor-message-follow-context.d.ts +46 -0
- package/dist/runtime/actors/actor-message-follow-context.js +257 -0
- package/dist/runtime/actors/actor-native-lookup.d.ts +4 -0
- package/dist/runtime/actors/actor-native-lookup.js +30 -0
- package/dist/runtime/actors/actor-packet-relay-wire.d.ts +73 -0
- package/dist/runtime/actors/actor-packet-relay-wire.js +144 -0
- package/dist/runtime/actors/actor-remote-joiner.d.ts +37 -0
- package/dist/runtime/actors/actor-remote-joiner.js +122 -0
- package/dist/runtime/actors/actor-remote-wire.d.ts +73 -0
- package/dist/runtime/actors/actor-remote-wire.js +84 -0
- package/dist/runtime/actors/actor-retry-delay.d.ts +5 -0
- package/dist/runtime/actors/actor-retry-delay.js +40 -0
- package/dist/runtime/actors/actor-routed-join-transport.d.ts +33 -0
- package/dist/runtime/actors/actor-routed-join-transport.js +2 -0
- package/dist/runtime/actors/actor-routed-json-request.d.ts +11 -0
- package/dist/runtime/actors/actor-routed-json-request.js +39 -0
- package/dist/runtime/actors/actor-runtime-contracts.d.ts +63 -0
- package/dist/runtime/actors/actor-runtime-contracts.js +2 -0
- package/dist/runtime/actors/actor-runtime-state.d.ts +152 -0
- package/dist/runtime/actors/actor-runtime-state.js +545 -0
- package/dist/runtime/actors/actor-source-transfer.d.ts +27 -0
- package/dist/runtime/actors/actor-source-transfer.js +2 -0
- package/dist/runtime/actors/actor-transfer-registry.d.ts +18 -0
- package/dist/runtime/actors/actor-transfer-registry.js +71 -0
- package/dist/runtime/actors/actor-transport-delivery-gate.d.ts +6 -0
- package/dist/runtime/actors/actor-transport-delivery-gate.js +4 -0
- package/dist/runtime/actors/bound-session-wire.d.ts +81 -0
- package/dist/runtime/actors/bound-session-wire.js +184 -0
- package/dist/runtime/actors/deferred-join-accepted-journal.d.ts +47 -0
- package/dist/runtime/actors/deferred-join-accepted-journal.js +962 -0
- package/dist/runtime/actors/index.d.ts +79 -0
- package/dist/runtime/actors/index.js +639 -0
- package/dist/runtime/actors/post-commit-actor-binder.d.ts +18 -0
- package/dist/runtime/actors/post-commit-actor-binder.js +68 -0
- package/dist/runtime/actors/post-commit-actor-location.d.ts +19 -0
- package/dist/runtime/actors/post-commit-actor-location.js +72 -0
- package/dist/runtime/actors/spot-actor-dispatch.d.ts +59 -0
- package/dist/runtime/actors/spot-actor-dispatch.js +179 -0
- package/dist/runtime/actors/transferred-actor-rollback.d.ts +16 -0
- package/dist/runtime/actors/transferred-actor-rollback.js +91 -0
- package/dist/runtime/admission.d.ts +20 -0
- package/dist/runtime/admission.js +166 -0
- package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +57 -0
- package/dist/runtime/application-jobs/application-ingress-record-owner.js +185 -0
- package/dist/runtime/application-jobs/application-job-queue-handler-start-gate.d.ts +8 -0
- package/dist/runtime/application-jobs/application-job-queue-handler-start-gate.js +8 -0
- package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +17 -0
- package/dist/runtime/application-jobs/application-job-queue-scope.js +57 -0
- package/dist/runtime/application-jobs/contracts.d.ts +19 -0
- package/dist/runtime/application-jobs/contracts.js +2 -0
- package/dist/runtime/application-jobs/receive-flow-controller.d.ts +32 -0
- package/dist/runtime/application-jobs/receive-flow-controller.js +165 -0
- package/dist/runtime/backend/contracts/index.d.ts +487 -0
- package/dist/runtime/backend/contracts/index.js +29 -0
- package/dist/runtime/backend/index.d.ts +9 -0
- package/dist/runtime/backend/index.js +25 -0
- package/dist/runtime/backend/mesh-actor-session-node-adapter.d.ts +3 -0
- package/dist/runtime/backend/mesh-actor-session-node-adapter.js +51 -0
- package/dist/runtime/backend/mesh-completion-table.d.ts +34 -0
- package/dist/runtime/backend/mesh-completion-table.js +124 -0
- package/dist/runtime/backend/mesh-dispatch-pump.d.ts +48 -0
- package/dist/runtime/backend/mesh-dispatch-pump.js +322 -0
- package/dist/runtime/backend/mesh-record-dispatcher.d.ts +19 -0
- package/dist/runtime/backend/mesh-record-dispatcher.js +53 -0
- package/dist/runtime/backend/node/index.d.ts +4 -0
- package/dist/runtime/backend/node/index.js +22 -0
- package/dist/runtime/backend/node/node-backend-adapter-factory.d.ts +12 -0
- package/dist/runtime/backend/node/node-backend-adapter-factory.js +161 -0
- package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +52 -0
- package/dist/runtime/backend/node/node-backend-adapter-support.js +203 -0
- package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +13 -0
- package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +52 -0
- package/dist/runtime/backend/node/node-mesh-backend-adapter.d.ts +11 -0
- package/dist/runtime/backend/node/node-mesh-backend-adapter.js +23 -0
- package/dist/runtime/backend/node/node-monitor-backend-adapter.d.ts +6 -0
- package/dist/runtime/backend/node/node-monitor-backend-adapter.js +38 -0
- package/dist/runtime/backend/node/node-raw-binding-port.d.ts +8 -0
- package/dist/runtime/backend/node/node-raw-binding-port.js +411 -0
- package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +266 -0
- package/dist/runtime/backend/node/node-raw-mesh-backend.js +1707 -0
- package/dist/runtime/backend/node/node-socket-backend-adapter.d.ts +9 -0
- package/dist/runtime/backend/node/node-socket-backend-adapter.js +286 -0
- package/dist/runtime/backend/node-backend-adapter.d.ts +9 -0
- package/dist/runtime/backend/node-backend-adapter.js +12 -0
- package/dist/runtime/backend/raw-binding-port.d.ts +58 -0
- package/dist/runtime/backend/raw-binding-port.js +2 -0
- package/dist/runtime/backend/runtime-message.d.ts +14 -0
- package/dist/runtime/backend/runtime-message.js +44 -0
- package/dist/runtime/backend/runtime-values.d.ts +78 -0
- package/dist/runtime/backend/runtime-values.js +66 -0
- package/dist/runtime/channels/channel-autoconnect.d.ts +14 -0
- package/dist/runtime/channels/channel-autoconnect.js +23 -0
- package/dist/runtime/channels/channel-clients.d.ts +50 -0
- package/dist/runtime/channels/channel-clients.js +329 -0
- package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +76 -0
- package/dist/runtime/channels/channel-dispatch-pipeline.js +237 -0
- package/dist/runtime/channels/channel-dispatch-services.d.ts +52 -0
- package/dist/runtime/channels/channel-dispatch-services.js +132 -0
- package/dist/runtime/channels/channel-dispatchers.d.ts +125 -0
- package/dist/runtime/channels/channel-dispatchers.js +575 -0
- package/dist/runtime/channels/channel-envelope-inspection.d.ts +25 -0
- package/dist/runtime/channels/channel-envelope-inspection.js +96 -0
- package/dist/runtime/channels/channel-envelope.d.ts +73 -0
- package/dist/runtime/channels/channel-envelope.js +546 -0
- package/dist/runtime/channels/channel-framework-packets.d.ts +2 -0
- package/dist/runtime/channels/channel-framework-packets.js +6 -0
- package/dist/runtime/channels/channel-multipart.d.ts +16 -0
- package/dist/runtime/channels/channel-multipart.js +31 -0
- package/dist/runtime/channels/channel-outbound-operations.d.ts +33 -0
- package/dist/runtime/channels/channel-outbound-operations.js +343 -0
- package/dist/runtime/channels/channel-receive-loops.d.ts +151 -0
- package/dist/runtime/channels/channel-receive-loops.js +728 -0
- package/dist/runtime/channels/channel-receive-task-tracker.d.ts +14 -0
- package/dist/runtime/channels/channel-receive-task-tracker.js +37 -0
- package/dist/runtime/channels/channel-runtime-lifecycle.d.ts +77 -0
- package/dist/runtime/channels/channel-runtime-lifecycle.js +630 -0
- package/dist/runtime/channels/channel-runtime-manager.d.ts +84 -0
- package/dist/runtime/channels/channel-runtime-manager.js +193 -0
- package/dist/runtime/channels/channel-socket-options.d.ts +18 -0
- package/dist/runtime/channels/channel-socket-options.js +119 -0
- package/dist/runtime/channels/channel-socket-registry.d.ts +157 -0
- package/dist/runtime/channels/channel-socket-registry.js +1428 -0
- package/dist/runtime/channels/channel-transports.d.ts +126 -0
- package/dist/runtime/channels/channel-transports.js +448 -0
- package/dist/runtime/channels/client-server-location-runtime.d.ts +41 -0
- package/dist/runtime/channels/client-server-location-runtime.js +465 -0
- package/dist/runtime/channels/client-server-service-wire.d.ts +48 -0
- package/dist/runtime/channels/client-server-service-wire.js +306 -0
- package/dist/runtime/channels/dispatch-error-reporter.d.ts +22 -0
- package/dist/runtime/channels/dispatch-error-reporter.js +133 -0
- package/dist/runtime/channels/fanout-location-runtime.d.ts +38 -0
- package/dist/runtime/channels/fanout-location-runtime.js +356 -0
- package/dist/runtime/channels/fanout-service-wire.d.ts +12 -0
- package/dist/runtime/channels/fanout-service-wire.js +29 -0
- package/dist/runtime/channels/handler-filter-scope.d.ts +8 -0
- package/dist/runtime/channels/handler-filter-scope.js +11 -0
- package/dist/runtime/channels/index.d.ts +9 -0
- package/dist/runtime/channels/index.js +30 -0
- package/dist/runtime/channels/local-spot-route-transport.d.ts +9 -0
- package/dist/runtime/channels/local-spot-route-transport.js +40 -0
- package/dist/runtime/channels/route-disconnected-error.d.ts +3 -0
- package/dist/runtime/channels/route-disconnected-error.js +10 -0
- package/dist/runtime/channels/route-member-snapshot.d.ts +10 -0
- package/dist/runtime/channels/route-member-snapshot.js +55 -0
- package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +12 -0
- package/dist/runtime/channels/router-socket-spot-route-transport.js +43 -0
- package/dist/runtime/channels/source-spot-router.d.ts +10 -0
- package/dist/runtime/channels/source-spot-router.js +46 -0
- package/dist/runtime/channels/spot-direct-envelope.d.ts +5 -0
- package/dist/runtime/channels/spot-direct-envelope.js +29 -0
- package/dist/runtime/channels/spot-node-route-transport.d.ts +13 -0
- package/dist/runtime/channels/spot-node-route-transport.js +60 -0
- package/dist/runtime/channels/spot-route-bridge-transport.d.ts +14 -0
- package/dist/runtime/channels/spot-route-bridge-transport.js +58 -0
- package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +50 -0
- package/dist/runtime/channels/spot-route-dispatch-strategy.js +128 -0
- package/dist/runtime/channels/spot-route-target-resolver.d.ts +16 -0
- package/dist/runtime/channels/spot-route-target-resolver.js +92 -0
- package/dist/runtime/codecs/index.d.ts +14 -0
- package/dist/runtime/codecs/index.js +44 -0
- package/dist/runtime/configuration/index.d.ts +1 -0
- package/dist/runtime/configuration/index.js +17 -0
- package/dist/runtime/diagnostics/dispatch-error-port.d.ts +8 -0
- package/dist/runtime/diagnostics/dispatch-error-port.js +2 -0
- package/dist/runtime/diagnostics/flow-context.d.ts +21 -0
- package/dist/runtime/diagnostics/flow-context.js +68 -0
- package/dist/runtime/diagnostics/index.d.ts +82 -0
- package/dist/runtime/diagnostics/index.js +335 -0
- package/dist/runtime/diagnostics/internal-event-contracts.d.ts +139 -0
- package/dist/runtime/diagnostics/internal-event-contracts.js +68 -0
- package/dist/runtime/diagnostics/message-flow.d.ts +55 -0
- package/dist/runtime/diagnostics/message-flow.js +420 -0
- package/dist/runtime/diagnostics/runtime-metrics.d.ts +123 -0
- package/dist/runtime/diagnostics/runtime-metrics.js +454 -0
- package/dist/runtime/diagnostics/runtime-observation-queue.d.ts +58 -0
- package/dist/runtime/diagnostics/runtime-observation-queue.js +324 -0
- package/dist/runtime/diagnostics/topology-runtime-projections.d.ts +33 -0
- package/dist/runtime/diagnostics/topology-runtime-projections.js +255 -0
- package/dist/runtime/execution/index.d.ts +114 -0
- package/dist/runtime/execution/index.js +363 -0
- package/dist/runtime/execution/serial-execution-queue.d.ts +94 -0
- package/dist/runtime/execution/serial-execution-queue.js +411 -0
- package/dist/runtime/execution/serial-work-size.d.ts +4 -0
- package/dist/runtime/execution/serial-work-size.js +28 -0
- package/dist/runtime/execution/state-lane.d.ts +28 -0
- package/dist/runtime/execution/state-lane.js +105 -0
- package/dist/runtime/foundation/actor-join-recovery-codec.d.ts +72 -0
- package/dist/runtime/foundation/actor-join-recovery-codec.js +333 -0
- package/dist/runtime/foundation/event-loop-resources.d.ts +37 -0
- package/dist/runtime/foundation/event-loop-resources.js +163 -0
- package/dist/runtime/foundation/index.d.ts +18 -0
- package/dist/runtime/foundation/index.js +34 -0
- package/dist/runtime/foundation/message-follow-suppression-registry.d.ts +38 -0
- package/dist/runtime/foundation/message-follow-suppression-registry.js +89 -0
- package/dist/runtime/foundation/operation-identity.d.ts +12 -0
- package/dist/runtime/foundation/operation-identity.js +33 -0
- package/dist/runtime/foundation/operation-registry.d.ts +42 -0
- package/dist/runtime/foundation/operation-registry.js +146 -0
- package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +143 -0
- package/dist/runtime/foundation/raw-service-mesh-runtime.js +1349 -0
- package/dist/runtime/foundation/route-mesh-connection-policy.d.ts +3 -0
- package/dist/runtime/foundation/route-mesh-connection-policy.js +13 -0
- package/dist/runtime/foundation/runtime-state-projections.d.ts +13 -0
- package/dist/runtime/foundation/runtime-state-projections.js +44 -0
- package/dist/runtime/foundation/service-authority-payload-codec.d.ts +56 -0
- package/dist/runtime/foundation/service-authority-payload-codec.js +411 -0
- package/dist/runtime/foundation/service-discovery-registry.d.ts +42 -0
- package/dist/runtime/foundation/service-discovery-registry.js +175 -0
- package/dist/runtime/foundation/service-instance-activation-recovery-codec.d.ts +19 -0
- package/dist/runtime/foundation/service-instance-activation-recovery-codec.js +287 -0
- package/dist/runtime/foundation/service-liveness-registry.d.ts +28 -0
- package/dist/runtime/foundation/service-liveness-registry.js +109 -0
- package/dist/runtime/foundation/service-mailbox.d.ts +60 -0
- package/dist/runtime/foundation/service-mailbox.js +283 -0
- package/dist/runtime/foundation/service-maintenance-runtime.d.ts +45 -0
- package/dist/runtime/foundation/service-maintenance-runtime.js +198 -0
- package/dist/runtime/foundation/service-metadata-codec.d.ts +2 -0
- package/dist/runtime/foundation/service-metadata-codec.js +69 -0
- package/dist/runtime/foundation/service-relocation-aggregate-committer.d.ts +35 -0
- package/dist/runtime/foundation/service-relocation-aggregate-committer.js +139 -0
- package/dist/runtime/foundation/service-relocation-coordinator.d.ts +19 -0
- package/dist/runtime/foundation/service-relocation-coordinator.js +16 -0
- package/dist/runtime/foundation/service-relocation-object-owner.d.ts +71 -0
- package/dist/runtime/foundation/service-relocation-object-owner.js +242 -0
- package/dist/runtime/foundation/service-relocation-runtime.d.ts +143 -0
- package/dist/runtime/foundation/service-relocation-runtime.js +1080 -0
- package/dist/runtime/foundation/service-runtime-contracts.d.ts +332 -0
- package/dist/runtime/foundation/service-runtime-contracts.js +66 -0
- package/dist/runtime/foundation/service-session-binding-ingress-port.d.ts +23 -0
- package/dist/runtime/foundation/service-session-binding-ingress-port.js +11 -0
- package/dist/runtime/foundation/service-stateful-registry.d.ts +142 -0
- package/dist/runtime/foundation/service-stateful-registry.js +465 -0
- package/dist/runtime/foundation/service-stateful-runtime.d.ts +393 -0
- package/dist/runtime/foundation/service-stateful-runtime.js +3898 -0
- package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +597 -0
- package/dist/runtime/foundation/service-stateful-wire-codec.js +2006 -0
- package/dist/runtime/foundation/service-topology-registry.d.ts +68 -0
- package/dist/runtime/foundation/service-topology-registry.js +393 -0
- package/dist/runtime/foundation/service-weighted-selection.d.ts +14 -0
- package/dist/runtime/foundation/service-weighted-selection.js +128 -0
- package/dist/runtime/foundation/service-wire-binary-primitives.d.ts +10 -0
- package/dist/runtime/foundation/service-wire-binary-primitives.js +53 -0
- package/dist/runtime/foundation/service-wire-codec.d.ts +22 -0
- package/dist/runtime/foundation/service-wire-codec.js +67 -0
- package/dist/runtime/foundation/service-wire-constants.generated.d.ts +110 -0
- package/dist/runtime/foundation/service-wire-constants.generated.js +132 -0
- package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +102 -0
- package/dist/runtime/foundation/service-wire-m6a-codec.js +568 -0
- package/dist/runtime/framework-errors-internal.d.ts +95 -0
- package/dist/runtime/framework-errors-internal.js +301 -0
- package/dist/runtime/handlers/handler-instance-scope.d.ts +11 -0
- package/dist/runtime/handlers/handler-instance-scope.js +284 -0
- package/dist/runtime/handlers/index.d.ts +13 -0
- package/dist/runtime/handlers/index.js +57 -0
- package/dist/runtime/host/actor-packet-relay.d.ts +60 -0
- package/dist/runtime/host/actor-packet-relay.js +664 -0
- package/dist/runtime/host/actor-placement-coordinator.d.ts +32 -0
- package/dist/runtime/host/actor-placement-coordinator.js +386 -0
- package/dist/runtime/host/actor-runtime-options-factory.d.ts +65 -0
- package/dist/runtime/host/actor-runtime-options-factory.js +160 -0
- package/dist/runtime/host/actor-transfer-authority-runtime.d.ts +26 -0
- package/dist/runtime/host/actor-transfer-authority-runtime.js +138 -0
- package/dist/runtime/host/actor-transfer-runtime.d.ts +149 -0
- package/dist/runtime/host/actor-transfer-runtime.js +1245 -0
- package/dist/runtime/host/application-job-queue.d.ts +99 -0
- package/dist/runtime/host/application-job-queue.js +409 -0
- package/dist/runtime/host/bound-session-relay.d.ts +41 -0
- package/dist/runtime/host/bound-session-relay.js +52 -0
- package/dist/runtime/host/bounded-replay-map.d.ts +12 -0
- package/dist/runtime/host/bounded-replay-map.js +42 -0
- package/dist/runtime/host/channel-runtime-options-factory.d.ts +22 -0
- package/dist/runtime/host/channel-runtime-options-factory.js +76 -0
- package/dist/runtime/host/entry-actor-runtime.d.ts +30 -0
- package/dist/runtime/host/entry-actor-runtime.js +80 -0
- package/dist/runtime/host/host-capacity-status.d.ts +11 -0
- package/dist/runtime/host/host-capacity-status.js +85 -0
- package/dist/runtime/host/index.d.ts +188 -0
- package/dist/runtime/host/index.js +2552 -0
- package/dist/runtime/host/instance-activation-authority.d.ts +33 -0
- package/dist/runtime/host/instance-activation-authority.js +496 -0
- package/dist/runtime/host/location-runtime-owner.d.ts +48 -0
- package/dist/runtime/host/location-runtime-owner.js +227 -0
- package/dist/runtime/host/mesh-router-resolver.d.ts +16 -0
- package/dist/runtime/host/mesh-router-resolver.js +108 -0
- package/dist/runtime/host/relocation-direct-transfer.d.ts +81 -0
- package/dist/runtime/host/relocation-direct-transfer.js +240 -0
- package/dist/runtime/host/relocation-integrity-fault-gate.d.ts +6 -0
- package/dist/runtime/host/relocation-integrity-fault-gate.js +5 -0
- package/dist/runtime/host/relocation-state-adapter.d.ts +8 -0
- package/dist/runtime/host/relocation-state-adapter.js +13 -0
- package/dist/runtime/host/remote-actor-join-receiver.d.ts +47 -0
- package/dist/runtime/host/remote-actor-join-receiver.js +161 -0
- package/dist/runtime/host/remote-actor-packet-target-store.d.ts +29 -0
- package/dist/runtime/host/remote-actor-packet-target-store.js +185 -0
- package/dist/runtime/host/remote-bound-session-relay.d.ts +58 -0
- package/dist/runtime/host/remote-bound-session-relay.js +540 -0
- package/dist/runtime/host/route-mesh-runtime-options.d.ts +9 -0
- package/dist/runtime/host/route-mesh-runtime-options.js +41 -0
- package/dist/runtime/host/route-mesh-runtime.d.ts +76 -0
- package/dist/runtime/host/route-mesh-runtime.js +746 -0
- package/dist/runtime/host/runtime-shutdown.d.ts +33 -0
- package/dist/runtime/host/runtime-shutdown.js +68 -0
- package/dist/runtime/host/service-relocation-control.d.ts +7 -0
- package/dist/runtime/host/service-relocation-control.js +24 -0
- package/dist/runtime/host/service-relocation-host-runtime.d.ts +241 -0
- package/dist/runtime/host/service-relocation-host-runtime.js +4113 -0
- package/dist/runtime/host/spot-address-transport.d.ts +47 -0
- package/dist/runtime/host/spot-address-transport.js +601 -0
- package/dist/runtime/host/spot-node-runtime-options-factory.d.ts +38 -0
- package/dist/runtime/host/spot-node-runtime-options-factory.js +36 -0
- package/dist/runtime/host/spot-runtime-options-factory.d.ts +48 -0
- package/dist/runtime/host/spot-runtime-options-factory.js +169 -0
- package/dist/runtime/host/stateful-authority-route-runtime.d.ts +34 -0
- package/dist/runtime/host/stateful-authority-route-runtime.js +440 -0
- package/dist/runtime/host/user-spot-creation-coordinator.d.ts +69 -0
- package/dist/runtime/host/user-spot-creation-coordinator.js +759 -0
- package/dist/runtime/locations/actor-location-claims.d.ts +43 -0
- package/dist/runtime/locations/actor-location-claims.js +319 -0
- package/dist/runtime/locations/actor-session-route-claims.d.ts +10 -0
- package/dist/runtime/locations/actor-session-route-claims.js +51 -0
- package/dist/runtime/locations/aggregate-inventory-store.d.ts +18 -0
- package/dist/runtime/locations/aggregate-inventory-store.js +399 -0
- package/dist/runtime/locations/authority-key-codec.d.ts +6 -0
- package/dist/runtime/locations/authority-key-codec.js +78 -0
- package/dist/runtime/locations/auto-connect-loop.d.ts +37 -0
- package/dist/runtime/locations/auto-connect-loop.js +112 -0
- package/dist/runtime/locations/auto-connect-planner.d.ts +9 -0
- package/dist/runtime/locations/auto-connect-planner.js +137 -0
- package/dist/runtime/locations/auto-connect-reconciler.d.ts +57 -0
- package/dist/runtime/locations/auto-connect-reconciler.js +358 -0
- package/dist/runtime/locations/auto-connect-types.d.ts +42 -0
- package/dist/runtime/locations/auto-connect-types.js +2 -0
- package/dist/runtime/locations/auto-connect.d.ts +4 -0
- package/dist/runtime/locations/auto-connect.js +20 -0
- package/dist/runtime/locations/canonical-codec.d.ts +7 -0
- package/dist/runtime/locations/canonical-codec.js +48 -0
- package/dist/runtime/locations/domain-store-contract.d.ts +34 -0
- package/dist/runtime/locations/domain-store-contract.js +2 -0
- package/dist/runtime/locations/in-memory-authority-store.d.ts +51 -0
- package/dist/runtime/locations/in-memory-authority-store.js +895 -0
- package/dist/runtime/locations/in-memory-location-store.d.ts +78 -0
- package/dist/runtime/locations/in-memory-location-store.js +1008 -0
- package/dist/runtime/locations/in-memory-provider-location-store.d.ts +19 -0
- package/dist/runtime/locations/in-memory-provider-location-store.js +183 -0
- package/dist/runtime/locations/index.d.ts +11 -0
- package/dist/runtime/locations/index.js +27 -0
- package/dist/runtime/locations/internal-location-contracts.d.ts +7 -0
- package/dist/runtime/locations/internal-location-contracts.js +21 -0
- package/dist/runtime/locations/internal-store-contracts.d.ts +35 -0
- package/dist/runtime/locations/internal-store-contracts.js +2 -0
- package/dist/runtime/locations/key-codec.d.ts +13 -0
- package/dist/runtime/locations/key-codec.js +41 -0
- package/dist/runtime/locations/lease-tracker.d.ts +36 -0
- package/dist/runtime/locations/lease-tracker.js +155 -0
- package/dist/runtime/locations/lifecycle-runtime.d.ts +19 -0
- package/dist/runtime/locations/lifecycle-runtime.js +2 -0
- package/dist/runtime/locations/lifecycle.d.ts +40 -0
- package/dist/runtime/locations/lifecycle.js +120 -0
- package/dist/runtime/locations/location-store-repository.d.ts +72 -0
- package/dist/runtime/locations/location-store-repository.js +3198 -0
- package/dist/runtime/locations/relocation-blob.d.ts +7 -0
- package/dist/runtime/locations/relocation-blob.js +24 -0
- package/dist/runtime/locations/resolvers.d.ts +145 -0
- package/dist/runtime/locations/resolvers.js +693 -0
- package/dist/runtime/locations/runtime.d.ts +144 -0
- package/dist/runtime/locations/runtime.js +792 -0
- package/dist/runtime/locations/spot-location-claims.d.ts +36 -0
- package/dist/runtime/locations/spot-location-claims.js +305 -0
- package/dist/runtime/messaging/creation-payload-codec.d.ts +4 -0
- package/dist/runtime/messaging/creation-payload-codec.js +40 -0
- package/dist/runtime/messaging/framework-json-v1.d.ts +7 -0
- package/dist/runtime/messaging/framework-json-v1.js +296 -0
- package/dist/runtime/messaging/index.d.ts +1 -0
- package/dist/runtime/messaging/index.js +2 -0
- package/dist/runtime/messaging/packet-name.d.ts +4 -0
- package/dist/runtime/messaging/packet-name.js +79 -0
- package/dist/runtime/messaging/payload-codec.d.ts +25 -0
- package/dist/runtime/messaging/payload-codec.js +255 -0
- package/dist/runtime/messaging/submission-result.d.ts +15 -0
- package/dist/runtime/messaging/submission-result.js +37 -0
- package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +395 -0
- package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +645 -0
- package/dist/runtime/routing-id.d.ts +8 -0
- package/dist/runtime/routing-id.js +112 -0
- package/dist/runtime/spots/formal-remote-actor-admission-registry.d.ts +124 -0
- package/dist/runtime/spots/formal-remote-actor-admission-registry.js +269 -0
- package/dist/runtime/spots/formal-remote-actor-transfer-registry.d.ts +33 -0
- package/dist/runtime/spots/formal-remote-actor-transfer-registry.js +94 -0
- package/dist/runtime/spots/index.d.ts +247 -0
- package/dist/runtime/spots/index.js +2090 -0
- package/dist/runtime/spots/spot-activation-registry.d.ts +47 -0
- package/dist/runtime/spots/spot-activation-registry.js +272 -0
- package/dist/runtime/spots/spot-activation-state.d.ts +104 -0
- package/dist/runtime/spots/spot-activation-state.js +288 -0
- package/dist/runtime/spots/spot-activation.d.ts +89 -0
- package/dist/runtime/spots/spot-activation.js +601 -0
- package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +20 -0
- package/dist/runtime/spots/spot-actor-admission-coordinator.js +194 -0
- package/dist/runtime/spots/spot-actor-join-dispatch.d.ts +83 -0
- package/dist/runtime/spots/spot-actor-join-dispatch.js +185 -0
- package/dist/runtime/spots/spot-actor-lifecycle-drain.d.ts +22 -0
- package/dist/runtime/spots/spot-actor-lifecycle-drain.js +51 -0
- package/dist/runtime/spots/spot-actor-membership.d.ts +39 -0
- package/dist/runtime/spots/spot-actor-membership.js +179 -0
- package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +91 -0
- package/dist/runtime/spots/spot-actor-packet-dispatch.js +315 -0
- package/dist/runtime/spots/spot-actor-packet-drain.d.ts +40 -0
- package/dist/runtime/spots/spot-actor-packet-drain.js +235 -0
- package/dist/runtime/spots/spot-actor-packet-relay-dispatch.d.ts +18 -0
- package/dist/runtime/spots/spot-actor-packet-relay-dispatch.js +110 -0
- package/dist/runtime/spots/spot-closing.d.ts +2 -0
- package/dist/runtime/spots/spot-closing.js +30 -0
- package/dist/runtime/spots/spot-context.d.ts +46 -0
- package/dist/runtime/spots/spot-context.js +113 -0
- package/dist/runtime/spots/spot-entry-activation.d.ts +107 -0
- package/dist/runtime/spots/spot-entry-activation.js +342 -0
- package/dist/runtime/spots/spot-handle.d.ts +28 -0
- package/dist/runtime/spots/spot-handle.js +38 -0
- package/dist/runtime/spots/spot-handler-registry.d.ts +52 -0
- package/dist/runtime/spots/spot-handler-registry.js +155 -0
- package/dist/runtime/spots/spot-lifecycle-metrics.d.ts +8 -0
- package/dist/runtime/spots/spot-lifecycle-metrics.js +16 -0
- package/dist/runtime/spots/spot-location-claim.d.ts +25 -0
- package/dist/runtime/spots/spot-location-claim.js +55 -0
- package/dist/runtime/spots/spot-manager-internal-contracts.d.ts +10 -0
- package/dist/runtime/spots/spot-manager-internal-contracts.js +2 -0
- package/dist/runtime/spots/spot-manager-public.d.ts +32 -0
- package/dist/runtime/spots/spot-manager-public.js +219 -0
- package/dist/runtime/spots/spot-native-actor-join-admission.d.ts +26 -0
- package/dist/runtime/spots/spot-native-actor-join-admission.js +105 -0
- package/dist/runtime/spots/spot-native-flags.d.ts +2 -0
- package/dist/runtime/spots/spot-native-flags.js +5 -0
- package/dist/runtime/spots/spot-node-autoconnect.d.ts +23 -0
- package/dist/runtime/spots/spot-node-autoconnect.js +246 -0
- package/dist/runtime/spots/spot-node-runtime-manager.d.ts +137 -0
- package/dist/runtime/spots/spot-node-runtime-manager.js +1111 -0
- package/dist/runtime/spots/spot-outbound.d.ts +78 -0
- package/dist/runtime/spots/spot-outbound.js +460 -0
- package/dist/runtime/spots/spot-provider.d.ts +4 -0
- package/dist/runtime/spots/spot-provider.js +28 -0
- package/dist/runtime/spots/spot-publisher-transport.d.ts +14 -0
- package/dist/runtime/spots/spot-publisher-transport.js +28 -0
- package/dist/runtime/spots/spot-remote-codec.d.ts +50 -0
- package/dist/runtime/spots/spot-remote-codec.js +190 -0
- package/dist/runtime/spots/spot-remote-route-codec.d.ts +47 -0
- package/dist/runtime/spots/spot-remote-route-codec.js +168 -0
- package/dist/runtime/spots/spot-route-packet-dispatch.d.ts +25 -0
- package/dist/runtime/spots/spot-route-packet-dispatch.js +238 -0
- package/dist/runtime/spots/spot-route-replies.d.ts +17 -0
- package/dist/runtime/spots/spot-route-replies.js +76 -0
- package/dist/runtime/spots/spot-route-reply-wire.d.ts +10 -0
- package/dist/runtime/spots/spot-route-reply-wire.js +6 -0
- package/dist/runtime/spots/spot-routed-actor-admission.d.ts +36 -0
- package/dist/runtime/spots/spot-routed-actor-admission.js +240 -0
- package/dist/runtime/spots/spot-routed-bound-session-dispatch.d.ts +19 -0
- package/dist/runtime/spots/spot-routed-bound-session-dispatch.js +46 -0
- package/dist/runtime/spots/spot-routed-frame-dispatch.d.ts +54 -0
- package/dist/runtime/spots/spot-routed-frame-dispatch.js +162 -0
- package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +43 -0
- package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +152 -0
- package/dist/runtime/spots/spot-routing-internal.d.ts +28 -0
- package/dist/runtime/spots/spot-routing-internal.js +2 -0
- package/dist/runtime/spots/spot-runtime-ports.d.ts +64 -0
- package/dist/runtime/spots/spot-runtime-ports.js +2 -0
- package/dist/runtime/spots/spot-serial-executor.d.ts +38 -0
- package/dist/runtime/spots/spot-serial-executor.js +133 -0
- package/dist/runtime/spots/spot-serial-turn-executor.d.ts +54 -0
- package/dist/runtime/spots/spot-serial-turn-executor.js +219 -0
- package/dist/runtime/spots/spot-subscription-dispatch.d.ts +32 -0
- package/dist/runtime/spots/spot-subscription-dispatch.js +194 -0
- package/dist/runtime/spots/spot-timer.d.ts +110 -0
- package/dist/runtime/spots/spot-timer.js +419 -0
- package/dist/runtime/streams/actor-session-binding-registry.d.ts +193 -0
- package/dist/runtime/streams/actor-session-binding-registry.js +1127 -0
- package/dist/runtime/streams/actor-session-binding-runtime-owner.d.ts +20 -0
- package/dist/runtime/streams/actor-session-binding-runtime-owner.js +19 -0
- package/dist/runtime/streams/actor-session-lifecycle-coordinator.d.ts +4 -0
- package/dist/runtime/streams/actor-session-lifecycle-coordinator.js +24 -0
- package/dist/runtime/streams/bound-actor-relay-sender.d.ts +29 -0
- package/dist/runtime/streams/bound-actor-relay-sender.js +181 -0
- package/dist/runtime/streams/bound-session-response-target.d.ts +25 -0
- package/dist/runtime/streams/bound-session-response-target.js +54 -0
- package/dist/runtime/streams/bound-session-service.d.ts +48 -0
- package/dist/runtime/streams/bound-session-service.js +201 -0
- package/dist/runtime/streams/index.d.ts +152 -0
- package/dist/runtime/streams/index.js +338 -0
- package/dist/runtime/streams/managed-stream.d.ts +53 -0
- package/dist/runtime/streams/managed-stream.js +329 -0
- package/dist/runtime/streams/native-fallback-bound-session.d.ts +24 -0
- package/dist/runtime/streams/native-fallback-bound-session.js +201 -0
- package/dist/runtime/streams/protocol.d.ts +67 -0
- package/dist/runtime/streams/protocol.js +244 -0
- package/dist/runtime/streams/session-actor-coordinator.d.ts +56 -0
- package/dist/runtime/streams/session-actor-coordinator.js +371 -0
- package/dist/runtime/streams/session-calls.d.ts +59 -0
- package/dist/runtime/streams/session-calls.js +123 -0
- package/dist/runtime/streams/session-context.d.ts +108 -0
- package/dist/runtime/streams/session-context.js +377 -0
- package/dist/runtime/streams/session-local-actors.d.ts +10 -0
- package/dist/runtime/streams/session-local-actors.js +26 -0
- package/dist/runtime/streams/session-provider.d.ts +4 -0
- package/dist/runtime/streams/session-provider.js +30 -0
- package/dist/runtime/streams/session-requests.d.ts +25 -0
- package/dist/runtime/streams/session-requests.js +100 -0
- package/dist/runtime/streams/session-serial-executor.d.ts +12 -0
- package/dist/runtime/streams/session-serial-executor.js +58 -0
- package/dist/runtime/streams/stream-binding-runtime-ports.d.ts +62 -0
- package/dist/runtime/streams/stream-binding-runtime-ports.js +2 -0
- package/dist/runtime/streams/stream-frame-factory.d.ts +44 -0
- package/dist/runtime/streams/stream-frame-factory.js +149 -0
- package/dist/runtime/streams/stream-message-utils.d.ts +5 -0
- package/dist/runtime/streams/stream-message-utils.js +74 -0
- package/dist/runtime/streams/stream-session-runtime.d.ts +166 -0
- package/dist/runtime/streams/stream-session-runtime.js +1144 -0
- package/dist/runtime/workers/index.d.ts +38 -0
- package/dist/runtime/workers/index.js +474 -0
- package/package.json +19 -0
- package/src/contracts/Actors/ZLinkActor.ts +8 -0
- package/src/contracts/Actors/ZLinkActorClient.ts +18 -0
- package/src/contracts/Actors/ZLinkActorContext.ts +15 -0
- package/src/contracts/Actors/ZLinkActorFactory.ts +41 -0
- package/src/contracts/Actors/ZLinkActorManager.ts +31 -0
- package/src/contracts/Actors/index.ts +5 -0
- package/src/contracts/Channels/Calls.ts +33 -0
- package/src/contracts/Channels/IZLinkChannelClient.ts +6 -0
- package/src/contracts/Channels/IZLinkFanoutClient.ts +13 -0
- package/src/contracts/Channels/RouteCalls.ts +13 -0
- package/src/contracts/Channels/index.ts +4 -0
- package/src/contracts/Codecs/IZLinkCodecRegistryBuilder.ts +22 -0
- package/src/contracts/Codecs/ZLinkMessageSerializer.ts +6 -0
- package/src/contracts/Codecs/index.ts +2 -0
- package/src/contracts/Common/ActorRef.ts +8 -0
- package/src/contracts/Common/CoreTypes.ts +6 -0
- package/src/contracts/Common/Message.ts +9 -0
- package/src/contracts/Common/ZLinkEncodedPayload.ts +47 -0
- package/src/contracts/Common/ZLinkMessage.ts +135 -0
- package/src/contracts/Common/ZLinkMessageMetadata.ts +77 -0
- package/src/contracts/Common/ZLinkProviderResolver.ts +6 -0
- package/src/contracts/Common/encoded-payload-storage.ts +16 -0
- package/src/contracts/Common/index.ts +5 -0
- package/src/contracts/Configuration/Builders.ts +200 -0
- package/src/contracts/Configuration/CodecContentType.ts +68 -0
- package/src/contracts/Configuration/CodecSerializerSelection.ts +28 -0
- package/src/contracts/Configuration/Configs.ts +27 -0
- package/src/contracts/Configuration/ConfigurationException.ts +6 -0
- package/src/contracts/Configuration/Connections.ts +5 -0
- package/src/contracts/Configuration/DiagnosticsValidation.ts +25 -0
- package/src/contracts/Configuration/EndpointNotation.ts +232 -0
- package/src/contracts/Configuration/InternalDefaults.ts +13 -0
- package/src/contracts/Configuration/ObjectRoles.ts +47 -0
- package/src/contracts/Configuration/Registration.ts +191 -0
- package/src/contracts/Configuration/RegistrationBuilderPolicy.ts +76 -0
- package/src/contracts/Configuration/RegistrationBuilders.ts +1705 -0
- package/src/contracts/Configuration/RegistrationCodecRegistry.ts +118 -0
- package/src/contracts/Configuration/RegistrationNormalizers.ts +404 -0
- package/src/contracts/Configuration/RegistrationTypes.ts +499 -0
- package/src/contracts/Configuration/RegistrationValidators.ts +698 -0
- package/src/contracts/Configuration/RouteChannelInternalState.ts +50 -0
- package/src/contracts/Configuration/RuntimeEndpointConnections.ts +91 -0
- package/src/contracts/Configuration/SendTimeoutValidation.ts +15 -0
- package/src/contracts/Configuration/TimerRegistrationValidator.ts +37 -0
- package/src/contracts/Configuration/index.ts +35 -0
- package/src/contracts/Dispatch/ZLinkDispatchOptions.ts +222 -0
- package/src/contracts/Dispatch/ZLinkFlowOrigin.ts +1 -0
- package/src/contracts/Dispatch/index.ts +2 -0
- package/src/contracts/Errors/ZLinkFrameworkException.ts +27 -0
- package/src/contracts/Errors/index.ts +4 -0
- package/src/contracts/Eventing/Metrics.ts +27 -0
- package/src/contracts/Eventing/index.ts +1 -0
- package/src/contracts/Handlers/Attributes.ts +111 -0
- package/src/contracts/Handlers/Contexts.ts +21 -0
- package/src/contracts/Handlers/IZLinkChannelHandlers.ts +69 -0
- package/src/contracts/Handlers/IZLinkHandlerFilter.ts +22 -0
- package/src/contracts/Handlers/JsonContract.ts +172 -0
- package/src/contracts/Handlers/ZLinkHandlerFilterNext.ts +1 -0
- package/src/contracts/Handlers/index.ts +17 -0
- package/src/contracts/Locations/ActorTransfer.ts +84 -0
- package/src/contracts/Locations/Authority.ts +308 -0
- package/src/contracts/Locations/Diagnostics.ts +48 -0
- package/src/contracts/Locations/Keys.ts +93 -0
- package/src/contracts/Locations/Models.ts +7 -0
- package/src/contracts/Locations/Options.ts +42 -0
- package/src/contracts/Locations/Readiness.ts +11 -0
- package/src/contracts/Locations/RelocationStore.ts +51 -0
- package/src/contracts/Locations/Resolvers.ts +8 -0
- package/src/contracts/Locations/Rows.ts +164 -0
- package/src/contracts/Locations/RuntimeQuery.ts +56 -0
- package/src/contracts/Locations/Stores.ts +92 -0
- package/src/contracts/Locations/Values.ts +32 -0
- package/src/contracts/Locations/Watch.ts +16 -0
- package/src/contracts/Locations/Writes.ts +56 -0
- package/src/contracts/Locations/index.ts +48 -0
- package/src/contracts/RouteMesh/Contracts.ts +145 -0
- package/src/contracts/RouteMesh/RuntimeTopology.ts +201 -0
- package/src/contracts/RouteMesh/index.ts +2 -0
- package/src/contracts/Spots/Builders.ts +11 -0
- package/src/contracts/Spots/Contracts.ts +150 -0
- package/src/contracts/Spots/SpotKind.ts +24 -0
- package/src/contracts/Spots/ZLinkSpot.ts +88 -0
- package/src/contracts/Spots/index.ts +3 -0
- package/src/contracts/Streams/BoundSessionContracts.ts +9 -0
- package/src/contracts/Streams/IZLinkSession.ts +52 -0
- package/src/contracts/Streams/IZLinkSessionActor.ts +17 -0
- package/src/contracts/Streams/IZLinkSessionPacketHandler.ts +11 -0
- package/src/contracts/Streams/IZLinkStream.ts +10 -0
- package/src/contracts/Streams/ZLinkMessageMetadata.ts +1 -0
- package/src/contracts/Streams/ZLinkStreamCompression.ts +9 -0
- package/src/contracts/Streams/ZLinkStreamError.ts +9 -0
- package/src/contracts/Streams/index.ts +8 -0
- package/src/contracts/Timers/IZLinkTimer.ts +5 -0
- package/src/contracts/Timers/ZLinkTimerOptions.ts +11 -0
- package/src/contracts/Timers/ZLinkTimerTick.ts +12 -0
- package/src/contracts/Timers/index.ts +3 -0
- package/src/contracts/index.ts +71 -0
- package/src/index.ts +1 -0
- package/src/internal.ts +29 -0
- package/src/location-store-integration.ts +51 -0
- package/src/nest-integration.ts +251 -0
- package/src/runtime/abort.ts +70 -0
- package/src/runtime/actors/actor-authority-payload-codec.ts +454 -0
- package/src/runtime/actors/actor-authority-publication.ts +277 -0
- package/src/runtime/actors/actor-client.ts +1018 -0
- package/src/runtime/actors/actor-context.ts +583 -0
- package/src/runtime/actors/actor-creation.ts +254 -0
- package/src/runtime/actors/actor-execution-context.ts +38 -0
- package/src/runtime/actors/actor-handoff.ts +1911 -0
- package/src/runtime/actors/actor-join-deferred-scope.ts +183 -0
- package/src/runtime/actors/actor-join-relocation.ts +39 -0
- package/src/runtime/actors/actor-lifecycle-snapshot.ts +90 -0
- package/src/runtime/actors/actor-local-native-join.ts +725 -0
- package/src/runtime/actors/actor-mailbox.ts +92 -0
- package/src/runtime/actors/actor-message-follow-context.ts +347 -0
- package/src/runtime/actors/actor-native-lookup.ts +38 -0
- package/src/runtime/actors/actor-packet-relay-wire.ts +223 -0
- package/src/runtime/actors/actor-remote-joiner.ts +238 -0
- package/src/runtime/actors/actor-remote-wire.ts +169 -0
- package/src/runtime/actors/actor-retry-delay.ts +37 -0
- package/src/runtime/actors/actor-routed-join-transport.ts +58 -0
- package/src/runtime/actors/actor-routed-json-request.ts +44 -0
- package/src/runtime/actors/actor-runtime-contracts.ts +126 -0
- package/src/runtime/actors/actor-runtime-state.ts +805 -0
- package/src/runtime/actors/actor-source-transfer.ts +62 -0
- package/src/runtime/actors/actor-transfer-registry.ts +112 -0
- package/src/runtime/actors/actor-transport-delivery-gate.ts +17 -0
- package/src/runtime/actors/bound-session-wire.ts +257 -0
- package/src/runtime/actors/deferred-join-accepted-journal.ts +1319 -0
- package/src/runtime/actors/index.ts +972 -0
- package/src/runtime/actors/post-commit-actor-binder.ts +70 -0
- package/src/runtime/actors/post-commit-actor-location.ts +114 -0
- package/src/runtime/actors/spot-actor-dispatch.ts +362 -0
- package/src/runtime/actors/transferred-actor-rollback.ts +123 -0
- package/src/runtime/admission.ts +192 -0
- package/src/runtime/application-jobs/application-ingress-record-owner.ts +216 -0
- package/src/runtime/application-jobs/application-job-queue-handler-start-gate.ts +10 -0
- package/src/runtime/application-jobs/application-job-queue-scope.ts +64 -0
- package/src/runtime/application-jobs/contracts.ts +26 -0
- package/src/runtime/application-jobs/receive-flow-controller.ts +188 -0
- package/src/runtime/backend/contracts/index.ts +765 -0
- package/src/runtime/backend/index.ts +9 -0
- package/src/runtime/backend/mesh-actor-session-node-adapter.ts +73 -0
- package/src/runtime/backend/mesh-completion-table.ts +165 -0
- package/src/runtime/backend/mesh-dispatch-pump.ts +363 -0
- package/src/runtime/backend/mesh-record-dispatcher.ts +65 -0
- package/src/runtime/backend/node/index.ts +4 -0
- package/src/runtime/backend/node/node-backend-adapter-factory.ts +204 -0
- package/src/runtime/backend/node/node-backend-adapter-support.ts +257 -0
- package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +133 -0
- package/src/runtime/backend/node/node-mesh-backend-adapter.ts +44 -0
- package/src/runtime/backend/node/node-monitor-backend-adapter.ts +39 -0
- package/src/runtime/backend/node/node-raw-binding-port.contract.ts +21 -0
- package/src/runtime/backend/node/node-raw-binding-port.ts +518 -0
- package/src/runtime/backend/node/node-raw-mesh-backend.ts +2669 -0
- package/src/runtime/backend/node/node-socket-backend-adapter.ts +372 -0
- package/src/runtime/backend/node-backend-adapter.ts +19 -0
- package/src/runtime/backend/raw-binding-port.ts +69 -0
- package/src/runtime/backend/runtime-message.ts +51 -0
- package/src/runtime/backend/runtime-values.ts +107 -0
- package/src/runtime/channels/channel-autoconnect.ts +46 -0
- package/src/runtime/channels/channel-clients.ts +527 -0
- package/src/runtime/channels/channel-dispatch-pipeline.ts +408 -0
- package/src/runtime/channels/channel-dispatch-services.ts +234 -0
- package/src/runtime/channels/channel-dispatchers.ts +790 -0
- package/src/runtime/channels/channel-envelope-inspection.ts +125 -0
- package/src/runtime/channels/channel-envelope.ts +743 -0
- package/src/runtime/channels/channel-framework-packets.ts +8 -0
- package/src/runtime/channels/channel-multipart.ts +61 -0
- package/src/runtime/channels/channel-outbound-operations.ts +584 -0
- package/src/runtime/channels/channel-receive-loops.ts +901 -0
- package/src/runtime/channels/channel-receive-task-tracker.ts +39 -0
- package/src/runtime/channels/channel-runtime-lifecycle.ts +969 -0
- package/src/runtime/channels/channel-runtime-manager.ts +444 -0
- package/src/runtime/channels/channel-socket-options.ts +153 -0
- package/src/runtime/channels/channel-socket-registry.ts +1837 -0
- package/src/runtime/channels/channel-transports.ts +1154 -0
- package/src/runtime/channels/client-server-location-runtime.ts +576 -0
- package/src/runtime/channels/client-server-service-wire.ts +390 -0
- package/src/runtime/channels/dispatch-error-reporter.ts +165 -0
- package/src/runtime/channels/fanout-location-runtime.ts +459 -0
- package/src/runtime/channels/fanout-service-wire.ts +43 -0
- package/src/runtime/channels/handler-filter-scope.ts +29 -0
- package/src/runtime/channels/index.ts +45 -0
- package/src/runtime/channels/local-spot-route-transport.ts +59 -0
- package/src/runtime/channels/route-disconnected-error.ts +6 -0
- package/src/runtime/channels/route-member-snapshot.ts +55 -0
- package/src/runtime/channels/router-socket-spot-route-transport.ts +77 -0
- package/src/runtime/channels/source-spot-router.ts +89 -0
- package/src/runtime/channels/spot-direct-envelope.ts +44 -0
- package/src/runtime/channels/spot-node-route-transport.ts +92 -0
- package/src/runtime/channels/spot-route-bridge-transport.ts +75 -0
- package/src/runtime/channels/spot-route-dispatch-strategy.ts +329 -0
- package/src/runtime/channels/spot-route-target-resolver.ts +101 -0
- package/src/runtime/codecs/index.ts +69 -0
- package/src/runtime/configuration/index.ts +1 -0
- package/src/runtime/diagnostics/dispatch-error-port.ts +8 -0
- package/src/runtime/diagnostics/flow-context.ts +84 -0
- package/src/runtime/diagnostics/index.ts +441 -0
- package/src/runtime/diagnostics/internal-event-contracts.ts +135 -0
- package/src/runtime/diagnostics/message-flow.ts +560 -0
- package/src/runtime/diagnostics/runtime-metrics.ts +601 -0
- package/src/runtime/diagnostics/runtime-observation-queue.ts +362 -0
- package/src/runtime/diagnostics/topology-runtime-projections.ts +298 -0
- package/src/runtime/execution/index.ts +466 -0
- package/src/runtime/execution/serial-execution-queue.ts +534 -0
- package/src/runtime/execution/serial-work-size.ts +31 -0
- package/src/runtime/execution/state-lane.ts +116 -0
- package/src/runtime/foundation/actor-join-recovery-codec.ts +465 -0
- package/src/runtime/foundation/event-loop-resources.ts +162 -0
- package/src/runtime/foundation/index.ts +18 -0
- package/src/runtime/foundation/message-follow-suppression-registry.ts +130 -0
- package/src/runtime/foundation/operation-identity.ts +49 -0
- package/src/runtime/foundation/operation-registry.ts +162 -0
- package/src/runtime/foundation/raw-service-mesh-runtime.ts +1771 -0
- package/src/runtime/foundation/route-mesh-connection-policy.ts +28 -0
- package/src/runtime/foundation/runtime-state-projections.ts +68 -0
- package/src/runtime/foundation/service-authority-payload-codec.ts +566 -0
- package/src/runtime/foundation/service-discovery-registry.ts +263 -0
- package/src/runtime/foundation/service-instance-activation-recovery-codec.ts +329 -0
- package/src/runtime/foundation/service-liveness-registry.ts +144 -0
- package/src/runtime/foundation/service-mailbox.ts +369 -0
- package/src/runtime/foundation/service-maintenance-runtime.ts +242 -0
- package/src/runtime/foundation/service-metadata-codec.ts +75 -0
- package/src/runtime/foundation/service-relocation-aggregate-committer.ts +218 -0
- package/src/runtime/foundation/service-relocation-coordinator.ts +37 -0
- package/src/runtime/foundation/service-relocation-object-owner.ts +428 -0
- package/src/runtime/foundation/service-relocation-runtime.ts +1407 -0
- package/src/runtime/foundation/service-runtime-contracts.ts +423 -0
- package/src/runtime/foundation/service-session-binding-ingress-port.ts +45 -0
- package/src/runtime/foundation/service-stateful-registry.ts +664 -0
- package/src/runtime/foundation/service-stateful-runtime.ts +5753 -0
- package/src/runtime/foundation/service-stateful-wire-codec.ts +3008 -0
- package/src/runtime/foundation/service-topology-registry.ts +599 -0
- package/src/runtime/foundation/service-weighted-selection.ts +166 -0
- package/src/runtime/foundation/service-wire-binary-primitives.ts +80 -0
- package/src/runtime/foundation/service-wire-codec.ts +91 -0
- package/src/runtime/foundation/service-wire-constants.generated.ts +131 -0
- package/src/runtime/foundation/service-wire-m6a-codec.ts +647 -0
- package/src/runtime/framework-errors-internal.ts +338 -0
- package/src/runtime/handlers/handler-instance-scope.ts +372 -0
- package/src/runtime/handlers/index.ts +93 -0
- package/src/runtime/host/actor-packet-relay.ts +1070 -0
- package/src/runtime/host/actor-placement-coordinator.ts +573 -0
- package/src/runtime/host/actor-runtime-options-factory.ts +282 -0
- package/src/runtime/host/actor-transfer-authority-runtime.ts +225 -0
- package/src/runtime/host/actor-transfer-runtime.ts +1958 -0
- package/src/runtime/host/application-job-queue.ts +518 -0
- package/src/runtime/host/bound-session-relay.ts +94 -0
- package/src/runtime/host/bounded-replay-map.ts +42 -0
- package/src/runtime/host/channel-runtime-options-factory.ts +104 -0
- package/src/runtime/host/entry-actor-runtime.ts +115 -0
- package/src/runtime/host/host-capacity-status.ts +103 -0
- package/src/runtime/host/index.ts +3492 -0
- package/src/runtime/host/instance-activation-authority.ts +658 -0
- package/src/runtime/host/location-runtime-owner.ts +313 -0
- package/src/runtime/host/mesh-router-resolver.ts +114 -0
- package/src/runtime/host/relocation-direct-transfer.ts +273 -0
- package/src/runtime/host/relocation-integrity-fault-gate.ts +8 -0
- package/src/runtime/host/relocation-state-adapter.ts +24 -0
- package/src/runtime/host/remote-actor-join-receiver.ts +264 -0
- package/src/runtime/host/remote-actor-packet-target-store.ts +244 -0
- package/src/runtime/host/remote-bound-session-relay.ts +900 -0
- package/src/runtime/host/route-mesh-runtime-options.ts +46 -0
- package/src/runtime/host/route-mesh-runtime.ts +891 -0
- package/src/runtime/host/runtime-shutdown.ts +101 -0
- package/src/runtime/host/service-relocation-control.ts +28 -0
- package/src/runtime/host/service-relocation-host-runtime.ts +5817 -0
- package/src/runtime/host/spot-address-transport.ts +997 -0
- package/src/runtime/host/spot-node-runtime-options-factory.ts +82 -0
- package/src/runtime/host/spot-runtime-options-factory.ts +286 -0
- package/src/runtime/host/stateful-authority-route-runtime.ts +662 -0
- package/src/runtime/host/user-spot-creation-coordinator.ts +1176 -0
- package/src/runtime/locations/actor-location-claims.ts +426 -0
- package/src/runtime/locations/actor-session-route-claims.ts +64 -0
- package/src/runtime/locations/aggregate-inventory-store.ts +581 -0
- package/src/runtime/locations/authority-key-codec.ts +80 -0
- package/src/runtime/locations/auto-connect-loop.ts +131 -0
- package/src/runtime/locations/auto-connect-planner.ts +178 -0
- package/src/runtime/locations/auto-connect-reconciler.ts +425 -0
- package/src/runtime/locations/auto-connect-types.ts +62 -0
- package/src/runtime/locations/auto-connect.ts +4 -0
- package/src/runtime/locations/canonical-codec.ts +54 -0
- package/src/runtime/locations/domain-store-contract.ts +149 -0
- package/src/runtime/locations/in-memory-authority-store.ts +1172 -0
- package/src/runtime/locations/in-memory-location-store.ts +1467 -0
- package/src/runtime/locations/in-memory-provider-location-store.ts +213 -0
- package/src/runtime/locations/index.ts +11 -0
- package/src/runtime/locations/internal-location-contracts.ts +22 -0
- package/src/runtime/locations/internal-store-contracts.ts +90 -0
- package/src/runtime/locations/key-codec.ts +61 -0
- package/src/runtime/locations/lease-tracker.ts +221 -0
- package/src/runtime/locations/lifecycle-runtime.ts +44 -0
- package/src/runtime/locations/lifecycle.ts +272 -0
- package/src/runtime/locations/location-store-repository.ts +4211 -0
- package/src/runtime/locations/relocation-blob.ts +36 -0
- package/src/runtime/locations/resolvers.ts +1054 -0
- package/src/runtime/locations/runtime.ts +1126 -0
- package/src/runtime/locations/spot-location-claims.ts +435 -0
- package/src/runtime/messaging/creation-payload-codec.ts +59 -0
- package/src/runtime/messaging/framework-json-v1.ts +307 -0
- package/src/runtime/messaging/index.ts +1 -0
- package/src/runtime/messaging/packet-name.ts +94 -0
- package/src/runtime/messaging/payload-codec.ts +418 -0
- package/src/runtime/messaging/submission-result.ts +61 -0
- package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +189 -0
- package/src/runtime/routing-id.ts +125 -0
- package/src/runtime/spots/formal-remote-actor-admission-registry.ts +418 -0
- package/src/runtime/spots/formal-remote-actor-transfer-registry.ts +147 -0
- package/src/runtime/spots/index.ts +3303 -0
- package/src/runtime/spots/spot-activation-registry.ts +335 -0
- package/src/runtime/spots/spot-activation-state.ts +414 -0
- package/src/runtime/spots/spot-activation.ts +1027 -0
- package/src/runtime/spots/spot-actor-admission-coordinator.ts +354 -0
- package/src/runtime/spots/spot-actor-join-dispatch.ts +303 -0
- package/src/runtime/spots/spot-actor-lifecycle-drain.ts +79 -0
- package/src/runtime/spots/spot-actor-membership.ts +266 -0
- package/src/runtime/spots/spot-actor-packet-dispatch.ts +593 -0
- package/src/runtime/spots/spot-actor-packet-drain.ts +328 -0
- package/src/runtime/spots/spot-actor-packet-relay-dispatch.ts +162 -0
- package/src/runtime/spots/spot-closing.ts +34 -0
- package/src/runtime/spots/spot-context.ts +259 -0
- package/src/runtime/spots/spot-entry-activation.ts +551 -0
- package/src/runtime/spots/spot-handle.ts +101 -0
- package/src/runtime/spots/spot-handler-registry.ts +273 -0
- package/src/runtime/spots/spot-lifecycle-metrics.ts +15 -0
- package/src/runtime/spots/spot-location-claim.ts +86 -0
- package/src/runtime/spots/spot-manager-internal-contracts.ts +11 -0
- package/src/runtime/spots/spot-manager-public.ts +361 -0
- package/src/runtime/spots/spot-native-actor-join-admission.ts +151 -0
- package/src/runtime/spots/spot-native-flags.ts +4 -0
- package/src/runtime/spots/spot-node-autoconnect.ts +325 -0
- package/src/runtime/spots/spot-node-runtime-manager.ts +1573 -0
- package/src/runtime/spots/spot-outbound.ts +761 -0
- package/src/runtime/spots/spot-provider.ts +36 -0
- package/src/runtime/spots/spot-publisher-transport.ts +69 -0
- package/src/runtime/spots/spot-remote-codec.ts +308 -0
- package/src/runtime/spots/spot-remote-route-codec.ts +284 -0
- package/src/runtime/spots/spot-route-packet-dispatch.ts +359 -0
- package/src/runtime/spots/spot-route-replies.ts +126 -0
- package/src/runtime/spots/spot-route-reply-wire.ts +15 -0
- package/src/runtime/spots/spot-routed-actor-admission.ts +351 -0
- package/src/runtime/spots/spot-routed-bound-session-dispatch.ts +132 -0
- package/src/runtime/spots/spot-routed-frame-dispatch.ts +250 -0
- package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +254 -0
- package/src/runtime/spots/spot-routing-internal.ts +33 -0
- package/src/runtime/spots/spot-runtime-ports.ts +196 -0
- package/src/runtime/spots/spot-serial-executor.ts +170 -0
- package/src/runtime/spots/spot-serial-turn-executor.ts +319 -0
- package/src/runtime/spots/spot-subscription-dispatch.ts +252 -0
- package/src/runtime/spots/spot-timer.ts +609 -0
- package/src/runtime/streams/actor-session-binding-registry.ts +1691 -0
- package/src/runtime/streams/actor-session-binding-runtime-owner.ts +78 -0
- package/src/runtime/streams/actor-session-lifecycle-coordinator.ts +20 -0
- package/src/runtime/streams/bound-actor-relay-sender.ts +275 -0
- package/src/runtime/streams/bound-session-response-target.ts +91 -0
- package/src/runtime/streams/bound-session-service.ts +500 -0
- package/src/runtime/streams/index.ts +706 -0
- package/src/runtime/streams/managed-stream.ts +509 -0
- package/src/runtime/streams/native-fallback-bound-session.ts +321 -0
- package/src/runtime/streams/protocol.ts +291 -0
- package/src/runtime/streams/session-actor-coordinator.ts +605 -0
- package/src/runtime/streams/session-calls.ts +221 -0
- package/src/runtime/streams/session-context.ts +609 -0
- package/src/runtime/streams/session-local-actors.ts +30 -0
- package/src/runtime/streams/session-provider.ts +50 -0
- package/src/runtime/streams/session-requests.ts +109 -0
- package/src/runtime/streams/session-serial-executor.ts +97 -0
- package/src/runtime/streams/stream-binding-runtime-ports.ts +106 -0
- package/src/runtime/streams/stream-frame-factory.ts +255 -0
- package/src/runtime/streams/stream-message-utils.ts +89 -0
- package/src/runtime/streams/stream-session-runtime.ts +1420 -0
- package/src/runtime/workers/index.ts +580 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,3898 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServiceStatefulRuntime = exports.ServiceInstanceActivationRedirectError = void 0;
|
|
4
|
+
exports.statefulMailboxData = statefulMailboxData;
|
|
5
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
6
|
+
const abort_1 = require("../abort");
|
|
7
|
+
const execution_1 = require("../execution");
|
|
8
|
+
const framework_errors_internal_1 = require("../framework-errors-internal");
|
|
9
|
+
const runtime_values_1 = require("../backend/runtime-values");
|
|
10
|
+
const service_runtime_contracts_1 = require("./service-runtime-contracts");
|
|
11
|
+
const message_follow_suppression_registry_1 = require("./message-follow-suppression-registry");
|
|
12
|
+
const service_stateful_registry_1 = require("./service-stateful-registry");
|
|
13
|
+
const service_stateful_wire_codec_1 = require("./service-stateful-wire-codec");
|
|
14
|
+
const routing_id_1 = require("../routing-id");
|
|
15
|
+
const service_wire_pilot_codec_generated_1 = require("../protocol/service_wire_pilot_codec.generated");
|
|
16
|
+
const actor_join_recovery_codec_1 = require("./actor-join-recovery-codec");
|
|
17
|
+
const service_wire_m6a_codec_1 = require("./service-wire-m6a-codec");
|
|
18
|
+
const service_metadata_codec_1 = require("./service-metadata-codec");
|
|
19
|
+
const contracts_1 = require("../../contracts");
|
|
20
|
+
const ACTOR_ROUTE_STALE = 21;
|
|
21
|
+
const SPOT_MOVING = 34;
|
|
22
|
+
const USER_SPOT_OPERATION_CAPACITY = 65_536;
|
|
23
|
+
const USER_SPOT_OPERATION_REPLAY_RETENTION_MS = 5 * 60_000;
|
|
24
|
+
const ACTOR_ROUTE_NOT_FOUND = 1;
|
|
25
|
+
class ServiceInstanceActivationRedirectError extends Error {
|
|
26
|
+
route;
|
|
27
|
+
constructor(route) {
|
|
28
|
+
super(`Instance Spot '${route.targetSpotId}' is owned by '${route.targetNodeRid}'.`);
|
|
29
|
+
this.route = route;
|
|
30
|
+
this.name = 'ServiceInstanceActivationRedirectError';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.ServiceInstanceActivationRedirectError = ServiceInstanceActivationRedirectError;
|
|
34
|
+
/**
|
|
35
|
+
* Owns M6B routing, identity fences and terminal operations. Application turns
|
|
36
|
+
* remain in the common mailbox, where a claimed Spot or Actor owner is serial.
|
|
37
|
+
*/
|
|
38
|
+
class ServiceStatefulRuntime {
|
|
39
|
+
raw;
|
|
40
|
+
nodeRid;
|
|
41
|
+
nodeGeneration;
|
|
42
|
+
// Captured at module load, before any application turn exists: running a
|
|
43
|
+
// callback through this snapshot detaches every AsyncLocalStorage context
|
|
44
|
+
// (Spot serial turn, execution area, flow) so local loopback ingress
|
|
45
|
+
// behaves exactly like a frame arriving from the receive pump.
|
|
46
|
+
static detachedIngressScope = node_async_hooks_1.AsyncLocalStorage.snapshot();
|
|
47
|
+
registry;
|
|
48
|
+
operations = new service_stateful_registry_1.ServiceTerminalOperationRegistry();
|
|
49
|
+
sessionDeliveries = new Map();
|
|
50
|
+
/**
|
|
51
|
+
* A local Actor owner can replace its own session binding before the
|
|
52
|
+
* replacement notice is looped back through ingress. Retain that exact old
|
|
53
|
+
* delivery until the old session performs its normal close cleanup.
|
|
54
|
+
*/
|
|
55
|
+
retiredSessionDeliveries = new Map();
|
|
56
|
+
appliedReplacementNotices = new Set();
|
|
57
|
+
subscriptions = new Map();
|
|
58
|
+
instanceIntents = new Map();
|
|
59
|
+
admittedInstanceOperations = new Map();
|
|
60
|
+
pendingInstanceTerminals = new Map();
|
|
61
|
+
pendingInstanceAuthorityTerminals = new Map();
|
|
62
|
+
instanceApplicationWaiters = new Map();
|
|
63
|
+
canonicalActorJoinHandoffs = new Map();
|
|
64
|
+
actorRoutes = new Map();
|
|
65
|
+
// Direct application messages use the logical Spot ID. Actor joins and
|
|
66
|
+
// lifecycle controls use the exact Spot object generation. Keep both views
|
|
67
|
+
// so changing one routing contract cannot hide the other route fence.
|
|
68
|
+
spotRoutes = new Map();
|
|
69
|
+
directSpotRoutes = new Map();
|
|
70
|
+
spotMessageFollow = new Map();
|
|
71
|
+
spotMessageFollowSuppression = new message_follow_suppression_registry_1.MessageFollowSuppressionRegistry();
|
|
72
|
+
nextMessageFollowSerial = 1n;
|
|
73
|
+
nextMessageFollowOperation = 1n;
|
|
74
|
+
nextSpotId = 1n;
|
|
75
|
+
nextSessionSequence = 1n;
|
|
76
|
+
nextInstanceOperation = 1n;
|
|
77
|
+
nextUserSpotOperation = 1n;
|
|
78
|
+
instanceAuthority;
|
|
79
|
+
asyncInstanceAuthority;
|
|
80
|
+
instanceApplicationLifecycle;
|
|
81
|
+
userSpotOperationHandler;
|
|
82
|
+
messageFollowHandler;
|
|
83
|
+
mailboxDropHandler;
|
|
84
|
+
admittedUserSpotOperations = new Map();
|
|
85
|
+
pendingInstanceActivations = new Map();
|
|
86
|
+
closed = false;
|
|
87
|
+
constructor(raw, nodeRid, nodeGeneration) {
|
|
88
|
+
this.raw = raw;
|
|
89
|
+
this.nodeRid = nodeRid;
|
|
90
|
+
this.nodeGeneration = nodeGeneration;
|
|
91
|
+
this.registry = new service_stateful_registry_1.ServiceStatefulRegistry(nodeRid, nodeGeneration);
|
|
92
|
+
this.registry.createEntrySpot(nodeRid);
|
|
93
|
+
raw.setServiceIngress(record => this.ingress(record));
|
|
94
|
+
}
|
|
95
|
+
setMailboxDropHandler(handler) {
|
|
96
|
+
this.mailboxDropHandler = handler;
|
|
97
|
+
}
|
|
98
|
+
createSpot(routingId, kind = 'user', stableType = kind) {
|
|
99
|
+
this.requireOpen();
|
|
100
|
+
return this.registry.createSpot(routingId ?? `spot-${this.nodeRid}-${this.nextSpotId++}`, kind, stableType);
|
|
101
|
+
}
|
|
102
|
+
restoreUserSpotAuthority(spotId, stableType, generation, authorityOwnerGeneration) {
|
|
103
|
+
this.requireOpen();
|
|
104
|
+
return this.registry.restoreSpot({ spotId, generation }, 'user', stableType, authorityOwnerGeneration);
|
|
105
|
+
}
|
|
106
|
+
restoreSpotAuthority(spotId, objectKind, stableType, generation, authorityOwnerGeneration) {
|
|
107
|
+
this.requireOpen();
|
|
108
|
+
return this.registry.restoreSpot({ spotId, generation }, objectKind === 'user_spot' ? 'user' : 'instance', stableType, authorityOwnerGeneration);
|
|
109
|
+
}
|
|
110
|
+
entrySpot() {
|
|
111
|
+
return this.registry.createEntrySpot(this.nodeRid);
|
|
112
|
+
}
|
|
113
|
+
createActor(actorId, stableType = 'actor') {
|
|
114
|
+
this.requireOpen();
|
|
115
|
+
return this.registry.createActor(actorId, stableType);
|
|
116
|
+
}
|
|
117
|
+
restoreActorAuthority(actorId, stableType, generation, authorityOwnerGeneration, spotId, spotGeneration, membershipEpoch) {
|
|
118
|
+
this.requireOpen();
|
|
119
|
+
return this.registry.restoreActor({ nodeRid: this.nodeRid, actorId, generation }, stableType, { spotId, generation: spotGeneration }, membershipEpoch, authorityOwnerGeneration);
|
|
120
|
+
}
|
|
121
|
+
discardRelocatedActor(actor) {
|
|
122
|
+
this.requireOpen();
|
|
123
|
+
this.registry.destroyActor(actor);
|
|
124
|
+
}
|
|
125
|
+
restoreActorSessionBinding(actorRef, sessionNodeRid, sessionRid, bindingGeneration) {
|
|
126
|
+
this.requireOpen();
|
|
127
|
+
const actor = this.registry.actor(actorRef.actorId);
|
|
128
|
+
if (actor === undefined
|
|
129
|
+
|| actor.ref.generation !== actorRef.generation
|
|
130
|
+
|| actor.ref.nodeRid !== actorRef.nodeRid) {
|
|
131
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('actor', actorRef.actorId);
|
|
132
|
+
}
|
|
133
|
+
const current = this.registry.binding(actor.ref);
|
|
134
|
+
if (current?.bindingGeneration === bindingGeneration
|
|
135
|
+
&& current.sessionOwnerNodeRid === sessionNodeRid
|
|
136
|
+
&& current.sessionRid === sessionRid) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
this.registry.installSessionBinding({
|
|
140
|
+
actor: actor.ref,
|
|
141
|
+
sessionRid,
|
|
142
|
+
sessionOwnerNodeRid: sessionNodeRid,
|
|
143
|
+
bindingGeneration,
|
|
144
|
+
membershipEpoch: actor.membershipEpoch
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
activateInstanceSpot(spotId, instanceType, attempt, authorityOwnerGeneration = attempt) {
|
|
148
|
+
this.requireOpen();
|
|
149
|
+
const current = this.registry.spot(spotId);
|
|
150
|
+
if (current !== undefined) {
|
|
151
|
+
if (current.kind !== 'instance' || current.stableType !== instanceType) {
|
|
152
|
+
throw new TypeError(`Instance Spot '${spotId}' is assigned to another type.`);
|
|
153
|
+
}
|
|
154
|
+
if (current.ref.generation > attempt) {
|
|
155
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', spotId);
|
|
156
|
+
}
|
|
157
|
+
if (current.ref.generation === attempt) {
|
|
158
|
+
return {
|
|
159
|
+
spot: current.authorityOwnerGeneration === authorityOwnerGeneration
|
|
160
|
+
? current
|
|
161
|
+
: this.registry.restoreSpot(current.ref, 'instance', instanceType, authorityOwnerGeneration),
|
|
162
|
+
created: false
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if (!this.registry.closeSpot(current.ref)) {
|
|
166
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', spotId);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
spot: this.registry.restoreSpot({ spotId, generation: attempt }, 'instance', instanceType, authorityOwnerGeneration),
|
|
171
|
+
created: true
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
registerInstanceIntent(instanceType, route, expectedCurrentRoute) {
|
|
175
|
+
if (route.targetNodeRid !== this.nodeRid || route.targetNodeGeneration !== this.nodeGeneration) {
|
|
176
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', route.targetSpotId);
|
|
177
|
+
}
|
|
178
|
+
const current = this.instanceIntents.get(route.targetSpotId);
|
|
179
|
+
if (current !== undefined) {
|
|
180
|
+
if (current.instanceType === instanceType && sameInstanceRoute(current.route, route)) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (!matchesExpectedInstanceRoute(current.route, expectedCurrentRoute))
|
|
184
|
+
return;
|
|
185
|
+
if (current.route.objectGeneration < route.objectGeneration) {
|
|
186
|
+
this.instanceIntents.set(route.targetSpotId, Object.freeze({ instanceType, route: { ...route } }));
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (current.route.objectGeneration > route.objectGeneration) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (current.route.authorityOwnerGeneration > route.authorityOwnerGeneration) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (current.route.authorityOwnerGeneration === route.authorityOwnerGeneration) {
|
|
196
|
+
if (!sameInstanceOwnerIdentity(current.route, route)) {
|
|
197
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', route.targetSpotId);
|
|
198
|
+
}
|
|
199
|
+
if (current.route.storeVersion === route.storeVersion) {
|
|
200
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', route.targetSpotId);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else if (!matchesExpectedInstanceRoute(undefined, expectedCurrentRoute)) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
this.instanceIntents.set(route.targetSpotId, Object.freeze({ instanceType, route: { ...route } }));
|
|
208
|
+
}
|
|
209
|
+
instanceSpotApplicationTarget(spotId) {
|
|
210
|
+
const intent = this.instanceIntents.get(spotId);
|
|
211
|
+
const spot = this.registry.spot(spotId);
|
|
212
|
+
if (intent === undefined
|
|
213
|
+
|| spot?.kind !== 'instance'
|
|
214
|
+
|| spot.state !== 'ready'
|
|
215
|
+
|| spot.ref.generation !== intent.route.objectGeneration) {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
stableType: intent.instanceType,
|
|
220
|
+
objectGeneration: intent.route.objectGeneration
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
forgetInstanceIntent(spotId, objectGeneration, authorityOwnerGeneration, storeVersion) {
|
|
224
|
+
const current = this.instanceIntents.get(spotId);
|
|
225
|
+
if (current?.route.objectGeneration === objectGeneration
|
|
226
|
+
&& current.route.authorityOwnerGeneration === authorityOwnerGeneration
|
|
227
|
+
&& (storeVersion === undefined || current.route.storeVersion === storeVersion)) {
|
|
228
|
+
this.instanceIntents.delete(spotId);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
registerInstanceActivationAuthority(authority) {
|
|
232
|
+
this.requireOpen();
|
|
233
|
+
if (this.asyncInstanceAuthority !== undefined
|
|
234
|
+
|| this.instanceAuthority !== undefined && this.instanceAuthority !== authority) {
|
|
235
|
+
throw new Error('Instance activation authority is already registered.');
|
|
236
|
+
}
|
|
237
|
+
this.instanceAuthority = authority;
|
|
238
|
+
}
|
|
239
|
+
registerAsyncInstanceActivationAuthority(authority) {
|
|
240
|
+
this.requireOpen();
|
|
241
|
+
if (this.instanceAuthority !== undefined
|
|
242
|
+
|| this.asyncInstanceAuthority !== undefined
|
|
243
|
+
&& this.asyncInstanceAuthority !== authority) {
|
|
244
|
+
throw new Error('Instance activation authority is already registered.');
|
|
245
|
+
}
|
|
246
|
+
this.asyncInstanceAuthority = authority;
|
|
247
|
+
}
|
|
248
|
+
registerInstanceApplicationLifecycle(lifecycle) {
|
|
249
|
+
if (this.instanceApplicationLifecycle !== undefined) {
|
|
250
|
+
throw new Error('Instance application lifecycle is already registered.');
|
|
251
|
+
}
|
|
252
|
+
this.instanceApplicationLifecycle = lifecycle;
|
|
253
|
+
}
|
|
254
|
+
registerUserSpotOperationHandler(handler) {
|
|
255
|
+
this.requireOpen();
|
|
256
|
+
if (this.userSpotOperationHandler !== undefined
|
|
257
|
+
&& this.userSpotOperationHandler !== handler) {
|
|
258
|
+
throw new Error('User Spot operation handler is already registered.');
|
|
259
|
+
}
|
|
260
|
+
this.userSpotOperationHandler = handler;
|
|
261
|
+
}
|
|
262
|
+
requestUserSpotCreate(targetNodeRid, request, timeoutMs) {
|
|
263
|
+
const correlation = this.nextUserSpotOperation++;
|
|
264
|
+
const operation = {
|
|
265
|
+
high: this.nodeGeneration,
|
|
266
|
+
low: correlation
|
|
267
|
+
};
|
|
268
|
+
return this.requestUserSpotOperation(targetNodeRid, (0, service_stateful_wire_codec_1.encodeUserSpotCreateHeader)({
|
|
269
|
+
...request,
|
|
270
|
+
sourceNodeRid: this.nodeRid,
|
|
271
|
+
sourceNodeGeneration: this.nodeGeneration,
|
|
272
|
+
correlation,
|
|
273
|
+
operation
|
|
274
|
+
}), correlation, 'userSpotCreate', timeoutMs);
|
|
275
|
+
}
|
|
276
|
+
requestUserSpotClose(targetNodeRid, request, timeoutMs) {
|
|
277
|
+
const correlation = this.nextUserSpotOperation++;
|
|
278
|
+
const operation = {
|
|
279
|
+
high: this.nodeGeneration,
|
|
280
|
+
low: correlation
|
|
281
|
+
};
|
|
282
|
+
return this.requestUserSpotOperation(targetNodeRid, (0, service_stateful_wire_codec_1.encodeUserSpotCloseHeader)({
|
|
283
|
+
...request,
|
|
284
|
+
sourceNodeRid: this.nodeRid,
|
|
285
|
+
sourceNodeGeneration: this.nodeGeneration,
|
|
286
|
+
correlation,
|
|
287
|
+
operation
|
|
288
|
+
}), correlation, 'userSpotClose', timeoutMs);
|
|
289
|
+
}
|
|
290
|
+
requestActorCreate(targetNodeRid, request, timeoutMs) {
|
|
291
|
+
const correlation = this.nextUserSpotOperation++;
|
|
292
|
+
const operation = {
|
|
293
|
+
high: this.nodeGeneration,
|
|
294
|
+
low: correlation
|
|
295
|
+
};
|
|
296
|
+
return this.requestUserSpotOperation(targetNodeRid, (0, service_stateful_wire_codec_1.encodeActorCreateHeader)({
|
|
297
|
+
...request,
|
|
298
|
+
sourceNodeRid: this.nodeRid,
|
|
299
|
+
sourceNodeGeneration: this.nodeGeneration,
|
|
300
|
+
correlation,
|
|
301
|
+
operation
|
|
302
|
+
}), correlation, 'actorCreate', timeoutMs);
|
|
303
|
+
}
|
|
304
|
+
async recoverInstanceActivation(envelope, route, expectedCurrentRoute) {
|
|
305
|
+
const target = envelope.target;
|
|
306
|
+
if (!matchesExpectedInstanceRoute(this.instanceIntents.get(target.targetSpotId)?.route, expectedCurrentRoute))
|
|
307
|
+
return false;
|
|
308
|
+
if (target.targetNodeRid !== this.nodeRid
|
|
309
|
+
|| target.targetNodeGeneration !== this.nodeGeneration
|
|
310
|
+
|| target.targetSpotId !== route.targetSpotId
|
|
311
|
+
|| route.targetNodeRid !== this.nodeRid
|
|
312
|
+
|| route.targetNodeGeneration !== this.nodeGeneration) {
|
|
313
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
314
|
+
}
|
|
315
|
+
const authority = this.asyncInstanceAuthority;
|
|
316
|
+
if (authority === undefined) {
|
|
317
|
+
throw new Error('Async Instance activation authority is not registered.');
|
|
318
|
+
}
|
|
319
|
+
await this.instanceApplicationLifecycle?.materialize(target, route.objectGeneration);
|
|
320
|
+
return this.finishRecoveredInstanceActivation(envelope, route, expectedCurrentRoute);
|
|
321
|
+
}
|
|
322
|
+
async finishRecoveredInstanceActivation(envelope, route, expectedCurrentRoute) {
|
|
323
|
+
const target = envelope.target;
|
|
324
|
+
const spot = this.registry.spot(target.targetSpotId)
|
|
325
|
+
?? this.registry.restoreSpot({
|
|
326
|
+
spotId: target.targetSpotId,
|
|
327
|
+
generation: route.objectGeneration
|
|
328
|
+
}, 'instance', target.stableType, route.authorityOwnerGeneration);
|
|
329
|
+
if (spot.kind !== 'instance'
|
|
330
|
+
|| spot.stableType !== target.stableType
|
|
331
|
+
|| spot.ref.generation !== route.objectGeneration
|
|
332
|
+
|| spot.authorityOwnerGeneration !== route.authorityOwnerGeneration) {
|
|
333
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
334
|
+
}
|
|
335
|
+
if (!matchesExpectedInstanceRoute(this.instanceIntents.get(target.targetSpotId)?.route, expectedCurrentRoute))
|
|
336
|
+
return false;
|
|
337
|
+
this.publishCommittedInstanceRoute(target.stableType, route, expectedCurrentRoute);
|
|
338
|
+
const record = {
|
|
339
|
+
kind: 'instanceSpot',
|
|
340
|
+
activation: 'missing',
|
|
341
|
+
target,
|
|
342
|
+
sourceNodeGeneration: envelope.sourceNodeGeneration,
|
|
343
|
+
sourceNodeRid: envelope.sourceNodeRid,
|
|
344
|
+
...(envelope.sourceSpotId === undefined
|
|
345
|
+
? {}
|
|
346
|
+
: { sourceSpotId: envelope.sourceSpotId }),
|
|
347
|
+
operationKind: envelope.operationKind,
|
|
348
|
+
operation: envelope.operation,
|
|
349
|
+
deadlineUnixMs: envelope.deadlineUnixMs,
|
|
350
|
+
...(envelope.replyRouteId === undefined ? {} : { replyRouteId: envelope.replyRouteId })
|
|
351
|
+
};
|
|
352
|
+
const applicationJobOwner = await this.raw.reserveLocalIngress();
|
|
353
|
+
try {
|
|
354
|
+
const admitted = this.enqueueActivatedInstanceSpot({
|
|
355
|
+
command: service_stateful_wire_codec_1.M6bServiceWireCommand.instanceSpot,
|
|
356
|
+
flags: envelope.metadataFrame === undefined ? 0 : service_stateful_wire_codec_1.M6bServiceWireFlag.metadata,
|
|
357
|
+
sourceRoutingId: envelope.sourceNodeRid,
|
|
358
|
+
parts: [
|
|
359
|
+
(0, service_stateful_wire_codec_1.encodeInstanceSpotActivationHeader)(target, envelope.sourceNodeGeneration, envelope.sourceNodeRid, envelope.sourceSpotId, envelope.operationKind, envelope.operation, envelope.deadlineUnixMs, envelope.replyRouteId, envelope.metadataFrame !== undefined)
|
|
360
|
+
],
|
|
361
|
+
applicationJobOwner
|
|
362
|
+
}, record, Buffer.from(envelope.applicationPayloadFrame), spot, undefined, this.activationTerminalCompletion(target, route), envelope.metadataFrame === undefined
|
|
363
|
+
? undefined
|
|
364
|
+
: (0, service_metadata_codec_1.validateServiceMetadataFrame)(envelope.metadataFrame), true, this.instanceApplicationTarget(record, route.objectGeneration));
|
|
365
|
+
if (admitted !== 'application') {
|
|
366
|
+
throw new Error('Recovered Instance activation was not admitted to the local queue.');
|
|
367
|
+
}
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
finally {
|
|
371
|
+
applicationJobOwner.close();
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
async recoverPendingInstanceActivation(envelope, pending, expectedCurrentRoute) {
|
|
375
|
+
const target = envelope.target;
|
|
376
|
+
if (!matchesExpectedInstanceRoute(this.instanceIntents.get(target.targetSpotId)?.route, expectedCurrentRoute))
|
|
377
|
+
return false;
|
|
378
|
+
if (target.targetNodeRid !== this.nodeRid
|
|
379
|
+
|| target.targetNodeGeneration !== this.nodeGeneration
|
|
380
|
+
|| pending.nodeRid !== this.nodeRid
|
|
381
|
+
|| pending.nodeGeneration !== this.nodeGeneration
|
|
382
|
+
|| pending.meshName !== envelope.targetMeshName) {
|
|
383
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
384
|
+
}
|
|
385
|
+
const authority = this.asyncInstanceAuthority;
|
|
386
|
+
if (authority === undefined) {
|
|
387
|
+
throw new Error('Async Instance activation authority is not registered.');
|
|
388
|
+
}
|
|
389
|
+
const reservation = await authority.resume(target, pending);
|
|
390
|
+
await this.instanceApplicationLifecycle?.materialize(target, pending.objectGeneration);
|
|
391
|
+
const spot = this.registry.restoreSpot({
|
|
392
|
+
spotId: target.targetSpotId,
|
|
393
|
+
generation: pending.objectGeneration
|
|
394
|
+
}, 'instance', target.stableType, pending.authorityOwnerGeneration);
|
|
395
|
+
const committed = await authority.commit(target, reservation, spot);
|
|
396
|
+
if (committed.kind !== 'committed') {
|
|
397
|
+
this.registry.closeSpot(spot.ref);
|
|
398
|
+
throw new ServiceInstanceActivationRedirectError(committed.route);
|
|
399
|
+
}
|
|
400
|
+
return this.finishRecoveredInstanceActivation(envelope, committed.route, expectedCurrentRoute);
|
|
401
|
+
}
|
|
402
|
+
async completeRecoveredInstanceActivation(target, route, expectedCurrentRoute) {
|
|
403
|
+
if (!matchesExpectedInstanceRoute(this.instanceIntents.get(target.targetSpotId)?.route, expectedCurrentRoute))
|
|
404
|
+
return undefined;
|
|
405
|
+
const authority = this.asyncInstanceAuthority;
|
|
406
|
+
if (authority === undefined) {
|
|
407
|
+
throw new Error('Async Instance activation authority is not registered.');
|
|
408
|
+
}
|
|
409
|
+
const released = await authority.complete(target, route);
|
|
410
|
+
const currentRoute = this.instanceIntents.get(target.targetSpotId)?.route;
|
|
411
|
+
if (!matchesExpectedInstanceRoute(currentRoute, expectedCurrentRoute))
|
|
412
|
+
return undefined;
|
|
413
|
+
if (currentRoute !== undefined && !sameInstanceRoute(currentRoute, route))
|
|
414
|
+
return undefined;
|
|
415
|
+
const authorityReleased = await this.instanceApplicationLifecycle?.completeTerminal({
|
|
416
|
+
targetSpotId: target.targetSpotId,
|
|
417
|
+
stableType: target.stableType,
|
|
418
|
+
objectGeneration: route.objectGeneration
|
|
419
|
+
})
|
|
420
|
+
?? false;
|
|
421
|
+
if (!authorityReleased) {
|
|
422
|
+
if (currentRoute === undefined) {
|
|
423
|
+
this.publishCommittedInstanceRoute(target.stableType, released, null);
|
|
424
|
+
}
|
|
425
|
+
else if (!this.replaceCommittedInstanceRoute(target.stableType, route, released)) {
|
|
426
|
+
return undefined;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
this.forgetClosedInstanceRoute(released);
|
|
431
|
+
}
|
|
432
|
+
return released;
|
|
433
|
+
}
|
|
434
|
+
waitForInstanceApplicationQuiescence(spotId, signal) {
|
|
435
|
+
const key = String(spotId);
|
|
436
|
+
if ((this.pendingInstanceTerminals.get(key) ?? 0) === 0
|
|
437
|
+
&& (this.pendingInstanceAuthorityTerminals.get(key) ?? 0) === 0) {
|
|
438
|
+
return Promise.resolve();
|
|
439
|
+
}
|
|
440
|
+
if (signal?.aborted === true) {
|
|
441
|
+
return Promise.reject(signal.reason);
|
|
442
|
+
}
|
|
443
|
+
return new Promise((resolve, reject) => {
|
|
444
|
+
const waiters = this.instanceApplicationWaiters.get(key) ?? new Set();
|
|
445
|
+
this.instanceApplicationWaiters.set(key, waiters);
|
|
446
|
+
const complete = () => {
|
|
447
|
+
signal?.removeEventListener('abort', abort);
|
|
448
|
+
resolve();
|
|
449
|
+
};
|
|
450
|
+
const abort = () => {
|
|
451
|
+
waiters.delete(complete);
|
|
452
|
+
if (waiters.size === 0)
|
|
453
|
+
this.instanceApplicationWaiters.delete(key);
|
|
454
|
+
reject(signal?.reason);
|
|
455
|
+
};
|
|
456
|
+
waiters.add(complete);
|
|
457
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
rememberActorRoute(route) {
|
|
461
|
+
if (route.actor.nodeRid.length === 0) {
|
|
462
|
+
throw new TypeError('Actor route requires a target node.');
|
|
463
|
+
}
|
|
464
|
+
this.actorRoutes.set(actorKey(route.actor), Object.freeze({
|
|
465
|
+
actor: Object.freeze({ ...route.actor }),
|
|
466
|
+
targetNodeGeneration: route.targetNodeGeneration,
|
|
467
|
+
authorityOwnerGeneration: route.authorityOwnerGeneration,
|
|
468
|
+
ownerLeaseGeneration: route.ownerLeaseGeneration
|
|
469
|
+
}));
|
|
470
|
+
}
|
|
471
|
+
rememberSpotRoute(route, expectedCurrentRoute) {
|
|
472
|
+
// Direct application messages address the logical Spot ID. Keep one
|
|
473
|
+
// current owner route per ID so a same-owner reactivation can replace the
|
|
474
|
+
// old object generation without making the next application message
|
|
475
|
+
// stale. Message Follow and lifecycle controls keep using spotKey().
|
|
476
|
+
const key = directSpotKey(route.spot.spotId);
|
|
477
|
+
const current = this.directSpotRoutes.get(key);
|
|
478
|
+
if (current !== undefined && sameDirectSpotRoute(current, route)) {
|
|
479
|
+
this.spotRoutes.set(spotKey(route.spot), current);
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
if (expectedCurrentRoute !== undefined
|
|
483
|
+
&& !matchesExpectedDirectSpotRoute(current, expectedCurrentRoute))
|
|
484
|
+
return;
|
|
485
|
+
if (current !== undefined) {
|
|
486
|
+
if (current.spot.generation < route.spot.generation) {
|
|
487
|
+
const next = freezeDirectSpotRoute(route);
|
|
488
|
+
this.directSpotRoutes.set(key, next);
|
|
489
|
+
this.spotRoutes.set(spotKey(route.spot), next);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
if (current.spot.generation > route.spot.generation) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
if (current.authorityOwnerGeneration > route.authorityOwnerGeneration) {
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
if (current.authorityOwnerGeneration === route.authorityOwnerGeneration) {
|
|
499
|
+
// StoreVersion is the mutable CAS fence for the same object and
|
|
500
|
+
// owner. A Preserve or membership update can advance it without
|
|
501
|
+
// changing the route identity. Keep the exact fence used by the
|
|
502
|
+
// latest authority projection instead of treating that update as a
|
|
503
|
+
// new object generation.
|
|
504
|
+
if (sameDirectSpotOwnerIdentity(current, route)) {
|
|
505
|
+
const next = freezeDirectSpotRoute(route);
|
|
506
|
+
this.directSpotRoutes.set(key, next);
|
|
507
|
+
this.spotRoutes.set(spotKey(route.spot), next);
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', route.spot.spotId);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
const next = freezeDirectSpotRoute(route);
|
|
514
|
+
this.directSpotRoutes.set(key, next);
|
|
515
|
+
this.spotRoutes.set(spotKey(route.spot), next);
|
|
516
|
+
}
|
|
517
|
+
async sendMessageFollowNotification(targetNodeRid, record) {
|
|
518
|
+
this.requireOpen();
|
|
519
|
+
return await this.raw.sendService(targetNodeRid, [(0, service_stateful_wire_codec_1.encodeMessageFollowHeader)(record)]);
|
|
520
|
+
}
|
|
521
|
+
setMessageFollowHandler(handler) {
|
|
522
|
+
this.messageFollowHandler = handler;
|
|
523
|
+
}
|
|
524
|
+
sealSpotMessageFollowIngress(source) {
|
|
525
|
+
this.requireOpen();
|
|
526
|
+
if (source.targetNodeRid !== this.nodeRid
|
|
527
|
+
|| source.targetNodeGeneration !== this.nodeGeneration) {
|
|
528
|
+
return undefined;
|
|
529
|
+
}
|
|
530
|
+
const key = spotKey(source.spot);
|
|
531
|
+
if (this.spotMessageFollow.has(key))
|
|
532
|
+
return undefined;
|
|
533
|
+
const sourceSpot = this.registry.requireSpot(source.spot);
|
|
534
|
+
const seal = Object.freeze({ key, serial: this.nextMessageFollowSerial++ });
|
|
535
|
+
this.spotMessageFollow.set(key, {
|
|
536
|
+
seal,
|
|
537
|
+
objectKind: sourceSpot.kind === 'user' ? 'userSpot' : 'instanceSpot',
|
|
538
|
+
source: freezeDirectSpotRoute(source),
|
|
539
|
+
queued: [],
|
|
540
|
+
queuedHead: 0,
|
|
541
|
+
queuedCount: 0,
|
|
542
|
+
queuedBytes: 0,
|
|
543
|
+
draining: false
|
|
544
|
+
});
|
|
545
|
+
return seal;
|
|
546
|
+
}
|
|
547
|
+
abortSpotMessageFollowIngress(seal) {
|
|
548
|
+
const state = this.exactSpotMessageFollow(seal);
|
|
549
|
+
if (state === undefined || state.target !== undefined)
|
|
550
|
+
return false;
|
|
551
|
+
this.removeSpotMessageFollow(state);
|
|
552
|
+
try {
|
|
553
|
+
while (state.queuedCount > 0) {
|
|
554
|
+
const record = this.peekSpotMessageFollow(state);
|
|
555
|
+
const result = this.restoreSpotMessageFollowRecord(record);
|
|
556
|
+
if (result !== 'application') {
|
|
557
|
+
throw new Error('Aborted Spot ingress could not be restored to its source queue.');
|
|
558
|
+
}
|
|
559
|
+
this.takeSpotMessageFollow(state);
|
|
560
|
+
}
|
|
561
|
+
return true;
|
|
562
|
+
}
|
|
563
|
+
catch (error) {
|
|
564
|
+
while (state.queuedCount > 0)
|
|
565
|
+
this.takeSpotMessageFollow(state);
|
|
566
|
+
throw error;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
async commitSpotMessageFollowIngress(seal, target, durationMs) {
|
|
570
|
+
const state = this.exactSpotMessageFollow(seal);
|
|
571
|
+
if (state === undefined || state.target !== undefined)
|
|
572
|
+
return false;
|
|
573
|
+
if (!Number.isSafeInteger(durationMs) || durationMs < 0) {
|
|
574
|
+
throw new RangeError('Message Follow duration must be a non-negative safe integer.');
|
|
575
|
+
}
|
|
576
|
+
if (target.spot.spotId !== state.source.spot.spotId
|
|
577
|
+
|| target.spot.generation !== state.source.spot.generation
|
|
578
|
+
|| target.authorityOwnerGeneration <= state.source.authorityOwnerGeneration
|
|
579
|
+
|| target.targetNodeRid === this.nodeRid) {
|
|
580
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', state.source.spot.spotId);
|
|
581
|
+
}
|
|
582
|
+
state.target = freezeDirectSpotRoute(target);
|
|
583
|
+
state.suppressionFence = spotMessageFollowSuppressionFence(state.objectKind, state.source, state.target);
|
|
584
|
+
this.spotMessageFollowSuppression.retainRoute(state.suppressionFence);
|
|
585
|
+
state.expiresAtMs = durationMs === 0
|
|
586
|
+
? Number.MAX_SAFE_INTEGER
|
|
587
|
+
: performance.now() + durationMs;
|
|
588
|
+
await this.drainSpotMessageFollow(state);
|
|
589
|
+
if (durationMs === 0)
|
|
590
|
+
this.removeSpotMessageFollow(state);
|
|
591
|
+
return true;
|
|
592
|
+
}
|
|
593
|
+
forgetSpotRoute(spot, authorityOwnerGeneration, storeVersion) {
|
|
594
|
+
const exactKey = spotKey(spot);
|
|
595
|
+
const exact = this.spotRoutes.get(exactKey);
|
|
596
|
+
const current = this.directSpotRoutes.get(directSpotKey(spot.spotId));
|
|
597
|
+
if (exact?.authorityOwnerGeneration === authorityOwnerGeneration
|
|
598
|
+
&& (storeVersion === undefined || exact.storeVersion === storeVersion)) {
|
|
599
|
+
this.spotRoutes.delete(exactKey);
|
|
600
|
+
}
|
|
601
|
+
const key = directSpotKey(spot.spotId);
|
|
602
|
+
if (current?.authorityOwnerGeneration === authorityOwnerGeneration
|
|
603
|
+
&& current.spot.generation === spot.generation
|
|
604
|
+
&& (storeVersion === undefined || current.storeVersion === storeVersion)) {
|
|
605
|
+
this.directSpotRoutes.delete(key);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
actor(actorId) {
|
|
609
|
+
return this.registry.actor(actorId);
|
|
610
|
+
}
|
|
611
|
+
setSubscription(spot, channelName, topicFilter) {
|
|
612
|
+
this.registry.requireSpot(spot.ref);
|
|
613
|
+
if (spot.kind === 'instance') {
|
|
614
|
+
throw new Error('Instance Spots do not support logical multicast subscriptions.');
|
|
615
|
+
}
|
|
616
|
+
const key = subscriptionKey(channelName, topicFilter);
|
|
617
|
+
const subscriptions = this.subscriptions.get(spot.ref.spotId) ?? new Set();
|
|
618
|
+
subscriptions.add(key);
|
|
619
|
+
this.subscriptions.set(spot.ref.spotId, subscriptions);
|
|
620
|
+
}
|
|
621
|
+
unsetSubscription(spot, channelName, topicFilter) {
|
|
622
|
+
const subscriptions = this.subscriptions.get(spot.ref.spotId);
|
|
623
|
+
if (subscriptions === undefined)
|
|
624
|
+
return;
|
|
625
|
+
subscriptions.delete(subscriptionKey(channelName, topicFilter));
|
|
626
|
+
if (subscriptions.size === 0)
|
|
627
|
+
this.subscriptions.delete(spot.ref.spotId);
|
|
628
|
+
}
|
|
629
|
+
clearSubscriptions(spotId) {
|
|
630
|
+
this.subscriptions.delete(spotId);
|
|
631
|
+
}
|
|
632
|
+
async publishLogicalMulticast(channelName, topic, payload, sourceSpotId = this.nodeRid) {
|
|
633
|
+
await this.enqueueLogicalMulticast(channelName, topic, sourceSpotId, payload);
|
|
634
|
+
const targets = this.raw.topology.peers()
|
|
635
|
+
.filter(peer => peer.descriptor.channels.some(channel => channel.name === channelName && channel.weight > 0));
|
|
636
|
+
const header = (0, service_stateful_wire_codec_1.encodeLogicalMulticastHeader)(channelName, topic, sourceSpotId);
|
|
637
|
+
const payloadFrame = (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload);
|
|
638
|
+
for (const target of targets) {
|
|
639
|
+
// Remote admission ends at the source outbound transport queue. The
|
|
640
|
+
// receiver's Spot queue and handler completion are not publish results.
|
|
641
|
+
await this.raw.sendService(target.descriptor.nodeRoutingId, [header, payloadFrame]);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
async sendToSpot(sourceSpotId, requested, payload) {
|
|
645
|
+
const target = this.acceptSpotAuthority(requested);
|
|
646
|
+
if (target === undefined) {
|
|
647
|
+
return runtime_values_1.SubmitResult.NotFound;
|
|
648
|
+
}
|
|
649
|
+
const header = (0, service_stateful_wire_codec_1.encodeSpotHeader)('spotSend', sourceSpotId, target);
|
|
650
|
+
return this.submitOneWay(target.targetNodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)]);
|
|
651
|
+
}
|
|
652
|
+
requestToSpot(sourceSpotId, requested, payload, timeoutMs) {
|
|
653
|
+
const pending = this.operations.reserve(timeoutMs);
|
|
654
|
+
const target = this.acceptSpotAuthority(requested);
|
|
655
|
+
if (target === undefined) {
|
|
656
|
+
this.operations.reply(pending.id, {
|
|
657
|
+
terminalResult: runtime_values_1.RequestResult.NotFound,
|
|
658
|
+
failureCode: ACTOR_ROUTE_STALE
|
|
659
|
+
});
|
|
660
|
+
return pending;
|
|
661
|
+
}
|
|
662
|
+
const header = (0, service_stateful_wire_codec_1.encodeSpotHeader)('spotRequest', sourceSpotId, target, pending.id);
|
|
663
|
+
this.submitRequest(pending, target.targetNodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)], timeoutMs, 'spotRequest');
|
|
664
|
+
return pending;
|
|
665
|
+
}
|
|
666
|
+
async sendToActor(target, _targetNodeGeneration, _authorityOwnerGeneration, payload, sourceActor, boundSession) {
|
|
667
|
+
const route = this.tryActorFence(target);
|
|
668
|
+
if (route === undefined)
|
|
669
|
+
return runtime_values_1.SubmitResult.NotFound;
|
|
670
|
+
const header = (0, service_stateful_wire_codec_1.encodeActorHeader)('actorSend', route, undefined, sourceActor, boundSession === undefined
|
|
671
|
+
? undefined
|
|
672
|
+
: {
|
|
673
|
+
...boundSession,
|
|
674
|
+
sequence: this.nextSessionSequence++
|
|
675
|
+
});
|
|
676
|
+
return this.submitOneWay(target.nodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)]);
|
|
677
|
+
}
|
|
678
|
+
requestToActor(target, _targetNodeGeneration, _authorityOwnerGeneration, payload, timeoutMs, sourceActor, boundSession) {
|
|
679
|
+
const pending = this.operations.reserve(timeoutMs);
|
|
680
|
+
const route = this.tryActorFence(target);
|
|
681
|
+
if (route === undefined) {
|
|
682
|
+
this.operations.reply(pending.id, {
|
|
683
|
+
terminalResult: runtime_values_1.RequestResult.NotFound,
|
|
684
|
+
failureCode: ACTOR_ROUTE_STALE
|
|
685
|
+
});
|
|
686
|
+
return pending;
|
|
687
|
+
}
|
|
688
|
+
const header = (0, service_stateful_wire_codec_1.encodeActorHeader)('actorRequest', route, pending.id, sourceActor, boundSession === undefined
|
|
689
|
+
? undefined
|
|
690
|
+
: {
|
|
691
|
+
...boundSession,
|
|
692
|
+
sequence: this.nextSessionSequence++
|
|
693
|
+
});
|
|
694
|
+
this.submitRequest(pending, target.nodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)], timeoutMs, 'actorRequest');
|
|
695
|
+
return pending;
|
|
696
|
+
}
|
|
697
|
+
async sendToInstanceSpot(route, payload, sourceSpotId, metadataFrame) {
|
|
698
|
+
return this.submitOneWay(route.targetNodeRid, instanceOperationParts([
|
|
699
|
+
(0, service_stateful_wire_codec_1.encodeInstanceSpotHeader)(route, this.nodeGeneration, this.nodeRid, sourceSpotId, 'send', { high: 0n, low: 0n }, undefined, metadataFrame !== undefined),
|
|
700
|
+
(0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)
|
|
701
|
+
], metadataFrame));
|
|
702
|
+
}
|
|
703
|
+
async sendToMissingInstanceSpot(target, payload, deadlineUnixMs, sourceSpotId, metadataFrame) {
|
|
704
|
+
return await this.sendToMissingInstanceSpotFrame(target, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload), deadlineUnixMs, sourceSpotId, metadataFrame);
|
|
705
|
+
}
|
|
706
|
+
async sendToMissingInstanceSpotFrame(target, payloadFrame, deadlineUnixMs, sourceSpotId, metadataFrame) {
|
|
707
|
+
const operation = { high: this.nodeGeneration, low: this.nextInstanceOperation++ };
|
|
708
|
+
return await this.submitOneWay(target.targetNodeRid, instanceOperationParts([
|
|
709
|
+
(0, service_stateful_wire_codec_1.encodeInstanceSpotActivationHeader)(target, this.nodeGeneration, this.nodeRid, sourceSpotId, 'send', operation, deadlineUnixMs, undefined, metadataFrame !== undefined),
|
|
710
|
+
payloadFrame
|
|
711
|
+
], metadataFrame));
|
|
712
|
+
}
|
|
713
|
+
requestToInstanceSpot(route, payload, timeoutMs, sourceSpotId, metadataFrame) {
|
|
714
|
+
const pending = this.operations.reserve(timeoutMs);
|
|
715
|
+
this.submitRequest(pending, route.targetNodeRid, instanceOperationParts([
|
|
716
|
+
(0, service_stateful_wire_codec_1.encodeInstanceSpotHeader)(route, this.nodeGeneration, this.nodeRid, sourceSpotId, 'request', { high: 2n, low: pending.id }, pending.id, metadataFrame !== undefined),
|
|
717
|
+
(0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)
|
|
718
|
+
], metadataFrame), timeoutMs, 'instanceSpotRequest');
|
|
719
|
+
return pending;
|
|
720
|
+
}
|
|
721
|
+
requestToMissingInstanceSpot(target, payload, timeoutMs, sourceSpotId, metadataFrame) {
|
|
722
|
+
const deadlineUnixMs = BigInt(Date.now() + timeoutMs);
|
|
723
|
+
const payloadFrame = (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload);
|
|
724
|
+
return this.requestToMissingInstanceSpotFrame(target, payloadFrame, deadlineUnixMs, sourceSpotId, metadataFrame);
|
|
725
|
+
}
|
|
726
|
+
requestToMissingInstanceSpotFrame(target, payloadFrame, deadlineUnixMs, sourceSpotId, metadataFrame) {
|
|
727
|
+
const timeoutMs = remainingDeadlineMs(deadlineUnixMs);
|
|
728
|
+
const pending = this.operations.reserve(timeoutMs);
|
|
729
|
+
this.submitRequest(pending, target.targetNodeRid, instanceOperationParts([
|
|
730
|
+
(0, service_stateful_wire_codec_1.encodeInstanceSpotActivationHeader)(target, this.nodeGeneration, this.nodeRid, sourceSpotId, 'request', { high: this.nodeGeneration, low: pending.id }, deadlineUnixMs, pending.id, metadataFrame !== undefined),
|
|
731
|
+
payloadFrame
|
|
732
|
+
], metadataFrame), timeoutMs, 'instanceSpotRequest');
|
|
733
|
+
return pending;
|
|
734
|
+
}
|
|
735
|
+
lookupRemoteActor(targetNodeRid, actorId, timeoutMs) {
|
|
736
|
+
const pending = this.operations.reserve(timeoutMs);
|
|
737
|
+
this.submitRequest(pending, targetNodeRid, [(0, service_stateful_wire_codec_1.encodeActorLookupHeader)(pending.id, actorId)], timeoutMs, 'actorLookup');
|
|
738
|
+
return pending;
|
|
739
|
+
}
|
|
740
|
+
destroyActor(actor, timeoutMs) {
|
|
741
|
+
const pending = this.operations.reserve(timeoutMs);
|
|
742
|
+
const local = actor.nodeRid === this.nodeRid;
|
|
743
|
+
if (local) {
|
|
744
|
+
queueMicrotask(() => {
|
|
745
|
+
try {
|
|
746
|
+
this.registry.destroyActor(actor);
|
|
747
|
+
this.operations.reply(pending.id, { terminalResult: runtime_values_1.RequestResult.Ok, failureCode: 0 });
|
|
748
|
+
}
|
|
749
|
+
catch (error) {
|
|
750
|
+
this.operations.reply(pending.id, failure(error));
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
return pending;
|
|
754
|
+
}
|
|
755
|
+
const header = (0, service_stateful_wire_codec_1.encodeActorDestroyHeader)(pending.id, this.actorFence(actor));
|
|
756
|
+
this.submitRequest(pending, actor.nodeRid, [header], timeoutMs, 'actorDestroy');
|
|
757
|
+
return pending;
|
|
758
|
+
}
|
|
759
|
+
joinActor(actor, targetNodeRid, targetSpot, targetSpotGeneration, payload, timeoutMs) {
|
|
760
|
+
const deadlineMs = performance.now() + timeoutMs;
|
|
761
|
+
const pending = this.operations.reserve(timeoutMs, targetNodeRid === this.nodeRid ? 'registry' : 'sender');
|
|
762
|
+
const target = this.trySpotFence(targetNodeRid, {
|
|
763
|
+
...targetSpot,
|
|
764
|
+
generation: targetSpotGeneration
|
|
765
|
+
});
|
|
766
|
+
this.submitActorJoin(pending, actor, targetNodeRid, target, payload, deadlineMs);
|
|
767
|
+
return pending;
|
|
768
|
+
}
|
|
769
|
+
joinActorCanonical(actor, targetNodeRid, targetSpot, targetSpotGeneration, request, actorFence, local, timeoutMs) {
|
|
770
|
+
const deadlineMs = performance.now() + timeoutMs;
|
|
771
|
+
const pending = this.operations.reserve(timeoutMs, targetNodeRid === this.nodeRid ? 'registry' : 'sender');
|
|
772
|
+
const target = this.trySpotFence(targetNodeRid, {
|
|
773
|
+
...targetSpot,
|
|
774
|
+
generation: targetSpotGeneration
|
|
775
|
+
});
|
|
776
|
+
this.submitActorJoin(pending, actor, targetNodeRid, target, request, deadlineMs, { request, actorFence, local });
|
|
777
|
+
return pending;
|
|
778
|
+
}
|
|
779
|
+
joinActorEntrySpot(actor, targetNodeRid, payload, timeoutMs) {
|
|
780
|
+
const deadlineMs = performance.now() + timeoutMs;
|
|
781
|
+
const pending = this.operations.reserve(timeoutMs, targetNodeRid === this.nodeRid ? 'registry' : 'sender');
|
|
782
|
+
this.submitActorJoin(pending, actor, targetNodeRid, this.tryEntrySpotFence(targetNodeRid), payload, deadlineMs);
|
|
783
|
+
return pending;
|
|
784
|
+
}
|
|
785
|
+
joinActorEntrySpotCanonical(actor, targetNodeRid, request, actorFence, local, timeoutMs) {
|
|
786
|
+
const deadlineMs = performance.now() + timeoutMs;
|
|
787
|
+
const pending = this.operations.reserve(timeoutMs, targetNodeRid === this.nodeRid ? 'registry' : 'sender');
|
|
788
|
+
this.submitActorJoin(pending, actor, targetNodeRid, this.tryEntrySpotFence(targetNodeRid), request, deadlineMs, { request, actorFence, local });
|
|
789
|
+
return pending;
|
|
790
|
+
}
|
|
791
|
+
leaveActor(actor, expectedMembershipEpoch, timeoutMs) {
|
|
792
|
+
const pending = this.operations.reserve(timeoutMs);
|
|
793
|
+
queueMicrotask(() => {
|
|
794
|
+
try {
|
|
795
|
+
const transition = this.registry.leaveActor(actor, expectedMembershipEpoch);
|
|
796
|
+
this.enqueueActorControl(transition.actor.spot.spotId, {
|
|
797
|
+
kind: 'actorControl',
|
|
798
|
+
lifecycleKind: service_runtime_contracts_1.ActorLifecycleKind.Left,
|
|
799
|
+
previousActor: transition.actor.ref,
|
|
800
|
+
currentActor: transition.actor.ref,
|
|
801
|
+
previousSpotId: transition.previousSpot.spotId,
|
|
802
|
+
currentSpotId: transition.currentSpot.spotId,
|
|
803
|
+
previousSpotGeneration: transition.previousSpot.generation,
|
|
804
|
+
currentSpotGeneration: transition.currentSpot.generation,
|
|
805
|
+
previousMembershipEpoch: transition.previousMembershipEpoch,
|
|
806
|
+
currentMembershipEpoch: transition.currentMembershipEpoch,
|
|
807
|
+
resultCode: 0
|
|
808
|
+
});
|
|
809
|
+
this.operations.reply(pending.id, { terminalResult: runtime_values_1.RequestResult.Ok, failureCode: 0 });
|
|
810
|
+
}
|
|
811
|
+
catch (error) {
|
|
812
|
+
this.operations.reply(pending.id, failure(error));
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
return pending;
|
|
816
|
+
}
|
|
817
|
+
bindSession(sessionRid, actor, timeoutMs, deliver, onBindingReplaced, bindingIngress, actorAuthority) {
|
|
818
|
+
const deadlineMs = performance.now() + timeoutMs;
|
|
819
|
+
const pending = this.operations.reserve(timeoutMs, 'sender');
|
|
820
|
+
const generation = this.nextSessionSequence++;
|
|
821
|
+
const localBinding = {
|
|
822
|
+
actor,
|
|
823
|
+
sessionRid,
|
|
824
|
+
sessionOwnerNodeRid: this.nodeRid,
|
|
825
|
+
sessionOwnerNodeGeneration: this.nodeGeneration,
|
|
826
|
+
sessionOwnerId: this.nodeRid,
|
|
827
|
+
sessionOwnerLeaseGeneration: this.nodeGeneration,
|
|
828
|
+
bindingGeneration: generation,
|
|
829
|
+
membershipEpoch: this.registry.actor(actor.actorId)?.membershipEpoch ?? 1n
|
|
830
|
+
};
|
|
831
|
+
const delivery = {
|
|
832
|
+
binding: localBinding,
|
|
833
|
+
deliver,
|
|
834
|
+
...(bindingIngress === undefined ? {} : { bindingIngress }),
|
|
835
|
+
...(onBindingReplaced === undefined ? {} : { onBindingReplaced })
|
|
836
|
+
};
|
|
837
|
+
const deliveryKey = actorKey(actor);
|
|
838
|
+
if (actor.nodeRid === this.nodeRid) {
|
|
839
|
+
let installedDelivery;
|
|
840
|
+
try {
|
|
841
|
+
const previous = this.registry.binding(actor);
|
|
842
|
+
if (previous !== undefined && sameSessionIdentity(previous, localBinding)) {
|
|
843
|
+
const currentDelivery = this.sessionDeliveries.get(deliveryKey);
|
|
844
|
+
if (currentDelivery !== undefined && sameSessionBinding(currentDelivery.binding, previous)) {
|
|
845
|
+
this.sessionDeliveries.set(deliveryKey, {
|
|
846
|
+
...delivery,
|
|
847
|
+
binding: previous
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
else {
|
|
851
|
+
this.sessionDeliveries.set(deliveryKey, { ...delivery, binding: previous });
|
|
852
|
+
}
|
|
853
|
+
this.operations.reply(pending.id, {
|
|
854
|
+
terminalResult: runtime_values_1.RequestResult.Ok,
|
|
855
|
+
failureCode: 0
|
|
856
|
+
});
|
|
857
|
+
return pending;
|
|
858
|
+
}
|
|
859
|
+
const previousDelivery = this.sessionDeliveries.get(deliveryKey);
|
|
860
|
+
const binding = this.registry.bindSession(actor, sessionRid, this.nodeRid, this.nodeGeneration, this.nodeRid, this.nodeGeneration);
|
|
861
|
+
if (previousDelivery !== undefined && previous !== undefined) {
|
|
862
|
+
this.retiredSessionDeliveries.set(sessionDeliveryKey(previous), previousDelivery);
|
|
863
|
+
}
|
|
864
|
+
installedDelivery = { ...delivery, binding };
|
|
865
|
+
this.sessionDeliveries.set(deliveryKey, installedDelivery);
|
|
866
|
+
this.operations.reply(pending.id, {
|
|
867
|
+
terminalResult: runtime_values_1.RequestResult.Ok,
|
|
868
|
+
failureCode: 0,
|
|
869
|
+
kindData: undefined
|
|
870
|
+
});
|
|
871
|
+
if (previous !== undefined) {
|
|
872
|
+
this.sendBoundSessionReplacement(previous, actorAuthorityFromRoute(this.tryActorFence(actor) ?? {
|
|
873
|
+
actor,
|
|
874
|
+
targetNodeGeneration: this.nodeGeneration,
|
|
875
|
+
authorityOwnerGeneration: this.registry.actor(actor.actorId)?.authorityOwnerGeneration
|
|
876
|
+
?? actor.generation,
|
|
877
|
+
ownerLeaseGeneration: this.nodeGeneration
|
|
878
|
+
}));
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
catch (error) {
|
|
882
|
+
if (installedDelivery !== undefined && this.sessionDeliveries.get(deliveryKey) === installedDelivery) {
|
|
883
|
+
this.sessionDeliveries.delete(deliveryKey);
|
|
884
|
+
}
|
|
885
|
+
this.operations.reply(pending.id, failure(error));
|
|
886
|
+
}
|
|
887
|
+
return pending;
|
|
888
|
+
}
|
|
889
|
+
const previousDelivery = this.sessionDeliveries.get(deliveryKey);
|
|
890
|
+
let bindingActorFence;
|
|
891
|
+
let header;
|
|
892
|
+
try {
|
|
893
|
+
bindingActorFence = actorAuthority === undefined
|
|
894
|
+
? this.actorFence(actor)
|
|
895
|
+
: { actor, ...actorAuthority };
|
|
896
|
+
header = (0, service_stateful_wire_codec_1.encodeBoundSessionBindHeader)(pending.id, bindingActorFence, sessionRid, { state: 'active', generation });
|
|
897
|
+
}
|
|
898
|
+
catch (error) {
|
|
899
|
+
this.operations.fail(pending.id, error);
|
|
900
|
+
return pending;
|
|
901
|
+
}
|
|
902
|
+
void this.requestDurableOperation(actor.nodeRid, [header], pending.id, 'streamBind', deadlineMs).then(reply => this.completeRemoteReply(pending, actor.nodeRid, 'streamBind', undefined, reply), error => this.operations.fail(pending.id, error));
|
|
903
|
+
return {
|
|
904
|
+
id: pending.id,
|
|
905
|
+
promise: pending.promise.then(result => {
|
|
906
|
+
if (result.terminalResult === runtime_values_1.RequestResult.Ok && result.streamBinding !== undefined) {
|
|
907
|
+
const committed = {
|
|
908
|
+
...delivery,
|
|
909
|
+
binding: {
|
|
910
|
+
...delivery.binding,
|
|
911
|
+
bindingGeneration: result.streamBinding.bindingGeneration
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
const current = this.sessionDeliveries.get(deliveryKey);
|
|
915
|
+
if (current === previousDelivery
|
|
916
|
+
|| current === undefined
|
|
917
|
+
|| sameSessionOwnerIdentity(current.binding, committed.binding)
|
|
918
|
+
&& current.binding.bindingGeneration < committed.binding.bindingGeneration) {
|
|
919
|
+
if (current !== undefined && !sameSessionBinding(current.binding, committed.binding)) {
|
|
920
|
+
this.retiredSessionDeliveries.set(sessionDeliveryKey(current.binding), current);
|
|
921
|
+
}
|
|
922
|
+
// Publish the exact Location authority used by command 38 in the
|
|
923
|
+
// same Session-owner completion turn as the binding route. Actor
|
|
924
|
+
// lookup only carries a peer-lifecycle fallback for owner lease.
|
|
925
|
+
this.rememberActorRoute(bindingActorFence);
|
|
926
|
+
this.sessionDeliveries.set(deliveryKey, committed);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
return result;
|
|
930
|
+
})
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
unbindSession(sessionRid, actor, expectedBindingGeneration, timeoutMs) {
|
|
934
|
+
const pending = this.operations.reserve(timeoutMs);
|
|
935
|
+
const delivery = this.sessionDeliveries.get(actorKey(actor));
|
|
936
|
+
if (delivery === undefined
|
|
937
|
+
|| delivery.binding.sessionRid !== sessionRid
|
|
938
|
+
|| delivery.binding.bindingGeneration !== expectedBindingGeneration) {
|
|
939
|
+
this.operations.reply(pending.id, {
|
|
940
|
+
terminalResult: runtime_values_1.RequestResult.NotFound,
|
|
941
|
+
failureCode: ACTOR_ROUTE_STALE
|
|
942
|
+
});
|
|
943
|
+
return pending;
|
|
944
|
+
}
|
|
945
|
+
this.sessionDeliveries.delete(actorKey(actor));
|
|
946
|
+
if (actor.nodeRid === this.nodeRid) {
|
|
947
|
+
try {
|
|
948
|
+
this.registry.unbindSession(actor, expectedBindingGeneration);
|
|
949
|
+
this.operations.reply(pending.id, { terminalResult: runtime_values_1.RequestResult.Ok, failureCode: 0 });
|
|
950
|
+
}
|
|
951
|
+
catch (error) {
|
|
952
|
+
this.operations.reply(pending.id, failure(error));
|
|
953
|
+
}
|
|
954
|
+
return pending;
|
|
955
|
+
}
|
|
956
|
+
const header = (0, service_stateful_wire_codec_1.encodeBoundSessionBindHeader)(pending.id, this.actorFence(actor), sessionRid, { state: 'tombstone', retiredGeneration: expectedBindingGeneration });
|
|
957
|
+
this.submitRequest(pending, actor.nodeRid, [header], timeoutMs, 'streamUnbind');
|
|
958
|
+
return pending;
|
|
959
|
+
}
|
|
960
|
+
sessionBindings(sessionRid) {
|
|
961
|
+
return [...this.sessionDeliveries.values()]
|
|
962
|
+
.map(value => value.binding)
|
|
963
|
+
.filter(binding => binding.sessionRid === sessionRid);
|
|
964
|
+
}
|
|
965
|
+
allSessionBindings() {
|
|
966
|
+
return [...this.sessionDeliveries.values()].map(value => value.binding);
|
|
967
|
+
}
|
|
968
|
+
async sendSessionToActor(sessionRid, actor, payload) {
|
|
969
|
+
const delivery = this.sessionDeliveries.get(actorKey(actor));
|
|
970
|
+
if (delivery === undefined || delivery.binding.sessionRid !== sessionRid) {
|
|
971
|
+
return runtime_values_1.SubmitResult.NotFound;
|
|
972
|
+
}
|
|
973
|
+
return this.sendToActor(actor, this.peerGeneration(actor.nodeRid), actor.generation, payload, undefined, {
|
|
974
|
+
sessionRid,
|
|
975
|
+
bindingGeneration: delivery.binding.bindingGeneration
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
async sendBoundSession(actor, expectedBindingGeneration, payload, senderFence) {
|
|
979
|
+
let binding;
|
|
980
|
+
try {
|
|
981
|
+
binding = this.registry.validateBoundSession(actor, expectedBindingGeneration);
|
|
982
|
+
}
|
|
983
|
+
catch {
|
|
984
|
+
return runtime_values_1.SubmitResult.InvalidState;
|
|
985
|
+
}
|
|
986
|
+
const actorFence = this.tryBoundSessionSendFence(actor, senderFence);
|
|
987
|
+
if (actorFence === undefined)
|
|
988
|
+
return runtime_values_1.SubmitResult.InvalidState;
|
|
989
|
+
const header = (0, service_stateful_wire_codec_1.encodeBoundSessionSendHeader)(actorFence, expectedBindingGeneration);
|
|
990
|
+
return this.submitOneWay(binding.sessionOwnerNodeRid, [header, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)]);
|
|
991
|
+
}
|
|
992
|
+
close() {
|
|
993
|
+
if (this.closed)
|
|
994
|
+
return;
|
|
995
|
+
this.closed = true;
|
|
996
|
+
this.operations.close();
|
|
997
|
+
const clearedActors = new Set();
|
|
998
|
+
for (const deliveries of [this.sessionDeliveries, this.retiredSessionDeliveries]) {
|
|
999
|
+
for (const delivery of deliveries.values()) {
|
|
1000
|
+
const actorId = delivery.binding.actor.actorId;
|
|
1001
|
+
if (clearedActors.has(actorId))
|
|
1002
|
+
continue;
|
|
1003
|
+
clearedActors.add(actorId);
|
|
1004
|
+
delivery.bindingIngress?.clearOutbound(actorId, new Error(`Actor '${actorId}' Session service closed with retained outbound delivery.`));
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
this.sessionDeliveries.clear();
|
|
1008
|
+
this.retiredSessionDeliveries.clear();
|
|
1009
|
+
this.appliedReplacementNotices.clear();
|
|
1010
|
+
this.instanceIntents.clear();
|
|
1011
|
+
this.pendingInstanceTerminals.clear();
|
|
1012
|
+
this.pendingInstanceAuthorityTerminals.clear();
|
|
1013
|
+
for (const waiters of this.instanceApplicationWaiters.values()) {
|
|
1014
|
+
for (const waiter of waiters)
|
|
1015
|
+
waiter();
|
|
1016
|
+
}
|
|
1017
|
+
this.instanceApplicationWaiters.clear();
|
|
1018
|
+
this.admittedUserSpotOperations.clear();
|
|
1019
|
+
this.actorRoutes.clear();
|
|
1020
|
+
this.spotRoutes.clear();
|
|
1021
|
+
this.directSpotRoutes.clear();
|
|
1022
|
+
for (const state of this.spotMessageFollow.values()) {
|
|
1023
|
+
while (state.queuedCount > 0)
|
|
1024
|
+
this.takeSpotMessageFollow(state);
|
|
1025
|
+
}
|
|
1026
|
+
this.spotMessageFollow.clear();
|
|
1027
|
+
}
|
|
1028
|
+
async ingress(record) {
|
|
1029
|
+
// These frozen relocation controls overlap the legacy stateful command
|
|
1030
|
+
// number range (30-34). They are bare infrastructure records and must
|
|
1031
|
+
// fall through to RawServiceMeshRuntime's relocation ingress instead of
|
|
1032
|
+
// being decoded as stateful actor/spot work.
|
|
1033
|
+
if (record.command === service_stateful_wire_codec_1.M6bServiceWireCommand.relocationReady
|
|
1034
|
+
|| record.command === service_stateful_wire_codec_1.M6bServiceWireCommand.relocationData
|
|
1035
|
+
|| record.command === service_stateful_wire_codec_1.M6bServiceWireCommand.replyRelay
|
|
1036
|
+
|| record.command === service_stateful_wire_codec_1.M6bServiceWireCommand.relocationCutover) {
|
|
1037
|
+
return undefined;
|
|
1038
|
+
}
|
|
1039
|
+
if (record.command < service_stateful_wire_codec_1.M6bServiceWireCommand.spotSend
|
|
1040
|
+
|| (record.command > service_stateful_wire_codec_1.M6bServiceWireCommand.instanceSpot
|
|
1041
|
+
&& record.command !== service_stateful_wire_codec_1.M6bServiceWireCommand.userSpotCreate
|
|
1042
|
+
&& record.command !== service_stateful_wire_codec_1.M6bServiceWireCommand.userSpotClose
|
|
1043
|
+
&& record.command !== service_stateful_wire_codec_1.M6bServiceWireCommand.actorCreate
|
|
1044
|
+
&& record.command !== service_stateful_wire_codec_1.M6bServiceWireCommand.messageFollow
|
|
1045
|
+
&& record.command !== service_stateful_wire_codec_1.M6bServiceWireCommand.boundSessionReplaced)) {
|
|
1046
|
+
return undefined;
|
|
1047
|
+
}
|
|
1048
|
+
let decoded;
|
|
1049
|
+
let canonicalActorJoin;
|
|
1050
|
+
try {
|
|
1051
|
+
if (record.command === service_stateful_wire_codec_1.M6bServiceWireCommand.actorJoin) {
|
|
1052
|
+
try {
|
|
1053
|
+
canonicalActorJoin = (0, service_wire_pilot_codec_generated_1.decodeActorJoin28)(record.parts);
|
|
1054
|
+
}
|
|
1055
|
+
catch {
|
|
1056
|
+
return 'protocolError';
|
|
1057
|
+
}
|
|
1058
|
+
decoded = statefulActorJoinFromCanonical(canonicalActorJoin);
|
|
1059
|
+
}
|
|
1060
|
+
else {
|
|
1061
|
+
decoded = (0, service_stateful_wire_codec_1.decodeStatefulHeader)(record.parts[0]);
|
|
1062
|
+
}
|
|
1063
|
+
const hasPayload = [
|
|
1064
|
+
'spotSend',
|
|
1065
|
+
'spotRequest',
|
|
1066
|
+
'logicalMulticast',
|
|
1067
|
+
'actorSend',
|
|
1068
|
+
'actorRequest',
|
|
1069
|
+
'actorJoin',
|
|
1070
|
+
'boundSessionSend'
|
|
1071
|
+
].includes(decoded.kind);
|
|
1072
|
+
const instanceMetadata = decoded.kind === 'instanceSpot'
|
|
1073
|
+
&& (record.flags & service_stateful_wire_codec_1.M6bServiceWireFlag.metadata) !== 0;
|
|
1074
|
+
const userSpotInfrastructure = decoded.kind === 'userSpotCreate'
|
|
1075
|
+
|| decoded.kind === 'userSpotClose'
|
|
1076
|
+
|| decoded.kind === 'actorCreate'
|
|
1077
|
+
|| decoded.kind === 'messageFollow'
|
|
1078
|
+
|| decoded.kind === 'boundSessionReplaced';
|
|
1079
|
+
if (record.parts.length < 1
|
|
1080
|
+
|| record.parts.length > (instanceMetadata ? 3 : 2)
|
|
1081
|
+
|| (hasPayload && decoded.kind !== 'actorJoin' && record.parts.length !== 2)
|
|
1082
|
+
|| (decoded.kind === 'instanceSpot'
|
|
1083
|
+
&& record.parts.length !== (instanceMetadata ? 3 : 2))
|
|
1084
|
+
|| (userSpotInfrastructure && record.parts.length !== 1)) {
|
|
1085
|
+
return 'protocolError';
|
|
1086
|
+
}
|
|
1087
|
+
const metadataFrame = instanceMetadata
|
|
1088
|
+
? (0, service_metadata_codec_1.validateServiceMetadataFrame)(record.parts[1])
|
|
1089
|
+
: undefined;
|
|
1090
|
+
const canonicalPayload = canonicalActorJoin?.payload === undefined
|
|
1091
|
+
? undefined
|
|
1092
|
+
: {
|
|
1093
|
+
packetName: canonicalActorJoin.payload.packetName,
|
|
1094
|
+
contentType: canonicalActorJoin.payload.contentType,
|
|
1095
|
+
payload: Buffer.from(canonicalActorJoin.payload.payload)
|
|
1096
|
+
};
|
|
1097
|
+
const payloadFrame = canonicalPayload === undefined
|
|
1098
|
+
? (record.parts.length >= 2 ? record.parts[record.parts.length - 1] : undefined)
|
|
1099
|
+
: (0, service_wire_m6a_codec_1.encodeApplicationPayload)(canonicalPayload);
|
|
1100
|
+
try {
|
|
1101
|
+
return await this.handleIngress(record, decoded, payloadFrame, metadataFrame, canonicalActorJoin, canonicalPayload);
|
|
1102
|
+
}
|
|
1103
|
+
catch (error) {
|
|
1104
|
+
const correlation = statefulCorrelation(decoded);
|
|
1105
|
+
if (correlation !== undefined) {
|
|
1106
|
+
const result = failure(error);
|
|
1107
|
+
this.replyWire(record, correlation, result.terminalResult, result.failureCode);
|
|
1108
|
+
return 'infrastructure';
|
|
1109
|
+
}
|
|
1110
|
+
if (error instanceof service_stateful_registry_1.ServiceStaleGenerationError)
|
|
1111
|
+
return 'protocolError';
|
|
1112
|
+
if (error instanceof contracts_1.ZLinkFrameworkException) {
|
|
1113
|
+
const kind = (0, framework_errors_internal_1.internalFrameworkErrorKind)(error);
|
|
1114
|
+
if (kind === framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RequestTargetNotFound
|
|
1115
|
+
|| kind === framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving
|
|
1116
|
+
|| kind === framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotGenerationStale) {
|
|
1117
|
+
return 'protocolError';
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
throw error;
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
catch (error) {
|
|
1124
|
+
if (error instanceof service_wire_m6a_codec_1.ServiceWireProtocolError)
|
|
1125
|
+
return 'protocolError';
|
|
1126
|
+
throw error;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
async handleIngress(ingress, record, payloadFrame, metadataFrame, canonicalActorJoin, canonicalActorJoinPayload) {
|
|
1130
|
+
switch (record.kind) {
|
|
1131
|
+
case 'messageFollow': {
|
|
1132
|
+
if (record.source.kind !== record.target.kind
|
|
1133
|
+
|| record.target.authorityOwnerGeneration
|
|
1134
|
+
<= record.source.authorityOwnerGeneration) {
|
|
1135
|
+
throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Message Follow target owner generation must increase at every hop.');
|
|
1136
|
+
}
|
|
1137
|
+
if (record.source.targetNodeRid !== ingress.sourceRoutingId) {
|
|
1138
|
+
throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Message Follow sender does not match the source route target.');
|
|
1139
|
+
}
|
|
1140
|
+
const admitted = this.raw.topology.peer(record.source.targetNodeRid);
|
|
1141
|
+
if (admitted?.descriptor.lifecycleGeneration !== record.source.targetNodeGeneration) {
|
|
1142
|
+
throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Message Follow source route is not the current admitted peer.');
|
|
1143
|
+
}
|
|
1144
|
+
const targetGeneration = record.target.targetNodeRid === this.nodeRid
|
|
1145
|
+
? this.nodeGeneration
|
|
1146
|
+
: this.raw.topology.peer(record.target.targetNodeRid)?.descriptor
|
|
1147
|
+
.lifecycleGeneration;
|
|
1148
|
+
if (targetGeneration !== record.target.targetNodeGeneration) {
|
|
1149
|
+
throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Message Follow target route is not the current topology target.');
|
|
1150
|
+
}
|
|
1151
|
+
if (record.source.kind === 'actor') {
|
|
1152
|
+
this.messageFollowHandler?.(record);
|
|
1153
|
+
}
|
|
1154
|
+
else {
|
|
1155
|
+
const directKey = directSpotKey(record.source.spot.spotId);
|
|
1156
|
+
const current = this.directSpotRoutes.get(directKey);
|
|
1157
|
+
if (current !== undefined
|
|
1158
|
+
&& sameMessageFollowSpotSource(current, record.source)) {
|
|
1159
|
+
this.directSpotRoutes.delete(directKey);
|
|
1160
|
+
const exactKey = spotKey(record.source.spot);
|
|
1161
|
+
const exact = this.spotRoutes.get(exactKey);
|
|
1162
|
+
if (exact !== undefined && sameMessageFollowSpotSource(exact, record.source)) {
|
|
1163
|
+
this.spotRoutes.delete(exactKey);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
return 'infrastructure';
|
|
1168
|
+
}
|
|
1169
|
+
case 'spotSend':
|
|
1170
|
+
case 'spotRequest': {
|
|
1171
|
+
const followed = this.holdOrRelaySpotMessage(ingress, record);
|
|
1172
|
+
if (followed !== undefined)
|
|
1173
|
+
return followed;
|
|
1174
|
+
this.validateDirectSpotFence(record.target);
|
|
1175
|
+
return this.enqueueApplicationFrame(ingress, `spot:${record.target.spot.spotId}`, payloadFrame, {
|
|
1176
|
+
receiveKind: record.kind === 'spotSend' ? service_runtime_contracts_1.ReceiveKind.SpotSend : service_runtime_contracts_1.ReceiveKind.SpotRequest,
|
|
1177
|
+
operationKind: record.kind === 'spotRequest' ? service_runtime_contracts_1.OperationKind.SpotRequest : 0,
|
|
1178
|
+
...(record.correlation === undefined ? {} : { correlation: record.correlation }),
|
|
1179
|
+
sourceSpotId: record.sourceSpotId,
|
|
1180
|
+
targetSpot: record.target.spot,
|
|
1181
|
+
...(record.kind === 'spotRequest'
|
|
1182
|
+
? { reply: this.replyPort(ingress, record.correlation, 'spotRequest') }
|
|
1183
|
+
: {})
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
case 'actorSend':
|
|
1187
|
+
case 'actorRequest': {
|
|
1188
|
+
const actor = record.boundSession === undefined
|
|
1189
|
+
? this.validateActorMessageFence(record.target)
|
|
1190
|
+
: this.validateActorFence(record.target);
|
|
1191
|
+
if (record.boundSession !== undefined) {
|
|
1192
|
+
const binding = this.registry.validateBoundSession(record.target.actor, record.boundSession.bindingGeneration);
|
|
1193
|
+
if (binding.sessionRid !== record.boundSession.sessionRid
|
|
1194
|
+
|| binding.sessionOwnerNodeRid !== ingress.sourceRoutingId) {
|
|
1195
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('binding', record.target.actor.actorId);
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
return this.enqueueApplicationFrame(ingress, `actor:${actor.ref.actorId}\0${actor.ref.generation}`, payloadFrame, {
|
|
1199
|
+
receiveKind: record.kind === 'actorSend' ? service_runtime_contracts_1.ReceiveKind.ActorSend : service_runtime_contracts_1.ReceiveKind.ActorRequest,
|
|
1200
|
+
operationKind: record.kind === 'actorRequest' ? service_runtime_contracts_1.OperationKind.ActorRequest : 0,
|
|
1201
|
+
...(record.correlation === undefined ? {} : { correlation: record.correlation }),
|
|
1202
|
+
...(record.sourceActor === undefined
|
|
1203
|
+
? {}
|
|
1204
|
+
: { sourceActor: { ...record.sourceActor, nodeRid: ingress.sourceRoutingId } }),
|
|
1205
|
+
...(record.boundSession === undefined
|
|
1206
|
+
? {}
|
|
1207
|
+
: { sourceBindingGeneration: record.boundSession.bindingGeneration }),
|
|
1208
|
+
targetActor: actor.ref,
|
|
1209
|
+
messageFollowOrigin: {
|
|
1210
|
+
sourceNodeRid: ingress.sourceRoutingId,
|
|
1211
|
+
originalOperation: {
|
|
1212
|
+
high: this.peerGeneration(ingress.sourceRoutingId),
|
|
1213
|
+
low: record.correlation ?? this.nextMessageFollowOperation++
|
|
1214
|
+
},
|
|
1215
|
+
originalReplyRouteId: ingress.requestSequence ?? 0n
|
|
1216
|
+
},
|
|
1217
|
+
...(record.kind === 'actorRequest'
|
|
1218
|
+
? { reply: this.replyPort(ingress, record.correlation, 'actorRequest') }
|
|
1219
|
+
: {})
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
case 'logicalMulticast':
|
|
1223
|
+
await this.enqueueLogicalMulticastFrame(record.channelName, record.topic, record.sourceSpotId, payloadFrame, ingress.sourceRoutingId, requireApplicationJobOwner(ingress));
|
|
1224
|
+
return 'application';
|
|
1225
|
+
case 'actorLookup':
|
|
1226
|
+
return this.replyLookup(ingress, record);
|
|
1227
|
+
case 'actorDestroy':
|
|
1228
|
+
return this.replyDestroy(ingress, record);
|
|
1229
|
+
case 'actorJoin':
|
|
1230
|
+
// Canonical command-28 is a request/reply control. A one-way ingress
|
|
1231
|
+
// cannot carry its typed terminal, so report it as a protocol error
|
|
1232
|
+
// through RawServiceMeshRuntime rather than attempting replyWire().
|
|
1233
|
+
if (canonicalActorJoin !== undefined && ingress.requestSequence === undefined) {
|
|
1234
|
+
return 'protocolError';
|
|
1235
|
+
}
|
|
1236
|
+
this.validateSpotFence(record.target);
|
|
1237
|
+
return this.enqueueActorJoin(ingress, record, payloadFrame, canonicalActorJoin, canonicalActorJoinPayload);
|
|
1238
|
+
case 'boundSessionBind':
|
|
1239
|
+
return this.replySessionBind(ingress, record);
|
|
1240
|
+
case 'boundSessionReplaced':
|
|
1241
|
+
return this.handleBoundSessionReplaced(ingress, record);
|
|
1242
|
+
case 'boundSessionSend':
|
|
1243
|
+
return await this.deliverBoundSession(ingress, record, payloadFrame);
|
|
1244
|
+
case 'instanceSpot':
|
|
1245
|
+
return this.enqueueInstanceSpot(ingress, record, payloadFrame, metadataFrame);
|
|
1246
|
+
case 'userSpotCreate':
|
|
1247
|
+
case 'userSpotClose':
|
|
1248
|
+
case 'actorCreate':
|
|
1249
|
+
return this.handleUserSpotOperation(ingress, record);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
enqueueInstanceSpot(ingress, record, payloadFrame, metadataFrame) {
|
|
1253
|
+
if (record.activation === 'missing' && this.asyncInstanceAuthority !== undefined) {
|
|
1254
|
+
const ownedIngress = shareIngressOwnership(ingress);
|
|
1255
|
+
void this.continueMissingInstanceActivation(ownedIngress, record, payloadFrame, undefined, metadataFrame).finally(() => ownedIngress.applicationJobOwner?.close());
|
|
1256
|
+
return 'infrastructure';
|
|
1257
|
+
}
|
|
1258
|
+
if (record.activation === 'ready'
|
|
1259
|
+
&& this.needsInstanceApplicationMaterialization(ingress, record)) {
|
|
1260
|
+
const ownedIngress = shareIngressOwnership(ingress);
|
|
1261
|
+
void this.continueReadyInstanceMaterialization(ownedIngress, record, payloadFrame, metadataFrame).finally(() => ownedIngress.applicationJobOwner?.close());
|
|
1262
|
+
return 'infrastructure';
|
|
1263
|
+
}
|
|
1264
|
+
const spot = this.requireInstanceActivation(ingress, record);
|
|
1265
|
+
const applicationTarget = record.activation === 'missing'
|
|
1266
|
+
? {
|
|
1267
|
+
targetSpotId: record.target.targetSpotId,
|
|
1268
|
+
stableType: record.target.stableType,
|
|
1269
|
+
objectGeneration: spot.ref.generation
|
|
1270
|
+
}
|
|
1271
|
+
: this.instanceApplicationTarget(record);
|
|
1272
|
+
return this.enqueueActivatedInstanceSpot(ingress, record, payloadFrame, spot, undefined, this.instanceApplicationTerminalCompletion(applicationTarget), metadataFrame);
|
|
1273
|
+
}
|
|
1274
|
+
needsInstanceApplicationMaterialization(ingress, record) {
|
|
1275
|
+
const lifecycle = this.instanceApplicationLifecycle;
|
|
1276
|
+
if (lifecycle === undefined)
|
|
1277
|
+
return false;
|
|
1278
|
+
const { intent } = this.requireReadyInstanceApplicationRoute(ingress, record);
|
|
1279
|
+
if (this.instanceApplicationLifecycle?.isIdleEvicting?.({
|
|
1280
|
+
targetSpotId: record.route.targetSpotId,
|
|
1281
|
+
stableType: intent.instanceType
|
|
1282
|
+
}) === true) {
|
|
1283
|
+
throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Instance Spot '${record.route.targetSpotId}' is entering idle eviction.`);
|
|
1284
|
+
}
|
|
1285
|
+
const applicationTarget = {
|
|
1286
|
+
targetSpotId: record.route.targetSpotId,
|
|
1287
|
+
stableType: intent.instanceType
|
|
1288
|
+
};
|
|
1289
|
+
// A close seals execution only after the current application count reaches
|
|
1290
|
+
// zero. A new Instance message must wait for that close even while the old
|
|
1291
|
+
// activation is still materialized; otherwise it can be admitted after
|
|
1292
|
+
// the close quiescence check and be removed with the old activation.
|
|
1293
|
+
if (lifecycle.isClosing?.(applicationTarget) === true)
|
|
1294
|
+
return true;
|
|
1295
|
+
return !lifecycle.isMaterialized(applicationTarget);
|
|
1296
|
+
}
|
|
1297
|
+
enqueueActivatedInstanceSpot(ingress, record, payloadFrame, spot, localReply, onTerminalCompletion, metadataFrame, activationTerminal = false, applicationTargetOverride) {
|
|
1298
|
+
let operationKey;
|
|
1299
|
+
if (record.activation === 'missing') {
|
|
1300
|
+
const now = BigInt(Date.now());
|
|
1301
|
+
for (const [key, deadline] of this.admittedInstanceOperations) {
|
|
1302
|
+
if (deadline < now)
|
|
1303
|
+
this.admittedInstanceOperations.delete(key);
|
|
1304
|
+
}
|
|
1305
|
+
operationKey = instanceOperationKey(record);
|
|
1306
|
+
if (this.admittedInstanceOperations.has(operationKey))
|
|
1307
|
+
return 'application';
|
|
1308
|
+
}
|
|
1309
|
+
const directReply = record.operationKind === 'request'
|
|
1310
|
+
? localReply ?? this.replyPort(ingress, record.replyRouteId, 'instanceSpotRequest')
|
|
1311
|
+
: undefined;
|
|
1312
|
+
const applicationTarget = applicationTargetOverride
|
|
1313
|
+
?? (record.activation === 'missing'
|
|
1314
|
+
? {
|
|
1315
|
+
targetSpotId: record.target.targetSpotId,
|
|
1316
|
+
stableType: record.target.stableType,
|
|
1317
|
+
objectGeneration: spot.ref.generation
|
|
1318
|
+
}
|
|
1319
|
+
: this.instanceApplicationTarget(record));
|
|
1320
|
+
let deferredReply;
|
|
1321
|
+
const terminalCompletion = onTerminalCompletion === undefined
|
|
1322
|
+
? undefined
|
|
1323
|
+
: async () => {
|
|
1324
|
+
// The application turn has returned before authority cleanup starts.
|
|
1325
|
+
// Mark it quiescent first so a close requested by that turn can finish
|
|
1326
|
+
// its local cleanup and release the exact authority fence below.
|
|
1327
|
+
this.completeInstanceApplicationOperation(applicationTarget.targetSpotId);
|
|
1328
|
+
try {
|
|
1329
|
+
await onTerminalCompletion();
|
|
1330
|
+
}
|
|
1331
|
+
finally {
|
|
1332
|
+
if (deferredReply !== undefined && directReply !== undefined) {
|
|
1333
|
+
directReply(...deferredReply);
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
const result = this.enqueueApplicationFrame(ingress, `spot:${spot.ref.spotId}`, payloadFrame, {
|
|
1338
|
+
receiveKind: service_runtime_contracts_1.ReceiveKind.InstanceSpotActivation,
|
|
1339
|
+
operationKind: record.operationKind === 'request' ? service_runtime_contracts_1.OperationKind.InstanceSpotRequest : 0,
|
|
1340
|
+
...(record.operationKind === 'request' ? { correlation: record.replyRouteId } : {}),
|
|
1341
|
+
...(record.sourceSpotId === undefined ? {} : { sourceSpotId: record.sourceSpotId }),
|
|
1342
|
+
targetSpot: spot.ref,
|
|
1343
|
+
...(metadataFrame === undefined ? {} : { applicationMetadata: metadataFrame }),
|
|
1344
|
+
...(terminalCompletion === undefined ? {} : { onTerminalCompletion: terminalCompletion }),
|
|
1345
|
+
...(record.operationKind === 'request'
|
|
1346
|
+
? {
|
|
1347
|
+
reply: onTerminalCompletion === undefined
|
|
1348
|
+
? directReply
|
|
1349
|
+
: ((...reply) => {
|
|
1350
|
+
deferredReply = reply;
|
|
1351
|
+
return true;
|
|
1352
|
+
})
|
|
1353
|
+
}
|
|
1354
|
+
: {})
|
|
1355
|
+
});
|
|
1356
|
+
if (operationKey !== undefined && result === 'application' && record.activation === 'missing') {
|
|
1357
|
+
this.admittedInstanceOperations.set(operationKey, record.deadlineUnixMs);
|
|
1358
|
+
}
|
|
1359
|
+
if (onTerminalCompletion !== undefined && result === 'application') {
|
|
1360
|
+
this.beginInstanceApplicationOperation(applicationTarget.targetSpotId);
|
|
1361
|
+
if (activationTerminal) {
|
|
1362
|
+
this.beginInstanceAuthorityOperation(applicationTarget.targetSpotId);
|
|
1363
|
+
}
|
|
1364
|
+
this.instanceApplicationLifecycle?.beginTerminal(applicationTarget);
|
|
1365
|
+
}
|
|
1366
|
+
return result;
|
|
1367
|
+
}
|
|
1368
|
+
async continueMissingInstanceActivation(ingress, record, payloadFrame, localReply, metadataFrame) {
|
|
1369
|
+
try {
|
|
1370
|
+
this.validateInstanceIngress(ingress, record);
|
|
1371
|
+
const activation = await this.activateMissingInstanceAsync(record, payloadFrame, metadataFrame);
|
|
1372
|
+
if (this.closed)
|
|
1373
|
+
return;
|
|
1374
|
+
const admitted = this.enqueueActivatedInstanceSpot(ingress, record, payloadFrame, activation.spot, localReply, this.activationTerminalCompletion(record.target, activation.route), metadataFrame, true, this.instanceApplicationTarget(record, activation.route.objectGeneration));
|
|
1375
|
+
if (admitted !== 'application') {
|
|
1376
|
+
throw new Error('Activated Instance message was not admitted to the local queue.');
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
catch (error) {
|
|
1380
|
+
let terminalError = error;
|
|
1381
|
+
if (error instanceof ServiceInstanceActivationRedirectError && !this.closed) {
|
|
1382
|
+
try {
|
|
1383
|
+
await this.relayMissingInstanceActivation(record, payloadFrame, error.route, ingress, localReply, metadataFrame);
|
|
1384
|
+
return;
|
|
1385
|
+
}
|
|
1386
|
+
catch (relayError) {
|
|
1387
|
+
terminalError = relayError;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
if (record.operationKind !== 'request')
|
|
1391
|
+
return;
|
|
1392
|
+
const result = failure(terminalError);
|
|
1393
|
+
if (localReply !== undefined) {
|
|
1394
|
+
localReply(result.terminalResult, result.failureCode);
|
|
1395
|
+
}
|
|
1396
|
+
else {
|
|
1397
|
+
if (record.replyRouteId === undefined)
|
|
1398
|
+
return;
|
|
1399
|
+
this.replyWire(ingress, record.replyRouteId, result.terminalResult, result.failureCode);
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
async continueReadyInstanceMaterialization(ingress, record, payloadFrame, metadataFrame) {
|
|
1404
|
+
try {
|
|
1405
|
+
if (!this.acceptsLocalMissingInstancePlacement()) {
|
|
1406
|
+
// A stale Ready route must not rematerialize an Instance Spot on a
|
|
1407
|
+
// node that has already withdrawn placement admission for relocation.
|
|
1408
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', record.route.targetSpotId);
|
|
1409
|
+
}
|
|
1410
|
+
const { intent, route } = this.requireReadyInstanceApplicationRoute(ingress, record);
|
|
1411
|
+
const applicationTarget = {
|
|
1412
|
+
targetSpotId: record.route.targetSpotId,
|
|
1413
|
+
stableType: intent.instanceType,
|
|
1414
|
+
objectGeneration: route.objectGeneration
|
|
1415
|
+
};
|
|
1416
|
+
await this.instanceApplicationLifecycle?.materialize(applicationTarget, route.objectGeneration);
|
|
1417
|
+
if (this.closed)
|
|
1418
|
+
return;
|
|
1419
|
+
const latestRoute = this.instanceIntents.get(record.route.targetSpotId)?.route;
|
|
1420
|
+
const refreshedRecord = latestRoute !== undefined
|
|
1421
|
+
&& sameInstanceApplicationOwner(latestRoute, record.route)
|
|
1422
|
+
? { ...record, route: latestRoute }
|
|
1423
|
+
: record;
|
|
1424
|
+
const spot = this.requireInstanceActivation(ingress, refreshedRecord);
|
|
1425
|
+
const admitted = this.enqueueActivatedInstanceSpot(ingress, refreshedRecord, payloadFrame, spot, undefined, this.instanceApplicationTerminalCompletion(this.instanceApplicationTarget(refreshedRecord)), metadataFrame);
|
|
1426
|
+
if (admitted !== 'application') {
|
|
1427
|
+
throw new Error('Rematerialized Instance message was not admitted to the local queue.');
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
catch (error) {
|
|
1431
|
+
if (record.operationKind !== 'request' || record.replyRouteId === undefined)
|
|
1432
|
+
return;
|
|
1433
|
+
const result = failure(error);
|
|
1434
|
+
this.replyWire(ingress, record.replyRouteId, result.terminalResult, result.failureCode);
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
activationTerminalCompletion(target, route) {
|
|
1438
|
+
let completion;
|
|
1439
|
+
const applicationTarget = {
|
|
1440
|
+
targetSpotId: target.targetSpotId,
|
|
1441
|
+
stableType: target.stableType,
|
|
1442
|
+
objectGeneration: route.objectGeneration
|
|
1443
|
+
};
|
|
1444
|
+
return () => completion ??= (async () => {
|
|
1445
|
+
let authorityCompletionSignaled = false;
|
|
1446
|
+
try {
|
|
1447
|
+
const released = await this.asyncInstanceAuthority?.complete(target, route);
|
|
1448
|
+
this.completeInstanceAuthorityOperation(target.targetSpotId);
|
|
1449
|
+
authorityCompletionSignaled = true;
|
|
1450
|
+
if (released !== undefined) {
|
|
1451
|
+
const authorityReleased = await this.instanceApplicationLifecycle?.completeTerminal(applicationTarget)
|
|
1452
|
+
?? false;
|
|
1453
|
+
if (!authorityReleased) {
|
|
1454
|
+
this.replaceCommittedInstanceRoute(target.stableType, route, released);
|
|
1455
|
+
}
|
|
1456
|
+
else {
|
|
1457
|
+
this.forgetClosedInstanceRoute(released);
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
finally {
|
|
1462
|
+
if (!authorityCompletionSignaled) {
|
|
1463
|
+
this.completeInstanceAuthorityOperation(target.targetSpotId);
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
})();
|
|
1467
|
+
}
|
|
1468
|
+
instanceApplicationTerminalCompletion(target) {
|
|
1469
|
+
return async () => {
|
|
1470
|
+
const authorityReleased = await this.instanceApplicationLifecycle?.completeTerminal(target)
|
|
1471
|
+
?? false;
|
|
1472
|
+
if (!authorityReleased)
|
|
1473
|
+
return;
|
|
1474
|
+
const current = this.instanceIntents.get(target.targetSpotId);
|
|
1475
|
+
if (current?.instanceType === target.stableType
|
|
1476
|
+
&& current.route.objectGeneration === target.objectGeneration) {
|
|
1477
|
+
this.forgetClosedInstanceRoute(current.route);
|
|
1478
|
+
}
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
instanceApplicationTarget(record, missingObjectGeneration) {
|
|
1482
|
+
if (record.activation === 'missing') {
|
|
1483
|
+
if (missingObjectGeneration === undefined) {
|
|
1484
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', record.target.targetSpotId);
|
|
1485
|
+
}
|
|
1486
|
+
return {
|
|
1487
|
+
targetSpotId: record.target.targetSpotId,
|
|
1488
|
+
stableType: record.target.stableType,
|
|
1489
|
+
objectGeneration: missingObjectGeneration
|
|
1490
|
+
};
|
|
1491
|
+
}
|
|
1492
|
+
const intent = this.instanceIntents.get(record.route.targetSpotId);
|
|
1493
|
+
if (intent === undefined) {
|
|
1494
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', record.route.targetSpotId);
|
|
1495
|
+
}
|
|
1496
|
+
return {
|
|
1497
|
+
targetSpotId: record.route.targetSpotId,
|
|
1498
|
+
stableType: intent.instanceType,
|
|
1499
|
+
objectGeneration: record.route.objectGeneration
|
|
1500
|
+
};
|
|
1501
|
+
}
|
|
1502
|
+
beginInstanceApplicationOperation(spotId) {
|
|
1503
|
+
const key = String(spotId);
|
|
1504
|
+
this.pendingInstanceTerminals.set(key, (this.pendingInstanceTerminals.get(key) ?? 0) + 1);
|
|
1505
|
+
}
|
|
1506
|
+
beginInstanceAuthorityOperation(spotId) {
|
|
1507
|
+
const key = String(spotId);
|
|
1508
|
+
this.pendingInstanceAuthorityTerminals.set(key, (this.pendingInstanceAuthorityTerminals.get(key) ?? 0) + 1);
|
|
1509
|
+
}
|
|
1510
|
+
completeInstanceApplicationOperation(spotId) {
|
|
1511
|
+
const key = String(spotId);
|
|
1512
|
+
const pending = this.pendingInstanceTerminals.get(key);
|
|
1513
|
+
if (pending === undefined || pending <= 1) {
|
|
1514
|
+
this.pendingInstanceTerminals.delete(key);
|
|
1515
|
+
this.completeInstanceApplicationWaitersIfQuiescent(key);
|
|
1516
|
+
return;
|
|
1517
|
+
}
|
|
1518
|
+
this.pendingInstanceTerminals.set(key, pending - 1);
|
|
1519
|
+
}
|
|
1520
|
+
completeInstanceAuthorityOperation(spotId) {
|
|
1521
|
+
const key = String(spotId);
|
|
1522
|
+
const pending = this.pendingInstanceAuthorityTerminals.get(key);
|
|
1523
|
+
if (pending === undefined || pending <= 1) {
|
|
1524
|
+
this.pendingInstanceAuthorityTerminals.delete(key);
|
|
1525
|
+
this.completeInstanceApplicationWaitersIfQuiescent(key);
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
this.pendingInstanceAuthorityTerminals.set(key, pending - 1);
|
|
1529
|
+
}
|
|
1530
|
+
completeInstanceApplicationWaitersIfQuiescent(key) {
|
|
1531
|
+
if ((this.pendingInstanceTerminals.get(key) ?? 0) !== 0
|
|
1532
|
+
|| (this.pendingInstanceAuthorityTerminals.get(key) ?? 0) !== 0)
|
|
1533
|
+
return;
|
|
1534
|
+
const waiters = this.instanceApplicationWaiters.get(key);
|
|
1535
|
+
if (waiters === undefined)
|
|
1536
|
+
return;
|
|
1537
|
+
this.instanceApplicationWaiters.delete(key);
|
|
1538
|
+
for (const waiter of waiters)
|
|
1539
|
+
waiter();
|
|
1540
|
+
}
|
|
1541
|
+
async relayMissingInstanceActivation(record, payloadFrame, route, ingress, localReply, metadataFrame) {
|
|
1542
|
+
const remainingMs = Number(record.deadlineUnixMs - BigInt(Date.now()));
|
|
1543
|
+
if (remainingMs <= 0) {
|
|
1544
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', route.targetSpotId);
|
|
1545
|
+
}
|
|
1546
|
+
const redirectedTarget = {
|
|
1547
|
+
...record.target,
|
|
1548
|
+
targetNodeRid: route.targetNodeRid,
|
|
1549
|
+
targetNodeGeneration: route.targetNodeGeneration,
|
|
1550
|
+
targetSpotId: route.targetSpotId
|
|
1551
|
+
};
|
|
1552
|
+
if (record.operationKind === 'send') {
|
|
1553
|
+
const submitted = await this.submitOneWay(route.targetNodeRid, instanceOperationParts([
|
|
1554
|
+
(0, service_stateful_wire_codec_1.encodeInstanceSpotActivationHeader)(redirectedTarget, this.nodeGeneration, this.nodeRid, record.sourceSpotId, 'send', record.operation, record.deadlineUnixMs, undefined, metadataFrame !== undefined),
|
|
1555
|
+
payloadFrame
|
|
1556
|
+
], metadataFrame));
|
|
1557
|
+
if (submitted !== runtime_values_1.SubmitResult.Ok) {
|
|
1558
|
+
throw new Error(`Instance activation redirect was not admitted: ${submitted}.`);
|
|
1559
|
+
}
|
|
1560
|
+
return;
|
|
1561
|
+
}
|
|
1562
|
+
const pending = this.operations.reserve(remainingMs);
|
|
1563
|
+
this.submitRequest(pending, route.targetNodeRid, instanceOperationParts([
|
|
1564
|
+
(0, service_stateful_wire_codec_1.encodeInstanceSpotActivationHeader)(redirectedTarget, this.nodeGeneration, this.nodeRid, record.sourceSpotId, 'request', record.operation, record.deadlineUnixMs, pending.id, metadataFrame !== undefined),
|
|
1565
|
+
payloadFrame
|
|
1566
|
+
], metadataFrame), remainingMs, 'instanceSpotRequest');
|
|
1567
|
+
const result = await pending.promise;
|
|
1568
|
+
if (localReply !== undefined) {
|
|
1569
|
+
localReply(result.terminalResult, result.failureCode, result.payload);
|
|
1570
|
+
return;
|
|
1571
|
+
}
|
|
1572
|
+
if (record.replyRouteId !== undefined) {
|
|
1573
|
+
this.replyWire(ingress, record.replyRouteId, result.terminalResult, result.failureCode, result.payload);
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
requireInstanceActivation(ingress, record) {
|
|
1577
|
+
const readyRoute = record.activation === 'ready' ? record.route : undefined;
|
|
1578
|
+
const spotId = readyRoute?.targetSpotId
|
|
1579
|
+
?? (record.activation === 'missing' ? record.target.targetSpotId : undefined);
|
|
1580
|
+
if (spotId === undefined)
|
|
1581
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', 'unknown');
|
|
1582
|
+
this.validateInstanceIngress(ingress, record);
|
|
1583
|
+
if (record.activation === 'missing') {
|
|
1584
|
+
return this.activateMissingInstance(record);
|
|
1585
|
+
}
|
|
1586
|
+
const { intent, route } = this.requireReadyInstanceApplicationRoute(ingress, record);
|
|
1587
|
+
const spot = this.registry.spot(route.targetSpotId)
|
|
1588
|
+
?? this.registry.restoreSpot({
|
|
1589
|
+
spotId: route.targetSpotId,
|
|
1590
|
+
generation: route.objectGeneration
|
|
1591
|
+
}, 'instance', intent.instanceType, route.authorityOwnerGeneration);
|
|
1592
|
+
if (spot.state !== 'ready'
|
|
1593
|
+
|| spot.kind !== 'instance'
|
|
1594
|
+
|| spot.stableType !== intent.instanceType
|
|
1595
|
+
|| spot.ref.generation !== route.objectGeneration
|
|
1596
|
+
|| spot.authorityOwnerGeneration !== route.authorityOwnerGeneration) {
|
|
1597
|
+
throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Instance Spot '${route.targetSpotId}' is not projected from its current Ready authority.`);
|
|
1598
|
+
}
|
|
1599
|
+
return spot;
|
|
1600
|
+
}
|
|
1601
|
+
requireReadyInstanceApplicationRoute(ingress, record) {
|
|
1602
|
+
this.validateInstanceIngress(ingress, record);
|
|
1603
|
+
let intent = this.instanceIntents.get(record.route.targetSpotId);
|
|
1604
|
+
if (intent === undefined) {
|
|
1605
|
+
// The authority commit is externally visible before the asynchronous
|
|
1606
|
+
// activation continuation can publish its in-memory intent. If the
|
|
1607
|
+
// local ready projection already carries the exact object and owner
|
|
1608
|
+
// fence from the received route, publish that validated projection
|
|
1609
|
+
// instead of exposing a transient NotFound result to a following
|
|
1610
|
+
// request. A mismatched or absent local projection remains NotFound.
|
|
1611
|
+
const local = this.registry.spot(record.route.targetSpotId);
|
|
1612
|
+
if (local?.kind === 'instance'
|
|
1613
|
+
&& local.state === 'ready'
|
|
1614
|
+
&& routeMatchesLocal(record.route, local, this.nodeRid, this.nodeGeneration)) {
|
|
1615
|
+
this.publishCommittedInstanceRoute(local.stableType, record.route);
|
|
1616
|
+
intent = this.instanceIntents.get(record.route.targetSpotId);
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
if (intent === undefined) {
|
|
1620
|
+
throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RequestTargetNotFound, `Instance Spot '${record.route.targetSpotId}' has no current Ready authority.`);
|
|
1621
|
+
}
|
|
1622
|
+
const current = intent.route;
|
|
1623
|
+
if (current.objectGeneration < record.route.objectGeneration) {
|
|
1624
|
+
throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotGenerationStale, `Instance Spot '${record.route.targetSpotId}' is behind the requested object generation.`);
|
|
1625
|
+
}
|
|
1626
|
+
if (!sameInstanceApplicationOwner(current, record.route)) {
|
|
1627
|
+
throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Instance Spot '${record.route.targetSpotId}' is owned by a different current route.`);
|
|
1628
|
+
}
|
|
1629
|
+
if (current.objectGeneration === record.route.objectGeneration
|
|
1630
|
+
&& current.authorityOwnerGeneration !== record.route.authorityOwnerGeneration) {
|
|
1631
|
+
throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Instance Spot '${record.route.targetSpotId}' has a different authority owner fence.`);
|
|
1632
|
+
}
|
|
1633
|
+
return { intent, route: current };
|
|
1634
|
+
}
|
|
1635
|
+
validateInstanceIngress(ingress, record) {
|
|
1636
|
+
const expectedSourceGeneration = this.peerGeneration(record.sourceNodeRid);
|
|
1637
|
+
if (record.sourceNodeRid !== ingress.sourceRoutingId
|
|
1638
|
+
|| record.sourceNodeGeneration !== expectedSourceGeneration) {
|
|
1639
|
+
if (record.activation === 'ready') {
|
|
1640
|
+
throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Instance Spot '${record.route.targetSpotId}' received a stale source lifecycle fence.`);
|
|
1641
|
+
}
|
|
1642
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', record.target.targetSpotId);
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
activateMissingInstance(record) {
|
|
1646
|
+
const target = record.target;
|
|
1647
|
+
if (target.targetNodeRid !== this.nodeRid
|
|
1648
|
+
|| target.targetNodeGeneration !== this.nodeGeneration
|
|
1649
|
+
|| record.deadlineUnixMs < BigInt(Date.now())) {
|
|
1650
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
1651
|
+
}
|
|
1652
|
+
if (this.instanceApplicationLifecycle?.isIdleEvicting?.(target) === true) {
|
|
1653
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
1654
|
+
}
|
|
1655
|
+
const authority = this.instanceAuthority;
|
|
1656
|
+
if (authority === undefined) {
|
|
1657
|
+
throw new Error('Instance activation authority is not registered.');
|
|
1658
|
+
}
|
|
1659
|
+
const local = this.registry.spot(target.targetSpotId);
|
|
1660
|
+
const current = authority.read(target);
|
|
1661
|
+
if (local !== undefined) {
|
|
1662
|
+
if (local.kind !== 'instance'
|
|
1663
|
+
|| local.stableType !== target.stableType
|
|
1664
|
+
|| current.kind !== 'ready'
|
|
1665
|
+
|| !routeMatchesLocal(current.route, local, this.nodeRid, this.nodeGeneration)) {
|
|
1666
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
1667
|
+
}
|
|
1668
|
+
return local;
|
|
1669
|
+
}
|
|
1670
|
+
if (current.kind === 'ready') {
|
|
1671
|
+
throw new ServiceInstanceActivationRedirectError(current.route);
|
|
1672
|
+
}
|
|
1673
|
+
const reserved = authority.reserve(target, record.operation, record.deadlineUnixMs);
|
|
1674
|
+
if (reserved.kind === 'ready') {
|
|
1675
|
+
throw new ServiceInstanceActivationRedirectError(reserved.route);
|
|
1676
|
+
}
|
|
1677
|
+
let activation;
|
|
1678
|
+
try {
|
|
1679
|
+
activation = this.activateInstanceSpot(target.targetSpotId, target.stableType, reserved.reservation.attempt, reserved.reservation.authorityOwnerGeneration);
|
|
1680
|
+
}
|
|
1681
|
+
catch (error) {
|
|
1682
|
+
authority.abort(target, reserved.reservation);
|
|
1683
|
+
throw error;
|
|
1684
|
+
}
|
|
1685
|
+
const committed = authority.commit(target, reserved.reservation, activation.spot);
|
|
1686
|
+
if (committed.kind === 'lost') {
|
|
1687
|
+
if (activation.created)
|
|
1688
|
+
this.registry.closeSpot(activation.spot.ref);
|
|
1689
|
+
throw new ServiceInstanceActivationRedirectError(committed.route);
|
|
1690
|
+
}
|
|
1691
|
+
if (!routeMatchesLocal(committed.route, activation.spot, this.nodeRid, this.nodeGeneration)) {
|
|
1692
|
+
if (activation.created)
|
|
1693
|
+
this.registry.closeSpot(activation.spot.ref);
|
|
1694
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
1695
|
+
}
|
|
1696
|
+
return activation.spot;
|
|
1697
|
+
}
|
|
1698
|
+
activateMissingInstanceAsync(record, payloadFrame, metadataFrame) {
|
|
1699
|
+
const key = instanceActivationKey(record);
|
|
1700
|
+
const pending = this.pendingInstanceActivations.get(key);
|
|
1701
|
+
if (pending !== undefined)
|
|
1702
|
+
return pending;
|
|
1703
|
+
const activation = this.runMissingInstanceActivation(record, payloadFrame, metadataFrame);
|
|
1704
|
+
this.pendingInstanceActivations.set(key, activation);
|
|
1705
|
+
const clear = () => {
|
|
1706
|
+
if (this.pendingInstanceActivations.get(key) === activation) {
|
|
1707
|
+
this.pendingInstanceActivations.delete(key);
|
|
1708
|
+
}
|
|
1709
|
+
};
|
|
1710
|
+
void activation.then(clear, clear);
|
|
1711
|
+
return activation;
|
|
1712
|
+
}
|
|
1713
|
+
async runMissingInstanceActivation(record, payloadFrame, metadataFrame) {
|
|
1714
|
+
const target = record.target;
|
|
1715
|
+
if (target.targetNodeRid !== this.nodeRid
|
|
1716
|
+
|| target.targetNodeGeneration !== this.nodeGeneration
|
|
1717
|
+
|| record.deadlineUnixMs < BigInt(Date.now())) {
|
|
1718
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
1719
|
+
}
|
|
1720
|
+
const authority = this.asyncInstanceAuthority;
|
|
1721
|
+
if (authority === undefined) {
|
|
1722
|
+
throw new Error('Async Instance activation authority is not registered.');
|
|
1723
|
+
}
|
|
1724
|
+
const local = this.registry.spot(target.targetSpotId);
|
|
1725
|
+
const current = await authority.read(target);
|
|
1726
|
+
if (!this.acceptsLocalMissingInstancePlacement()) {
|
|
1727
|
+
if (current.kind === 'ready' && current.route.targetNodeRid !== this.nodeRid) {
|
|
1728
|
+
throw new ServiceInstanceActivationRedirectError(current.route);
|
|
1729
|
+
}
|
|
1730
|
+
// A draining or retiring node must not create a successor generation
|
|
1731
|
+
// from a stale client route while relocation is publishing its target.
|
|
1732
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
1733
|
+
}
|
|
1734
|
+
if (current.kind === 'ready') {
|
|
1735
|
+
if (current.route.targetNodeRid !== this.nodeRid) {
|
|
1736
|
+
throw new ServiceInstanceActivationRedirectError(current.route);
|
|
1737
|
+
}
|
|
1738
|
+
if (current.route.targetNodeGeneration !== this.nodeGeneration) {
|
|
1739
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
1740
|
+
}
|
|
1741
|
+
if (local !== undefined
|
|
1742
|
+
&& (local.kind !== 'instance'
|
|
1743
|
+
|| local.stableType !== target.stableType)) {
|
|
1744
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
1745
|
+
}
|
|
1746
|
+
if (local !== undefined
|
|
1747
|
+
&& routeMatchesLocal(current.route, local, this.nodeRid, this.nodeGeneration)) {
|
|
1748
|
+
return { spot: local, route: current.route };
|
|
1749
|
+
}
|
|
1750
|
+
return await this.reconcileReadyInstanceProjection(target, current.route, authority);
|
|
1751
|
+
}
|
|
1752
|
+
if (local !== undefined) {
|
|
1753
|
+
const lifecycle = this.instanceApplicationLifecycle;
|
|
1754
|
+
const closing = lifecycle?.isClosing?.(target) === true;
|
|
1755
|
+
let materialized = lifecycle === undefined
|
|
1756
|
+
? undefined
|
|
1757
|
+
: lifecycle.isMaterialized(target);
|
|
1758
|
+
const materializing = lifecycle?.isMaterializing?.(target) === true;
|
|
1759
|
+
if (local.kind !== 'instance'
|
|
1760
|
+
|| local.stableType !== target.stableType) {
|
|
1761
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
1762
|
+
}
|
|
1763
|
+
const joinsCreating = current.kind === 'creating'
|
|
1764
|
+
&& local.ref.generation === current.objectGeneration
|
|
1765
|
+
&& local.authorityOwnerGeneration === current.authorityOwnerGeneration;
|
|
1766
|
+
const replacesClosingProjection = current.kind === 'creating' && closing;
|
|
1767
|
+
if (current.kind === 'missing'
|
|
1768
|
+
&& !closing
|
|
1769
|
+
&& !materializing
|
|
1770
|
+
&& materialized === true
|
|
1771
|
+
&& lifecycle !== undefined) {
|
|
1772
|
+
// The durable authority is the ownership source of truth. Its removal
|
|
1773
|
+
// can become visible before the route reconciler has discarded the
|
|
1774
|
+
// previous application projection. Converge that orphan here before
|
|
1775
|
+
// reserving a successor generation; otherwise every activation keeps
|
|
1776
|
+
// returning a stale terminal while no owner can make progress.
|
|
1777
|
+
await lifecycle.discard(target);
|
|
1778
|
+
materialized = lifecycle.isMaterialized(target);
|
|
1779
|
+
}
|
|
1780
|
+
// The authority can still be in a Creating reservation after the local
|
|
1781
|
+
// registry exposes the activation. Allow the authority reserve operation
|
|
1782
|
+
// to join that attempt instead of treating the local projection as stale.
|
|
1783
|
+
// A newer reservation can also become visible after an explicit close
|
|
1784
|
+
// releases authority but before local disposal removes the old
|
|
1785
|
+
// projection. The close gate serializes that replacement; rejecting it
|
|
1786
|
+
// here turns a valid next-generation Instance intent into a stale-route
|
|
1787
|
+
// failure.
|
|
1788
|
+
// If disposal did not remove an orphaned materialization, keep fencing
|
|
1789
|
+
// it instead of admitting work into two application generations.
|
|
1790
|
+
if ((!joinsCreating && !replacesClosingProjection && current.kind !== 'missing')
|
|
1791
|
+
|| (!joinsCreating && !closing && materialized !== false && !materializing)) {
|
|
1792
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
const reserved = await authority.reserve({
|
|
1796
|
+
target,
|
|
1797
|
+
sourceNodeRid: record.sourceNodeRid,
|
|
1798
|
+
sourceNodeGeneration: record.sourceNodeGeneration,
|
|
1799
|
+
...(record.sourceSpotId === undefined ? {} : { sourceSpotId: record.sourceSpotId }),
|
|
1800
|
+
operationKind: record.operationKind,
|
|
1801
|
+
operation: record.operation,
|
|
1802
|
+
...(record.replyRouteId === undefined ? {} : { replyRouteId: record.replyRouteId }),
|
|
1803
|
+
deadlineUnixMs: record.deadlineUnixMs,
|
|
1804
|
+
...(metadataFrame === undefined ? {} : { metadataFrame }),
|
|
1805
|
+
applicationPayloadFrame: payloadFrame
|
|
1806
|
+
});
|
|
1807
|
+
if (reserved.kind === 'ready') {
|
|
1808
|
+
throw new ServiceInstanceActivationRedirectError(reserved.route);
|
|
1809
|
+
}
|
|
1810
|
+
if (this.closed || record.deadlineUnixMs < BigInt(Date.now())) {
|
|
1811
|
+
await authority.abort(target, reserved.reservation);
|
|
1812
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
1813
|
+
}
|
|
1814
|
+
let activation;
|
|
1815
|
+
try {
|
|
1816
|
+
await this.instanceApplicationLifecycle?.materialize(target, reserved.reservation.attempt);
|
|
1817
|
+
activation = this.activateInstanceSpot(target.targetSpotId, target.stableType, reserved.reservation.attempt, reserved.reservation.authorityOwnerGeneration);
|
|
1818
|
+
}
|
|
1819
|
+
catch (error) {
|
|
1820
|
+
await authority.abort(target, reserved.reservation);
|
|
1821
|
+
await this.instanceApplicationLifecycle?.discard(target);
|
|
1822
|
+
throw error;
|
|
1823
|
+
}
|
|
1824
|
+
let committed;
|
|
1825
|
+
try {
|
|
1826
|
+
committed = await authority.commit(target, reserved.reservation, activation.spot);
|
|
1827
|
+
}
|
|
1828
|
+
catch (error) {
|
|
1829
|
+
if (activation.created)
|
|
1830
|
+
this.registry.closeSpot(activation.spot.ref);
|
|
1831
|
+
await this.instanceApplicationLifecycle?.discard(target);
|
|
1832
|
+
throw error;
|
|
1833
|
+
}
|
|
1834
|
+
if (committed.kind === 'lost') {
|
|
1835
|
+
if (activation.created)
|
|
1836
|
+
this.registry.closeSpot(activation.spot.ref);
|
|
1837
|
+
await this.instanceApplicationLifecycle?.discard(target);
|
|
1838
|
+
throw new ServiceInstanceActivationRedirectError(committed.route);
|
|
1839
|
+
}
|
|
1840
|
+
if (!routeMatchesLocal(committed.route, activation.spot, this.nodeRid, this.nodeGeneration)) {
|
|
1841
|
+
if (activation.created)
|
|
1842
|
+
this.registry.closeSpot(activation.spot.ref);
|
|
1843
|
+
await this.instanceApplicationLifecycle?.discard(target);
|
|
1844
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
1845
|
+
}
|
|
1846
|
+
this.publishCommittedInstanceRoute(target.stableType, committed.route);
|
|
1847
|
+
return { spot: activation.spot, route: committed.route };
|
|
1848
|
+
}
|
|
1849
|
+
acceptsLocalMissingInstancePlacement() {
|
|
1850
|
+
const topology = this.raw.topology;
|
|
1851
|
+
const descriptor = topology.localDescriptor?.();
|
|
1852
|
+
return descriptor === undefined
|
|
1853
|
+
|| (descriptor.state === 'serving' && descriptor.placementWeight > 0);
|
|
1854
|
+
}
|
|
1855
|
+
async reconcileReadyInstanceProjection(target, route, authority) {
|
|
1856
|
+
await this.instanceApplicationLifecycle?.materialize(target, route.objectGeneration);
|
|
1857
|
+
const activation = this.activateInstanceSpot(target.targetSpotId, target.stableType, route.objectGeneration, route.authorityOwnerGeneration);
|
|
1858
|
+
if (!routeMatchesLocal(route, activation.spot, this.nodeRid, this.nodeGeneration)) {
|
|
1859
|
+
if (activation.created)
|
|
1860
|
+
this.registry.closeSpot(activation.spot.ref);
|
|
1861
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
1862
|
+
}
|
|
1863
|
+
this.publishCommittedInstanceRoute(target.stableType, route);
|
|
1864
|
+
const confirmed = await authority.read(target);
|
|
1865
|
+
if (confirmed.kind !== 'ready' || !sameInstanceRoute(confirmed.route, route)) {
|
|
1866
|
+
if (confirmed.kind === 'ready'
|
|
1867
|
+
&& confirmed.route.targetNodeRid !== this.nodeRid) {
|
|
1868
|
+
throw new ServiceInstanceActivationRedirectError(confirmed.route);
|
|
1869
|
+
}
|
|
1870
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
1871
|
+
}
|
|
1872
|
+
const current = this.registry.spot(target.targetSpotId);
|
|
1873
|
+
if (current === undefined
|
|
1874
|
+
|| !routeMatchesLocal(confirmed.route, current, this.nodeRid, this.nodeGeneration)) {
|
|
1875
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', target.targetSpotId);
|
|
1876
|
+
}
|
|
1877
|
+
return { spot: current, route: confirmed.route };
|
|
1878
|
+
}
|
|
1879
|
+
publishCommittedInstanceRoute(stableType, route, expectedCurrentRoute) {
|
|
1880
|
+
const directRoute = instanceRouteAsDirectRoute(route);
|
|
1881
|
+
const expectedDirectRoute = expectedCurrentRoute === undefined
|
|
1882
|
+
? undefined
|
|
1883
|
+
: expectedCurrentRoute === null
|
|
1884
|
+
? null
|
|
1885
|
+
: instanceRouteAsDirectRoute(expectedCurrentRoute);
|
|
1886
|
+
this.rememberSpotRoute(directRoute, expectedDirectRoute);
|
|
1887
|
+
this.registerInstanceIntent(stableType, route, expectedCurrentRoute);
|
|
1888
|
+
}
|
|
1889
|
+
replaceCommittedInstanceRoute(stableType, previous, next) {
|
|
1890
|
+
const current = this.instanceIntents.get(previous.targetSpotId);
|
|
1891
|
+
if (current === undefined || !sameInstanceRoute(current.route, previous)) {
|
|
1892
|
+
return false;
|
|
1893
|
+
}
|
|
1894
|
+
// A terminal completion can advance only the durable StoreVersion while
|
|
1895
|
+
// the same authority owner continues to serve the same Instance. Remove
|
|
1896
|
+
// the exact previous cache entry before publishing that validated result;
|
|
1897
|
+
// rememberSpotRoute must continue rejecting an unrelated same-generation
|
|
1898
|
+
// stale route.
|
|
1899
|
+
this.forgetSpotRoute({
|
|
1900
|
+
spotId: previous.targetSpotId,
|
|
1901
|
+
generation: previous.objectGeneration
|
|
1902
|
+
}, previous.authorityOwnerGeneration, previous.storeVersion);
|
|
1903
|
+
this.publishCommittedInstanceRoute(stableType, next, previous);
|
|
1904
|
+
return true;
|
|
1905
|
+
}
|
|
1906
|
+
forgetClosedInstanceRoute(route) {
|
|
1907
|
+
const local = this.registry.spot(route.targetSpotId);
|
|
1908
|
+
if (local?.kind === 'instance'
|
|
1909
|
+
&& local.ref.generation === route.objectGeneration
|
|
1910
|
+
&& local.authorityOwnerGeneration === route.authorityOwnerGeneration) {
|
|
1911
|
+
this.registry.closeSpot(local.ref);
|
|
1912
|
+
}
|
|
1913
|
+
this.forgetSpotRoute({ spotId: route.targetSpotId, generation: route.objectGeneration }, route.authorityOwnerGeneration, route.storeVersion);
|
|
1914
|
+
this.forgetInstanceIntent(route.targetSpotId, route.objectGeneration, route.authorityOwnerGeneration);
|
|
1915
|
+
}
|
|
1916
|
+
enqueueActorJoin(ingress, record, payloadFrame, canonicalActorJoin, canonicalApplicationPayload) {
|
|
1917
|
+
const current = this.registry.actor(record.actor.actor.actorId);
|
|
1918
|
+
const previousEpoch = current?.membershipEpoch ?? 0n;
|
|
1919
|
+
const actor = {
|
|
1920
|
+
...record.actor.actor,
|
|
1921
|
+
nodeRid: this.nodeRid
|
|
1922
|
+
};
|
|
1923
|
+
const control = {
|
|
1924
|
+
kind: 'actorControl',
|
|
1925
|
+
lifecycleKind: service_runtime_contracts_1.ActorLifecycleKind.Joined,
|
|
1926
|
+
previousActor: current?.ref ?? record.actor.actor,
|
|
1927
|
+
currentActor: actor,
|
|
1928
|
+
previousSpotId: current?.spot.spotId ?? null,
|
|
1929
|
+
currentSpotId: record.target.spot.spotId,
|
|
1930
|
+
previousSpotGeneration: current?.spot.generation ?? 0n,
|
|
1931
|
+
currentSpotGeneration: record.target.spot.generation,
|
|
1932
|
+
previousMembershipEpoch: previousEpoch,
|
|
1933
|
+
currentMembershipEpoch: previousEpoch + 1n,
|
|
1934
|
+
resultCode: 0,
|
|
1935
|
+
...(canonicalActorJoin === undefined
|
|
1936
|
+
? {}
|
|
1937
|
+
: {
|
|
1938
|
+
canonicalActorJoin: {
|
|
1939
|
+
handoffId: (0, actor_join_recovery_codec_1.canonicalActorJoinHandoffId)({
|
|
1940
|
+
sourceActorNodeRid: canonicalActorJoin.actor.targetNodeRid,
|
|
1941
|
+
actorId: record.actor.actor.actorId,
|
|
1942
|
+
actorGeneration: record.actor.actor.generation,
|
|
1943
|
+
sourceActorNodeGeneration: record.actor.targetNodeGeneration,
|
|
1944
|
+
correlation: record.correlation
|
|
1945
|
+
}),
|
|
1946
|
+
actorNodeRid: record.actor.actor.nodeRid,
|
|
1947
|
+
actorGeneration: record.actor.actor.generation,
|
|
1948
|
+
actorNodeGeneration: record.actor.targetNodeGeneration,
|
|
1949
|
+
authorityOwnerGeneration: record.actor.authorityOwnerGeneration,
|
|
1950
|
+
ownerLeaseGeneration: record.actor.ownerLeaseGeneration
|
|
1951
|
+
}
|
|
1952
|
+
})
|
|
1953
|
+
};
|
|
1954
|
+
const applicationFrame = payloadFrame ?? (0, service_wire_m6a_codec_1.encodeApplicationPayload)(emptyPayload());
|
|
1955
|
+
return this.enqueueLifecycleFrame(ingress, `spot:${record.target.spot.spotId}`, applicationFrame, {
|
|
1956
|
+
receiveKind: service_runtime_contracts_1.ReceiveKind.SpotControl,
|
|
1957
|
+
operationKind: service_runtime_contracts_1.OperationKind.ActorJoin,
|
|
1958
|
+
correlation: record.correlation,
|
|
1959
|
+
targetSpot: record.target.spot,
|
|
1960
|
+
targetActor: actor,
|
|
1961
|
+
kindData: control,
|
|
1962
|
+
...(canonicalApplicationPayload === undefined ? {} : { canonicalApplicationPayload }),
|
|
1963
|
+
reply: (terminalResult, failureCode, replyPayload, tail) => {
|
|
1964
|
+
return this.replyPort(ingress, record.correlation, 'actorJoin')(terminalResult, failureCode, replyPayload, tail);
|
|
1965
|
+
}
|
|
1966
|
+
});
|
|
1967
|
+
}
|
|
1968
|
+
replyLookup(ingress, record) {
|
|
1969
|
+
const actor = this.registry.actor(record.actorId);
|
|
1970
|
+
if (actor === undefined) {
|
|
1971
|
+
this.replyWire(ingress, record.correlation, runtime_values_1.RequestResult.NotFound, ACTOR_ROUTE_NOT_FOUND);
|
|
1972
|
+
}
|
|
1973
|
+
else {
|
|
1974
|
+
this.replyWire(ingress, record.correlation, runtime_values_1.RequestResult.Ok, 0, undefined, {
|
|
1975
|
+
kind: 'actorLookup',
|
|
1976
|
+
actor: actor.ref,
|
|
1977
|
+
spot: actor.spot,
|
|
1978
|
+
membershipEpoch: actor.membershipEpoch,
|
|
1979
|
+
authorityOwnerGeneration: actor.authorityOwnerGeneration
|
|
1980
|
+
});
|
|
1981
|
+
}
|
|
1982
|
+
return 'infrastructure';
|
|
1983
|
+
}
|
|
1984
|
+
replyDestroy(ingress, record) {
|
|
1985
|
+
try {
|
|
1986
|
+
this.validateActorFence(record.actor);
|
|
1987
|
+
this.registry.destroyActor(record.actor.actor);
|
|
1988
|
+
this.replyWire(ingress, record.correlation, runtime_values_1.RequestResult.Ok, 0);
|
|
1989
|
+
}
|
|
1990
|
+
catch (error) {
|
|
1991
|
+
const result = failure(error);
|
|
1992
|
+
this.replyWire(ingress, record.correlation, result.terminalResult, result.failureCode);
|
|
1993
|
+
}
|
|
1994
|
+
return 'infrastructure';
|
|
1995
|
+
}
|
|
1996
|
+
replySessionBind(ingress, record) {
|
|
1997
|
+
try {
|
|
1998
|
+
if (record.binding.state === 'active') {
|
|
1999
|
+
const actor = this.validateActorFence(record.actor);
|
|
2000
|
+
const previous = this.registry.binding(actor.ref);
|
|
2001
|
+
const sourceGeneration = ingress.sourceNodeGeneration
|
|
2002
|
+
?? this.peerGeneration(ingress.sourceRoutingId);
|
|
2003
|
+
const binding = (0, service_stateful_wire_codec_1.sessionBindingFromWire)(actor.ref, record.sessionRid, ingress.sourceRoutingId, record.binding.generation, actor.membershipEpoch, sourceGeneration, ingress.sourceRoutingId, sourceGeneration);
|
|
2004
|
+
if (previous !== undefined && sameSessionIdentity(previous, binding)) {
|
|
2005
|
+
// Registry publication is the last step of the first binding owner
|
|
2006
|
+
// turn, so an observable same-Session binding already has every
|
|
2007
|
+
// Actor route projection installed and can complete idempotently.
|
|
2008
|
+
this.replyWire(ingress, record.correlation, runtime_values_1.RequestResult.Ok, 0, undefined, {
|
|
2009
|
+
kind: 'streamBind',
|
|
2010
|
+
bindingGeneration: previous.bindingGeneration,
|
|
2011
|
+
authorityOwnerGeneration: actor.authorityOwnerGeneration
|
|
2012
|
+
});
|
|
2013
|
+
return 'infrastructure';
|
|
2014
|
+
}
|
|
2015
|
+
const accepted = this.enqueueActorBindingControl(ingress, binding, record.actor, (terminalResult, failureCode) => {
|
|
2016
|
+
let completedBinding = binding;
|
|
2017
|
+
let replacedBinding;
|
|
2018
|
+
if (terminalResult === runtime_values_1.RequestResult.Ok) {
|
|
2019
|
+
// This callback runs inside the Actor binding control turn,
|
|
2020
|
+
// after the Host has installed its Actor-to-session projection.
|
|
2021
|
+
// Publish the authority-owned registry view in that same turn
|
|
2022
|
+
// before making the terminal reply observable.
|
|
2023
|
+
const turnCurrent = this.registry.binding(actor.ref);
|
|
2024
|
+
if (turnCurrent !== undefined && sameSessionIdentity(turnCurrent, binding)) {
|
|
2025
|
+
completedBinding = turnCurrent;
|
|
2026
|
+
}
|
|
2027
|
+
else {
|
|
2028
|
+
replacedBinding = turnCurrent;
|
|
2029
|
+
this.registry.installSessionBinding(binding);
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
this.replyWire(ingress, record.correlation, terminalResult, failureCode, undefined, terminalResult === runtime_values_1.RequestResult.Ok
|
|
2033
|
+
? {
|
|
2034
|
+
kind: 'streamBind',
|
|
2035
|
+
bindingGeneration: completedBinding.bindingGeneration,
|
|
2036
|
+
authorityOwnerGeneration: actor.authorityOwnerGeneration
|
|
2037
|
+
}
|
|
2038
|
+
: undefined);
|
|
2039
|
+
if (terminalResult === runtime_values_1.RequestResult.Ok
|
|
2040
|
+
&& replacedBinding !== undefined
|
|
2041
|
+
&& !sameSessionBinding(replacedBinding, completedBinding)) {
|
|
2042
|
+
this.sendBoundSessionReplacement(replacedBinding, actorAuthorityFromRoute({
|
|
2043
|
+
...record.actor,
|
|
2044
|
+
ownerLeaseGeneration: record.actor.ownerLeaseGeneration
|
|
2045
|
+
}));
|
|
2046
|
+
}
|
|
2047
|
+
return true;
|
|
2048
|
+
});
|
|
2049
|
+
if (!accepted) {
|
|
2050
|
+
const result = failure((0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Actor '${actor.ref.actorId}' no longer accepts session bindings.`));
|
|
2051
|
+
this.replyWire(ingress, record.correlation, result.terminalResult, result.failureCode);
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
else {
|
|
2055
|
+
this.enqueueSessionBindingTombstone(ingress, record);
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
catch (error) {
|
|
2059
|
+
const result = failure(error);
|
|
2060
|
+
this.replyWire(ingress, record.correlation, result.terminalResult, result.failureCode);
|
|
2061
|
+
}
|
|
2062
|
+
return 'infrastructure';
|
|
2063
|
+
}
|
|
2064
|
+
/**
|
|
2065
|
+
* Handles the replacement notice at the retired session owner. This path
|
|
2066
|
+
* intentionally never calls validateActorFence(): the notice is authorized
|
|
2067
|
+
* by its transport source and exact retired session identity, not by a
|
|
2068
|
+
* local Actor registry entry.
|
|
2069
|
+
*/
|
|
2070
|
+
handleBoundSessionReplaced(ingress, record) {
|
|
2071
|
+
const authority = record.actorAuthority;
|
|
2072
|
+
if (authority.actor.nodeRid !== ingress.sourceRoutingId) {
|
|
2073
|
+
return 'protocolError';
|
|
2074
|
+
}
|
|
2075
|
+
const sourceGeneration = ingress.sourceNodeGeneration
|
|
2076
|
+
?? this.tryPeerGeneration(ingress.sourceRoutingId);
|
|
2077
|
+
if (sourceGeneration === undefined)
|
|
2078
|
+
return 'infrastructure';
|
|
2079
|
+
if (sourceGeneration !== authority.targetNodeGeneration) {
|
|
2080
|
+
// A notice from a restarted authority is stale. It must not tear down a
|
|
2081
|
+
// session that belongs to the new lifecycle.
|
|
2082
|
+
return 'infrastructure';
|
|
2083
|
+
}
|
|
2084
|
+
if (record.retiredSession.sessionOwnerNodeRid !== this.nodeRid
|
|
2085
|
+
|| record.retiredSession.sessionOwnerNodeGeneration !== this.nodeGeneration
|
|
2086
|
+
|| record.retiredSession.sessionOwnerId !== this.nodeRid
|
|
2087
|
+
|| record.retiredSession.sessionOwnerLeaseGeneration !== this.nodeGeneration) {
|
|
2088
|
+
return 'infrastructure';
|
|
2089
|
+
}
|
|
2090
|
+
const actor = authority.actor;
|
|
2091
|
+
const key = replacementNoticeKey(record);
|
|
2092
|
+
if (this.appliedReplacementNotices.has(key))
|
|
2093
|
+
return 'infrastructure';
|
|
2094
|
+
const deliveryKey = actorKey(actor);
|
|
2095
|
+
const current = this.sessionDeliveries.get(deliveryKey);
|
|
2096
|
+
const retired = this.retiredSessionDeliveries.get(sessionDeliveryKey({
|
|
2097
|
+
actor,
|
|
2098
|
+
sessionRid: record.retiredSession.sessionRid,
|
|
2099
|
+
sessionOwnerNodeRid: this.nodeRid,
|
|
2100
|
+
sessionOwnerNodeGeneration: record.retiredSession.sessionOwnerNodeGeneration,
|
|
2101
|
+
sessionOwnerId: record.retiredSession.sessionOwnerId,
|
|
2102
|
+
sessionOwnerLeaseGeneration: record.retiredSession.sessionOwnerLeaseGeneration,
|
|
2103
|
+
bindingGeneration: record.retiredSession.retiredBindingGeneration,
|
|
2104
|
+
}));
|
|
2105
|
+
const delivery = current !== undefined
|
|
2106
|
+
&& exactRetiredDelivery(current.binding, record.retiredSession)
|
|
2107
|
+
? current
|
|
2108
|
+
: retired !== undefined
|
|
2109
|
+
&& exactRetiredDelivery(retired.binding, record.retiredSession)
|
|
2110
|
+
? retired
|
|
2111
|
+
: undefined;
|
|
2112
|
+
if (delivery === undefined)
|
|
2113
|
+
return 'infrastructure';
|
|
2114
|
+
this.appliedReplacementNotices.add(key);
|
|
2115
|
+
delivery.onBindingReplaced?.(actor.actorId, record.retiredSession, actor);
|
|
2116
|
+
if (retired !== undefined) {
|
|
2117
|
+
this.retiredSessionDeliveries.delete(sessionDeliveryKey(retired.binding));
|
|
2118
|
+
}
|
|
2119
|
+
return 'infrastructure';
|
|
2120
|
+
}
|
|
2121
|
+
sendBoundSessionReplacement(previous, actorAuthority) {
|
|
2122
|
+
const ownerGeneration = previous.sessionOwnerNodeGeneration
|
|
2123
|
+
?? this.tryPeerGeneration(previous.sessionOwnerNodeRid);
|
|
2124
|
+
if (ownerGeneration === undefined)
|
|
2125
|
+
return;
|
|
2126
|
+
const header = (0, service_stateful_wire_codec_1.encodeBoundSessionReplacedHeader)(actorAuthority, {
|
|
2127
|
+
sessionOwnerNodeRid: previous.sessionOwnerNodeRid,
|
|
2128
|
+
sessionOwnerNodeGeneration: ownerGeneration,
|
|
2129
|
+
sessionOwnerId: previous.sessionOwnerId ?? previous.sessionOwnerNodeRid,
|
|
2130
|
+
sessionOwnerLeaseGeneration: previous.sessionOwnerLeaseGeneration ?? ownerGeneration,
|
|
2131
|
+
sessionRid: previous.sessionRid,
|
|
2132
|
+
retiredBindingGeneration: previous.bindingGeneration
|
|
2133
|
+
});
|
|
2134
|
+
// submitOneWay owns the normal transport admission timeout. A replacement
|
|
2135
|
+
// notice is one-way, so an unsuccessful admission has no caller terminal
|
|
2136
|
+
// to complete and must not delay the already-completed bind.
|
|
2137
|
+
void this.submitOneWay(previous.sessionOwnerNodeRid, [header]).catch(() => { });
|
|
2138
|
+
}
|
|
2139
|
+
enqueueSessionBindingTombstone(ingress, record) {
|
|
2140
|
+
if (record.binding.state !== 'tombstone')
|
|
2141
|
+
return;
|
|
2142
|
+
const actor = record.actor.actor;
|
|
2143
|
+
const current = this.registry.binding(actor);
|
|
2144
|
+
const sourceGeneration = ingress.sourceNodeGeneration
|
|
2145
|
+
?? this.tryPeerGeneration(ingress.sourceRoutingId);
|
|
2146
|
+
if (current === undefined
|
|
2147
|
+
|| sourceGeneration === undefined
|
|
2148
|
+
|| current.bindingGeneration !== record.binding.retiredGeneration
|
|
2149
|
+
|| current.sessionRid !== record.sessionRid
|
|
2150
|
+
|| current.sessionOwnerNodeRid !== ingress.sourceRoutingId
|
|
2151
|
+
|| current.sessionOwnerNodeGeneration !== sourceGeneration
|
|
2152
|
+
|| current.sessionOwnerId !== ingress.sourceRoutingId
|
|
2153
|
+
|| current.sessionOwnerLeaseGeneration !== sourceGeneration) {
|
|
2154
|
+
this.replyWire(ingress, record.correlation, runtime_values_1.RequestResult.Ok, 0);
|
|
2155
|
+
return;
|
|
2156
|
+
}
|
|
2157
|
+
const delivery = this.sessionDeliveries.get(actorKey(actor));
|
|
2158
|
+
const currentDelivery = delivery !== undefined
|
|
2159
|
+
&& sameSessionBinding(delivery.binding, current)
|
|
2160
|
+
? delivery
|
|
2161
|
+
: undefined;
|
|
2162
|
+
const accepted = this.enqueueSessionBindingRetirement(ingress, current, record.actor, (terminalResult, failureCode) => {
|
|
2163
|
+
if (terminalResult === runtime_values_1.RequestResult.Ok) {
|
|
2164
|
+
const turnCurrent = this.registry.binding(actor);
|
|
2165
|
+
if (turnCurrent !== undefined && sameSessionBinding(turnCurrent, current)) {
|
|
2166
|
+
this.registry.unbindSession(actor, current.bindingGeneration, current.sessionRid, current.sessionOwnerNodeRid);
|
|
2167
|
+
}
|
|
2168
|
+
if (currentDelivery !== undefined
|
|
2169
|
+
&& this.sessionDeliveries.get(actorKey(actor)) === currentDelivery) {
|
|
2170
|
+
this.sessionDeliveries.delete(actorKey(actor));
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
this.replyWire(ingress, record.correlation, terminalResult, failureCode);
|
|
2174
|
+
return true;
|
|
2175
|
+
});
|
|
2176
|
+
if (!accepted) {
|
|
2177
|
+
const result = failure((0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Actor '${actor.actorId}' no longer accepts session binding tombstones.`));
|
|
2178
|
+
this.replyWire(ingress, record.correlation, result.terminalResult, result.failureCode);
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
enqueueSessionBindingRetirement(ingress, binding, actorAuthority, reply) {
|
|
2182
|
+
const actor = binding.actor;
|
|
2183
|
+
const sessionOwner = requireSessionOwnerIdentity(binding);
|
|
2184
|
+
const applicationJob = requireApplicationJobOwner(ingress).takeInitial('infrastructure');
|
|
2185
|
+
const accepted = this.raw.mailbox.tryEnqueue({
|
|
2186
|
+
owner: `actor:${actor.actorId}\0${actor.generation}`,
|
|
2187
|
+
domain: 'infrastructure',
|
|
2188
|
+
parts: [Buffer.from([0x5a, 0x4d, 1, service_stateful_wire_codec_1.M6bServiceWireCommand.boundSessionBind, 0])],
|
|
2189
|
+
sourceRoutingId: binding.sessionOwnerNodeRid,
|
|
2190
|
+
stateful: {
|
|
2191
|
+
receiveKind: service_runtime_contracts_1.ReceiveKind.ActorBinding,
|
|
2192
|
+
operationKind: service_runtime_contracts_1.OperationKind.StreamUnbind,
|
|
2193
|
+
targetActor: actor,
|
|
2194
|
+
kindData: {
|
|
2195
|
+
kind: 'actorBinding',
|
|
2196
|
+
transition: 'tombstone',
|
|
2197
|
+
actor,
|
|
2198
|
+
actorNodeGeneration: actorAuthority.targetNodeGeneration,
|
|
2199
|
+
authorityOwnerGeneration: actorAuthority.authorityOwnerGeneration,
|
|
2200
|
+
ownerLeaseGeneration: actorAuthority.ownerLeaseGeneration,
|
|
2201
|
+
bindingGeneration: binding.bindingGeneration,
|
|
2202
|
+
sessionNodeRid: binding.sessionOwnerNodeRid,
|
|
2203
|
+
sessionRid: binding.sessionRid,
|
|
2204
|
+
sessionOwnerNodeGeneration: sessionOwner.nodeGeneration,
|
|
2205
|
+
sessionOwnerId: sessionOwner.ownerId,
|
|
2206
|
+
sessionOwnerLeaseGeneration: sessionOwner.leaseGeneration
|
|
2207
|
+
},
|
|
2208
|
+
reply
|
|
2209
|
+
},
|
|
2210
|
+
applicationJob
|
|
2211
|
+
});
|
|
2212
|
+
if (!accepted)
|
|
2213
|
+
applicationJob.close();
|
|
2214
|
+
return accepted;
|
|
2215
|
+
}
|
|
2216
|
+
async deliverBoundSession(ingress, record, payloadFrame) {
|
|
2217
|
+
const delivery = this.sessionDeliveries.get(actorKey(record.actor.actor));
|
|
2218
|
+
if (delivery === undefined
|
|
2219
|
+
|| delivery.binding.bindingGeneration !== record.expectedBindingGeneration
|
|
2220
|
+
|| payloadFrame === undefined
|
|
2221
|
+
|| ingress.sourceNodeGeneration === undefined
|
|
2222
|
+
|| !(0, routing_id_1.routingIdsEqual)(ingress.sourceRoutingId, record.actor.actor.nodeRid)
|
|
2223
|
+
|| ingress.sourceNodeGeneration !== record.actor.targetNodeGeneration) {
|
|
2224
|
+
return 'protocolError';
|
|
2225
|
+
}
|
|
2226
|
+
const sessionRid = delivery.binding.sessionRid;
|
|
2227
|
+
let retainedPayload = payloadFrame;
|
|
2228
|
+
let settled = false;
|
|
2229
|
+
const settle = () => {
|
|
2230
|
+
if (settled)
|
|
2231
|
+
return false;
|
|
2232
|
+
settled = true;
|
|
2233
|
+
retainedPayload = undefined;
|
|
2234
|
+
return true;
|
|
2235
|
+
};
|
|
2236
|
+
const operation = {
|
|
2237
|
+
deliver: async () => {
|
|
2238
|
+
if (settled || retainedPayload === undefined)
|
|
2239
|
+
return false;
|
|
2240
|
+
const delivered = await delivery.deliver(sessionRid, retainedPayload);
|
|
2241
|
+
if (delivered)
|
|
2242
|
+
settle();
|
|
2243
|
+
return delivered;
|
|
2244
|
+
},
|
|
2245
|
+
fail: (_error) => {
|
|
2246
|
+
settle();
|
|
2247
|
+
}
|
|
2248
|
+
};
|
|
2249
|
+
const decision = await delivery.bindingIngress?.retainOutbound({
|
|
2250
|
+
actorId: record.actor.actor.actorId,
|
|
2251
|
+
objectGeneration: record.actor.actor.generation,
|
|
2252
|
+
actorNodeRid: record.actor.actor.nodeRid,
|
|
2253
|
+
actorNodeGeneration: record.actor.targetNodeGeneration,
|
|
2254
|
+
authorityOwnerGeneration: record.actor.authorityOwnerGeneration,
|
|
2255
|
+
ownerLeaseGeneration: record.actor.ownerLeaseGeneration,
|
|
2256
|
+
producerNodeRid: ingress.sourceRoutingId,
|
|
2257
|
+
producerNodeGeneration: ingress.sourceNodeGeneration,
|
|
2258
|
+
sessionIdentity: sessionRid,
|
|
2259
|
+
bindingGeneration: record.expectedBindingGeneration
|
|
2260
|
+
}, operation);
|
|
2261
|
+
if (decision === 'retained')
|
|
2262
|
+
return 'application';
|
|
2263
|
+
if (decision === 'rejected') {
|
|
2264
|
+
return 'protocolError';
|
|
2265
|
+
}
|
|
2266
|
+
try {
|
|
2267
|
+
const delivered = await delivery.deliver(sessionRid, retainedPayload);
|
|
2268
|
+
settle();
|
|
2269
|
+
if (!delivered)
|
|
2270
|
+
return 'protocolError';
|
|
2271
|
+
}
|
|
2272
|
+
catch (error) {
|
|
2273
|
+
operation.fail(error);
|
|
2274
|
+
// Remote command 36 is one-way: its source transport admission has
|
|
2275
|
+
// already completed, so a later client delivery terminal is local to
|
|
2276
|
+
// this session owner. Local fast paths still preserve the typed result.
|
|
2277
|
+
if (ingress.sourceRoutingId !== this.nodeRid
|
|
2278
|
+
&& (0, runtime_values_1.isZLinkBackendResultError)(error)
|
|
2279
|
+
&& error.operation === 'submit') {
|
|
2280
|
+
return 'application';
|
|
2281
|
+
}
|
|
2282
|
+
throw error;
|
|
2283
|
+
}
|
|
2284
|
+
return 'application';
|
|
2285
|
+
}
|
|
2286
|
+
enqueueApplicationFrame(ingress, owner, payloadFrame, stateful) {
|
|
2287
|
+
return this.enqueueFrame('application', ingress, owner, payloadFrame, stateful);
|
|
2288
|
+
}
|
|
2289
|
+
enqueueLifecycleFrame(ingress, owner, payloadFrame, stateful) {
|
|
2290
|
+
return this.enqueueFrame('infrastructure', ingress, owner, payloadFrame, stateful);
|
|
2291
|
+
}
|
|
2292
|
+
enqueueFrame(domain, ingress, owner, payloadFrame, stateful) {
|
|
2293
|
+
const applicationJob = requireApplicationJobOwner(ingress).takeInitial(domain);
|
|
2294
|
+
const accepted = this.raw.mailbox.tryEnqueue({
|
|
2295
|
+
owner,
|
|
2296
|
+
domain,
|
|
2297
|
+
parts: [ingress.parts[0], payloadFrame],
|
|
2298
|
+
sourceRoutingId: ingress.sourceRoutingId,
|
|
2299
|
+
sourceRoute: ingress.sourceRoute,
|
|
2300
|
+
...(ingress.reply === undefined ? {} : { reply: ingress.reply }),
|
|
2301
|
+
...(ingress.requestSequence === undefined ? {} : { requestSequence: ingress.requestSequence }),
|
|
2302
|
+
...(stateful.correlation === undefined ? {} : { correlation: stateful.correlation }),
|
|
2303
|
+
stateful,
|
|
2304
|
+
applicationJob
|
|
2305
|
+
});
|
|
2306
|
+
if (accepted)
|
|
2307
|
+
return domain;
|
|
2308
|
+
applicationJob.close();
|
|
2309
|
+
if (stateful.reply !== undefined) {
|
|
2310
|
+
const result = failure((0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Mailbox owner '${owner}' no longer accepts work on this runtime.`));
|
|
2311
|
+
stateful.reply(result.terminalResult, result.failureCode);
|
|
2312
|
+
return 'infrastructure';
|
|
2313
|
+
}
|
|
2314
|
+
return 'protocolError';
|
|
2315
|
+
}
|
|
2316
|
+
async enqueueLogicalMulticast(channelName, topic, sourceSpotId, payload, sourceNodeRid = this.nodeRid) {
|
|
2317
|
+
const applicationJobOwner = await this.raw.reserveLocalIngress();
|
|
2318
|
+
try {
|
|
2319
|
+
await this.enqueueLogicalMulticastFrame(channelName, topic, sourceSpotId, (0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload), sourceNodeRid, applicationJobOwner);
|
|
2320
|
+
}
|
|
2321
|
+
finally {
|
|
2322
|
+
applicationJobOwner.close();
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
async enqueueLogicalMulticastFrame(channelName, topic, sourceSpotId, payloadFrame, sourceNodeRid, applicationJobOwner) {
|
|
2326
|
+
const targets = [...this.subscriptions.entries()]
|
|
2327
|
+
.filter(([, values]) => [...values].some(value => {
|
|
2328
|
+
const separator = value.indexOf('\0');
|
|
2329
|
+
return value.slice(0, separator) === channelName
|
|
2330
|
+
&& topicMatches(value.slice(separator + 1), topic);
|
|
2331
|
+
}))
|
|
2332
|
+
.map(([spotId]) => spotId)
|
|
2333
|
+
.sort();
|
|
2334
|
+
for (const spotId of targets) {
|
|
2335
|
+
const spot = this.registry.spot(spotId);
|
|
2336
|
+
if (spot === undefined)
|
|
2337
|
+
continue;
|
|
2338
|
+
const applicationJob = await applicationJobOwner.acquire('application');
|
|
2339
|
+
const accepted = this.raw.mailbox.tryEnqueue({
|
|
2340
|
+
owner: `spot:${spotId}`,
|
|
2341
|
+
domain: 'application',
|
|
2342
|
+
parts: [
|
|
2343
|
+
(0, service_stateful_wire_codec_1.encodeLogicalMulticastHeader)(channelName, topic, sourceSpotId),
|
|
2344
|
+
payloadFrame
|
|
2345
|
+
],
|
|
2346
|
+
sourceRoutingId: sourceNodeRid,
|
|
2347
|
+
stateful: {
|
|
2348
|
+
receiveKind: service_runtime_contracts_1.ReceiveKind.SpotMulticast,
|
|
2349
|
+
operationKind: 0,
|
|
2350
|
+
sourceSpotId,
|
|
2351
|
+
channelName,
|
|
2352
|
+
topic,
|
|
2353
|
+
targetSpot: spot.ref
|
|
2354
|
+
},
|
|
2355
|
+
applicationJob
|
|
2356
|
+
});
|
|
2357
|
+
if (!accepted) {
|
|
2358
|
+
applicationJob.close();
|
|
2359
|
+
this.mailboxDropHandler?.({ kind: 'spot_multicast', owner: spotId });
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
enqueueActorControl(spotId, control, onTerminalCompletion) {
|
|
2364
|
+
const header = Buffer.from([0x5a, 0x4d, 1, service_stateful_wire_codec_1.M6bServiceWireCommand.actorJoined, 0]);
|
|
2365
|
+
let terminalAttempted = false;
|
|
2366
|
+
void (async () => {
|
|
2367
|
+
const applicationJobOwner = await this.raw.reserveLocalIngress();
|
|
2368
|
+
let accepted = false;
|
|
2369
|
+
try {
|
|
2370
|
+
const applicationJob = applicationJobOwner.takeInitial('infrastructure');
|
|
2371
|
+
accepted = this.raw.mailbox.tryEnqueue({
|
|
2372
|
+
owner: `spot:${spotId}`,
|
|
2373
|
+
domain: 'infrastructure',
|
|
2374
|
+
parts: [header],
|
|
2375
|
+
sourceRoutingId: this.nodeRid,
|
|
2376
|
+
stateful: {
|
|
2377
|
+
receiveKind: service_runtime_contracts_1.ReceiveKind.SpotControl,
|
|
2378
|
+
operationKind: 0,
|
|
2379
|
+
targetSpot: this.registry.spot(spotId)?.ref,
|
|
2380
|
+
kindData: control,
|
|
2381
|
+
...(onTerminalCompletion === undefined ? {} : { onTerminalCompletion })
|
|
2382
|
+
},
|
|
2383
|
+
applicationJob
|
|
2384
|
+
});
|
|
2385
|
+
if (!accepted)
|
|
2386
|
+
applicationJob.close();
|
|
2387
|
+
}
|
|
2388
|
+
finally {
|
|
2389
|
+
applicationJobOwner.close();
|
|
2390
|
+
}
|
|
2391
|
+
if (accepted)
|
|
2392
|
+
return;
|
|
2393
|
+
this.mailboxDropHandler?.({ kind: 'actor_control', owner: spotId });
|
|
2394
|
+
terminalAttempted = true;
|
|
2395
|
+
await onTerminalCompletion?.();
|
|
2396
|
+
})().catch(async () => {
|
|
2397
|
+
this.mailboxDropHandler?.({ kind: 'actor_control', owner: spotId });
|
|
2398
|
+
if (!terminalAttempted) {
|
|
2399
|
+
terminalAttempted = true;
|
|
2400
|
+
await onTerminalCompletion?.();
|
|
2401
|
+
}
|
|
2402
|
+
});
|
|
2403
|
+
}
|
|
2404
|
+
enqueueActorBindingControl(ingress, binding, actorAuthority, reply) {
|
|
2405
|
+
const actor = binding.actor;
|
|
2406
|
+
const sessionOwner = requireSessionOwnerIdentity(binding);
|
|
2407
|
+
const header = Buffer.from([0x5a, 0x4d, 1, service_stateful_wire_codec_1.M6bServiceWireCommand.boundSessionBind, 0]);
|
|
2408
|
+
const applicationJob = requireApplicationJobOwner(ingress).takeInitial('infrastructure');
|
|
2409
|
+
const accepted = this.raw.mailbox.tryEnqueue({
|
|
2410
|
+
owner: `actor:${actor.actorId}\0${actor.generation}`,
|
|
2411
|
+
domain: 'infrastructure',
|
|
2412
|
+
parts: [header],
|
|
2413
|
+
sourceRoutingId: this.nodeRid,
|
|
2414
|
+
stateful: {
|
|
2415
|
+
receiveKind: service_runtime_contracts_1.ReceiveKind.ActorBinding,
|
|
2416
|
+
operationKind: 0,
|
|
2417
|
+
targetActor: actor,
|
|
2418
|
+
kindData: {
|
|
2419
|
+
kind: 'actorBinding',
|
|
2420
|
+
transition: 'active',
|
|
2421
|
+
actor,
|
|
2422
|
+
actorNodeGeneration: actorAuthority.targetNodeGeneration,
|
|
2423
|
+
authorityOwnerGeneration: actorAuthority.authorityOwnerGeneration,
|
|
2424
|
+
ownerLeaseGeneration: actorAuthority.ownerLeaseGeneration,
|
|
2425
|
+
bindingGeneration: binding.bindingGeneration,
|
|
2426
|
+
sessionNodeRid: binding.sessionOwnerNodeRid,
|
|
2427
|
+
sessionRid: binding.sessionRid,
|
|
2428
|
+
sessionOwnerNodeGeneration: sessionOwner.nodeGeneration,
|
|
2429
|
+
sessionOwnerId: sessionOwner.ownerId,
|
|
2430
|
+
sessionOwnerLeaseGeneration: sessionOwner.leaseGeneration
|
|
2431
|
+
},
|
|
2432
|
+
reply
|
|
2433
|
+
},
|
|
2434
|
+
applicationJob
|
|
2435
|
+
});
|
|
2436
|
+
if (!accepted) {
|
|
2437
|
+
applicationJob.close();
|
|
2438
|
+
this.mailboxDropHandler?.({ kind: 'actor_binding', owner: actor.actorId });
|
|
2439
|
+
}
|
|
2440
|
+
return accepted;
|
|
2441
|
+
}
|
|
2442
|
+
replyPort(ingress, correlation, operationKind) {
|
|
2443
|
+
if (correlation === undefined)
|
|
2444
|
+
throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Request correlation is missing.');
|
|
2445
|
+
return (terminalResult, failureCode, payload, tail) => {
|
|
2446
|
+
this.replyWire(ingress, correlation, terminalResult, failureCode, payload, tail);
|
|
2447
|
+
void operationKind;
|
|
2448
|
+
return true;
|
|
2449
|
+
};
|
|
2450
|
+
}
|
|
2451
|
+
replyWire(ingress, correlation, terminalResult, failureCode, payload, tail) {
|
|
2452
|
+
this.raw.replyService(ingress, [
|
|
2453
|
+
(0, service_stateful_wire_codec_1.encodeStatefulReply)(correlation, terminalResult, failureCode, tail),
|
|
2454
|
+
...(payload === undefined ? [] : [(0, service_wire_m6a_codec_1.encodeApplicationPayload)(payload)])
|
|
2455
|
+
]);
|
|
2456
|
+
}
|
|
2457
|
+
handleUserSpotOperation(ingress, record) {
|
|
2458
|
+
if (ingress.requestSequence === undefined
|
|
2459
|
+
|| record.sourceNodeRid !== ingress.sourceRoutingId
|
|
2460
|
+
|| record.sourceNodeGeneration !== this.peerGeneration(ingress.sourceRoutingId)
|
|
2461
|
+
|| (record.kind === 'actorCreate' && record.reservation.pendingCapacityDelta !== 1)) {
|
|
2462
|
+
return 'protocolError';
|
|
2463
|
+
}
|
|
2464
|
+
const target = record.kind === 'userSpotCreate' || record.kind === 'actorCreate'
|
|
2465
|
+
? record.reservation
|
|
2466
|
+
: record.target;
|
|
2467
|
+
if (target.targetNodeRid !== this.nodeRid
|
|
2468
|
+
|| target.targetNodeGeneration !== this.nodeGeneration) {
|
|
2469
|
+
this.replyWire(ingress, record.correlation, runtime_values_1.RequestResult.Conflict, SPOT_MOVING);
|
|
2470
|
+
return 'infrastructure';
|
|
2471
|
+
}
|
|
2472
|
+
const operationKey = [
|
|
2473
|
+
record.sourceNodeRid,
|
|
2474
|
+
record.sourceNodeGeneration,
|
|
2475
|
+
record.operation.high,
|
|
2476
|
+
record.operation.low
|
|
2477
|
+
].join('\0');
|
|
2478
|
+
const encodedRequest = userSpotOperationFingerprint(record);
|
|
2479
|
+
let admitted = this.admittedUserSpotOperations.get(operationKey);
|
|
2480
|
+
if (admitted?.settled === true
|
|
2481
|
+
&& operationReplayExpired(admitted.replayExpiresAtMs)) {
|
|
2482
|
+
this.admittedUserSpotOperations.delete(operationKey);
|
|
2483
|
+
admitted = undefined;
|
|
2484
|
+
}
|
|
2485
|
+
if (admitted !== undefined && admitted.request !== encodedRequest) {
|
|
2486
|
+
return 'protocolError';
|
|
2487
|
+
}
|
|
2488
|
+
if (admitted === undefined) {
|
|
2489
|
+
if (record.deadlineUnixMs < BigInt(Date.now())) {
|
|
2490
|
+
this.replyWire(ingress, record.correlation, runtime_values_1.RequestResult.TimedOut, 0);
|
|
2491
|
+
return 'infrastructure';
|
|
2492
|
+
}
|
|
2493
|
+
if (this.admittedUserSpotOperations.size >= USER_SPOT_OPERATION_CAPACITY) {
|
|
2494
|
+
this.releaseExpiredUserSpotOperations();
|
|
2495
|
+
}
|
|
2496
|
+
if (this.admittedUserSpotOperations.size >= USER_SPOT_OPERATION_CAPACITY) {
|
|
2497
|
+
this.replyWire(ingress, record.correlation, runtime_values_1.RequestResult.Busy, 0);
|
|
2498
|
+
return 'infrastructure';
|
|
2499
|
+
}
|
|
2500
|
+
const replayExpiresAtMs = performance.now()
|
|
2501
|
+
+ Number(record.deadlineUnixMs - BigInt(Date.now()))
|
|
2502
|
+
+ USER_SPOT_OPERATION_REPLAY_RETENTION_MS;
|
|
2503
|
+
const handler = this.userSpotOperationHandler;
|
|
2504
|
+
const result = handler === undefined
|
|
2505
|
+
? Promise.resolve({
|
|
2506
|
+
terminalResult: runtime_values_1.RequestResult.InvalidState,
|
|
2507
|
+
failureCode: 0
|
|
2508
|
+
})
|
|
2509
|
+
: this.executeUserSpotOperation(handler, record);
|
|
2510
|
+
admitted = {
|
|
2511
|
+
request: encodedRequest,
|
|
2512
|
+
replayExpiresAtMs,
|
|
2513
|
+
result,
|
|
2514
|
+
settled: false
|
|
2515
|
+
};
|
|
2516
|
+
this.admittedUserSpotOperations.set(operationKey, admitted);
|
|
2517
|
+
void result.finally(() => {
|
|
2518
|
+
const current = this.admittedUserSpotOperations.get(operationKey);
|
|
2519
|
+
if (current?.result === result)
|
|
2520
|
+
current.settled = true;
|
|
2521
|
+
}).catch(() => undefined);
|
|
2522
|
+
}
|
|
2523
|
+
void admitted.result.then(result => {
|
|
2524
|
+
if (this.closed)
|
|
2525
|
+
return;
|
|
2526
|
+
this.raw.replyService(ingress, [
|
|
2527
|
+
(0, service_stateful_wire_codec_1.encodeStatefulReply)(record.correlation, result.terminalResult, result.failureCode, result.tail),
|
|
2528
|
+
...(result.payload === undefined
|
|
2529
|
+
? []
|
|
2530
|
+
: [(0, service_wire_m6a_codec_1.encodeApplicationPayload)(result.payload)])
|
|
2531
|
+
]);
|
|
2532
|
+
}, error => {
|
|
2533
|
+
if (this.closed)
|
|
2534
|
+
return;
|
|
2535
|
+
const failed = failure(error);
|
|
2536
|
+
this.replyWire(ingress, record.correlation, failed.terminalResult, failed.failureCode);
|
|
2537
|
+
});
|
|
2538
|
+
return 'infrastructure';
|
|
2539
|
+
}
|
|
2540
|
+
releaseExpiredUserSpotOperations() {
|
|
2541
|
+
for (const [key, operation] of this.admittedUserSpotOperations) {
|
|
2542
|
+
if (operation.settled && operationReplayExpired(operation.replayExpiresAtMs)) {
|
|
2543
|
+
this.admittedUserSpotOperations.delete(key);
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
async executeUserSpotOperation(handler, record) {
|
|
2548
|
+
const deadline = userSpotDeadline(record.deadlineUnixMs);
|
|
2549
|
+
try {
|
|
2550
|
+
const result = record.kind === 'userSpotCreate'
|
|
2551
|
+
? await handler.create(record, deadline.signal)
|
|
2552
|
+
: record.kind === 'userSpotClose'
|
|
2553
|
+
? await handler.close(record, deadline.signal)
|
|
2554
|
+
: handler.createActor === undefined
|
|
2555
|
+
? {
|
|
2556
|
+
terminalResult: runtime_values_1.RequestResult.InvalidState,
|
|
2557
|
+
failureCode: 0
|
|
2558
|
+
}
|
|
2559
|
+
: await handler.createActor(record, deadline.signal);
|
|
2560
|
+
if (result.terminalResult === runtime_values_1.RequestResult.Ok
|
|
2561
|
+
&& (result.tail === undefined
|
|
2562
|
+
|| result.tail.kind !== record.kind)) {
|
|
2563
|
+
throw new service_wire_m6a_codec_1.ServiceWireProtocolError('User Spot success result omits its operation tail.');
|
|
2564
|
+
}
|
|
2565
|
+
return result;
|
|
2566
|
+
}
|
|
2567
|
+
catch (error) {
|
|
2568
|
+
const failed = failure(error);
|
|
2569
|
+
return failed;
|
|
2570
|
+
}
|
|
2571
|
+
finally {
|
|
2572
|
+
deadline.close();
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
async requestUserSpotOperation(targetNodeRid, header, correlation, operationKind, timeoutMs) {
|
|
2576
|
+
const parts = await this.requestDurableOperation(targetNodeRid, [header], correlation, operationKind, performance.now() + Math.max(1, timeoutMs));
|
|
2577
|
+
// A received envelope, including a decode failure, ends sender replay.
|
|
2578
|
+
try {
|
|
2579
|
+
if (parts.length < 1 || parts.length > 2) {
|
|
2580
|
+
throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Invalid creation operation reply parts.');
|
|
2581
|
+
}
|
|
2582
|
+
const decoded = (0, service_stateful_wire_codec_1.decodeStatefulReply)(parts[0], correlation, operationKind, parts.length >= 2);
|
|
2583
|
+
if (decoded.terminalResult !== runtime_values_1.RequestResult.Ok
|
|
2584
|
+
&& parts.length !== 1) {
|
|
2585
|
+
throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Failed creation operation reply carries a payload.');
|
|
2586
|
+
}
|
|
2587
|
+
if (operationKind === 'userSpotClose'
|
|
2588
|
+
&& parts.length !== 1) {
|
|
2589
|
+
throw new service_wire_m6a_codec_1.ServiceWireProtocolError('User Spot close reply carries a payload.');
|
|
2590
|
+
}
|
|
2591
|
+
return {
|
|
2592
|
+
terminalResult: decoded.terminalResult,
|
|
2593
|
+
failureCode: decoded.failureCode,
|
|
2594
|
+
...(decoded.tail === undefined ? {} : { tail: decoded.tail }),
|
|
2595
|
+
...(parts.length === 2
|
|
2596
|
+
? { payload: (0, service_wire_m6a_codec_1.decodeApplicationPayload)(parts[1]) }
|
|
2597
|
+
: {})
|
|
2598
|
+
};
|
|
2599
|
+
}
|
|
2600
|
+
catch (error) {
|
|
2601
|
+
throw (0, framework_errors_internal_1.translateWireReplyDecodeError)(error);
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
async requestDurableOperation(targetNodeRid, parts, correlation, operationKind, deadlineMs) {
|
|
2605
|
+
const stop = new AbortController();
|
|
2606
|
+
const unobserve = this.raw.observePeerConnectionIntentRemoved(nodeRoutingId => {
|
|
2607
|
+
if (nodeRoutingId === targetNodeRid) {
|
|
2608
|
+
stop.abort((0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RouteNotConnected, `${operationKind} target node lifecycle ended.`, true));
|
|
2609
|
+
}
|
|
2610
|
+
});
|
|
2611
|
+
let wasAdmitted = false;
|
|
2612
|
+
try {
|
|
2613
|
+
// Only durable lifecycle operations replay these frozen frames. Received
|
|
2614
|
+
// envelopes leave this loop before decoding, including failure terminals.
|
|
2615
|
+
for (;;) {
|
|
2616
|
+
this.requireOpen();
|
|
2617
|
+
stop.signal.throwIfAborted();
|
|
2618
|
+
const remainingMs = Math.ceil(deadlineMs - performance.now());
|
|
2619
|
+
if (remainingMs <= 0)
|
|
2620
|
+
throw durableOperationExhausted(operationKind, wasAdmitted);
|
|
2621
|
+
try {
|
|
2622
|
+
return await (0, abort_1.awaitWithAbort)(targetNodeRid === this.nodeRid
|
|
2623
|
+
? this.requestLocalInfrastructure(parts[0], correlation, remainingMs)
|
|
2624
|
+
: this.raw.requestService(targetNodeRid, parts, remainingMs), stop.signal);
|
|
2625
|
+
}
|
|
2626
|
+
catch (error) {
|
|
2627
|
+
stop.signal.throwIfAborted();
|
|
2628
|
+
if (!durableRequestCanReplay(error))
|
|
2629
|
+
throw error;
|
|
2630
|
+
if (durableRequestWasAdmitted(error))
|
|
2631
|
+
wasAdmitted = true;
|
|
2632
|
+
const retryDelayMs = Math.min(20, deadlineMs - performance.now());
|
|
2633
|
+
if (retryDelayMs <= 0) {
|
|
2634
|
+
throw durableOperationExhausted(operationKind, wasAdmitted, error);
|
|
2635
|
+
}
|
|
2636
|
+
let timer;
|
|
2637
|
+
try {
|
|
2638
|
+
await (0, abort_1.awaitWithAbort)(new Promise(resolve => {
|
|
2639
|
+
timer = setTimeout(resolve, retryDelayMs);
|
|
2640
|
+
}), stop.signal);
|
|
2641
|
+
}
|
|
2642
|
+
finally {
|
|
2643
|
+
if (timer !== undefined)
|
|
2644
|
+
clearTimeout(timer);
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
catch (error) {
|
|
2650
|
+
stop.signal.throwIfAborted();
|
|
2651
|
+
throw error;
|
|
2652
|
+
}
|
|
2653
|
+
finally {
|
|
2654
|
+
unobserve();
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
requestLocalInfrastructure(header, requestSequence, timeoutMs) {
|
|
2658
|
+
return new Promise((resolve, reject) => {
|
|
2659
|
+
let settled = false;
|
|
2660
|
+
const fail = (error) => {
|
|
2661
|
+
if (settled)
|
|
2662
|
+
return;
|
|
2663
|
+
settled = true;
|
|
2664
|
+
clearTimeout(timer);
|
|
2665
|
+
reject(error);
|
|
2666
|
+
};
|
|
2667
|
+
const timer = setTimeout(() => {
|
|
2668
|
+
fail(new Error('Local infrastructure request timed out.'));
|
|
2669
|
+
}, timeoutMs);
|
|
2670
|
+
const finish = (parts) => {
|
|
2671
|
+
if (settled)
|
|
2672
|
+
return;
|
|
2673
|
+
settled = true;
|
|
2674
|
+
clearTimeout(timer);
|
|
2675
|
+
resolve(parts.map(part => Buffer.from(part)));
|
|
2676
|
+
};
|
|
2677
|
+
void (async () => {
|
|
2678
|
+
const applicationJobOwner = await this.raw.reserveLocalIngress();
|
|
2679
|
+
try {
|
|
2680
|
+
const result = await this.ingress({
|
|
2681
|
+
command: header[3],
|
|
2682
|
+
flags: header[4],
|
|
2683
|
+
sourceRoutingId: this.nodeRid,
|
|
2684
|
+
requestSequence,
|
|
2685
|
+
reply: finish,
|
|
2686
|
+
parts: [header],
|
|
2687
|
+
applicationJobOwner
|
|
2688
|
+
});
|
|
2689
|
+
if (result !== 'infrastructure') {
|
|
2690
|
+
fail(new service_wire_m6a_codec_1.ServiceWireProtocolError(`Local infrastructure request was rejected as '${result ?? 'unsupported'}'.`));
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
finally {
|
|
2694
|
+
applicationJobOwner.close();
|
|
2695
|
+
}
|
|
2696
|
+
})().catch(fail);
|
|
2697
|
+
});
|
|
2698
|
+
}
|
|
2699
|
+
async submitOneWay(targetNodeRid, parts) {
|
|
2700
|
+
this.requireOpen();
|
|
2701
|
+
if (targetNodeRid === this.nodeRid) {
|
|
2702
|
+
const applicationJobOwner = await this.raw.reserveLocalIngress();
|
|
2703
|
+
if ((0, execution_1.captureZLinkExecutionTurn)() !== undefined) {
|
|
2704
|
+
// The sender is inside a Spot serial turn. Running ingress inline
|
|
2705
|
+
// would inherit that turn, so a send to an object of the same
|
|
2706
|
+
// serial owner nests a turn and is rejected with "cannot
|
|
2707
|
+
// implicitly execute another turn for the same owner". A one-way
|
|
2708
|
+
// submit completes at admission, exactly like the remote path
|
|
2709
|
+
// (sendService returns once the transport accepts the frame), so
|
|
2710
|
+
// run the ingress detached like a frame arriving on the receive
|
|
2711
|
+
// pump (spec 26 §2.1 `sent` boundary; spec 33 pre-handler flow).
|
|
2712
|
+
void ServiceStatefulRuntime.detachedIngressScope(async () => {
|
|
2713
|
+
try {
|
|
2714
|
+
await this.ingress({
|
|
2715
|
+
command: parts[0][3],
|
|
2716
|
+
flags: parts[0][4],
|
|
2717
|
+
sourceRoutingId: this.nodeRid,
|
|
2718
|
+
sourceNodeGeneration: this.nodeGeneration,
|
|
2719
|
+
parts,
|
|
2720
|
+
applicationJobOwner
|
|
2721
|
+
});
|
|
2722
|
+
}
|
|
2723
|
+
catch {
|
|
2724
|
+
// Dispatch failures already produced their
|
|
2725
|
+
// zlink.dispatch_error record; a one-way submit has no caller
|
|
2726
|
+
// completion to fail, matching the remote pump's handling.
|
|
2727
|
+
}
|
|
2728
|
+
finally {
|
|
2729
|
+
applicationJobOwner.close();
|
|
2730
|
+
}
|
|
2731
|
+
});
|
|
2732
|
+
return runtime_values_1.SubmitResult.Ok;
|
|
2733
|
+
}
|
|
2734
|
+
try {
|
|
2735
|
+
const result = await this.ingress({
|
|
2736
|
+
command: parts[0][3],
|
|
2737
|
+
flags: parts[0][4],
|
|
2738
|
+
sourceRoutingId: this.nodeRid,
|
|
2739
|
+
sourceNodeGeneration: this.nodeGeneration,
|
|
2740
|
+
parts,
|
|
2741
|
+
applicationJobOwner
|
|
2742
|
+
});
|
|
2743
|
+
return result === 'application' || result === 'infrastructure'
|
|
2744
|
+
? runtime_values_1.SubmitResult.Ok
|
|
2745
|
+
: runtime_values_1.SubmitResult.InvalidState;
|
|
2746
|
+
}
|
|
2747
|
+
catch (error) {
|
|
2748
|
+
if ((0, runtime_values_1.isZLinkBackendResultError)(error) && error.operation === 'submit') {
|
|
2749
|
+
return error.result;
|
|
2750
|
+
}
|
|
2751
|
+
throw error;
|
|
2752
|
+
}
|
|
2753
|
+
finally {
|
|
2754
|
+
applicationJobOwner.close();
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
return await this.raw.sendService(targetNodeRid, parts)
|
|
2758
|
+
? runtime_values_1.SubmitResult.Ok
|
|
2759
|
+
: runtime_values_1.SubmitResult.NotConnected;
|
|
2760
|
+
}
|
|
2761
|
+
submitRequest(pending, targetNodeRid, parts, timeoutMs, operationKind, actor) {
|
|
2762
|
+
if (targetNodeRid === this.nodeRid) {
|
|
2763
|
+
const deadlineUnixMs = BigInt(Date.now() + Math.max(0, timeoutMs));
|
|
2764
|
+
void (async () => {
|
|
2765
|
+
const applicationJobOwner = await this.raw.reserveLocalIngress();
|
|
2766
|
+
const localIngress = {
|
|
2767
|
+
command: parts[0][3],
|
|
2768
|
+
flags: parts[0][4],
|
|
2769
|
+
sourceRoutingId: this.nodeRid,
|
|
2770
|
+
requestSequence: pending.id,
|
|
2771
|
+
parts,
|
|
2772
|
+
applicationJobOwner
|
|
2773
|
+
};
|
|
2774
|
+
try {
|
|
2775
|
+
this.submitLocalRequest(localIngress, pending, operationKind, actor, deadlineUnixMs);
|
|
2776
|
+
}
|
|
2777
|
+
catch (error) {
|
|
2778
|
+
this.operations.reply(pending.id, failure(error));
|
|
2779
|
+
}
|
|
2780
|
+
finally {
|
|
2781
|
+
applicationJobOwner.close();
|
|
2782
|
+
}
|
|
2783
|
+
})().catch(error => this.operations.reply(pending.id, failure(error)));
|
|
2784
|
+
return;
|
|
2785
|
+
}
|
|
2786
|
+
void this.raw.requestService(targetNodeRid, parts, timeoutMs).then(reply => this.completeRemoteReply(pending, targetNodeRid, operationKind, actor, reply), error => this.operations.fail(pending.id, error));
|
|
2787
|
+
}
|
|
2788
|
+
submitActorJoin(pending, actor, targetNodeRid, target, payload, deadlineMs, canonical) {
|
|
2789
|
+
const actorRoute = canonical === undefined
|
|
2790
|
+
? this.tryActorFence(actor)
|
|
2791
|
+
: this.acceptCanonicalActorFence(actor, canonical.actorFence);
|
|
2792
|
+
if (target === undefined || actorRoute === undefined) {
|
|
2793
|
+
this.operations.reply(pending.id, {
|
|
2794
|
+
terminalResult: runtime_values_1.RequestResult.NotFound,
|
|
2795
|
+
failureCode: ACTOR_ROUTE_STALE
|
|
2796
|
+
});
|
|
2797
|
+
return;
|
|
2798
|
+
}
|
|
2799
|
+
if (canonical !== undefined) {
|
|
2800
|
+
this.canonicalActorJoinHandoffs.set(pending.id, (0, actor_join_recovery_codec_1.canonicalActorJoinHandoffId)({
|
|
2801
|
+
sourceActorNodeRid: (0, actor_join_recovery_codec_1.routingIdBytes)(actor.nodeRid),
|
|
2802
|
+
actorId: actor.actorId,
|
|
2803
|
+
actorGeneration: actor.generation,
|
|
2804
|
+
sourceActorNodeGeneration: actorRoute.targetNodeGeneration,
|
|
2805
|
+
correlation: pending.id
|
|
2806
|
+
}));
|
|
2807
|
+
}
|
|
2808
|
+
let parts;
|
|
2809
|
+
try {
|
|
2810
|
+
parts = (0, service_wire_pilot_codec_generated_1.encodeActorJoin28)({
|
|
2811
|
+
correlation: pending.id,
|
|
2812
|
+
actor: {
|
|
2813
|
+
id: actor.actorId,
|
|
2814
|
+
generation: actor.generation,
|
|
2815
|
+
targetNodeRid: (0, actor_join_recovery_codec_1.routingIdBytes)(actor.nodeRid),
|
|
2816
|
+
targetNodeGeneration: actorRoute.targetNodeGeneration,
|
|
2817
|
+
expectedAuthorityOwnerGeneration: actorRoute.authorityOwnerGeneration,
|
|
2818
|
+
expectedOwnerLeaseGeneration: actorRoute.ownerLeaseGeneration
|
|
2819
|
+
},
|
|
2820
|
+
entry: target.spot.spotId === targetNodeRid,
|
|
2821
|
+
targetSpot: {
|
|
2822
|
+
id: target.spot.spotId,
|
|
2823
|
+
generation: target.spot.generation,
|
|
2824
|
+
targetNodeRid: (0, actor_join_recovery_codec_1.routingIdBytes)(target.targetNodeRid),
|
|
2825
|
+
targetNodeGeneration: target.targetNodeGeneration,
|
|
2826
|
+
expectedAuthorityOwnerGeneration: target.authorityOwnerGeneration,
|
|
2827
|
+
expectedOwnerLeaseGeneration: target.ownerLeaseGeneration
|
|
2828
|
+
},
|
|
2829
|
+
...(payload === undefined ? {} : { payload })
|
|
2830
|
+
}).map(frame => Buffer.from(frame));
|
|
2831
|
+
}
|
|
2832
|
+
catch (error) {
|
|
2833
|
+
this.canonicalActorJoinHandoffs.delete(pending.id);
|
|
2834
|
+
this.operations.fail(pending.id, error);
|
|
2835
|
+
return;
|
|
2836
|
+
}
|
|
2837
|
+
if (targetNodeRid === this.nodeRid) {
|
|
2838
|
+
this.submitRequest(pending, targetNodeRid, parts, Math.max(0, Math.ceil(deadlineMs - performance.now())), 'actorJoin', actor);
|
|
2839
|
+
return;
|
|
2840
|
+
}
|
|
2841
|
+
void this.requestDurableOperation(targetNodeRid, parts, pending.id, 'actorJoin', deadlineMs).then(reply => this.completeRemoteReply(pending, targetNodeRid, 'actorJoin', actor, reply), error => {
|
|
2842
|
+
this.canonicalActorJoinHandoffs.delete(pending.id);
|
|
2843
|
+
this.operations.fail(pending.id, error);
|
|
2844
|
+
});
|
|
2845
|
+
}
|
|
2846
|
+
submitLocalRequest(ingress, pending, operationKind, actor, deadlineUnixMs) {
|
|
2847
|
+
const canonicalActorJoin = operationKind === 'actorJoin'
|
|
2848
|
+
? (0, service_wire_pilot_codec_generated_1.decodeActorJoin28)(ingress.parts)
|
|
2849
|
+
: undefined;
|
|
2850
|
+
const decoded = canonicalActorJoin === undefined
|
|
2851
|
+
? (0, service_stateful_wire_codec_1.decodeStatefulHeader)(ingress.parts[0])
|
|
2852
|
+
: statefulActorJoinFromCanonical(canonicalActorJoin);
|
|
2853
|
+
const payloadFrame = canonicalActorJoin?.payload === undefined
|
|
2854
|
+
? (ingress.parts.length < 2 ? undefined : ingress.parts[1])
|
|
2855
|
+
: (0, service_wire_m6a_codec_1.encodeApplicationPayload)({
|
|
2856
|
+
packetName: canonicalActorJoin.payload.packetName,
|
|
2857
|
+
contentType: canonicalActorJoin.payload.contentType,
|
|
2858
|
+
payload: Buffer.from(canonicalActorJoin.payload.payload)
|
|
2859
|
+
});
|
|
2860
|
+
if (decoded.kind === 'actorLookup') {
|
|
2861
|
+
const found = this.registry.actor(decoded.actorId);
|
|
2862
|
+
this.operations.reply(pending.id, found === undefined
|
|
2863
|
+
? { terminalResult: runtime_values_1.RequestResult.NotFound, failureCode: ACTOR_ROUTE_NOT_FOUND }
|
|
2864
|
+
: {
|
|
2865
|
+
terminalResult: runtime_values_1.RequestResult.Ok,
|
|
2866
|
+
failureCode: 0,
|
|
2867
|
+
kindData: lookupKindData(found)
|
|
2868
|
+
});
|
|
2869
|
+
return;
|
|
2870
|
+
}
|
|
2871
|
+
if (decoded.kind === 'actorDestroy') {
|
|
2872
|
+
try {
|
|
2873
|
+
this.registry.destroyActor(decoded.actor.actor);
|
|
2874
|
+
this.operations.reply(pending.id, { terminalResult: runtime_values_1.RequestResult.Ok, failureCode: 0 });
|
|
2875
|
+
}
|
|
2876
|
+
catch (error) {
|
|
2877
|
+
this.operations.reply(pending.id, failure(error));
|
|
2878
|
+
}
|
|
2879
|
+
return;
|
|
2880
|
+
}
|
|
2881
|
+
const localReply = (terminalResult, failureCode, replyPayload, tail) => this.operations.reply(pending.id, this.resultFromReply(terminalResult, failureCode, replyPayload, tail, this.nodeRid, actor));
|
|
2882
|
+
if (decoded.kind === 'spotRequest') {
|
|
2883
|
+
this.validateDirectSpotFence(decoded.target);
|
|
2884
|
+
this.enqueueApplicationFrame(ingress, `spot:${decoded.target.spot.spotId}`, payloadFrame, {
|
|
2885
|
+
receiveKind: service_runtime_contracts_1.ReceiveKind.SpotRequest,
|
|
2886
|
+
operationKind: service_runtime_contracts_1.OperationKind.SpotRequest,
|
|
2887
|
+
correlation: decoded.correlation,
|
|
2888
|
+
sourceSpotId: decoded.sourceSpotId,
|
|
2889
|
+
targetSpot: decoded.target.spot,
|
|
2890
|
+
reply: localReply
|
|
2891
|
+
});
|
|
2892
|
+
return;
|
|
2893
|
+
}
|
|
2894
|
+
if (decoded.kind === 'actorRequest') {
|
|
2895
|
+
const current = decoded.boundSession === undefined
|
|
2896
|
+
? this.validateActorMessageFence(decoded.target)
|
|
2897
|
+
: this.validateActorFence(decoded.target);
|
|
2898
|
+
this.enqueueApplicationFrame(ingress, `actor:${current.ref.actorId}\0${current.ref.generation}`, payloadFrame, {
|
|
2899
|
+
receiveKind: service_runtime_contracts_1.ReceiveKind.ActorRequest,
|
|
2900
|
+
operationKind: service_runtime_contracts_1.OperationKind.ActorRequest,
|
|
2901
|
+
correlation: decoded.correlation,
|
|
2902
|
+
targetActor: current.ref,
|
|
2903
|
+
...(decoded.sourceActor === undefined ? {} : { sourceActor: decoded.sourceActor }),
|
|
2904
|
+
...(decoded.boundSession === undefined
|
|
2905
|
+
? {}
|
|
2906
|
+
: { sourceBindingGeneration: decoded.boundSession.bindingGeneration }),
|
|
2907
|
+
reply: localReply
|
|
2908
|
+
});
|
|
2909
|
+
return;
|
|
2910
|
+
}
|
|
2911
|
+
if (decoded.kind === 'actorJoin') {
|
|
2912
|
+
this.validateSpotFence(decoded.target);
|
|
2913
|
+
const previous = this.registry.actor(decoded.actor.actor.actorId);
|
|
2914
|
+
const targetSpotKind = this.registry.spot(decoded.target.spot.spotId)?.kind;
|
|
2915
|
+
let actorJoinReplyAccepted = false;
|
|
2916
|
+
let completeOnJoinDispatchTerminal;
|
|
2917
|
+
const control = {
|
|
2918
|
+
kind: 'actorControl',
|
|
2919
|
+
lifecycleKind: service_runtime_contracts_1.ActorLifecycleKind.Joined,
|
|
2920
|
+
previousActor: previous?.ref ?? decoded.actor.actor,
|
|
2921
|
+
currentActor: decoded.actor.actor,
|
|
2922
|
+
previousSpotId: previous?.spot.spotId ?? null,
|
|
2923
|
+
currentSpotId: decoded.target.spot.spotId,
|
|
2924
|
+
previousSpotGeneration: previous?.spot.generation ?? 0n,
|
|
2925
|
+
currentSpotGeneration: decoded.target.spot.generation,
|
|
2926
|
+
previousMembershipEpoch: previous?.membershipEpoch ?? 0n,
|
|
2927
|
+
currentMembershipEpoch: (previous?.membershipEpoch ?? 0n) + 1n,
|
|
2928
|
+
resultCode: 0
|
|
2929
|
+
};
|
|
2930
|
+
this.enqueueLifecycleFrame(ingress, `spot:${decoded.target.spot.spotId}`, payloadFrame ?? (0, service_wire_m6a_codec_1.encodeApplicationPayload)(emptyPayload()), {
|
|
2931
|
+
receiveKind: service_runtime_contracts_1.ReceiveKind.SpotControl,
|
|
2932
|
+
operationKind: service_runtime_contracts_1.OperationKind.ActorJoin,
|
|
2933
|
+
correlation: decoded.correlation,
|
|
2934
|
+
targetSpot: decoded.target.spot,
|
|
2935
|
+
targetActor: decoded.actor.actor,
|
|
2936
|
+
kindData: control,
|
|
2937
|
+
...(canonicalActorJoin?.payload === undefined
|
|
2938
|
+
? {}
|
|
2939
|
+
: {
|
|
2940
|
+
canonicalApplicationPayload: {
|
|
2941
|
+
packetName: canonicalActorJoin.payload.packetName,
|
|
2942
|
+
contentType: canonicalActorJoin.payload.contentType,
|
|
2943
|
+
payload: Buffer.from(canonicalActorJoin.payload.payload)
|
|
2944
|
+
}
|
|
2945
|
+
}),
|
|
2946
|
+
isPending: () => this.operations.isPending(pending.id),
|
|
2947
|
+
...(deadlineUnixMs === undefined ? {} : { deadlineUnixMs }),
|
|
2948
|
+
onTerminalCompletion: () => completeOnJoinDispatchTerminal?.(),
|
|
2949
|
+
reply: (terminalResult, failureCode, replyPayload, tail) => {
|
|
2950
|
+
if (actorJoinReplyAccepted)
|
|
2951
|
+
return false;
|
|
2952
|
+
const acceptedJoin = terminalResult === runtime_values_1.RequestResult.Ok
|
|
2953
|
+
&& tail?.kind === 'actorJoin'
|
|
2954
|
+
&& tail.joinResult === 0;
|
|
2955
|
+
if (acceptedJoin && this.operations.isPending(pending.id)) {
|
|
2956
|
+
// Commit membership now, but keep the source operation behind
|
|
2957
|
+
// target OnJoinedActor. Entry finishes on this record; User
|
|
2958
|
+
// Spot lifecycle finishes on the Joined control below.
|
|
2959
|
+
actorJoinReplyAccepted = true;
|
|
2960
|
+
let completed = false;
|
|
2961
|
+
const completeReply = () => {
|
|
2962
|
+
if (completed)
|
|
2963
|
+
return;
|
|
2964
|
+
completed = true;
|
|
2965
|
+
localReply(terminalResult, failureCode, replyPayload, tail);
|
|
2966
|
+
};
|
|
2967
|
+
this.commitJoinedActor(decoded.actor.actor, decoded.target.spot, control.currentMembershipEpoch, targetSpotKind === 'user' ? completeReply : undefined);
|
|
2968
|
+
if (targetSpotKind === 'entry') {
|
|
2969
|
+
completeOnJoinDispatchTerminal = completeReply;
|
|
2970
|
+
}
|
|
2971
|
+
else if (targetSpotKind !== 'user') {
|
|
2972
|
+
completeReply();
|
|
2973
|
+
}
|
|
2974
|
+
return true;
|
|
2975
|
+
}
|
|
2976
|
+
const acceptedReply = localReply(terminalResult, failureCode, replyPayload, tail);
|
|
2977
|
+
if (acceptedReply)
|
|
2978
|
+
actorJoinReplyAccepted = true;
|
|
2979
|
+
return acceptedReply;
|
|
2980
|
+
}
|
|
2981
|
+
});
|
|
2982
|
+
return;
|
|
2983
|
+
}
|
|
2984
|
+
if (decoded.kind === 'boundSessionBind') {
|
|
2985
|
+
try {
|
|
2986
|
+
const current = this.validateActorFence(decoded.actor);
|
|
2987
|
+
if (decoded.binding.state === 'active') {
|
|
2988
|
+
this.registry.installSessionBinding((0, service_stateful_wire_codec_1.sessionBindingFromWire)(current.ref, decoded.sessionRid, this.nodeRid, decoded.binding.generation, current.membershipEpoch));
|
|
2989
|
+
}
|
|
2990
|
+
else {
|
|
2991
|
+
this.registry.unbindSession(current.ref, decoded.binding.retiredGeneration, decoded.sessionRid, this.nodeRid);
|
|
2992
|
+
}
|
|
2993
|
+
this.operations.reply(pending.id, { terminalResult: runtime_values_1.RequestResult.Ok, failureCode: 0 });
|
|
2994
|
+
}
|
|
2995
|
+
catch (error) {
|
|
2996
|
+
this.operations.reply(pending.id, failure(error));
|
|
2997
|
+
}
|
|
2998
|
+
return;
|
|
2999
|
+
}
|
|
3000
|
+
if (decoded.kind === 'instanceSpot') {
|
|
3001
|
+
if (decoded.activation === 'missing' && this.asyncInstanceAuthority !== undefined) {
|
|
3002
|
+
void this.continueMissingInstanceActivation(ingress, decoded, payloadFrame, localReply);
|
|
3003
|
+
return;
|
|
3004
|
+
}
|
|
3005
|
+
try {
|
|
3006
|
+
const activation = this.requireInstanceActivation(ingress, decoded);
|
|
3007
|
+
this.enqueueApplicationFrame(ingress, `spot:${activation.ref.spotId}`, payloadFrame, {
|
|
3008
|
+
receiveKind: service_runtime_contracts_1.ReceiveKind.InstanceSpotActivation,
|
|
3009
|
+
operationKind: service_runtime_contracts_1.OperationKind.InstanceSpotRequest,
|
|
3010
|
+
correlation: pending.id,
|
|
3011
|
+
...(decoded.sourceSpotId === undefined ? {} : { sourceSpotId: decoded.sourceSpotId }),
|
|
3012
|
+
targetSpot: activation.ref,
|
|
3013
|
+
reply: localReply
|
|
3014
|
+
});
|
|
3015
|
+
}
|
|
3016
|
+
catch (error) {
|
|
3017
|
+
this.operations.reply(pending.id, failure(error));
|
|
3018
|
+
}
|
|
3019
|
+
return;
|
|
3020
|
+
}
|
|
3021
|
+
this.operations.reply(pending.id, {
|
|
3022
|
+
terminalResult: runtime_values_1.RequestResult.ProtocolError,
|
|
3023
|
+
failureCode: 0
|
|
3024
|
+
});
|
|
3025
|
+
void operationKind;
|
|
3026
|
+
}
|
|
3027
|
+
completeRemoteReply(pending, targetNodeRid, operationKind, actor, reply) {
|
|
3028
|
+
const canonicalActorJoinHandoffId = operationKind === 'actorJoin'
|
|
3029
|
+
? this.canonicalActorJoinHandoffs.get(pending.id)
|
|
3030
|
+
: undefined;
|
|
3031
|
+
try {
|
|
3032
|
+
if (reply.length < 1 || reply.length > 2)
|
|
3033
|
+
throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Invalid M6B reply parts.');
|
|
3034
|
+
const decoded = (0, service_stateful_wire_codec_1.decodeStatefulReply)(reply[0], pending.id, operationKind, reply.length >= 2);
|
|
3035
|
+
const payload = reply.length < 2 ? undefined : (0, service_wire_m6a_codec_1.decodeApplicationPayload)(reply[1]);
|
|
3036
|
+
this.operations.reply(pending.id, this.resultFromReply(decoded.terminalResult, decoded.failureCode, payload, decoded.tail, targetNodeRid, actor, canonicalActorJoinHandoffId));
|
|
3037
|
+
}
|
|
3038
|
+
catch (error) {
|
|
3039
|
+
// Spec 32-framework-error-model:58-60, 91-92 — an unprocessable remote
|
|
3040
|
+
// reply (decode/shape failure) fails the awaiting operation with a
|
|
3041
|
+
// Framework ProtocolError instead of leaking the codec's plain Error.
|
|
3042
|
+
this.operations.fail(pending.id, (0, framework_errors_internal_1.translateWireReplyDecodeError)(error));
|
|
3043
|
+
}
|
|
3044
|
+
finally {
|
|
3045
|
+
if (operationKind === 'actorJoin') {
|
|
3046
|
+
this.canonicalActorJoinHandoffs.delete(pending.id);
|
|
3047
|
+
}
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
resultFromReply(terminalResult, failureCode, payload, tail, targetNodeRid, actor, canonicalActorJoinHandoffId) {
|
|
3051
|
+
let kindData;
|
|
3052
|
+
if (tail?.kind === 'actorLookup') {
|
|
3053
|
+
const resolvedActor = { ...tail.actor, nodeRid: targetNodeRid };
|
|
3054
|
+
this.rememberActorRoute({
|
|
3055
|
+
actor: resolvedActor,
|
|
3056
|
+
targetNodeGeneration: this.peerGeneration(targetNodeRid),
|
|
3057
|
+
authorityOwnerGeneration: tail.authorityOwnerGeneration,
|
|
3058
|
+
ownerLeaseGeneration: this.peerGeneration(targetNodeRid)
|
|
3059
|
+
});
|
|
3060
|
+
kindData = {
|
|
3061
|
+
kind: 'actorLookupCompletion',
|
|
3062
|
+
location: {
|
|
3063
|
+
actor: resolvedActor,
|
|
3064
|
+
spotId: tail.spot.spotId,
|
|
3065
|
+
spotGeneration: tail.spot.generation,
|
|
3066
|
+
membershipEpoch: tail.membershipEpoch
|
|
3067
|
+
}
|
|
3068
|
+
};
|
|
3069
|
+
}
|
|
3070
|
+
else if (tail?.kind === 'actorJoin' && actor !== undefined) {
|
|
3071
|
+
const joinedActor = { ...actor, nodeRid: targetNodeRid };
|
|
3072
|
+
const spot = tail.spot;
|
|
3073
|
+
kindData = {
|
|
3074
|
+
kind: 'actorJoinCompletion',
|
|
3075
|
+
joinResult: tail.joinResult,
|
|
3076
|
+
actor: joinedActor,
|
|
3077
|
+
location: {
|
|
3078
|
+
actor: joinedActor,
|
|
3079
|
+
spotId: spot?.spotId ?? null,
|
|
3080
|
+
spotGeneration: spot?.generation ?? 0n,
|
|
3081
|
+
membershipEpoch: tail.membershipEpoch ?? 1n
|
|
3082
|
+
},
|
|
3083
|
+
...(tail.receiveChunkLimitBytes === undefined
|
|
3084
|
+
? {}
|
|
3085
|
+
: { receiveChunkLimitBytes: tail.receiveChunkLimitBytes }),
|
|
3086
|
+
...(payload === undefined ? {} : { replyContentType: payload.contentType }),
|
|
3087
|
+
...(canonicalActorJoinHandoffId === undefined
|
|
3088
|
+
? {}
|
|
3089
|
+
: { canonicalHandoffId: canonicalActorJoinHandoffId })
|
|
3090
|
+
};
|
|
3091
|
+
}
|
|
3092
|
+
return {
|
|
3093
|
+
terminalResult,
|
|
3094
|
+
failureCode,
|
|
3095
|
+
...(payload === undefined ? {} : { payload }),
|
|
3096
|
+
...(tail?.kind === 'streamBind'
|
|
3097
|
+
? {
|
|
3098
|
+
streamBinding: {
|
|
3099
|
+
bindingGeneration: tail.bindingGeneration,
|
|
3100
|
+
authorityOwnerGeneration: tail.authorityOwnerGeneration
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
: {}),
|
|
3104
|
+
...(kindData === undefined ? {} : { kindData })
|
|
3105
|
+
};
|
|
3106
|
+
}
|
|
3107
|
+
validateActorFence(fence) {
|
|
3108
|
+
if (fence.actor.nodeRid !== this.nodeRid || fence.targetNodeGeneration !== this.nodeGeneration) {
|
|
3109
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('actor', fence.actor.actorId);
|
|
3110
|
+
}
|
|
3111
|
+
const actor = this.registry.requireActor(fence.actor);
|
|
3112
|
+
if (actor.authorityOwnerGeneration !== fence.authorityOwnerGeneration) {
|
|
3113
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('actor', fence.actor.actorId);
|
|
3114
|
+
}
|
|
3115
|
+
return actor;
|
|
3116
|
+
}
|
|
3117
|
+
validateActorMessageFence(fence) {
|
|
3118
|
+
if (fence.actor.nodeRid !== this.nodeRid || fence.targetNodeGeneration !== this.nodeGeneration) {
|
|
3119
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('actor', fence.actor.actorId);
|
|
3120
|
+
}
|
|
3121
|
+
const actor = this.registry.actor(fence.actor.actorId);
|
|
3122
|
+
if (actor === undefined) {
|
|
3123
|
+
throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RequestTargetNotFound, `Actor '${fence.actor.actorId}' has no current Ready authority.`);
|
|
3124
|
+
}
|
|
3125
|
+
return actor;
|
|
3126
|
+
}
|
|
3127
|
+
validateSpotFence(fence) {
|
|
3128
|
+
if (fence.targetNodeRid !== this.nodeRid || fence.targetNodeGeneration !== this.nodeGeneration) {
|
|
3129
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', fence.spot.spotId);
|
|
3130
|
+
}
|
|
3131
|
+
const spot = this.registry.requireSpot(fence.spot);
|
|
3132
|
+
if (spot.authorityOwnerGeneration !== fence.authorityOwnerGeneration) {
|
|
3133
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('spot', fence.spot.spotId);
|
|
3134
|
+
}
|
|
3135
|
+
return spot;
|
|
3136
|
+
}
|
|
3137
|
+
validateDirectSpotFence(fence) {
|
|
3138
|
+
const spot = this.registry.spot(fence.spot.spotId);
|
|
3139
|
+
if (spot === undefined) {
|
|
3140
|
+
throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RequestTargetNotFound, `Spot '${fence.spot.spotId}' has no current Ready authority.`);
|
|
3141
|
+
}
|
|
3142
|
+
if (spot.state !== 'ready') {
|
|
3143
|
+
throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Spot '${fence.spot.spotId}' is not Ready.`);
|
|
3144
|
+
}
|
|
3145
|
+
if (fence.targetNodeRid !== this.nodeRid || fence.targetNodeGeneration !== this.nodeGeneration) {
|
|
3146
|
+
throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Spot '${fence.spot.spotId}' targets an unavailable owner route.`);
|
|
3147
|
+
}
|
|
3148
|
+
if (spot.kind === 'entry') {
|
|
3149
|
+
if (!isEntrySpotFence(fence)) {
|
|
3150
|
+
throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Entry Spot '${fence.spot.spotId}' has an invalid owner fence.`);
|
|
3151
|
+
}
|
|
3152
|
+
return spot;
|
|
3153
|
+
}
|
|
3154
|
+
const current = this.directSpotRoutes.get(directSpotKey(spot.ref.spotId));
|
|
3155
|
+
if (current === undefined) {
|
|
3156
|
+
throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Spot '${fence.spot.spotId}' has no current owner route.`);
|
|
3157
|
+
}
|
|
3158
|
+
if (current.targetNodeRid !== this.nodeRid
|
|
3159
|
+
|| current.targetNodeGeneration !== this.nodeGeneration
|
|
3160
|
+
|| current.ownerLeaseGeneration !== fence.ownerLeaseGeneration
|
|
3161
|
+
|| (current.spot.generation === fence.spot.generation
|
|
3162
|
+
&& (current.authorityOwnerGeneration !== fence.authorityOwnerGeneration))) {
|
|
3163
|
+
throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Spot '${fence.spot.spotId}' has a stale owner fence.`);
|
|
3164
|
+
}
|
|
3165
|
+
return spot;
|
|
3166
|
+
}
|
|
3167
|
+
holdOrRelaySpotMessage(ingress, wire) {
|
|
3168
|
+
const state = this.spotMessageFollow.get(spotKey(wire.target.spot));
|
|
3169
|
+
if (state === undefined || !sameDirectSpotRoute(state.source, wire.target)) {
|
|
3170
|
+
return undefined;
|
|
3171
|
+
}
|
|
3172
|
+
if (state.expiresAtMs !== undefined && state.expiresAtMs <= performance.now()) {
|
|
3173
|
+
this.failExpiredSpotMessageFollow(state);
|
|
3174
|
+
return undefined;
|
|
3175
|
+
}
|
|
3176
|
+
const bytes = ingress.parts.reduce((sum, part) => sum + part.byteLength, 0);
|
|
3177
|
+
state.queued.push({
|
|
3178
|
+
ingress: shareIngressOwnership(ingress),
|
|
3179
|
+
wire,
|
|
3180
|
+
bytes
|
|
3181
|
+
});
|
|
3182
|
+
state.queuedCount += 1;
|
|
3183
|
+
state.queuedBytes += bytes;
|
|
3184
|
+
if (state.target !== undefined)
|
|
3185
|
+
void this.drainSpotMessageFollow(state);
|
|
3186
|
+
return 'application';
|
|
3187
|
+
}
|
|
3188
|
+
restoreSpotMessageFollowRecord(retained) {
|
|
3189
|
+
const { ingress, wire } = retained;
|
|
3190
|
+
this.validateDirectSpotFence(wire.target);
|
|
3191
|
+
return this.enqueueApplicationFrame(ingress, `spot:${wire.target.spot.spotId}`, ingress.parts[1], {
|
|
3192
|
+
receiveKind: wire.kind === 'spotSend' ? service_runtime_contracts_1.ReceiveKind.SpotSend : service_runtime_contracts_1.ReceiveKind.SpotRequest,
|
|
3193
|
+
operationKind: wire.kind === 'spotRequest' ? service_runtime_contracts_1.OperationKind.SpotRequest : 0,
|
|
3194
|
+
...(wire.correlation === undefined ? {} : { correlation: wire.correlation }),
|
|
3195
|
+
sourceSpotId: wire.sourceSpotId,
|
|
3196
|
+
targetSpot: wire.target.spot,
|
|
3197
|
+
...(wire.kind === 'spotRequest'
|
|
3198
|
+
? { reply: this.replyPort(ingress, wire.correlation, 'spotRequest') }
|
|
3199
|
+
: {})
|
|
3200
|
+
});
|
|
3201
|
+
}
|
|
3202
|
+
async drainSpotMessageFollow(state) {
|
|
3203
|
+
if (state.draining || state.target === undefined)
|
|
3204
|
+
return;
|
|
3205
|
+
state.draining = true;
|
|
3206
|
+
try {
|
|
3207
|
+
while (state.queuedCount > 0 && this.spotMessageFollow.get(state.seal.key) === state) {
|
|
3208
|
+
if (state.expiresAtMs === undefined || state.expiresAtMs <= performance.now()) {
|
|
3209
|
+
this.failExpiredSpotMessageFollow(state);
|
|
3210
|
+
return;
|
|
3211
|
+
}
|
|
3212
|
+
const current = this.peekSpotMessageFollow(state);
|
|
3213
|
+
try {
|
|
3214
|
+
const parts = [
|
|
3215
|
+
(0, service_stateful_wire_codec_1.encodeSpotHeader)(current.wire.kind, current.wire.sourceSpotId, state.target, current.wire.correlation),
|
|
3216
|
+
current.ingress.parts[1]
|
|
3217
|
+
];
|
|
3218
|
+
if (current.wire.kind === 'spotSend') {
|
|
3219
|
+
if (!await this.raw.sendService(state.target.targetNodeRid, parts))
|
|
3220
|
+
continue;
|
|
3221
|
+
}
|
|
3222
|
+
else {
|
|
3223
|
+
try {
|
|
3224
|
+
const remainingMs = Math.max(1, Math.min(30_000, Math.ceil(state.expiresAtMs - performance.now())));
|
|
3225
|
+
const reply = await this.raw.requestService(state.target.targetNodeRid, parts, remainingMs);
|
|
3226
|
+
this.raw.replyService(current.ingress, reply);
|
|
3227
|
+
}
|
|
3228
|
+
catch (error) {
|
|
3229
|
+
const result = failure(error);
|
|
3230
|
+
this.replyWire(current.ingress, current.wire.correlation, result.terminalResult, result.failureCode);
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
await this.notifySpotMessageFollowSource(state, current);
|
|
3234
|
+
}
|
|
3235
|
+
finally {
|
|
3236
|
+
if (this.peekSpotMessageFollow(state) === current) {
|
|
3237
|
+
this.takeSpotMessageFollow(state);
|
|
3238
|
+
state.queuedBytes -= current.bytes;
|
|
3239
|
+
}
|
|
3240
|
+
}
|
|
3241
|
+
}
|
|
3242
|
+
}
|
|
3243
|
+
finally {
|
|
3244
|
+
state.draining = false;
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
async notifySpotMessageFollowSource(state, current) {
|
|
3248
|
+
const target = state.target;
|
|
3249
|
+
const suppressionFence = state.suppressionFence;
|
|
3250
|
+
if (target === undefined || suppressionFence === undefined)
|
|
3251
|
+
return;
|
|
3252
|
+
const claim = this.spotMessageFollowSuppression.begin(suppressionFence);
|
|
3253
|
+
if (claim === undefined)
|
|
3254
|
+
return;
|
|
3255
|
+
const operationLow = current.ingress.requestSequence !== undefined
|
|
3256
|
+
&& current.ingress.requestSequence !== 0n
|
|
3257
|
+
? current.ingress.requestSequence
|
|
3258
|
+
: this.nextMessageFollowOperation++;
|
|
3259
|
+
const accepted = await this.raw.sendService(current.ingress.sourceRoutingId, [(0, service_stateful_wire_codec_1.encodeMessageFollowHeader)({
|
|
3260
|
+
source: messageFollowSpotRoute(state.source),
|
|
3261
|
+
target: messageFollowSpotRoute(target),
|
|
3262
|
+
hopCount: 1,
|
|
3263
|
+
queuedMessages: Math.min(state.queuedCount, 0xffff_ffff),
|
|
3264
|
+
queuedBytes: Math.min(state.queuedBytes, 0xffff_ffff),
|
|
3265
|
+
originalOperation: {
|
|
3266
|
+
high: this.nodeGeneration,
|
|
3267
|
+
low: operationLow
|
|
3268
|
+
},
|
|
3269
|
+
originalReplyRouteId: current.ingress.requestSequence ?? 0n
|
|
3270
|
+
})]);
|
|
3271
|
+
if (accepted) {
|
|
3272
|
+
this.spotMessageFollowSuppression.markSent(claim);
|
|
3273
|
+
}
|
|
3274
|
+
else {
|
|
3275
|
+
this.spotMessageFollowSuppression.abort(claim);
|
|
3276
|
+
}
|
|
3277
|
+
}
|
|
3278
|
+
failExpiredSpotMessageFollow(state) {
|
|
3279
|
+
this.removeSpotMessageFollow(state);
|
|
3280
|
+
while (state.queuedCount > 0) {
|
|
3281
|
+
const current = this.peekSpotMessageFollow(state);
|
|
3282
|
+
if (current.wire.kind === 'spotRequest') {
|
|
3283
|
+
const result = failure(new service_stateful_registry_1.ServiceStaleGenerationError('spot', current.wire.target.spot.spotId));
|
|
3284
|
+
this.replyWire(current.ingress, current.wire.correlation, result.terminalResult, result.failureCode);
|
|
3285
|
+
}
|
|
3286
|
+
this.takeSpotMessageFollow(state);
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
exactSpotMessageFollow(seal) {
|
|
3290
|
+
const state = this.spotMessageFollow.get(seal.key);
|
|
3291
|
+
return state?.seal.serial === seal.serial ? state : undefined;
|
|
3292
|
+
}
|
|
3293
|
+
removeSpotMessageFollow(state) {
|
|
3294
|
+
if (this.spotMessageFollow.get(state.seal.key) === state) {
|
|
3295
|
+
this.spotMessageFollow.delete(state.seal.key);
|
|
3296
|
+
}
|
|
3297
|
+
if (state.suppressionFence !== undefined) {
|
|
3298
|
+
this.spotMessageFollowSuppression.expireRoute(state.suppressionFence);
|
|
3299
|
+
}
|
|
3300
|
+
}
|
|
3301
|
+
peekSpotMessageFollow(state) {
|
|
3302
|
+
while (state.queuedHead < state.queued.length && state.queued[state.queuedHead] === undefined) {
|
|
3303
|
+
state.queuedHead += 1;
|
|
3304
|
+
}
|
|
3305
|
+
return state.queued[state.queuedHead];
|
|
3306
|
+
}
|
|
3307
|
+
takeSpotMessageFollow(state) {
|
|
3308
|
+
const current = this.peekSpotMessageFollow(state);
|
|
3309
|
+
if (current === undefined)
|
|
3310
|
+
return;
|
|
3311
|
+
current.ingress.applicationJobOwner?.close();
|
|
3312
|
+
state.queued[state.queuedHead] = undefined;
|
|
3313
|
+
state.queuedHead += 1;
|
|
3314
|
+
state.queuedCount -= 1;
|
|
3315
|
+
if (state.queuedCount === 0) {
|
|
3316
|
+
state.queued.length = 0;
|
|
3317
|
+
state.queuedHead = 0;
|
|
3318
|
+
}
|
|
3319
|
+
else if (state.queuedHead >= 1024 && state.queuedHead * 2 >= state.queued.length) {
|
|
3320
|
+
state.queued.splice(0, state.queuedHead);
|
|
3321
|
+
state.queuedHead = 0;
|
|
3322
|
+
}
|
|
3323
|
+
}
|
|
3324
|
+
actorFence(actor) {
|
|
3325
|
+
const route = this.tryActorFence(actor);
|
|
3326
|
+
if (route === undefined)
|
|
3327
|
+
throw new service_stateful_registry_1.ServiceStaleGenerationError('actor', actor.actorId);
|
|
3328
|
+
return route;
|
|
3329
|
+
}
|
|
3330
|
+
tryBoundSessionSendFence(actor, senderFence) {
|
|
3331
|
+
if (senderFence === undefined
|
|
3332
|
+
|| senderFence.targetNodeGeneration !== this.nodeGeneration
|
|
3333
|
+
|| senderFence.authorityOwnerGeneration <= 0n
|
|
3334
|
+
|| senderFence.ownerLeaseGeneration <= 0n) {
|
|
3335
|
+
return undefined;
|
|
3336
|
+
}
|
|
3337
|
+
const local = actor.nodeRid === this.nodeRid ? this.registry.actor(actor.actorId) : undefined;
|
|
3338
|
+
if (local === undefined
|
|
3339
|
+
|| !sameActorRef(local.ref, actor)
|
|
3340
|
+
|| local.authorityOwnerGeneration !== senderFence.authorityOwnerGeneration) {
|
|
3341
|
+
return undefined;
|
|
3342
|
+
}
|
|
3343
|
+
return {
|
|
3344
|
+
actor,
|
|
3345
|
+
targetNodeGeneration: senderFence.targetNodeGeneration,
|
|
3346
|
+
authorityOwnerGeneration: senderFence.authorityOwnerGeneration,
|
|
3347
|
+
ownerLeaseGeneration: senderFence.ownerLeaseGeneration
|
|
3348
|
+
};
|
|
3349
|
+
}
|
|
3350
|
+
tryActorFence(actor) {
|
|
3351
|
+
const local = actor.nodeRid === this.nodeRid ? this.registry.actor(actor.actorId) : undefined;
|
|
3352
|
+
if (local !== undefined && sameActorRef(local.ref, actor)) {
|
|
3353
|
+
return {
|
|
3354
|
+
actor,
|
|
3355
|
+
targetNodeGeneration: this.nodeGeneration,
|
|
3356
|
+
authorityOwnerGeneration: local.authorityOwnerGeneration,
|
|
3357
|
+
ownerLeaseGeneration: this.nodeGeneration
|
|
3358
|
+
};
|
|
3359
|
+
}
|
|
3360
|
+
const route = this.actorRoutes.get(actorKey(actor));
|
|
3361
|
+
return route !== undefined && sameActorRef(route.actor, actor) ? route : undefined;
|
|
3362
|
+
}
|
|
3363
|
+
acceptCanonicalActorFence(actor, fence) {
|
|
3364
|
+
// Canonical command 28 carries the current Location Store authority
|
|
3365
|
+
// snapshot selected for this attempt. A private Core route may describe a
|
|
3366
|
+
// previous visit to the same owner, so it cannot veto that snapshot; the
|
|
3367
|
+
// receiving runtime validates every field against the Store before
|
|
3368
|
+
// application admission (spec 15 section 4.2 / spec 51 section 9).
|
|
3369
|
+
// Object/authority/lease are bounded counters. Node lifecycle is a
|
|
3370
|
+
// full-range opaque token, where only zero represents absence.
|
|
3371
|
+
if (actor.generation <= 0n
|
|
3372
|
+
|| fence.targetNodeGeneration === 0n
|
|
3373
|
+
|| fence.authorityOwnerGeneration <= 0n
|
|
3374
|
+
|| fence.ownerLeaseGeneration <= 0n) {
|
|
3375
|
+
return undefined;
|
|
3376
|
+
}
|
|
3377
|
+
return {
|
|
3378
|
+
actor,
|
|
3379
|
+
targetNodeGeneration: fence.targetNodeGeneration,
|
|
3380
|
+
authorityOwnerGeneration: fence.authorityOwnerGeneration,
|
|
3381
|
+
ownerLeaseGeneration: fence.ownerLeaseGeneration
|
|
3382
|
+
};
|
|
3383
|
+
}
|
|
3384
|
+
trySpotFence(targetNodeRid, spot) {
|
|
3385
|
+
const local = targetNodeRid === this.nodeRid ? this.registry.spot(spot.spotId) : undefined;
|
|
3386
|
+
if (local !== undefined && sameSpotRef(local.ref, spot)) {
|
|
3387
|
+
return {
|
|
3388
|
+
spot,
|
|
3389
|
+
targetNodeRid,
|
|
3390
|
+
targetNodeGeneration: this.nodeGeneration,
|
|
3391
|
+
authorityOwnerGeneration: local.authorityOwnerGeneration,
|
|
3392
|
+
ownerLeaseGeneration: this.nodeGeneration
|
|
3393
|
+
};
|
|
3394
|
+
}
|
|
3395
|
+
const route = this.spotRoutes.get(spotKey(spot));
|
|
3396
|
+
return route !== undefined
|
|
3397
|
+
&& route.targetNodeRid === targetNodeRid
|
|
3398
|
+
&& sameSpotRef(route.spot, spot)
|
|
3399
|
+
? route
|
|
3400
|
+
: undefined;
|
|
3401
|
+
}
|
|
3402
|
+
tryEntrySpotFence(targetNodeRid) {
|
|
3403
|
+
const targetNodeGeneration = targetNodeRid === this.nodeRid
|
|
3404
|
+
? this.nodeGeneration
|
|
3405
|
+
: this.raw.topology.peer(targetNodeRid)?.descriptor.lifecycleGeneration;
|
|
3406
|
+
if (targetNodeGeneration === undefined)
|
|
3407
|
+
return undefined;
|
|
3408
|
+
return {
|
|
3409
|
+
spot: {
|
|
3410
|
+
spotId: targetNodeRid,
|
|
3411
|
+
generation: targetNodeGeneration
|
|
3412
|
+
},
|
|
3413
|
+
targetNodeRid,
|
|
3414
|
+
targetNodeGeneration,
|
|
3415
|
+
authorityOwnerGeneration: targetNodeGeneration,
|
|
3416
|
+
ownerLeaseGeneration: targetNodeGeneration,
|
|
3417
|
+
storeVersion: `entry:${targetNodeGeneration}`
|
|
3418
|
+
};
|
|
3419
|
+
}
|
|
3420
|
+
acceptSpotAuthority(requested) {
|
|
3421
|
+
const { targetNodeRid, spot, targetNodeGeneration } = requested;
|
|
3422
|
+
if (targetNodeRid === this.nodeRid) {
|
|
3423
|
+
const local = this.registry.spot(spot.spotId);
|
|
3424
|
+
if (local?.kind === 'entry'
|
|
3425
|
+
&& sameSpotRef(local.ref, spot)
|
|
3426
|
+
&& targetNodeGeneration === this.nodeGeneration
|
|
3427
|
+
&& requested.authorityOwnerGeneration === local.authorityOwnerGeneration
|
|
3428
|
+
&& isEntrySpotFence(requested)) {
|
|
3429
|
+
return requested;
|
|
3430
|
+
}
|
|
3431
|
+
const current = this.directSpotRoutes.get(directSpotKey(spot.spotId));
|
|
3432
|
+
return local !== undefined
|
|
3433
|
+
&& local.state === 'ready'
|
|
3434
|
+
&& targetNodeGeneration === this.nodeGeneration
|
|
3435
|
+
&& current !== undefined
|
|
3436
|
+
&& current.targetNodeRid === this.nodeRid
|
|
3437
|
+
&& current.targetNodeGeneration === this.nodeGeneration
|
|
3438
|
+
&& current.ownerLeaseGeneration === requested.ownerLeaseGeneration
|
|
3439
|
+
&& (current.spot.generation !== requested.spot.generation
|
|
3440
|
+
|| (current.authorityOwnerGeneration === requested.authorityOwnerGeneration))
|
|
3441
|
+
? current
|
|
3442
|
+
: undefined;
|
|
3443
|
+
}
|
|
3444
|
+
const peer = this.raw.topology.peer(targetNodeRid);
|
|
3445
|
+
if (peer?.descriptor.lifecycleGeneration !== targetNodeGeneration) {
|
|
3446
|
+
return undefined;
|
|
3447
|
+
}
|
|
3448
|
+
this.rememberSpotRoute(requested);
|
|
3449
|
+
return this.directSpotRoutes.get(directSpotKey(spot.spotId));
|
|
3450
|
+
}
|
|
3451
|
+
peerGeneration(nodeRid) {
|
|
3452
|
+
const generation = this.tryPeerGeneration(nodeRid);
|
|
3453
|
+
if (generation === undefined) {
|
|
3454
|
+
throw new Error(`Node '${nodeRid}' has no admitted lifecycle generation.`);
|
|
3455
|
+
}
|
|
3456
|
+
return generation;
|
|
3457
|
+
}
|
|
3458
|
+
tryPeerGeneration(nodeRid) {
|
|
3459
|
+
if (nodeRid === this.nodeRid)
|
|
3460
|
+
return this.nodeGeneration;
|
|
3461
|
+
return this.raw.topology.peer(nodeRid)?.descriptor.lifecycleGeneration;
|
|
3462
|
+
}
|
|
3463
|
+
commitJoinedActor(actor, spot, membershipEpoch, onTargetLifecycleCompleted) {
|
|
3464
|
+
const current = this.registry.actor(actor.actorId);
|
|
3465
|
+
const previousActor = current?.ref ?? actor;
|
|
3466
|
+
const previousSpot = current?.spot;
|
|
3467
|
+
const previousSpotState = previousSpot === undefined
|
|
3468
|
+
? undefined
|
|
3469
|
+
: this.registry.spot(previousSpot.spotId);
|
|
3470
|
+
const previousMembershipEpoch = current?.membershipEpoch ?? membershipEpoch - 1n;
|
|
3471
|
+
if (current === undefined) {
|
|
3472
|
+
this.registry.restoreActor({ ...actor, nodeRid: this.nodeRid }, 'actor', spot, membershipEpoch);
|
|
3473
|
+
}
|
|
3474
|
+
else {
|
|
3475
|
+
this.registry.joinActor(current.ref, spot);
|
|
3476
|
+
}
|
|
3477
|
+
const committed = this.registry.requireActor({
|
|
3478
|
+
...actor,
|
|
3479
|
+
nodeRid: this.nodeRid
|
|
3480
|
+
});
|
|
3481
|
+
const targetSpot = this.registry.spot(spot.spotId);
|
|
3482
|
+
if (targetSpot?.kind !== 'entry') {
|
|
3483
|
+
this.enqueueActorControl(spot.spotId, {
|
|
3484
|
+
kind: 'actorControl',
|
|
3485
|
+
lifecycleKind: service_runtime_contracts_1.ActorLifecycleKind.Joined,
|
|
3486
|
+
previousActor,
|
|
3487
|
+
currentActor: committed.ref,
|
|
3488
|
+
previousSpotId: previousSpot?.spotId ?? null,
|
|
3489
|
+
currentSpotId: spot.spotId,
|
|
3490
|
+
previousSpotGeneration: previousSpot?.generation ?? 0n,
|
|
3491
|
+
currentSpotGeneration: spot.generation,
|
|
3492
|
+
previousMembershipEpoch,
|
|
3493
|
+
currentMembershipEpoch: committed.membershipEpoch,
|
|
3494
|
+
resultCode: 0
|
|
3495
|
+
}, onTargetLifecycleCompleted);
|
|
3496
|
+
}
|
|
3497
|
+
if (actor.nodeRid === this.nodeRid
|
|
3498
|
+
&& previousSpot !== undefined
|
|
3499
|
+
&& previousSpot.spotId !== spot.spotId
|
|
3500
|
+
&& previousSpotState?.ref.generation === previousSpot.generation
|
|
3501
|
+
&& (previousSpotState.kind === 'entry' || previousSpotState.kind === 'user')) {
|
|
3502
|
+
// A same-node Core join commits the target membership and publishes
|
|
3503
|
+
// the source LEFT control separately. Remote joins use the formal
|
|
3504
|
+
// transfer source terminal instead; the wire ActorRef still identifies
|
|
3505
|
+
// the source owner, so a remote target must not publish a second LEFT.
|
|
3506
|
+
this.enqueueActorControl(previousSpot.spotId, {
|
|
3507
|
+
kind: 'actorControl',
|
|
3508
|
+
lifecycleKind: service_runtime_contracts_1.ActorLifecycleKind.Left,
|
|
3509
|
+
previousActor,
|
|
3510
|
+
currentActor: previousActor,
|
|
3511
|
+
previousSpotId: previousSpot.spotId,
|
|
3512
|
+
currentSpotId: spot.spotId,
|
|
3513
|
+
previousSpotGeneration: previousSpot.generation,
|
|
3514
|
+
currentSpotGeneration: spot.generation,
|
|
3515
|
+
previousMembershipEpoch,
|
|
3516
|
+
currentMembershipEpoch: committed.membershipEpoch,
|
|
3517
|
+
resultCode: 0
|
|
3518
|
+
});
|
|
3519
|
+
}
|
|
3520
|
+
}
|
|
3521
|
+
requireOpen() {
|
|
3522
|
+
if (this.closed)
|
|
3523
|
+
throw new Error('Stateful runtime is closed.');
|
|
3524
|
+
}
|
|
3525
|
+
}
|
|
3526
|
+
exports.ServiceStatefulRuntime = ServiceStatefulRuntime;
|
|
3527
|
+
function isEntrySpotFence(fence) {
|
|
3528
|
+
return fence.spot.spotId === fence.targetNodeRid
|
|
3529
|
+
&& fence.spot.generation === fence.targetNodeGeneration
|
|
3530
|
+
&& fence.authorityOwnerGeneration === fence.targetNodeGeneration
|
|
3531
|
+
&& fence.ownerLeaseGeneration === fence.targetNodeGeneration
|
|
3532
|
+
&& fence.storeVersion === `entry:${fence.targetNodeGeneration}`;
|
|
3533
|
+
}
|
|
3534
|
+
function userSpotDeadline(deadlineUnixMs) {
|
|
3535
|
+
const controller = new AbortController();
|
|
3536
|
+
const delay = Number(deadlineUnixMs - BigInt(Date.now()));
|
|
3537
|
+
const timeout = setTimeout(() => controller.abort(new Error('User Spot operation deadline exceeded.')), Math.max(0, Math.min(delay, 0x7fff_ffff)));
|
|
3538
|
+
return {
|
|
3539
|
+
signal: controller.signal,
|
|
3540
|
+
close: () => clearTimeout(timeout)
|
|
3541
|
+
};
|
|
3542
|
+
}
|
|
3543
|
+
function operationReplayExpired(replayExpiresAtMs) {
|
|
3544
|
+
return performance.now() > replayExpiresAtMs;
|
|
3545
|
+
}
|
|
3546
|
+
function durableRequestWasAdmitted(error) {
|
|
3547
|
+
// Request NotConnected includes Core handover of an admitted request. The
|
|
3548
|
+
// submit/request phase, rather than the result number, owns this distinction.
|
|
3549
|
+
return (0, runtime_values_1.isZLinkBackendResultError)(error) && error.operation === 'request';
|
|
3550
|
+
}
|
|
3551
|
+
function durableOperationExhausted(operationKind, wasAdmitted, cause) {
|
|
3552
|
+
return (0, framework_errors_internal_1.createInternalFrameworkException)(wasAdmitted
|
|
3553
|
+
? framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.DeadlineExceeded
|
|
3554
|
+
: framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RouteNotConnected, `${operationKind} exhausted its end-to-end deadline.`, true, cause);
|
|
3555
|
+
}
|
|
3556
|
+
function durableRequestCanReplay(error) {
|
|
3557
|
+
if (!(0, runtime_values_1.isZLinkBackendResultError)(error))
|
|
3558
|
+
return false;
|
|
3559
|
+
return error.operation === 'request'
|
|
3560
|
+
? error.result === runtime_values_1.RequestResult.NotConnected || error.result === runtime_values_1.RequestResult.TimedOut
|
|
3561
|
+
: error.result === runtime_values_1.SubmitResult.NotConnected
|
|
3562
|
+
|| error.result === runtime_values_1.SubmitResult.NotFound
|
|
3563
|
+
|| error.result === runtime_values_1.SubmitResult.NotAdmitted
|
|
3564
|
+
|| error.result === runtime_values_1.SubmitResult.Backpressured;
|
|
3565
|
+
}
|
|
3566
|
+
function remainingDeadlineMs(deadlineUnixMs) {
|
|
3567
|
+
const remainingMs = deadlineUnixMs - BigInt(Date.now());
|
|
3568
|
+
if (remainingMs <= 0n) {
|
|
3569
|
+
throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.DeadlineExceeded, 'Stateful request exceeded its end-to-end deadline.', true);
|
|
3570
|
+
}
|
|
3571
|
+
return Number(remainingMs);
|
|
3572
|
+
}
|
|
3573
|
+
function userSpotOperationFingerprint(record) {
|
|
3574
|
+
const { correlation: _correlation, ...semantic } = record;
|
|
3575
|
+
return JSON.stringify(semantic, (_key, value) => typeof value === 'bigint' ? `${value}n` : value);
|
|
3576
|
+
}
|
|
3577
|
+
function lookupKindData(actor) {
|
|
3578
|
+
return {
|
|
3579
|
+
kind: 'actorLookupCompletion',
|
|
3580
|
+
location: actorLocation(actor)
|
|
3581
|
+
};
|
|
3582
|
+
}
|
|
3583
|
+
function actorLocation(actor) {
|
|
3584
|
+
return {
|
|
3585
|
+
actor: actor.ref,
|
|
3586
|
+
spotId: actor.spot.spotId,
|
|
3587
|
+
spotGeneration: actor.spot.generation,
|
|
3588
|
+
membershipEpoch: actor.membershipEpoch
|
|
3589
|
+
};
|
|
3590
|
+
}
|
|
3591
|
+
function failure(error) {
|
|
3592
|
+
if (error instanceof service_stateful_registry_1.ServiceStaleGenerationError) {
|
|
3593
|
+
return { terminalResult: runtime_values_1.RequestResult.NotFound, failureCode: ACTOR_ROUTE_STALE };
|
|
3594
|
+
}
|
|
3595
|
+
if (error instanceof contracts_1.ZLinkFrameworkException) {
|
|
3596
|
+
return (0, framework_errors_internal_1.internalFrameworkWireReply)(error);
|
|
3597
|
+
}
|
|
3598
|
+
return { terminalResult: runtime_values_1.RequestResult.InternalError, failureCode: 17 };
|
|
3599
|
+
}
|
|
3600
|
+
function actorKey(actor) {
|
|
3601
|
+
return `${actor.actorId}\0${actor.generation}`;
|
|
3602
|
+
}
|
|
3603
|
+
function sameSessionBinding(left, right) {
|
|
3604
|
+
return sameActorRef(left.actor, right.actor)
|
|
3605
|
+
&& left.sessionRid === right.sessionRid
|
|
3606
|
+
&& sameSessionOwnerIdentity(left, right)
|
|
3607
|
+
&& left.bindingGeneration === right.bindingGeneration;
|
|
3608
|
+
}
|
|
3609
|
+
function sameSessionIdentity(left, right) {
|
|
3610
|
+
return sameActorRef(left.actor, right.actor)
|
|
3611
|
+
&& left.sessionRid === right.sessionRid
|
|
3612
|
+
&& sameSessionOwnerIdentity(left, right);
|
|
3613
|
+
}
|
|
3614
|
+
function sameSessionOwnerIdentity(left, right) {
|
|
3615
|
+
return left.sessionOwnerNodeRid === right.sessionOwnerNodeRid
|
|
3616
|
+
&& left.sessionOwnerNodeGeneration === right.sessionOwnerNodeGeneration
|
|
3617
|
+
&& left.sessionOwnerId === right.sessionOwnerId
|
|
3618
|
+
&& left.sessionOwnerLeaseGeneration === right.sessionOwnerLeaseGeneration;
|
|
3619
|
+
}
|
|
3620
|
+
function requireSessionOwnerIdentity(binding) {
|
|
3621
|
+
if (binding.sessionOwnerNodeGeneration === undefined
|
|
3622
|
+
|| binding.sessionOwnerId === undefined
|
|
3623
|
+
|| binding.sessionOwnerLeaseGeneration === undefined) {
|
|
3624
|
+
throw new service_wire_m6a_codec_1.ServiceWireProtocolError(`Session binding '${binding.sessionRid}' omits its owner lifecycle identity.`);
|
|
3625
|
+
}
|
|
3626
|
+
return {
|
|
3627
|
+
nodeGeneration: binding.sessionOwnerNodeGeneration,
|
|
3628
|
+
ownerId: binding.sessionOwnerId,
|
|
3629
|
+
leaseGeneration: binding.sessionOwnerLeaseGeneration
|
|
3630
|
+
};
|
|
3631
|
+
}
|
|
3632
|
+
function sessionDeliveryKey(binding) {
|
|
3633
|
+
return `${actorKey(binding.actor)}\0${binding.sessionOwnerNodeRid}\0${binding.sessionRid}`
|
|
3634
|
+
+ `\0${binding.sessionOwnerNodeGeneration ?? ''}`
|
|
3635
|
+
+ `\0${binding.sessionOwnerId ?? ''}`
|
|
3636
|
+
+ `\0${binding.sessionOwnerLeaseGeneration ?? ''}`
|
|
3637
|
+
+ `\0${binding.bindingGeneration}`;
|
|
3638
|
+
}
|
|
3639
|
+
function exactRetiredDelivery(binding, retired) {
|
|
3640
|
+
return binding.sessionRid === retired.sessionRid
|
|
3641
|
+
&& binding.sessionOwnerNodeRid === retired.sessionOwnerNodeRid
|
|
3642
|
+
&& binding.sessionOwnerNodeGeneration === retired.sessionOwnerNodeGeneration
|
|
3643
|
+
&& binding.sessionOwnerId === retired.sessionOwnerId
|
|
3644
|
+
&& binding.sessionOwnerLeaseGeneration === retired.sessionOwnerLeaseGeneration
|
|
3645
|
+
&& binding.bindingGeneration === retired.retiredBindingGeneration;
|
|
3646
|
+
}
|
|
3647
|
+
function replacementNoticeKey(record) {
|
|
3648
|
+
return `${actorKey(record.actorAuthority.actor)}\0${record.retiredSession.sessionOwnerNodeRid}`
|
|
3649
|
+
+ `\0${record.actorAuthority.targetNodeGeneration}`
|
|
3650
|
+
+ `\0${record.actorAuthority.authorityOwnerGeneration}`
|
|
3651
|
+
+ `\0${record.actorAuthority.ownerLeaseGeneration}`
|
|
3652
|
+
+ `\0${record.retiredSession.sessionOwnerNodeGeneration}`
|
|
3653
|
+
+ `\0${record.retiredSession.sessionOwnerId}`
|
|
3654
|
+
+ `\0${record.retiredSession.sessionOwnerLeaseGeneration}`
|
|
3655
|
+
+ `\0${record.retiredSession.sessionRid}`
|
|
3656
|
+
+ `\0${record.retiredSession.retiredBindingGeneration}`;
|
|
3657
|
+
}
|
|
3658
|
+
function actorAuthorityFromRoute(route) {
|
|
3659
|
+
return {
|
|
3660
|
+
actor: route.actor,
|
|
3661
|
+
targetNodeGeneration: route.targetNodeGeneration,
|
|
3662
|
+
authorityOwnerGeneration: route.authorityOwnerGeneration,
|
|
3663
|
+
ownerLeaseGeneration: route.ownerLeaseGeneration
|
|
3664
|
+
};
|
|
3665
|
+
}
|
|
3666
|
+
function spotKey(spot) {
|
|
3667
|
+
return `${spot.spotId}\0${spot.generation}`;
|
|
3668
|
+
}
|
|
3669
|
+
function directSpotKey(spotId) {
|
|
3670
|
+
return spotId;
|
|
3671
|
+
}
|
|
3672
|
+
function sameActorRef(left, right) {
|
|
3673
|
+
return left.nodeRid === right.nodeRid
|
|
3674
|
+
&& left.actorId === right.actorId
|
|
3675
|
+
&& left.generation === right.generation;
|
|
3676
|
+
}
|
|
3677
|
+
function sameSpotRef(left, right) {
|
|
3678
|
+
return left.spotId === right.spotId && left.generation === right.generation;
|
|
3679
|
+
}
|
|
3680
|
+
function freezeSpotRoute(route) {
|
|
3681
|
+
return Object.freeze({
|
|
3682
|
+
spot: Object.freeze({ ...route.spot }),
|
|
3683
|
+
targetNodeRid: route.targetNodeRid,
|
|
3684
|
+
targetNodeGeneration: route.targetNodeGeneration,
|
|
3685
|
+
authorityOwnerGeneration: route.authorityOwnerGeneration,
|
|
3686
|
+
ownerLeaseGeneration: route.ownerLeaseGeneration
|
|
3687
|
+
});
|
|
3688
|
+
}
|
|
3689
|
+
function freezeDirectSpotRoute(route) {
|
|
3690
|
+
return Object.freeze({
|
|
3691
|
+
...freezeSpotRoute(route),
|
|
3692
|
+
ownerLeaseGeneration: route.ownerLeaseGeneration,
|
|
3693
|
+
storeVersion: route.storeVersion
|
|
3694
|
+
});
|
|
3695
|
+
}
|
|
3696
|
+
function shareIngressOwnership(record) {
|
|
3697
|
+
// Raw binding ingress already owns stable Buffer values. Relocation follow
|
|
3698
|
+
// queues retain the same record until the route decision completes.
|
|
3699
|
+
const applicationJobOwner = requireApplicationJobOwner(record).retain();
|
|
3700
|
+
return { ...record, applicationJobOwner };
|
|
3701
|
+
}
|
|
3702
|
+
function requireApplicationJobOwner(record) {
|
|
3703
|
+
if (record.applicationJobOwner === undefined) {
|
|
3704
|
+
throw new Error('Service ingress requires the host Application Job Queue owner.');
|
|
3705
|
+
}
|
|
3706
|
+
return record.applicationJobOwner;
|
|
3707
|
+
}
|
|
3708
|
+
function statefulCorrelation(record) {
|
|
3709
|
+
if ('correlation' in record)
|
|
3710
|
+
return record.correlation;
|
|
3711
|
+
return record.kind === 'instanceSpot' && record.operationKind === 'request'
|
|
3712
|
+
? record.replyRouteId
|
|
3713
|
+
: undefined;
|
|
3714
|
+
}
|
|
3715
|
+
function matchesExpectedInstanceRoute(current, expected) {
|
|
3716
|
+
if (expected === undefined)
|
|
3717
|
+
return true;
|
|
3718
|
+
return expected === null
|
|
3719
|
+
? current === undefined
|
|
3720
|
+
: current !== undefined && sameInstanceRoute(current, expected);
|
|
3721
|
+
}
|
|
3722
|
+
function sameInstanceRoute(left, right) {
|
|
3723
|
+
return left.targetNodeRid === right.targetNodeRid
|
|
3724
|
+
&& left.targetNodeGeneration === right.targetNodeGeneration
|
|
3725
|
+
&& left.targetSpotId === right.targetSpotId
|
|
3726
|
+
&& left.objectGeneration === right.objectGeneration
|
|
3727
|
+
&& left.ownerId === right.ownerId
|
|
3728
|
+
&& left.authorityOwnerGeneration === right.authorityOwnerGeneration
|
|
3729
|
+
&& left.leaseGeneration === right.leaseGeneration
|
|
3730
|
+
&& left.storeVersion === right.storeVersion;
|
|
3731
|
+
}
|
|
3732
|
+
function sameInstanceOwnerIdentity(left, right) {
|
|
3733
|
+
return left.targetNodeRid === right.targetNodeRid
|
|
3734
|
+
&& left.targetNodeGeneration === right.targetNodeGeneration
|
|
3735
|
+
&& left.targetSpotId === right.targetSpotId
|
|
3736
|
+
&& left.objectGeneration === right.objectGeneration
|
|
3737
|
+
&& left.ownerId === right.ownerId
|
|
3738
|
+
&& left.authorityOwnerGeneration === right.authorityOwnerGeneration
|
|
3739
|
+
&& left.leaseGeneration === right.leaseGeneration;
|
|
3740
|
+
}
|
|
3741
|
+
function sameInstanceApplicationOwner(left, right) {
|
|
3742
|
+
return left.targetNodeRid === right.targetNodeRid
|
|
3743
|
+
&& left.targetNodeGeneration === right.targetNodeGeneration
|
|
3744
|
+
&& left.targetSpotId === right.targetSpotId
|
|
3745
|
+
&& left.ownerId === right.ownerId
|
|
3746
|
+
&& left.leaseGeneration === right.leaseGeneration;
|
|
3747
|
+
}
|
|
3748
|
+
function matchesExpectedDirectSpotRoute(current, expected) {
|
|
3749
|
+
return expected === null
|
|
3750
|
+
? current === undefined
|
|
3751
|
+
: current !== undefined && sameDirectSpotRoute(current, expected);
|
|
3752
|
+
}
|
|
3753
|
+
function instanceRouteAsDirectRoute(route) {
|
|
3754
|
+
return {
|
|
3755
|
+
spot: {
|
|
3756
|
+
spotId: route.targetSpotId,
|
|
3757
|
+
generation: route.objectGeneration
|
|
3758
|
+
},
|
|
3759
|
+
targetNodeRid: route.targetNodeRid,
|
|
3760
|
+
targetNodeGeneration: route.targetNodeGeneration,
|
|
3761
|
+
authorityOwnerGeneration: route.authorityOwnerGeneration,
|
|
3762
|
+
ownerLeaseGeneration: route.leaseGeneration,
|
|
3763
|
+
storeVersion: route.storeVersion
|
|
3764
|
+
};
|
|
3765
|
+
}
|
|
3766
|
+
function sameDirectSpotRoute(left, right) {
|
|
3767
|
+
return sameDirectSpotRouteIdentity(left, right)
|
|
3768
|
+
&& left.storeVersion === right.storeVersion;
|
|
3769
|
+
}
|
|
3770
|
+
function messageFollowSpotRoute(route) {
|
|
3771
|
+
return {
|
|
3772
|
+
kind: 'spot',
|
|
3773
|
+
spot: route.spot,
|
|
3774
|
+
targetNodeRid: route.targetNodeRid,
|
|
3775
|
+
targetNodeGeneration: route.targetNodeGeneration,
|
|
3776
|
+
authorityOwnerGeneration: route.authorityOwnerGeneration,
|
|
3777
|
+
ownerLeaseGeneration: route.ownerLeaseGeneration
|
|
3778
|
+
};
|
|
3779
|
+
}
|
|
3780
|
+
function spotMessageFollowSuppressionFence(objectKind, source, target) {
|
|
3781
|
+
return Object.freeze({
|
|
3782
|
+
objectKind,
|
|
3783
|
+
logicalObjectId: source.spot.spotId,
|
|
3784
|
+
objectGeneration: source.spot.generation.toString(),
|
|
3785
|
+
sourceNodeRid: source.targetNodeRid,
|
|
3786
|
+
sourceNodeGeneration: source.targetNodeGeneration.toString(),
|
|
3787
|
+
sourceAuthorityOwnerGeneration: source.authorityOwnerGeneration.toString(),
|
|
3788
|
+
sourceOwnerLeaseGeneration: source.ownerLeaseGeneration.toString(),
|
|
3789
|
+
targetNodeRid: target.targetNodeRid,
|
|
3790
|
+
targetNodeGeneration: target.targetNodeGeneration.toString(),
|
|
3791
|
+
targetAuthorityOwnerGeneration: target.authorityOwnerGeneration.toString(),
|
|
3792
|
+
targetOwnerLeaseGeneration: target.ownerLeaseGeneration.toString()
|
|
3793
|
+
});
|
|
3794
|
+
}
|
|
3795
|
+
function sameMessageFollowSpotSource(current, source) {
|
|
3796
|
+
return current.spot.spotId === source.spot.spotId
|
|
3797
|
+
&& current.spot.generation === source.spot.generation
|
|
3798
|
+
&& current.targetNodeRid === source.targetNodeRid
|
|
3799
|
+
&& current.targetNodeGeneration === source.targetNodeGeneration
|
|
3800
|
+
&& current.authorityOwnerGeneration === source.authorityOwnerGeneration
|
|
3801
|
+
&& current.ownerLeaseGeneration === source.ownerLeaseGeneration;
|
|
3802
|
+
}
|
|
3803
|
+
function sameDirectSpotRouteIdentity(left, right) {
|
|
3804
|
+
return sameDirectSpotOwnerIdentity(left, right)
|
|
3805
|
+
&& left.spot.generation === right.spot.generation;
|
|
3806
|
+
}
|
|
3807
|
+
function sameDirectSpotOwnerIdentity(left, right) {
|
|
3808
|
+
return left.spot.spotId === right.spot.spotId
|
|
3809
|
+
&& left.targetNodeRid === right.targetNodeRid
|
|
3810
|
+
&& left.targetNodeGeneration === right.targetNodeGeneration
|
|
3811
|
+
&& left.authorityOwnerGeneration === right.authorityOwnerGeneration
|
|
3812
|
+
&& left.ownerLeaseGeneration === right.ownerLeaseGeneration;
|
|
3813
|
+
}
|
|
3814
|
+
function routeMatchesLocal(route, spot, nodeRid, nodeGeneration) {
|
|
3815
|
+
return route.targetNodeRid === nodeRid
|
|
3816
|
+
&& route.targetNodeGeneration === nodeGeneration
|
|
3817
|
+
&& route.targetSpotId === spot.ref.spotId
|
|
3818
|
+
&& route.objectGeneration === spot.ref.generation
|
|
3819
|
+
&& route.authorityOwnerGeneration === spot.authorityOwnerGeneration;
|
|
3820
|
+
}
|
|
3821
|
+
function instanceOperationKey(record) {
|
|
3822
|
+
return `${record.sourceNodeRid}\0${record.sourceNodeGeneration}\0`
|
|
3823
|
+
+ `${record.operation.high}\0${record.operation.low}`;
|
|
3824
|
+
}
|
|
3825
|
+
function instanceActivationKey(record) {
|
|
3826
|
+
return `${record.target.targetNodeRid}\0${record.target.targetNodeGeneration}\0`
|
|
3827
|
+
+ `${record.target.targetSpotId}\0${record.target.stableType}`;
|
|
3828
|
+
}
|
|
3829
|
+
function subscriptionKey(channelName, topicFilter) {
|
|
3830
|
+
if (channelName.length === 0 || topicFilter.length === 0) {
|
|
3831
|
+
throw new TypeError('Channel name and topic filter must be non-empty.');
|
|
3832
|
+
}
|
|
3833
|
+
return `${channelName}\0${topicFilter}`;
|
|
3834
|
+
}
|
|
3835
|
+
function topicMatches(filter, topic) {
|
|
3836
|
+
if (filter === '*' || filter === '#')
|
|
3837
|
+
return true;
|
|
3838
|
+
if (filter.endsWith('*'))
|
|
3839
|
+
return topic.startsWith(filter.slice(0, -1));
|
|
3840
|
+
return filter === topic;
|
|
3841
|
+
}
|
|
3842
|
+
function emptyPayload() {
|
|
3843
|
+
return {
|
|
3844
|
+
packetName: 'ZLinkFrameworkEmpty',
|
|
3845
|
+
contentType: 'application/octet-stream',
|
|
3846
|
+
payload: Buffer.alloc(0)
|
|
3847
|
+
};
|
|
3848
|
+
}
|
|
3849
|
+
/**
|
|
3850
|
+
* The generated command-28 decoder is the canonical wire authority. Keep
|
|
3851
|
+
* the stateful mailbox's internal record shape as an adapter only; it must
|
|
3852
|
+
* not re-parse the canonical bytes with the legacy hand-written decoder.
|
|
3853
|
+
*/
|
|
3854
|
+
function statefulActorJoinFromCanonical(value) {
|
|
3855
|
+
return {
|
|
3856
|
+
kind: 'actorJoin',
|
|
3857
|
+
correlation: value.correlation,
|
|
3858
|
+
actor: {
|
|
3859
|
+
actor: {
|
|
3860
|
+
actorId: value.actor.id,
|
|
3861
|
+
generation: value.actor.generation,
|
|
3862
|
+
nodeRid: decodeCanonicalRoutingId(value.actor.targetNodeRid)
|
|
3863
|
+
},
|
|
3864
|
+
targetNodeGeneration: value.actor.targetNodeGeneration,
|
|
3865
|
+
authorityOwnerGeneration: value.actor.expectedAuthorityOwnerGeneration,
|
|
3866
|
+
ownerLeaseGeneration: value.actor.expectedOwnerLeaseGeneration
|
|
3867
|
+
},
|
|
3868
|
+
entry: value.entry,
|
|
3869
|
+
target: {
|
|
3870
|
+
spot: {
|
|
3871
|
+
spotId: value.targetSpot.id,
|
|
3872
|
+
generation: value.targetSpot.generation
|
|
3873
|
+
},
|
|
3874
|
+
targetNodeRid: decodeCanonicalRoutingId(value.targetSpot.targetNodeRid),
|
|
3875
|
+
targetNodeGeneration: value.targetSpot.targetNodeGeneration,
|
|
3876
|
+
authorityOwnerGeneration: value.targetSpot.expectedAuthorityOwnerGeneration,
|
|
3877
|
+
ownerLeaseGeneration: value.targetSpot.expectedOwnerLeaseGeneration
|
|
3878
|
+
}
|
|
3879
|
+
};
|
|
3880
|
+
}
|
|
3881
|
+
function decodeCanonicalRoutingId(bytes) {
|
|
3882
|
+
return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('utf8');
|
|
3883
|
+
}
|
|
3884
|
+
function instanceOperationParts(headerAndPayload, metadataFrame) {
|
|
3885
|
+
if (headerAndPayload.length !== 2) {
|
|
3886
|
+
throw new TypeError('Instance operation requires one header and one payload frame.');
|
|
3887
|
+
}
|
|
3888
|
+
if (metadataFrame === undefined)
|
|
3889
|
+
return headerAndPayload;
|
|
3890
|
+
return [
|
|
3891
|
+
headerAndPayload[0],
|
|
3892
|
+
(0, service_metadata_codec_1.validateServiceMetadataFrame)(metadataFrame),
|
|
3893
|
+
headerAndPayload[1]
|
|
3894
|
+
];
|
|
3895
|
+
}
|
|
3896
|
+
function statefulMailboxData(record) {
|
|
3897
|
+
return record.stateful;
|
|
3898
|
+
}
|