@bastani/atomic 0.10.17 → 0.10.18
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/CHANGELOG.md +63 -0
- package/dist/_shared/dist-KOELCESV.js +2 -2
- package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
- package/dist/_shared/lib-4PES5P4V.js +2 -2
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +6 -6
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +16 -4
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js.map +1 -1
- package/dist/_shared/mode-shared-2QJSCUM6.js +16 -9
- package/dist/_shared/mode-shared-2QJSCUM6.js.map +1 -1
- package/dist/_shared/p0-cli-BB45ZQY6.js +1 -0
- package/dist/_shared/p0-cli-BB45ZQY6.js.map +1 -1
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +4 -3
- package/dist/_shared/p1a-prewarm-XIU57JHF.js.map +1 -1
- package/dist/_shared/p2-shell-main-B2WIALFD.js +1 -1
- package/dist/_shared/p2-shell-main-B2WIALFD.js.map +1 -1
- package/dist/_shared/runtime-O4KCSG4C.js +2 -2
- package/dist/_shared/sdk-OHKMDJ74.js +18 -15
- package/dist/_shared/sdk-OHKMDJ74.js.map +1 -1
- package/dist/_shared/session-data-AHTU7IS6.js +2 -2
- package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
- package/dist/_shared/{startup-0-0-ERMIDHQT.js → startup-0-0-OV6RAEAP.js} +338 -75
- package/dist/_shared/startup-0-0-OV6RAEAP.js.map +1 -0
- package/dist/_shared/{startup-0-1-RTASI3HG.js → startup-0-1-EZAJI6RE.js} +82 -5
- package/dist/_shared/startup-0-1-EZAJI6RE.js.map +1 -0
- package/dist/_shared/startup-0-2-YZZOC22D.js +4 -4
- package/dist/_shared/startup-0-3-DE2NCS6A.js +4 -4
- package/dist/_shared/startup-0-4-ZMJV547D.js +12 -7
- package/dist/_shared/startup-0-4-ZMJV547D.js.map +1 -1
- package/dist/_shared/startup-0-5-HZX3ZPTP.js +41 -12
- package/dist/_shared/startup-0-5-HZX3ZPTP.js.map +1 -1
- package/dist/_shared/startup-10-0-TDQNBDDL.js +5 -5
- package/dist/_shared/startup-10-0-TDQNBDDL.js.map +1 -1
- package/dist/_shared/startup-12-0-55AAXBJZ.js +1 -1
- package/dist/_shared/startup-14-0-MLX36RBG.js +2 -2
- package/dist/_shared/startup-15-0-YUKGAC63.js +2 -2
- package/dist/_shared/startup-15-1-4S7FLMNG.js +261 -75
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +23 -8
- package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
- package/dist/_shared/startup-8-1-LZFXSD3Z.js +328 -19
- package/dist/_shared/startup-8-1-LZFXSD3Z.js.map +1 -1
- package/dist/_shared/storage-command-7MGXLJGZ.js +74 -10
- package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
- package/dist/_shared/storage-status-K7PX2RXA.js +2 -2
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/team-DOQKICG2.js +1 -1
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/broker/broker.bundle.mjs +158 -78
- package/dist/builtin/intercom/broker/multinode-router.ts +41 -8
- package/dist/builtin/intercom/broker/multinode-state-store.ts +6 -1
- package/dist/builtin/intercom/broker/sql-lease-store.ts +89 -80
- package/dist/builtin/intercom/broker/sql-pending-ask-store.ts +65 -6
- package/dist/builtin/intercom/index.bundle.mjs +1 -1
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/index.bundle.mjs +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/cli/args.js +2 -2
- package/dist/cli/auth-cli.code.js +2 -2
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.code.js +1 -1
- package/dist/cli/blueprint-command.impl.js +3 -3
- package/dist/cli/blueprint-command.js +3 -3
- package/dist/cli/intercom-command.code.js +2 -2
- package/dist/cli/intercom-command.impl.js +3 -3
- package/dist/cli/intercom-command.js +3 -3
- package/dist/cli/list-models.code.js +2 -2
- package/dist/cli/list-models.impl.js +3 -3
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/session-picker.code.js +1 -1
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +1 -1
- package/dist/cli/startup-ui.impl.js +3 -3
- package/dist/cli/startup-ui.js +3 -3
- package/dist/cli/storage-command.impl.js +3 -3
- package/dist/cli/storage-command.js +3 -3
- package/dist/cli/storage-search-session.code.js +1 -1
- package/dist/cli/storage-search-session.impl.js +3 -3
- package/dist/cli/storage-search-session.js +3 -3
- package/dist/cli/team-command.code.js +1 -1
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +2 -2
- package/dist/core/debug.impl.js +3 -3
- package/dist/core/debug.js +3 -3
- package/dist/core/export-html/card-projection.impl.js +3 -3
- package/dist/core/export-html/card-projection.js +3 -3
- package/dist/core/export-html/index.code.js +2 -2
- package/dist/core/export-html/index.impl.js +3 -3
- package/dist/core/export-html/index.js +3 -3
- package/dist/core/export-html/json-spans.impl.js +3 -3
- package/dist/core/export-html/json-spans.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.js +3 -3
- package/dist/core/export-html/tool-renderer.impl.js +3 -3
- package/dist/core/export-html/tool-renderer.js +3 -3
- package/dist/core/extensions/jiti-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-loader.js +3 -3
- package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-static-loader.js +3 -3
- package/dist/core/extensions/loader-host-modules.code.js +1 -1
- package/dist/core/extensions/loader-host-modules.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- package/dist/core/extensions/loader-virtual-modules.js +1 -1
- package/dist/core/extensions/runner-context.js +1 -1
- package/dist/core/intercom-broker-control-host.impl.js +3 -3
- package/dist/core/intercom-broker-control-host.js +3 -3
- package/dist/core/intercom-broker-control.code.js +3 -3
- package/dist/core/intercom-broker-control.impl.js +3 -3
- package/dist/core/intercom-broker-control.js +3 -3
- package/dist/core/package-manager-storage-adapters.impl.js +3 -3
- package/dist/core/package-manager-storage-adapters.js +3 -3
- package/dist/core/sdk.code.js +2 -2
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-append-recovery.d.ts +3 -3
- package/dist/core/session-manager-core.d.ts +1 -1
- package/dist/core/session-manager-core.js +14 -13
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-list.impl.js +3 -3
- package/dist/core/session-manager-list.js +3 -3
- package/dist/core/session-manager.code.js +1 -1
- package/dist/core/session-manager.impl.js +3 -3
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-storage.impl.js +3 -3
- package/dist/core/session-storage.js +3 -3
- package/dist/core/storage/database.d.ts +6 -2
- package/dist/core/storage/database.js.map +1 -1
- package/dist/core/storage/errors.d.ts +8 -5
- package/dist/core/storage/errors.js +5 -3
- package/dist/core/storage/errors.js.map +1 -1
- package/dist/core/storage/fenced-paths.d.ts +15 -0
- package/dist/core/storage/fenced-paths.js +25 -0
- package/dist/core/storage/fenced-paths.js.map +1 -1
- package/dist/core/storage/index.js +2 -2
- package/dist/core/storage/migrations.d.ts +2 -11
- package/dist/core/storage/migrations.js +2 -9
- package/dist/core/storage/migrations.js.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +2 -2
- package/dist/core/storage/node-sqlite.js +2 -2
- package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
- package/dist/core/storage/offline-snapshot-file.js +3 -3
- package/dist/core/storage/postgres-locks.d.ts +11 -0
- package/dist/core/storage/postgres-locks.js +9 -0
- package/dist/core/storage/postgres-locks.js.map +1 -0
- package/dist/core/storage/provider.js +2 -2
- package/dist/core/storage/selection.js +2 -2
- package/dist/core/storage/session/branch-fork-source.code.js +2 -2
- package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
- package/dist/core/storage/session/branch-fork-source.js +3 -3
- package/dist/core/storage/session/card-view.impl.js +3 -3
- package/dist/core/storage/session/card-view.js +3 -3
- package/dist/core/storage/session/child-reader.code.js +3 -3
- package/dist/core/storage/session/child-reader.impl.js +3 -3
- package/dist/core/storage/session/child-reader.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.js +3 -3
- package/dist/core/storage/session/expanded-child-details.code.js +2 -2
- package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
- package/dist/core/storage/session/expanded-child-details.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.js +3 -3
- package/dist/core/storage/session/fork-row-index.impl.js +3 -3
- package/dist/core/storage/session/fork-row-index.js +3 -3
- package/dist/core/storage/session/fork-staging.code.js +1 -1
- package/dist/core/storage/session/fork-staging.impl.js +3 -3
- package/dist/core/storage/session/fork-staging.js +3 -3
- package/dist/core/storage/session/fork-window.code.js +3 -3
- package/dist/core/storage/session/fork-window.impl.js +3 -3
- package/dist/core/storage/session/fork-window.js +3 -3
- package/dist/core/storage/session/history-pages.impl.js +3 -3
- package/dist/core/storage/session/history-pages.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.d.ts +1 -0
- package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.js +3 -3
- package/dist/core/storage/session/memory-session-store.d.ts +1 -0
- package/dist/core/storage/session/memory-session-store.impl.js +3 -3
- package/dist/core/storage/session/memory-session-store.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.js +3 -3
- package/dist/core/storage/session/released-history-files.code.js +2 -2
- package/dist/core/storage/session/released-history-files.impl.js +3 -3
- package/dist/core/storage/session/released-history-files.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.js +3 -3
- package/dist/core/storage/session/session-resume.impl.js +3 -3
- package/dist/core/storage/session/session-resume.js +3 -3
- package/dist/core/storage/session/session-summary.d.ts +9 -1
- package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
- package/dist/core/storage/session/snapshot-cut.js +3 -3
- package/dist/core/storage/session/snapshot-history.code.js +3 -3
- package/dist/core/storage/session/snapshot-history.impl.js +3 -3
- package/dist/core/storage/session/snapshot-history.js +3 -3
- package/dist/core/storage/session/sql-session-store.d.ts +2 -1
- package/dist/core/storage/session/sql-session-store.impl.js +3 -3
- package/dist/core/storage/session/sql-session-store.js +3 -3
- package/dist/core/storage/session/tree-outline.impl.js +3 -3
- package/dist/core/storage/session/tree-outline.js +3 -3
- package/dist/core/storage/session/tree-presentation.impl.js +3 -3
- package/dist/core/storage/session/tree-presentation.js +3 -3
- package/dist/core/storage/session/types.d.ts +1 -0
- package/dist/core/storage/sqlite-facade.js +12 -5
- package/dist/core/storage/sqlite-facade.js.map +1 -1
- package/dist/core/storage/storage-status.impl.js +3 -3
- package/dist/core/storage/storage-status.js +3 -3
- package/dist/core/storage/team.impl.js +3 -3
- package/dist/core/storage/team.js +3 -3
- package/dist/core/structured-output/index.impl.js +3 -3
- package/dist/core/structured-output/index.js +3 -3
- package/dist/core/tasks/heartbeat-notice.d.ts +0 -1
- package/dist/core/tasks/task-completion-entry.impl.js +3 -3
- package/dist/core/tasks/task-completion-entry.js +3 -3
- package/dist/core/tasks/task-file-history.code.js +3 -3
- package/dist/core/tasks/task-file-history.impl.js +3 -3
- package/dist/core/tasks/task-file-history.js +3 -3
- package/dist/core/tasks/task-reference-archive.code.js +3 -3
- package/dist/core/tasks/task-reference-archive.js +3 -3
- package/dist/core/tasks/task-reference-identity.js +3 -3
- package/dist/core/tasks/task-reference-stream.impl.js +3 -3
- package/dist/core/tasks/task-reference-stream.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.js +3 -3
- package/dist/core/tasks/task-view-source.impl.js +3 -3
- package/dist/core/tasks/task-view-source.js +3 -3
- package/dist/core/tools/history-session.d.ts +1 -1
- package/dist/core/tools/output-accumulator.d.ts +3 -0
- package/dist/core/tools/read-url.code.js +2 -2
- package/dist/core/tools/read-url.impl.js +3 -3
- package/dist/core/tools/read-url.js +3 -3
- package/dist/core/worktree-snapshot/blob-store.d.ts +14 -16
- package/dist/core/worktree-snapshot/blob-store.js +194 -81
- package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
- package/dist/core/worktree-snapshot/collection-claim.js +8 -0
- package/dist/core/worktree-snapshot/collection-claim.js.map +1 -0
- package/dist/core/worktree-snapshot/errors.code.js +2 -2
- package/dist/core/worktree-snapshot/errors.impl.js +3 -3
- package/dist/core/worktree-snapshot/errors.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
- package/dist/core/worktree-snapshot/snapshot-epoch-migration.js +209 -0
- package/dist/core/worktree-snapshot/snapshot-epoch-migration.js.map +1 -0
- package/dist/core/worktree-snapshot/snapshot-epoch.js +100 -0
- package/dist/core/worktree-snapshot/snapshot-epoch.js.map +1 -0
- package/dist/extensions/codemode/execute.code.js +1 -1
- package/dist/extensions/codemode/execute.impl.js +3 -3
- package/dist/extensions/codemode/execute.js +3 -3
- package/dist/extensions/codemode/renderer.code.js +1 -1
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +1 -1
- package/dist/extensions/mcp/cli.impl.js +3 -3
- package/dist/extensions/mcp/cli.js +3 -3
- package/dist/extensions/mcp/cli.lazy.code.js +2 -2
- package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
- package/dist/extensions/mcp/cli.lazy.js +3 -3
- package/dist/extensions/mcp/runtime.impl.js +3 -3
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/index.js +2 -2
- package/dist/main-first-time-setup.code.js +1 -1
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
- package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
- package/dist/modes/interactive/interactive-mode-helpers.d.ts +8 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +21 -0
- package/dist/modes/interactive-engine/protocol.d.ts +6 -0
- package/dist/modes/rpc/rpc-client.d.ts +2 -0
- package/dist/package-manager-cli.code.js +4 -4
- package/dist/package-manager-cli.impl.js +3 -3
- package/dist/package-manager-cli.js +3 -3
- package/dist/rpc-entry.js +1 -1
- package/dist/startup-files.json +1 -1
- package/dist/startup-stages/4.js +1 -1
- package/dist/startup-stages/6.js +1 -1
- package/dist/utils/interactive-engine-bootstrap.d.ts +2 -0
- package/dist/utils/interactive-engine-env.d.ts +2 -0
- package/dist/utils/startup-database-spare.code.js +2 -2
- package/dist/utils/startup-database-spare.impl.js +3 -3
- package/dist/utils/startup-database-spare.js +3 -3
- package/dist/utils/tools-manager.code.js +1 -1
- package/dist/utils/tools-manager.impl.js +3 -3
- package/dist/utils/tools-manager.js +3 -3
- package/docs/background-tasks/reference.md +1 -1
- package/docs/background-tasks.md +1 -1
- package/docs/changelog.mdx +18 -1
- package/docs/guides/resume-on-any-machine.md +1 -1
- package/docs/reference/cli.md +4 -3
- package/docs/sdk.md +2 -1
- package/docs/sessions.md +5 -2
- package/docs/settings.md +1 -0
- package/docs/storage/custom-adapters.md +1 -1
- package/docs/storage/postgres/pgbouncer.md +3 -1
- package/docs/storage/postgres/tuning.md +2 -0
- package/docs/storage/postgres.md +58 -7
- package/docs/storage.md +4 -2
- package/docs/tools.md +1 -0
- package/docs/worktree-snapshots/reference.md +1 -1
- package/package.json +8 -8
- package/dist/_shared/startup-0-0-ERMIDHQT.js.map +0 -1
- package/dist/_shared/startup-0-1-RTASI3HG.js.map +0 -1
|
@@ -1071,9 +1071,11 @@ async function holdsSessionId(knownSessions, sessionId, returnAddress) {
|
|
|
1071
1071
|
const bound = await knownSessions.binding(sessionId, KNOWN_SESSION_RETENTION_MS);
|
|
1072
1072
|
return bound.status !== "bound" || bound.returnAddress === (returnAddress ?? "");
|
|
1073
1073
|
}
|
|
1074
|
-
var BROKER_LEASE_RENEW_INTERVAL_MS = 1e4, BROKER_LEASE_STALE_AFTER_MS = 30000, OUTBOX_CLAIM_STALE_AFTER_MS = 30000, OUTBOX_BACKUP_POLL_INTERVAL_MS = 30000, MAINTENANCE_INTERVAL_MS, MAINTENANCE_STALE_AFTER_MS, KNOWN_SESSION_RETENTION_MS, OUTBOX_TARGET_MAX_ROWS = 1000, OUTBOX_TARGET_MAX_BYTES, OUTBOX_EXPIRED_REASON, SETTLED_ASK_RETENTION_MS;
|
|
1074
|
+
var BROKER_LEASE_RENEW_INTERVAL_MS = 1e4, BROKER_LEASE_STALE_AFTER_MS = 30000, OUTBOX_CLAIM_STALE_AFTER_MS = 30000, OUTBOX_BACKUP_POLL_INTERVAL_MS = 30000, LOST_SWEEP_STALE_AFTER_MS, LOST_SWEEP_MAINTENANCE, MAINTENANCE_INTERVAL_MS, MAINTENANCE_STALE_AFTER_MS, KNOWN_SESSION_RETENTION_MS, OUTBOX_TARGET_MAX_ROWS = 1000, OUTBOX_TARGET_MAX_BYTES, OUTBOX_EXPIRED_REASON, SETTLED_ASK_RETENTION_MS;
|
|
1075
1075
|
var init_multinode_state_store = __esm(() => {
|
|
1076
1076
|
init_released_children();
|
|
1077
|
+
LOST_SWEEP_STALE_AFTER_MS = 2 * OUTBOX_BACKUP_POLL_INTERVAL_MS;
|
|
1078
|
+
LOST_SWEEP_MAINTENANCE = { kind: "maintenance", task: "lost-recipients" };
|
|
1077
1079
|
MAINTENANCE_INTERVAL_MS = 5 * 60000;
|
|
1078
1080
|
MAINTENANCE_STALE_AFTER_MS = 2 * MAINTENANCE_INTERVAL_MS;
|
|
1079
1081
|
KNOWN_SESSION_RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
|
|
@@ -4524,6 +4526,16 @@ async function openBrokerLeaseStoreInCatalog(options) {
|
|
|
4524
4526
|
concurrency: { kind: "fenced", audit: fencedPath("intercom-lease") }
|
|
4525
4527
|
};
|
|
4526
4528
|
const renewal = { ...fenced, relaxedDurability: true };
|
|
4529
|
+
const renewPostgresRow = async (kind, id, holderId, fencingToken, subject) => {
|
|
4530
|
+
const guarded = [kind, id, holderId, fencingToken];
|
|
4531
|
+
const write = subject === null ? { sql: `UPDATE ${table} SET renewed_at = ${nowMs} WHERE ${owned}`, params: guarded } : { sql: `UPDATE ${table} SET renewed_at = ${nowMs}, subject_json = ? WHERE ${owned}`, params: [subject, ...guarded] };
|
|
4532
|
+
const { changes } = await database.transaction((tx) => tx.run(write.sql, ...write.params), {
|
|
4533
|
+
...renewal,
|
|
4534
|
+
leading: [write],
|
|
4535
|
+
leadingOnly: true
|
|
4536
|
+
});
|
|
4537
|
+
return changes === 1;
|
|
4538
|
+
};
|
|
4527
4539
|
const largestOrder = `(SELECT COALESCE(MAX(first_acquired_order), 0) FROM ${table})`;
|
|
4528
4540
|
const sequence = `to_regclass('${table}_order')`;
|
|
4529
4541
|
const nextOrder = dialect.name === "postgres" ? {
|
|
@@ -4605,6 +4617,10 @@ async function openBrokerLeaseStoreInCatalog(options) {
|
|
|
4605
4617
|
if (subject !== undefined && (subject.kind !== lease.key.kind || keyId(keyOf2(subject)) !== keyId(lease.key))) {
|
|
4606
4618
|
return invalid3("subject-key-mismatch");
|
|
4607
4619
|
}
|
|
4620
|
+
if (dialect.name === "postgres") {
|
|
4621
|
+
const renewed = await renewPostgresRow(lease.key.kind, keyId(lease.key), lease.holderId, lease.fencingToken, subject === undefined ? null : subjectJson(subject));
|
|
4622
|
+
return renewed ? { status: "renewed" } : stale(await holderOf(reader, lease.key));
|
|
4623
|
+
}
|
|
4608
4624
|
return database.transaction(async (tx) => {
|
|
4609
4625
|
const { changes } = subject === undefined ? await tx.run(`UPDATE ${table} SET renewed_at = ${nowMs} WHERE ${owned}`, ...ownedParams(lease)) : await tx.run(`UPDATE ${table} SET renewed_at = ${nowMs}, subject_json = ? WHERE ${owned}`, subjectJson(subject), ...ownedParams(lease));
|
|
4610
4626
|
return changes === 1 ? { status: "renewed" } : stale(await holderOf(tx, lease.key));
|
|
@@ -4632,7 +4648,6 @@ async function openBrokerLeaseStoreInCatalog(options) {
|
|
|
4632
4648
|
const pairKey = (kind, id) => JSON.stringify([kind, id.toWellFormed()]);
|
|
4633
4649
|
const byTuple = new Map;
|
|
4634
4650
|
const validPairs = new Map;
|
|
4635
|
-
let hasNonSafeIntToken = false;
|
|
4636
4651
|
for (let i = 0;i < requests.length; i++) {
|
|
4637
4652
|
if (invalidResults[i] !== undefined)
|
|
4638
4653
|
continue;
|
|
@@ -4641,10 +4656,8 @@ async function openBrokerLeaseStoreInCatalog(options) {
|
|
|
4641
4656
|
const pKey = pairKey(lease.key.kind, id);
|
|
4642
4657
|
if (!validPairs.has(pKey))
|
|
4643
4658
|
validPairs.set(pKey, [lease.key.kind, id]);
|
|
4644
|
-
if (!Number.isSafeInteger(lease.fencingToken))
|
|
4645
|
-
hasNonSafeIntToken = true;
|
|
4659
|
+
if (!Number.isSafeInteger(lease.fencingToken))
|
|
4646
4660
|
continue;
|
|
4647
|
-
}
|
|
4648
4661
|
const tKey = tupleKey(lease.key.kind, id, lease.holderId, lease.fencingToken);
|
|
4649
4662
|
const nextSubject = subject === undefined ? undefined : subjectJson(subject);
|
|
4650
4663
|
const existing = byTuple.get(tKey);
|
|
@@ -4671,27 +4684,19 @@ async function openBrokerLeaseStoreInCatalog(options) {
|
|
|
4671
4684
|
return stale(found.get(pairKey(lease.key.kind, id)));
|
|
4672
4685
|
});
|
|
4673
4686
|
if (dialect.name === "postgres") {
|
|
4674
|
-
const
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
FROM
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
};
|
|
4688
|
-
return database.transaction(async (tx) => {
|
|
4689
|
-
const found = new Map;
|
|
4690
|
-
for (const row of await tx.all(readAll.sql, ...readAll.params))
|
|
4691
|
-
found.set(pairKey(row.kind, row.key), row);
|
|
4692
|
-
return answer(new Set, found);
|
|
4693
|
-
}, { ...renewal, leading: [readAll], leadingOnly: true });
|
|
4694
|
-
}
|
|
4687
|
+
const readHolders = async (pairs) => {
|
|
4688
|
+
const rows = await reader.all(`WITH missed AS MATERIALIZED (
|
|
4689
|
+
SELECT entry ->> 0 AS kind, entry ->> 1 AS key
|
|
4690
|
+
FROM jsonb_array_elements((?)::jsonb) AS entry
|
|
4691
|
+
)
|
|
4692
|
+
SELECT t.kind, t.key, t.holder_id, t.fencing_token
|
|
4693
|
+
FROM ${table} AS t JOIN missed ON t.kind = missed.kind AND t.key = missed.key
|
|
4694
|
+
WHERE t.kind = ANY(ARRAY(SELECT DISTINCT kind FROM missed))
|
|
4695
|
+
AND t.key = ANY(ARRAY(SELECT DISTINCT key FROM missed))`, JSON.stringify([...pairs.values()], wellFormed));
|
|
4696
|
+
return new Map(rows.map((row) => [pairKey(row.kind, row.key), row]));
|
|
4697
|
+
};
|
|
4698
|
+
if (entries.length === 0)
|
|
4699
|
+
return answer(new Set, await readHolders(validPairs));
|
|
4695
4700
|
const write = {
|
|
4696
4701
|
sql: `WITH requested AS MATERIALIZED (
|
|
4697
4702
|
SELECT
|
|
@@ -4713,25 +4718,14 @@ async function openBrokerLeaseStoreInCatalog(options) {
|
|
|
4713
4718
|
WHERE t.kind = ANY(ARRAY(SELECT DISTINCT kind FROM requested))
|
|
4714
4719
|
AND t.key = ANY(ARRAY(SELECT DISTINCT key FROM requested))
|
|
4715
4720
|
ORDER BY t.kind, t.key
|
|
4716
|
-
FOR UPDATE OF t
|
|
4717
|
-
),
|
|
4718
|
-
renewed AS (
|
|
4719
|
-
UPDATE ${table} AS t
|
|
4720
|
-
SET renewed_at = ${nowMs}, subject_json = COALESCE(locked.subject_json, t.subject_json)
|
|
4721
|
-
FROM locked
|
|
4722
|
-
WHERE t.kind = locked.kind
|
|
4723
|
-
AND t.key = locked.key
|
|
4724
|
-
AND t.holder_id = locked.holder_id
|
|
4725
|
-
AND t.fencing_token = locked.fencing_token
|
|
4726
|
-
RETURNING t.kind, t.key, t.holder_id, t.fencing_token
|
|
4727
|
-
),
|
|
4728
|
-
gate AS MATERIALIZED (
|
|
4729
|
-
SELECT set_config('${LEASE_RENEW_MISSES}',
|
|
4730
|
-
CASE WHEN (SELECT COUNT(*) FROM renewed) < CAST(? AS ${types.int}) THEN '1' ELSE '' END,
|
|
4731
|
-
true) AS misses
|
|
4721
|
+
FOR NO KEY UPDATE OF t SKIP LOCKED
|
|
4732
4722
|
)
|
|
4733
|
-
|
|
4734
|
-
|
|
4723
|
+
UPDATE ${table} AS t
|
|
4724
|
+
SET renewed_at = ${nowMs}, subject_json = COALESCE(locked.subject_json, t.subject_json)
|
|
4725
|
+
FROM locked
|
|
4726
|
+
WHERE t.kind = locked.kind AND t.key = locked.key
|
|
4727
|
+
AND t.holder_id = locked.holder_id AND t.fencing_token = locked.fencing_token
|
|
4728
|
+
RETURNING t.kind, t.key, t.holder_id, t.fencing_token`,
|
|
4735
4729
|
params: [
|
|
4736
4730
|
JSON.stringify(entries.map((entry) => [
|
|
4737
4731
|
entry.kind,
|
|
@@ -4739,34 +4733,47 @@ async function openBrokerLeaseStoreInCatalog(options) {
|
|
|
4739
4733
|
entry.holderId,
|
|
4740
4734
|
entry.fencingToken,
|
|
4741
4735
|
entry.subjectJson
|
|
4742
|
-
]), wellFormed)
|
|
4743
|
-
entries.length + (hasNonSafeIntToken ? 1 : 0)
|
|
4736
|
+
]), wellFormed)
|
|
4744
4737
|
]
|
|
4745
4738
|
};
|
|
4746
|
-
const
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
}
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
const
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4739
|
+
const rows = await database.transaction((tx) => tx.all(write.sql, ...write.params), {
|
|
4740
|
+
...renewal,
|
|
4741
|
+
leading: [write],
|
|
4742
|
+
leadingOnly: true
|
|
4743
|
+
});
|
|
4744
|
+
const renewed = new Set(rows.map((row) => tupleKey(row.kind, row.key, row.holder_id, Number(row.fencing_token))));
|
|
4745
|
+
const missed = new Map;
|
|
4746
|
+
for (const [i, { lease }] of requests.entries()) {
|
|
4747
|
+
if (invalidResults[i] !== undefined)
|
|
4748
|
+
continue;
|
|
4749
|
+
const id = keyId(lease.key);
|
|
4750
|
+
if (!Number.isSafeInteger(lease.fencingToken) || !renewed.has(tupleKey(lease.key.kind, id, lease.holderId, lease.fencingToken)))
|
|
4751
|
+
missed.set(pairKey(lease.key.kind, id), [lease.key.kind, id]);
|
|
4752
|
+
}
|
|
4753
|
+
if (missed.size === 0)
|
|
4754
|
+
return answer(renewed, new Map);
|
|
4755
|
+
const found = await readHolders(missed);
|
|
4756
|
+
const changed = new Map;
|
|
4757
|
+
await Promise.all(entries.map(async ({ kind, id, holderId, fencingToken, subjectJson }) => {
|
|
4758
|
+
const tuple = tupleKey(kind, id, holderId, fencingToken);
|
|
4759
|
+
if (renewed.has(tuple))
|
|
4760
|
+
return;
|
|
4761
|
+
const pair = pairKey(kind, id);
|
|
4762
|
+
const holder = found.get(pair);
|
|
4763
|
+
if (holder?.holder_id !== holderId.toWellFormed() || Number(holder.fencing_token) !== fencingToken)
|
|
4764
|
+
return;
|
|
4765
|
+
if (await renewPostgresRow(kind, id, holderId, fencingToken, subjectJson))
|
|
4766
|
+
renewed.add(tuple);
|
|
4767
|
+
else
|
|
4768
|
+
changed.set(pair, [kind, id]);
|
|
4769
|
+
}));
|
|
4770
|
+
if (changed.size > 0) {
|
|
4771
|
+
for (const pair of changed.keys())
|
|
4772
|
+
found.delete(pair);
|
|
4773
|
+
for (const [pair, holder] of await readHolders(changed))
|
|
4774
|
+
found.set(pair, holder);
|
|
4775
|
+
}
|
|
4776
|
+
return answer(renewed, found);
|
|
4770
4777
|
}
|
|
4771
4778
|
const write = entries.length === 0 ? undefined : {
|
|
4772
4779
|
sql: `WITH requested AS (
|
|
@@ -4880,7 +4887,7 @@ async function openBrokerLeaseStoreInCatalog(options) {
|
|
|
4880
4887
|
}
|
|
4881
4888
|
};
|
|
4882
4889
|
}
|
|
4883
|
-
var age = ({ greatest, nowMs }) => greatest("0", `${nowMs} - renewed_at`), fillfactorApi, LEASE_FILLFACTOR = 80, LEASE_LOCK_WAIT_MS = 2000, SENDS_PASSED,
|
|
4890
|
+
var age = ({ greatest, nowMs }) => greatest("0", `${nowMs} - renewed_at`), fillfactorApi, LEASE_FILLFACTOR = 80, LEASE_LOCK_WAIT_MS = 2000, SENDS_PASSED, ACQUISITION_ORDER_KIND = "acquisition-order", ADDRESS_COLUMNS, leasesByAge = (dialect, table, comparison) => `WITH clock AS (SELECT ${dialect.nowMs} AS now)
|
|
4884
4891
|
SELECT kind, key, holder_id, fencing_token, subject_json, ${dialect.greatest("0", "(SELECT now FROM clock) - renewed_at")} AS age_ms
|
|
4885
4892
|
FROM ${table} WHERE kind = ? AND holder_id IS NOT NULL
|
|
4886
4893
|
AND ${dialect.greatest("0", "(SELECT now FROM clock) - renewed_at")} ${comparison} ? ORDER BY first_acquired_order, key`, liveLeases = (dialect, table) => leasesByAge(dialect, table, "<="), compare = (a, b) => a < b ? -1 : a > b ? 1 : 0, invalid3 = (reason) => ({ status: "invalid", reason });
|
|
@@ -4917,8 +4924,9 @@ async function openPendingAskStoreInCatalog({
|
|
|
4917
4924
|
database,
|
|
4918
4925
|
prefix
|
|
4919
4926
|
}) {
|
|
4920
|
-
const
|
|
4921
|
-
const
|
|
4927
|
+
const { name, types, nowMs } = dialectOf(database);
|
|
4928
|
+
const storagePrefix = validateStoragePrefix(prefix, name);
|
|
4929
|
+
const table = `${storagePrefix}intercom_pending_asks`;
|
|
4922
4930
|
const serial = { ...RETRY_UNAPPLIED, concurrency: { kind: "serial", domain: table } };
|
|
4923
4931
|
await ensureBrokerSchema(database, prefix, "pending-asks", (tx) => tx.exec(`
|
|
4924
4932
|
CREATE TABLE IF NOT EXISTS ${table}(
|
|
@@ -4951,7 +4959,10 @@ async function openPendingAskStoreInCatalog({
|
|
|
4951
4959
|
const parkedBy = (ownerSessionId, reservationKey) => reservationKey === undefined ? { where: "park_owner = ?", params: [ownerSessionId] } : { where: "park_owner = ? AND park_key = ?", params: [ownerSessionId, reservationKey] };
|
|
4952
4960
|
const reverseRoute = "sender_session_id = ? AND target_session_id = ? AND message_id = ?";
|
|
4953
4961
|
const reverseParams = (route) => [route.replyTargetSessionId, route.replySenderSessionId, route.replyTo];
|
|
4962
|
+
const leases = `${storagePrefix}intercom_leases`;
|
|
4963
|
+
let addressColumns;
|
|
4954
4964
|
return {
|
|
4965
|
+
...name === "postgres" ? { coordinatesLostSweep: true } : {},
|
|
4955
4966
|
async record(ask) {
|
|
4956
4967
|
const bad = invalidAsk(ask);
|
|
4957
4968
|
if (bad !== undefined)
|
|
@@ -5109,9 +5120,49 @@ async function openPendingAskStoreInCatalog({
|
|
|
5109
5120
|
ORDER BY ended_at, "order"`, olderThanMs);
|
|
5110
5121
|
return { status: "listed", asks: rows.map(toAsk) };
|
|
5111
5122
|
},
|
|
5112
|
-
async endLost(targetSessionId) {
|
|
5123
|
+
async endLost(targetSessionId, guard) {
|
|
5113
5124
|
if (targetSessionId.length === 0)
|
|
5114
5125
|
return invalid4("empty-session-id");
|
|
5126
|
+
if (name === "postgres") {
|
|
5127
|
+
if (guard !== undefined && (guard.sweeper.key.kind !== "maintenance" || guard.sweeper.key.task !== LOST_SWEEP_MAINTENANCE.task))
|
|
5128
|
+
return { status: "listed", asks: [] };
|
|
5129
|
+
let fences = "";
|
|
5130
|
+
let canMark = "";
|
|
5131
|
+
const params = [];
|
|
5132
|
+
if (guard !== undefined) {
|
|
5133
|
+
const indexed = await (addressColumns ??= brokerSchemaCurrent(database, prefix, "lease-addresses"));
|
|
5134
|
+
const presenceId = indexed ? "presence_id" : `CASE WHEN subject_json !~ (chr(92) || chr(92) || 'u(0000|[dD][89a-fA-F])')
|
|
5135
|
+
THEN subject_json::json #>> '{session,id}' END`;
|
|
5136
|
+
fences = `sweeper AS MATERIALIZED (
|
|
5137
|
+
SELECT 1 FROM ${leases} WHERE kind = 'maintenance' AND key = ? AND holder_id = ?
|
|
5138
|
+
AND fencing_token = ? AND renewed_at >= ${nowMs} - ? FOR SHARE NOWAIT
|
|
5139
|
+
), recipient AS MATERIALIZED (
|
|
5140
|
+
SELECT holder_id, renewed_at FROM ${leases} WHERE kind = 'presence'
|
|
5141
|
+
AND (key IN (?, ?) OR ${presenceId} IN (?, ?)) ORDER BY key FOR SHARE NOWAIT
|
|
5142
|
+
), `;
|
|
5143
|
+
canMark = `AND EXISTS (SELECT 1 FROM sweeper) AND NOT EXISTS (
|
|
5144
|
+
SELECT 1 FROM recipient WHERE holder_id IS NOT NULL AND renewed_at >= ${nowMs} - ?
|
|
5145
|
+
)`;
|
|
5146
|
+
params.push(LOST_SWEEP_MAINTENANCE.task, guard.sweeper.holderId, guard.sweeper.fencingToken, LOST_SWEEP_STALE_AFTER_MS, guard.targetIdentity, targetSessionId, targetSessionId, guard.targetIdentity);
|
|
5147
|
+
}
|
|
5148
|
+
const open = "target_session_id = ? AND park_owner IS NULL AND replied IS NULL AND ended_at IS NULL";
|
|
5149
|
+
const mark = {
|
|
5150
|
+
sql: `WITH ${fences} open_asks AS MATERIALIZED (
|
|
5151
|
+
SELECT "order" FROM ${table} WHERE ${open} ${canMark} ORDER BY "order" FOR UPDATE SKIP LOCKED
|
|
5152
|
+
), marked AS (
|
|
5153
|
+
UPDATE ${table} SET ended_at = ${nowMs} WHERE "order" IN (SELECT "order" FROM open_asks)
|
|
5154
|
+
RETURNING "order", sender_session_id, target_session_id, message_id
|
|
5155
|
+
) SELECT sender_session_id, target_session_id, message_id FROM marked ORDER BY "order"`,
|
|
5156
|
+
params: [...params, targetSessionId, ...guard === undefined ? [] : [BROKER_LEASE_STALE_AFTER_MS]]
|
|
5157
|
+
};
|
|
5158
|
+
const rows = await database.transaction((tx) => tx.all(mark.sql, ...mark.params), {
|
|
5159
|
+
...RETRY_UNAPPLIED,
|
|
5160
|
+
concurrency: { kind: "fenced", audit: fencedPath("intercom-lost-ask") },
|
|
5161
|
+
leading: [mark],
|
|
5162
|
+
leadingOnly: true
|
|
5163
|
+
});
|
|
5164
|
+
return { status: "listed", asks: rows.map(toAsk) };
|
|
5165
|
+
}
|
|
5115
5166
|
const rows = await database.transaction(async (tx) => {
|
|
5116
5167
|
const open = await tx.all(`SELECT "order", sender_session_id, target_session_id, message_id FROM ${table}
|
|
5117
5168
|
WHERE target_session_id = ? AND park_owner IS NULL AND replied IS NULL AND ended_at IS NULL
|
|
@@ -12681,6 +12732,8 @@ class MultiNodeRouter {
|
|
|
12681
12732
|
lostBounds;
|
|
12682
12733
|
membership;
|
|
12683
12734
|
maintenance;
|
|
12735
|
+
lostSweep;
|
|
12736
|
+
lostSweepRunning;
|
|
12684
12737
|
subscription;
|
|
12685
12738
|
presence = new Map;
|
|
12686
12739
|
inflight = new Map;
|
|
@@ -13876,9 +13929,32 @@ class MultiNodeRouter {
|
|
|
13876
13929
|
if (ended.status === "listed")
|
|
13877
13930
|
await this.failAsksOfEnded(ended.asks);
|
|
13878
13931
|
}
|
|
13879
|
-
|
|
13932
|
+
sweepLostRecipients() {
|
|
13933
|
+
return this.lostSweepRunning ??= this.sweepLostRecipientsOnce().finally(() => {
|
|
13934
|
+
this.lostSweepRunning = undefined;
|
|
13935
|
+
});
|
|
13936
|
+
}
|
|
13937
|
+
async sweepLostRecipientsOnce() {
|
|
13938
|
+
if (this.closed)
|
|
13939
|
+
return;
|
|
13880
13940
|
const { afterRestartMs, afterStaleLeaseMs } = this.lostBounds;
|
|
13881
|
-
const { leases } = this.state;
|
|
13941
|
+
const { leases, pendingAsks } = this.state;
|
|
13942
|
+
let sweeper;
|
|
13943
|
+
if (pendingAsks.coordinatesLostSweep === true) {
|
|
13944
|
+
if (this.lostSweep === undefined) {
|
|
13945
|
+
const current = await leases.read(LOST_SWEEP_MAINTENANCE);
|
|
13946
|
+
if (current.status === "found" && current.lease.holderId !== this.brokerId && current.lease.ageMs <= LOST_SWEEP_STALE_AFTER_MS)
|
|
13947
|
+
return;
|
|
13948
|
+
}
|
|
13949
|
+
const acquired = await leases.acquire(LOST_SWEEP_MAINTENANCE, this.brokerId, LOST_SWEEP_STALE_AFTER_MS);
|
|
13950
|
+
this.lostSweep = sweeper = acquired.status === "acquired" ? acquired.lease : undefined;
|
|
13951
|
+
if (sweeper === undefined)
|
|
13952
|
+
return;
|
|
13953
|
+
if (this.closed) {
|
|
13954
|
+
await leases.release(sweeper);
|
|
13955
|
+
return;
|
|
13956
|
+
}
|
|
13957
|
+
}
|
|
13882
13958
|
const lostAfterMs = BROKER_LEASE_STALE_AFTER_MS + afterStaleLeaseMs;
|
|
13883
13959
|
const aged = leases.listAged === undefined ? (await leases.listLive("presence", Number.MAX_SAFE_INTEGER)).filter((lease) => lease.ageMs >= lostAfterMs) : await leases.listAged("presence", lostAfterMs);
|
|
13884
13960
|
const lost = new Map;
|
|
@@ -13913,11 +13989,13 @@ class MultiNodeRouter {
|
|
|
13913
13989
|
live.add(subject.targetIdentity);
|
|
13914
13990
|
}
|
|
13915
13991
|
for (const [sessionId, { from, targetIdentity, boundMs }] of lost) {
|
|
13992
|
+
if (this.closed)
|
|
13993
|
+
return;
|
|
13916
13994
|
if (live.has(sessionId) || live.has(targetIdentity) || this.host.sessions.has(sessionId))
|
|
13917
13995
|
continue;
|
|
13918
|
-
if (await this.reservedForReturn(sessionId, targetIdentity, from))
|
|
13996
|
+
if (await this.reservedForReturn(sessionId, targetIdentity, from) || this.host.sessions.has(sessionId))
|
|
13919
13997
|
continue;
|
|
13920
|
-
const ended = await
|
|
13998
|
+
const ended = await pendingAsks.endLost(sessionId, sweeper === undefined ? undefined : { targetIdentity, sweeper });
|
|
13921
13999
|
if (ended.status !== "listed")
|
|
13922
14000
|
continue;
|
|
13923
14001
|
const reason = lostRecipientReason(from.name ?? sessionId, boundMs);
|
|
@@ -17040,6 +17118,8 @@ class MultiNodeRouter {
|
|
|
17040
17118
|
await this.state.leases.release(this.membership);
|
|
17041
17119
|
if (this.maintenance !== undefined)
|
|
17042
17120
|
await this.state.leases.release(this.maintenance);
|
|
17121
|
+
if (this.lostSweep !== undefined)
|
|
17122
|
+
await this.state.leases.release(this.lostSweep);
|
|
17043
17123
|
} catch (error) {
|
|
17044
17124
|
this.report(error);
|
|
17045
17125
|
}
|
|
@@ -46,6 +46,8 @@ import {
|
|
|
46
46
|
type LeaseRenewalRequest,
|
|
47
47
|
type LeaseRenewResult,
|
|
48
48
|
type LeaseState,
|
|
49
|
+
LOST_SWEEP_MAINTENANCE,
|
|
50
|
+
LOST_SWEEP_STALE_AFTER_MS,
|
|
49
51
|
MAINTENANCE_INTERVAL_MS,
|
|
50
52
|
MAINTENANCE_STALE_AFTER_MS,
|
|
51
53
|
type MaintenanceSubject,
|
|
@@ -1102,6 +1104,8 @@ export class MultiNodeRouter {
|
|
|
1102
1104
|
private membership: Lease | undefined;
|
|
1103
1105
|
/** The maintenance lease while this broker is the swarm's maintainer (`maintain`). */
|
|
1104
1106
|
private maintenance: Lease | undefined;
|
|
1107
|
+
private lostSweep: Lease | undefined;
|
|
1108
|
+
private lostSweepRunning: Promise<void> | undefined;
|
|
1105
1109
|
private subscription: WakeUpSubscription | undefined;
|
|
1106
1110
|
private readonly presence = new Map<BrokerConnectedSession, PresenceEntry>();
|
|
1107
1111
|
private readonly inflight = new Map<string, Inflight>();
|
|
@@ -2793,12 +2797,36 @@ export class MultiNodeRouter {
|
|
|
2793
2797
|
* for its return, has its unparked asks failed as "unavailable": marked ended, so of brokers that find it lost at
|
|
2794
2798
|
* once only the one that marked an ask tells its asker, through the outbox as an ended recipient's failure.
|
|
2795
2799
|
*/
|
|
2796
|
-
private
|
|
2800
|
+
private sweepLostRecipients(): Promise<void> {
|
|
2801
|
+
return (this.lostSweepRunning ??= this.sweepLostRecipientsOnce().finally(() => {
|
|
2802
|
+
this.lostSweepRunning = undefined;
|
|
2803
|
+
}));
|
|
2804
|
+
}
|
|
2805
|
+
|
|
2806
|
+
private async sweepLostRecipientsOnce(): Promise<void> {
|
|
2807
|
+
if (this.closed) return;
|
|
2797
2808
|
const { afterRestartMs, afterStaleLeaseMs } = this.lostBounds;
|
|
2798
|
-
const { leases } = this.state;
|
|
2809
|
+
const { leases, pendingAsks } = this.state;
|
|
2810
|
+
let sweeper: Lease | undefined;
|
|
2811
|
+
if (pendingAsks.coordinatesLostSweep === true) {
|
|
2812
|
+
if (this.lostSweep === undefined) {
|
|
2813
|
+
const current = await leases.read(LOST_SWEEP_MAINTENANCE);
|
|
2814
|
+
if (
|
|
2815
|
+
current.status === "found" &&
|
|
2816
|
+
current.lease.holderId !== this.brokerId &&
|
|
2817
|
+
current.lease.ageMs <= LOST_SWEEP_STALE_AFTER_MS
|
|
2818
|
+
) return;
|
|
2819
|
+
}
|
|
2820
|
+
const acquired = await leases.acquire(LOST_SWEEP_MAINTENANCE, this.brokerId, LOST_SWEEP_STALE_AFTER_MS);
|
|
2821
|
+
this.lostSweep = sweeper = acquired.status === "acquired" ? acquired.lease : undefined;
|
|
2822
|
+
if (sweeper === undefined) return;
|
|
2823
|
+
if (this.closed) {
|
|
2824
|
+
await leases.release(sweeper);
|
|
2825
|
+
return;
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2799
2828
|
const lostAfterMs = BROKER_LEASE_STALE_AFTER_MS + afterStaleLeaseMs;
|
|
2800
|
-
// #6560: only the leases stale past the bound
|
|
2801
|
-
// broker sweeps every backup poll, and reading every lease each time grew with the square of the swarm.
|
|
2829
|
+
// #6560: read only the leases stale past the bound. While every broker renews its sessions', this is none.
|
|
2802
2830
|
const aged =
|
|
2803
2831
|
leases.listAged === undefined
|
|
2804
2832
|
? (await leases.listLive("presence", Number.MAX_SAFE_INTEGER)).filter((lease) => lease.ageMs >= lostAfterMs)
|
|
@@ -2835,9 +2863,13 @@ export class MultiNodeRouter {
|
|
|
2835
2863
|
live.add(subject.targetIdentity);
|
|
2836
2864
|
}
|
|
2837
2865
|
for (const [sessionId, { from, targetIdentity, boundMs }] of lost) {
|
|
2866
|
+
if (this.closed) return;
|
|
2838
2867
|
if (live.has(sessionId) || live.has(targetIdentity) || this.host.sessions.has(sessionId)) continue;
|
|
2839
|
-
if (await this.reservedForReturn(sessionId, targetIdentity, from)) continue;
|
|
2840
|
-
const ended = await
|
|
2868
|
+
if (await this.reservedForReturn(sessionId, targetIdentity, from) || this.host.sessions.has(sessionId)) continue;
|
|
2869
|
+
const ended = await pendingAsks.endLost(
|
|
2870
|
+
sessionId,
|
|
2871
|
+
sweeper === undefined ? undefined : { targetIdentity, sweeper },
|
|
2872
|
+
);
|
|
2841
2873
|
if (ended.status !== "listed") continue;
|
|
2842
2874
|
const reason = lostRecipientReason(from.name ?? sessionId, boundMs);
|
|
2843
2875
|
await this.failAsksTo(from, ended.asks, reason, "ended", "outside-groups", true);
|
|
@@ -6596,8 +6628,8 @@ export class MultiNodeRouter {
|
|
|
6596
6628
|
* maintainer reads the lease and goes on while another holds it live; the maintainer takes it again, which renews
|
|
6597
6629
|
* it, and so stays the maintainer while it runs. Once it stops, its lease goes stale after
|
|
6598
6630
|
* `MAINTENANCE_STALE_AFTER_MS` (or is free at once, when it closed) and the next broker to check takes it over.
|
|
6599
|
-
* Nothing here is needed for delivery
|
|
6600
|
-
*
|
|
6631
|
+
* Nothing here is needed for delivery; that stays in `backupPoll`. On PostgreSQL the more frequent sweep for a
|
|
6632
|
+
* stopped broker's recipients elects its own leader, independently of retention.
|
|
6601
6633
|
*/
|
|
6602
6634
|
private async maintain(): Promise<void> {
|
|
6603
6635
|
const { leases } = this.state;
|
|
@@ -6764,6 +6796,7 @@ export class MultiNodeRouter {
|
|
|
6764
6796
|
if (this.membership !== undefined) await this.state.leases.release(this.membership);
|
|
6765
6797
|
// Free for the next broker to check, rather than once it went stale.
|
|
6766
6798
|
if (this.maintenance !== undefined) await this.state.leases.release(this.maintenance);
|
|
6799
|
+
if (this.lostSweep !== undefined) await this.state.leases.release(this.lostSweep);
|
|
6767
6800
|
} catch (error) {
|
|
6768
6801
|
this.report(error);
|
|
6769
6802
|
}
|
|
@@ -26,6 +26,9 @@ export const BROKER_LEASE_STALE_AFTER_MS = 30_000;
|
|
|
26
26
|
export const OUTBOX_CLAIM_STALE_AFTER_MS = 30_000;
|
|
27
27
|
/** Safety-net outbox scan interval for brokers whose wake-ups were lost. */
|
|
28
28
|
export const OUTBOX_BACKUP_POLL_INTERVAL_MS = 30_000;
|
|
29
|
+
/** A backup-poll sweeper that missed two polls no longer gets to mark questions ended. */
|
|
30
|
+
export const LOST_SWEEP_STALE_AFTER_MS = 2 * OUTBOX_BACKUP_POLL_INTERVAL_MS;
|
|
31
|
+
export const LOST_SWEEP_MAINTENANCE: MaintenanceSubject = { kind: "maintenance", task: "lost-recipients" };
|
|
29
32
|
/**
|
|
30
33
|
* How often the swarm's maintainer, one broker holding the maintenance lease, prunes the shared state past its retention
|
|
31
34
|
* and expires the outbox rows left queued too long; each other broker checks this often whether the lease went stale.
|
|
@@ -765,7 +768,9 @@ export interface PendingAskStore {
|
|
|
765
768
|
* this call marked, so of brokers that find it lost at once only one tells each asker. An ask marked earlier is
|
|
766
769
|
* left to whoever marked it, or to `listEnded` once that broker stopped.
|
|
767
770
|
*/
|
|
768
|
-
endLost(targetSessionId: string): Promise<PendingAskListResult>;
|
|
771
|
+
endLost(targetSessionId: string, guard?: { targetIdentity: string; sweeper: Lease }): Promise<PendingAskListResult>;
|
|
772
|
+
/** Whether the store can recheck this recipient's presence and the sweep leader's fence when it marks asks. */
|
|
773
|
+
readonly coordinatesLostSweep?: true;
|
|
769
774
|
/** #4992: the ended ask's failure is queued; its route stays only to authorize that failure when it is delivered. */
|
|
770
775
|
unmarkEnded(route: ReplyRoute): Promise<PendingAskMarkResult>;
|
|
771
776
|
}
|