@cadenza.io/service 2.21.1 → 2.21.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -204,6 +204,16 @@ var DELEGATION_FAILURE_CONTEXT_KEYS = [
204
204
  "transportProtocols",
205
205
  "transportProtocol"
206
206
  ];
207
+ var ACTOR_SESSION_STATE_REMOTE_ROUTINE = "Insert actor_session_state";
208
+ var ACTOR_SESSION_SNAPSHOT_ROOT_KEYS = [
209
+ "__remoteRoutineName",
210
+ "__serviceName",
211
+ "__localTaskName",
212
+ "__localTaskVersion",
213
+ "__localServiceName",
214
+ "__timeout",
215
+ ...ROOT_METADATA_PASSTHROUGH_KEYS
216
+ ];
207
217
  function isPlainObject(value) {
208
218
  if (!value || typeof value !== "object" || Array.isArray(value)) {
209
219
  return false;
@@ -228,6 +238,9 @@ function cloneDelegationValue(value) {
228
238
  return value;
229
239
  }
230
240
  function buildDelegationRequestSnapshot(context) {
241
+ if (typeof context.__remoteRoutineName === "string" && context.__remoteRoutineName.trim() === ACTOR_SESSION_STATE_REMOTE_ROUTINE) {
242
+ return buildActorSessionDelegationSnapshot(context);
243
+ }
231
244
  const snapshot = {};
232
245
  for (const [key, value] of Object.entries(context)) {
233
246
  if (key === DELEGATION_REQUEST_SNAPSHOT_KEY || key === "task" || key === "routine") {
@@ -237,6 +250,21 @@ function buildDelegationRequestSnapshot(context) {
237
250
  }
238
251
  return snapshot;
239
252
  }
253
+ function buildActorSessionDelegationSnapshot(context) {
254
+ const snapshot = {};
255
+ for (const key of ACTOR_SESSION_SNAPSHOT_ROOT_KEYS) {
256
+ if (context[key] !== void 0) {
257
+ snapshot[key] = cloneDelegationValue(context[key]);
258
+ }
259
+ }
260
+ if (context.data !== void 0) {
261
+ snapshot.data = cloneDelegationValue(context.data);
262
+ }
263
+ if (context.queryData !== void 0) {
264
+ snapshot.queryData = cloneDelegationValue(context.queryData);
265
+ }
266
+ return snapshot;
267
+ }
240
268
  function hoistDelegationMetadataFields(input, metadataInput) {
241
269
  const context = input && typeof input === "object" ? { ...input } : {};
242
270
  const mutableContext = context;
@@ -7237,6 +7265,7 @@ var ServiceRegistry = class _ServiceRegistry {
7237
7265
  this.authorityBootstrapHandshakeRetryIndex = 0;
7238
7266
  this.authorityBootstrapHandshakeRetryGeneration = 0;
7239
7267
  this.authorityBootstrapHandshakeRetryReason = null;
7268
+ this.authorityBootstrapRecoveryActive = false;
7240
7269
  this.authorityFullSyncResponderTask = null;
7241
7270
  this.authorityServiceCommunicationPersistenceTask = null;
7242
7271
  this.localLifecycleFlushActor = CadenzaService.createActor(
@@ -7811,6 +7840,9 @@ var ServiceRegistry = class _ServiceRegistry {
7811
7840
  if (serviceName === "CadenzaDB" && (isFetchHandshakeFailure && recoverableFetchHandshakeFailure || isFetchDelegateFailure && recoverableFetchDelegateFailure)) {
7812
7841
  return false;
7813
7842
  }
7843
+ if (serviceName === "CadenzaDB" && this.authorityBootstrapRecoveryActive) {
7844
+ return false;
7845
+ }
7814
7846
  const serviceInstances = this.instances.get(serviceName);
7815
7847
  const instances = serviceInstances?.filter((instance) => {
7816
7848
  if (serviceInstanceId && instance.uuid === serviceInstanceId) {
@@ -8103,6 +8135,9 @@ var ServiceRegistry = class _ServiceRegistry {
8103
8135
  return false;
8104
8136
  }
8105
8137
  }
8138
+ if (this.authorityBootstrapRecoveryActive) {
8139
+ return false;
8140
+ }
8106
8141
  this.restartAuthorityBootstrapRecovery("cadenza_db_unreachable");
8107
8142
  return true;
8108
8143
  },
@@ -10784,6 +10819,7 @@ var ServiceRegistry = class _ServiceRegistry {
10784
10819
  this.clearAuthorityBootstrapHandshakeRetryTimer();
10785
10820
  this.authorityBootstrapHandshakeRetryIndex = AUTHORITY_BOOTSTRAP_HANDSHAKE_RETRY_DELAYS_MS.length;
10786
10821
  this.authorityBootstrapHandshakeRetryReason = null;
10822
+ this.authorityBootstrapRecoveryActive = false;
10787
10823
  }
10788
10824
  buildJitteredAuthorityBootstrapHandshakeRetryDelayMs(baseDelayMs, attempt) {
10789
10825
  return buildDeterministicJitteredDelayMs(
@@ -10840,6 +10876,13 @@ var ServiceRegistry = class _ServiceRegistry {
10840
10876
  return this.scheduleAuthorityBootstrapHandshakeRetry(reason);
10841
10877
  }
10842
10878
  restartAuthorityBootstrapRecovery(reason) {
10879
+ if (this.authorityBootstrapRecoveryActive) {
10880
+ if (typeof reason === "string" && reason.trim()) {
10881
+ this.authorityBootstrapHandshakeRetryReason = reason.trim();
10882
+ }
10883
+ return false;
10884
+ }
10885
+ this.authorityBootstrapRecoveryActive = true;
10843
10886
  this.invalidateAuthorityBootstrapHandshake();
10844
10887
  this.invalidateBootstrapFullSyncRetryState(reason);
10845
10888
  return this.restartAuthorityBootstrapHandshakeRetryChain(reason);