@bastani/atomic 0.10.11-alpha.2 → 0.10.11-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +99 -0
- package/README.md +5 -8
- 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-rpc-sdk-IOPGDYR4.js +5 -5
- package/dist/_shared/mode-shared-2QJSCUM6.js +6 -6
- package/dist/_shared/p0-cli-BB45ZQY6.js +46 -67
- package/dist/_shared/p0-cli-BB45ZQY6.js.map +1 -1
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +7 -8
- package/dist/_shared/p1a-prewarm-XIU57JHF.js.map +1 -1
- package/dist/_shared/{p1b-elig-ENCUPKKJ.js → p1b-elig-TVB5CBLL.js} +14 -2
- package/dist/_shared/{p1b-elig-ENCUPKKJ.js.map → p1b-elig-TVB5CBLL.js.map} +1 -1
- package/dist/_shared/runtime-O4KCSG4C.js +3 -3
- package/dist/_shared/{sdk-IQMULKFU.js → sdk-B5LEWGGI.js} +340 -163
- package/dist/_shared/sdk-B5LEWGGI.js.map +1 -0
- 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-3IXNMFM2.js → startup-0-0-EZUKEP4Q.js} +48 -40
- package/dist/_shared/startup-0-0-EZUKEP4Q.js.map +1 -0
- package/dist/_shared/{startup-0-1-7T2IAE7J.js → startup-0-1-RTOHJFDJ.js} +195 -42
- package/dist/_shared/startup-0-1-RTOHJFDJ.js.map +1 -0
- package/dist/_shared/startup-0-2-5QHPCEON.js +33 -43
- package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -1
- package/dist/_shared/startup-0-3-4ZYBYQNM.js +5 -5
- 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-YDW47QX6.js +7 -7
- package/dist/_shared/startup-0-5-YDW47QX6.js.map +1 -1
- package/dist/_shared/startup-10-0-TDQNBDDL.js +6 -6
- package/dist/_shared/startup-12-0-55AAXBJZ.js +2 -2
- package/dist/_shared/startup-14-0-MLX36RBG.js +4 -5
- package/dist/_shared/startup-14-0-MLX36RBG.js.map +1 -1
- package/dist/_shared/startup-15-0-YUKGAC63.js +4 -4
- package/dist/_shared/startup-15-1-4S7FLMNG.js +19 -27
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +39 -23
- package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
- package/dist/_shared/{startup-8-1-X32CYSXB.js → startup-8-1-LZFXSD3Z.js} +90 -1176
- package/dist/_shared/startup-8-1-LZFXSD3Z.js.map +1 -0
- package/dist/_shared/storage-command-7MGXLJGZ.js +186 -35
- package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
- package/dist/_shared/storage-status-K7PX2RXA.js +557 -0
- package/dist/_shared/storage-status-K7PX2RXA.js.map +1 -0
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/team-DOQKICG2.js +376 -0
- package/dist/_shared/team-DOQKICG2.js.map +1 -0
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/CHANGELOG.md +23 -0
- package/dist/builtin/intercom/README.md +2 -2
- package/dist/builtin/intercom/broker/broker.bundle.mjs +913 -289
- package/dist/builtin/intercom/broker/database-wake-up-bus.ts +243 -64
- package/dist/builtin/intercom/broker/multinode-router.ts +154 -22
- package/dist/builtin/intercom/broker/multinode-state-store.ts +30 -3
- package/dist/builtin/intercom/broker/open-broker-state.ts +14 -0
- package/dist/builtin/intercom/broker/sql-add-column.ts +29 -5
- package/dist/builtin/intercom/broker/sql-ended-child-queue-store.ts +3 -2
- package/dist/builtin/intercom/broker/sql-held-send-store.ts +2 -2
- package/dist/builtin/intercom/broker/sql-known-session-store.ts +43 -19
- package/dist/builtin/intercom/broker/sql-lease-store.ts +170 -74
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +298 -47
- package/dist/builtin/intercom/broker/sql-pending-ask-store.ts +8 -5
- package/dist/builtin/intercom/broker/sql-released-ask-store.ts +12 -5
- package/dist/builtin/intercom/broker/sql-restoring-reservation-store.ts +24 -7
- package/dist/builtin/intercom/broker/sql-retention.ts +141 -0
- package/dist/builtin/intercom/broker/sql-schema.ts +136 -19
- package/dist/builtin/intercom/broker/sql-sent-message-authority.ts +74 -19
- package/dist/builtin/intercom/broker/wake-up-bus.ts +6 -0
- package/dist/builtin/intercom/index.bundle.mjs +2 -3
- 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 +2 -10
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/bun/bundled-sqlite.js +41 -0
- package/dist/bun/bundled-sqlite.js.map +1 -0
- package/dist/cli/args.js +2 -2
- package/dist/cli/auth-cli.code.js +4 -4
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.code.js +3 -3
- package/dist/cli/blueprint-command.impl.js +3 -3
- package/dist/cli/blueprint-command.js +3 -3
- package/dist/cli/intercom-command.code.js +3 -3
- package/dist/cli/intercom-command.code.js.map +1 -1
- 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 +3 -3
- 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 +19 -113
- package/dist/cli/team-command.code.js.map +1 -1
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +5 -18
- package/dist/cli.js.map +1 -1
- package/dist/core/agent-rehydrate-errors.d.ts +4 -9
- package/dist/core/compaction/compactor.d.ts +3 -3
- package/dist/core/debug.code.js +1 -1
- 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 +2 -2
- package/dist/core/intercom-broker-control-host.code.js +2 -2
- 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.code.js +1 -1
- package/dist/core/package-manager-storage-adapters.impl.js +3 -3
- package/dist/core/package-manager-storage-adapters.js +3 -3
- package/dist/core/process-start-token.d.ts +8 -0
- package/dist/core/process-tree-containment.d.ts +16 -0
- package/dist/core/sdk-types.d.ts +1 -2
- package/dist/core/sdk-types.js.map +1 -1
- package/dist/core/sdk.code.js +3 -3
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +5 -5
- 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.code.js +1 -1
- package/dist/core/session-storage.impl.js +3 -3
- package/dist/core/session-storage.js +3 -3
- package/dist/core/settings-schema.d.ts +0 -3
- package/dist/core/storage/added-exports-0-10-11.js +19 -0
- package/dist/core/storage/added-exports-0-10-11.js.map +1 -0
- package/dist/core/storage/creation-time.js +105 -0
- package/dist/core/storage/creation-time.js.map +1 -0
- package/dist/core/storage/database.d.ts +19 -5
- package/dist/core/storage/database.js.map +1 -1
- package/dist/core/storage/dialect.d.ts +1 -1
- package/dist/core/storage/dialect.js +1 -1
- package/dist/core/storage/dialect.js.map +1 -1
- package/dist/core/storage/errors.d.ts +13 -13
- package/dist/core/storage/errors.js +10 -16
- package/dist/core/storage/errors.js.map +1 -1
- package/dist/core/storage/fenced-paths.d.ts +11 -0
- package/dist/core/storage/fenced-paths.js +11 -0
- package/dist/core/storage/fenced-paths.js.map +1 -1
- package/dist/core/storage/file-identity.d.ts +2 -0
- package/dist/core/storage/file-identity.js +24 -8
- package/dist/core/storage/file-identity.js.map +1 -1
- package/dist/core/storage/index.d.ts +3 -2
- package/dist/core/storage/index.js +5 -3
- package/dist/core/storage/index.js.map +1 -1
- package/dist/core/storage/libsql-removed.d.ts +71 -0
- package/dist/core/storage/libsql-removed.js +123 -0
- package/dist/core/storage/libsql-removed.js.map +1 -0
- package/dist/core/storage/migrations.d.ts +78 -14
- package/dist/core/storage/migrations.js +375 -49
- package/dist/core/storage/migrations.js.map +1 -1
- package/dist/core/storage/node-sqlite-file-gate.js +0 -15
- package/dist/core/storage/node-sqlite-file-gate.js.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +8 -13
- package/dist/core/storage/node-sqlite-thread.js.map +1 -1
- package/dist/core/storage/node-sqlite.js +51 -3
- package/dist/core/storage/node-sqlite.js.map +1 -1
- 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/prefix.d.ts +1 -1
- package/dist/core/storage/prefix.js +9 -2
- package/dist/core/storage/prefix.js.map +1 -1
- package/dist/core/storage/process-selection.d.ts +5 -5
- package/dist/core/storage/provider.js +2 -2
- package/dist/core/storage/schema-catalog.d.ts +7 -8
- package/dist/core/storage/schema-catalog.js +8 -8
- package/dist/core/storage/schema-catalog.js.map +1 -1
- package/dist/core/storage/selection.d.ts +7 -82
- package/dist/core/storage/selection.js +20 -235
- package/dist/core/storage/selection.js.map +1 -1
- 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 +4 -7
- package/dist/core/storage/session/fork-staging.code.js.map +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 +5 -1
- 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.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 +3 -3
- 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-search-index.d.ts +43 -4
- 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.code.js +1 -1
- package/dist/core/storage/session/sql-session-store.d.ts +48 -11
- 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/sqlite-facade.d.ts +6 -1
- package/dist/core/storage/sqlite-facade.js +1 -0
- package/dist/core/storage/sqlite-facade.js.map +1 -1
- package/dist/core/storage/storage-status.code.js +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.code.js +1 -1
- package/dist/core/storage/team.d.ts +26 -115
- package/dist/core/storage/team.impl.js +3 -3
- package/dist/core/storage/team.js +3 -3
- package/dist/core/structured-output/index.code.js +1 -1
- package/dist/core/structured-output/index.impl.js +3 -3
- package/dist/core/structured-output/index.js +3 -3
- 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 +4 -4
- 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.code.js +1 -1
- 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-tasks.d.ts +3 -2
- package/dist/core/tools/read-url.code.js +4 -4
- 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 +40 -3
- package/dist/core/worktree-snapshot/blob-store.js +414 -21
- package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
- 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/fork-blob-guard.js +81 -0
- package/dist/core/worktree-snapshot/fork-blob-guard.js.map +1 -0
- package/dist/core/worktree-snapshot/fork-snapshot-index.js +79 -38
- package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -1
- package/dist/core/worktree-snapshot/session-index-reset.code.js +4 -0
- package/dist/core/worktree-snapshot/session-index-reset.code.js.map +1 -1
- 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/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 +2 -2
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +3 -3
- 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.code.js +1 -1
- package/dist/extensions/mcp/runtime.impl.js +3 -3
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -5
- 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/main.js +1 -1
- 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/startup-shell-eligibility.js +1 -1
- package/dist/modes/interactive-engine/engine-prewarm.d.ts +1 -1
- package/dist/modes/print-mode.js +1 -1
- package/dist/package-manager-cli.code.js +6 -6
- 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/10.js +1 -1
- package/dist/startup-stages/11.js +1 -1
- package/dist/startup-stages/12.js +1 -1
- package/dist/startup-stages/2.js +2 -4
- package/dist/startup-stages/3.js +1 -3
- package/dist/startup-stages/4.js +1 -2
- package/dist/startup-stages/5.js +1 -1
- package/dist/startup-stages/6.js +5 -7
- package/dist/startup-stages/7.js +3 -10
- package/dist/startup-stages/8.js +7 -2
- package/dist/startup-stages/9.js +1 -7
- package/dist/startup-stages/stages.json +1 -1
- package/dist/utils/compile-cache-deferral.js +8 -13
- package/dist/utils/compile-cache-deferral.js.map +1 -1
- package/dist/utils/compile-cache-warmup-host.js +3 -4
- package/dist/utils/compile-cache-warmup-host.js.map +1 -1
- package/dist/utils/compile-cache.js +12 -100
- package/dist/utils/compile-cache.js.map +1 -1
- 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/dist/utils/worker-threads.js +2 -15
- package/dist/utils/worker-threads.js.map +1 -1
- package/docs/build.md +3 -3
- package/docs/changelog.mdx +1421 -69
- package/docs/compaction/reference.md +5 -5
- package/docs/compaction.md +7 -9
- package/docs/containerization.md +2 -2
- package/docs/custom-provider/api-reference.md +1 -1
- package/docs/docs.json +37 -10
- package/docs/environment-variables.md +0 -2
- package/docs/extensions/api-reference.md +4 -4
- package/docs/getting-started/installation.md +3 -0
- package/docs/guides/configuration.md +1 -1
- package/docs/guides/non-interactive.md +1 -1
- package/docs/guides/resume-on-any-machine.md +14 -22
- package/docs/guides/team-setup.md +56 -83
- package/docs/guides.md +2 -4
- package/docs/herdr.md +1 -1
- package/docs/index.md +1 -1
- package/docs/intercom/operations.md +26 -21
- package/docs/intercom/reference.md +2 -2
- package/docs/intercom.md +1 -1
- package/docs/libraries/storage-postgres.md +9 -9
- package/docs/libraries.md +2 -3
- package/docs/models-configuration.md +2 -2
- package/docs/models.md +2 -3
- package/docs/packages/authoring.md +7 -7
- package/docs/packages.md +1 -1
- package/docs/programmatic.md +2 -2
- package/docs/quickstart.md +1 -1
- package/docs/reference/cli.md +6 -11
- package/docs/reference.md +2 -2
- package/docs/rpc/extension-ui.md +2 -2
- package/docs/sdk/reference.md +5 -4
- package/docs/sdk/storage.md +8 -92
- package/docs/sdk/structured-decisions.md +1 -1
- package/docs/sdk/web-server.md +3 -3
- package/docs/sdk.md +14 -4
- package/docs/security.md +1 -1
- package/docs/session-format.md +5 -5
- package/docs/sessions.md +29 -49
- package/docs/settings.md +7 -8
- package/docs/storage/custom-adapters.md +255 -0
- package/docs/storage/jsonl.md +117 -0
- package/docs/{guides/postgres-pgbouncer.md → storage/postgres/pgbouncer.md} +66 -68
- package/docs/storage/postgres/tuning.md +337 -0
- package/docs/storage/postgres.md +556 -0
- package/docs/storage/sqlite.md +99 -0
- package/docs/storage.md +326 -990
- package/docs/subagents/authoring.md +1 -1
- package/docs/subagents.md +2 -2
- package/docs/tools.md +1 -1
- package/docs/worktree-snapshots.md +2 -2
- package/package.json +9 -9
- package/schemas/models.schema.json +2 -2
- package/schemas/settings.schema.json +0 -14
- package/dist/_shared/sdk-IQMULKFU.js.map +0 -1
- package/dist/_shared/startup-0-0-3IXNMFM2.js.map +0 -1
- package/dist/_shared/startup-0-1-7T2IAE7J.js.map +0 -1
- package/dist/_shared/startup-8-1-X32CYSXB.js.map +0 -1
- package/dist/core/intercom-broker-control.d.ts +0 -129
- package/dist/startup-stages/13.js +0 -1
- package/docs/guides/postgres-tuning.md +0 -311
- package/docs/libraries/storage-libsql.md +0 -97
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { transactionFinisher } from "../storage/added-exports.js";
|
|
1
|
+
import { storageSchemaCurrent, transactionFinisher } from "../storage/added-exports.js";
|
|
2
|
+
import { noteStorageSchemaTables } from "../storage/added-exports-0-10-11.js";
|
|
2
3
|
import { dialectOf } from "../storage/dialect.js";
|
|
3
4
|
import { StorageWriteLockTimeoutError } from "../storage/errors.js";
|
|
4
|
-
import { applyStorageMigrations, withShortSchemaLockWaits } from "../storage/migrations.js";
|
|
5
|
+
import { applyStorageMigrations, ensureStorageSchema, withShortSchemaLockWaits } from "../storage/migrations.js";
|
|
5
6
|
import { renderStorageIdentifiers, storageMigrationTable, validateStoragePrefix } from "../storage/prefix.js";
|
|
6
7
|
import { schemaCatalogOf } from "../storage/schema-catalog.js";
|
|
7
8
|
import { statementBatch } from "../storage/statement-batches.js";
|
|
8
|
-
import {
|
|
9
|
+
import { forkInheritedBlobGuard, forkInheritedBlobGuardName } from "./fork-blob-guard.js";
|
|
10
|
+
import { entriesIndexComplete, forkLinksCheck, forkSegmentsTable, forkSessionLink, legacyForkLinksTriggerName, materializedForkLinks, ownDuplicate, ownParentSeq, parentColumns, snapshotEntryCondition, } from "./fork-snapshot-index.js";
|
|
9
11
|
/**
|
|
10
12
|
* The key under which a failed rename's error carries the trigger or view that stopped it, once confirmed in the
|
|
11
13
|
* database (#5622); `WorkspaceCollectionError` names it in its hint. A `Symbol.for` key, shared without an import.
|
|
@@ -209,7 +211,7 @@ export const SNAPSHOT_COLLECTION_DELETE_BATCH = 8;
|
|
|
209
211
|
export const SNAPSHOT_COLLECTION_SESSION_REFS = 2_048;
|
|
210
212
|
/**
|
|
211
213
|
* The most bytes of legacy blobs one write transaction of a collection stamps or moves. A blob stored before blob ages
|
|
212
|
-
* has an unknown age, which collection stamps; changing one column rewrites the whole row on SQLite
|
|
214
|
+
* has an unknown age, which collection stamps; changing one column rewrites the whole row on SQLite, its
|
|
213
215
|
* blob included, and holds the writer for as long as that takes, so a stamping transaction stops at this many bytes of
|
|
214
216
|
* blobs. An in-row blob larger than {@link SNAPSHOT_BLOB_CHUNK_BYTES} is moved to chunks regardless of age,
|
|
215
217
|
* at most this many bytes per transaction. Publishing frees its old value while holding the writer, with time
|
|
@@ -223,7 +225,7 @@ export const SNAPSHOT_LEGACY_STAMP_BYTES = 16 * SNAPSHOT_BLOB_CHUNK_BYTES;
|
|
|
223
225
|
*/
|
|
224
226
|
export const SNAPSHOT_CHUNK_MOVE_ROWS = 4;
|
|
225
227
|
/**
|
|
226
|
-
* The free space a chunk table's move to the row layout leaves on the file system of a SQLite
|
|
228
|
+
* The free space a chunk table's move to the row layout leaves on the file system of a SQLite database file
|
|
227
229
|
* beyond its copy, at least (#5694): the move starts only when the disk has room for the copy, its write-ahead log and
|
|
228
230
|
* this much more, so other writes keep room on the disk.
|
|
229
231
|
*/
|
|
@@ -520,14 +522,19 @@ function indexSources(prefix, t, d, forkSegments) {
|
|
|
520
522
|
const parentType = "r.parent_type";
|
|
521
523
|
const parentId = "r.parent_id";
|
|
522
524
|
const isSnapshot = snapshotEntryCondition(d, entryRow);
|
|
523
|
-
|
|
525
|
+
// The parent is the first link before the entry with the parent's id, as `forkSessionLink` finds it (#6560).
|
|
526
|
+
const parentOf = (rows) => `${rows} AS r LEFT JOIN ${t.sessionLinks} AS parent ON parent.session_id = r.session_id AND parent.seq = ${ownParentSeq(t.sessionLinks)}`;
|
|
524
527
|
/**
|
|
525
|
-
* Indexes one session entry's link in the session tree. `rows` yields that one entry as `r
|
|
526
|
-
*
|
|
528
|
+
* Indexes one session entry's link in the session tree. `rows` yields that one entry as `r`. Only the links before
|
|
529
|
+
* it count: its parent, an earlier entry of the same id, and the entries whose child it is, whose children it adds
|
|
530
|
+
* to, once. A row linked again gets the same anchor and broken mark, so a session's rows linked in seq order end
|
|
531
|
+
* the same whether a save or the index's rebuild linked them, and whatever links after them were there (#6560).
|
|
527
532
|
*/
|
|
528
533
|
const sessionLink = (rows) => [
|
|
529
|
-
`UPDATE ${t.sessionLinks} SET children = children + 1 FROM ${rows} AS r WHERE ${t.sessionLinks}.session_id = r.session_id AND ${t.sessionLinks}.entry_id = ${parentId} AND ${parentType} = 'text' AND NOT EXISTS (SELECT 1 FROM ${t.sessionLinks} AS own WHERE own.session_id = r.session_id AND own.seq = r.seq)`,
|
|
530
|
-
|
|
534
|
+
`UPDATE ${t.sessionLinks} SET children = children + 1 FROM ${rows} AS r WHERE ${t.sessionLinks}.session_id = r.session_id AND ${t.sessionLinks}.entry_id = ${parentId} AND ${parentType} = 'text' AND +${t.sessionLinks}.seq < r.seq AND NOT EXISTS (SELECT 1 FROM ${t.sessionLinks} AS own WHERE own.session_id = r.session_id AND own.seq = r.seq)`,
|
|
535
|
+
`INSERT INTO ${t.sessionLinks} (session_id, seq, entry_id, parent_id, anchor_seq, children, broken)
|
|
536
|
+
SELECT r.session_id, r.seq, r.entry_id, CASE WHEN ${parentType} = 'text' THEN ${parentId} END, CASE WHEN ${isSnapshot} THEN r.seq ELSE parent.anchor_seq END, 0, CASE WHEN ${ownDuplicate(t.sessionLinks)} THEN 1 WHEN ${parentType} IS NULL OR ${parentType} = 'null' THEN 0 WHEN parent.entry_id IS NOT NULL THEN parent.broken ELSE 1 END FROM ${parentOf(rows)} WHERE true
|
|
537
|
+
ON CONFLICT (session_id, seq) DO UPDATE SET anchor_seq = excluded.anchor_seq, broken = excluded.broken`,
|
|
531
538
|
];
|
|
532
539
|
/** Indexes a snapshot entry's reference and the blobs of its record; any other entry adds nothing. */
|
|
533
540
|
const sessionRecord = (rows) => {
|
|
@@ -586,6 +593,10 @@ function indexSources(prefix, t, d, forkSegments) {
|
|
|
586
593
|
/** One entry as `r`, with its parent named once, so that each statement parses the entry's JSON for it only once. */
|
|
587
594
|
const triggerEntry = `(SELECT ${entryColumns.map((name) => `NEW.${name} AS ${name}`).join(", ")}, ${parentColumns(d, "NEW.entry_json")})`;
|
|
588
595
|
const storedEntry = `(SELECT ${entryColumns.join(", ")}, ${parentColumns(d, "entry_json")} FROM ${entries} WHERE ${d.rowOrder()} = ?)`;
|
|
596
|
+
/** The rows session `?` stores from seq `?` on, as `storedEntry` yields one. */
|
|
597
|
+
const entriesFrom = `(SELECT ${entryColumns.join(", ")}, ${parentColumns(d, "entry_json")} FROM ${entries} WHERE session_id = ? AND seq >= ?)`;
|
|
598
|
+
/** Sets the previous snapshot of the references of `rows` to their parent's anchor: when a pin began stays. */
|
|
599
|
+
const refsAgain = (rows) => `UPDATE ${t.sessionRefs} SET prev_seq = linked.anchor_seq FROM (SELECT r.session_id, r.seq, parent.anchor_seq FROM ${parentOf(rows)} WHERE ${isSnapshot}) AS linked WHERE ${t.sessionRefs}.session_id = linked.session_id AND ${t.sessionRefs}.seq = linked.seq`;
|
|
589
600
|
const indexComplete = entriesIndexComplete(t.sources);
|
|
590
601
|
const newRowOrder = d.rowOrder("NEW");
|
|
591
602
|
const forkLink = (rows) => forkSegments === undefined ? [] : [forkSessionLink(t.sessionLinks, forkSegments, rows, isSnapshot)];
|
|
@@ -615,6 +626,15 @@ function indexSources(prefix, t, d, forkSegments) {
|
|
|
615
626
|
].map((trigger) => withMarker(trigger, ENTRIES_OWN_PROGRESS)),
|
|
616
627
|
backfill: [],
|
|
617
628
|
rowwise: [...sessionLink(storedEntry), ...forkLink(storedEntry), ...sessionRecord(storedEntry)],
|
|
629
|
+
...(forkSegments === undefined ? {} : { segments: forkSegments }),
|
|
630
|
+
entriesFrom,
|
|
631
|
+
relink: {
|
|
632
|
+
link: sessionLink(storedEntry)[1],
|
|
633
|
+
...(forkSegments === undefined ? {} : { fork: forkLink(storedEntry)[0] }),
|
|
634
|
+
// The reference's previous snapshot only: when a pin began stays as its first indexing recorded it.
|
|
635
|
+
refs: refsAgain(storedEntry),
|
|
636
|
+
refsFrom: refsAgain(entriesFrom),
|
|
637
|
+
},
|
|
618
638
|
// The triggers that index degraded pins (#4922). Older builds install theirs under the same names (#5065).
|
|
619
639
|
version: "session-entries@degraded-pins",
|
|
620
640
|
own: ENTRIES_OWN_PROGRESS,
|
|
@@ -643,6 +663,176 @@ function indexSources(prefix, t, d, forkSegments) {
|
|
|
643
663
|
});
|
|
644
664
|
return [eventsSource, runsSource, entriesSource, workSource, rootSource];
|
|
645
665
|
}
|
|
666
|
+
/** The session entries' {@link EntryLinking} of `source`, with the dialect and links table it runs on. */
|
|
667
|
+
function entryLinking(source, dialect, links) {
|
|
668
|
+
return {
|
|
669
|
+
dialect,
|
|
670
|
+
links,
|
|
671
|
+
entries: source.table,
|
|
672
|
+
segments: source.segments,
|
|
673
|
+
statements: source.rowwise,
|
|
674
|
+
relink: source.relink,
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Runs `statements` in order, each sent without waiting for the answer to the one before: a database runs a
|
|
679
|
+
* connection's calls in the order they are made, and a pipelined connection sends them together.
|
|
680
|
+
*/
|
|
681
|
+
async function runInOrder(executor, statements) {
|
|
682
|
+
await Promise.all(statements.map(({ sql, params }) => executor.run(sql, ...params)));
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Links the rows session `sessionId` stores from seq `fromSeq` on again, in seq order, each behind the rows before it
|
|
686
|
+
* (#6560), then counts their children again: an entry's children are the rows after it in the session whose parent
|
|
687
|
+
* has its id. A materialization runs it once it copied rows in below the rows a fork appended, and the index's rebuild
|
|
688
|
+
* when it meets a row stored before rows below it: both link every row as a save in seq order did.
|
|
689
|
+
*/
|
|
690
|
+
async function relinkSessionEntries(executor, linking, sessionId, fromSeq) {
|
|
691
|
+
const { dialect, links, entries, segments, statements, relink } = linking;
|
|
692
|
+
const rows = await executor.all(`SELECT ${dialect.rowOrder("e")} AS id,
|
|
693
|
+
CASE WHEN EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = e.session_id AND l.seq = e.seq) THEN 1 ELSE 0 END AS linked,
|
|
694
|
+
CASE WHEN ${dialect.contains("e.entry_json", `'"worktree_snapshot"'`)} THEN 1 ELSE 0 END AS snapshot
|
|
695
|
+
FROM ${entries} AS e WHERE e.session_id = ? AND e.seq >= ? ORDER BY e.seq`, sessionId, fromSeq);
|
|
696
|
+
const forked = segments !== undefined &&
|
|
697
|
+
relink.fork !== undefined &&
|
|
698
|
+
(await executor.get(`SELECT 1 AS found FROM ${segments} WHERE session_id = ? LIMIT 1`, sessionId)) !== undefined;
|
|
699
|
+
// A row not linked yet gets every statement; one linked already only those that write its link and reference again.
|
|
700
|
+
const again = (snapshot) => [
|
|
701
|
+
relink.link,
|
|
702
|
+
...(forked ? [relink.fork] : []),
|
|
703
|
+
...(snapshot ? [relink.refs] : []),
|
|
704
|
+
];
|
|
705
|
+
await runInOrder(executor, rows.flatMap(({ id, linked, snapshot }) => (Number(linked) === 1 ? again(Number(snapshot) === 1) : statements).map((sql) => ({ sql, params: [id] }))));
|
|
706
|
+
const linked = await executor.all(`SELECT seq, entry_id, parent_id, children FROM ${links} WHERE session_id = ? AND seq >= ? ORDER BY seq DESC`, sessionId, fromSeq);
|
|
707
|
+
const later = new Map();
|
|
708
|
+
const counts = [];
|
|
709
|
+
for (const link of linked) {
|
|
710
|
+
const children = later.get(link.entry_id) ?? 0;
|
|
711
|
+
if (Number(link.children) !== children)
|
|
712
|
+
counts.push({
|
|
713
|
+
sql: `UPDATE ${links} SET children = ? WHERE session_id = ? AND seq = ?`,
|
|
714
|
+
params: [children, sessionId, Number(link.seq)],
|
|
715
|
+
});
|
|
716
|
+
if (link.parent_id !== null)
|
|
717
|
+
later.set(link.parent_id, (later.get(link.parent_id) ?? 0) + 1);
|
|
718
|
+
}
|
|
719
|
+
await runInOrder(executor, counts);
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Links, in seq order, every row session `sessionId` stores up to seq `seq` that is not linked yet, behind the rows of
|
|
723
|
+
* its sources that its segments before `seq` name, which are linked first, the same way. Where the session has a row
|
|
724
|
+
* linked already after the first row this links, the rows after it are linked again with it (see
|
|
725
|
+
* {@link relinkSessionEntries}). A session linked this way has every row before a linked row linked, so the link of a
|
|
726
|
+
* segment's last row tells that its source is linked through it.
|
|
727
|
+
*/
|
|
728
|
+
async function linkThrough(executor, linking, sessionId, seq) {
|
|
729
|
+
const { dialect, links, entries, segments, statements } = linking;
|
|
730
|
+
const sources = async (through) => {
|
|
731
|
+
if (segments === undefined)
|
|
732
|
+
return;
|
|
733
|
+
const pending = await executor.all(`SELECT seg.source_id, seg.to_seq FROM ${segments} AS seg WHERE seg.session_id = ? AND seg.base_seq < ? AND NOT EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = seg.source_id AND l.seq = seg.to_seq) ORDER BY seg.base_seq`, sessionId, through);
|
|
734
|
+
for (const segment of pending)
|
|
735
|
+
await linkThrough(executor, linking, segment.source_id, Number(segment.to_seq));
|
|
736
|
+
};
|
|
737
|
+
await sources(seq);
|
|
738
|
+
const first = await executor.get(`SELECT f.seq, CASE WHEN EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = ? AND l.seq > f.seq) THEN 1 ELSE 0 END AS later
|
|
739
|
+
FROM (SELECT min(e.seq) AS seq FROM ${entries} AS e WHERE e.session_id = ? AND e.seq <= ? AND NOT EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = e.session_id AND l.seq = e.seq)) AS f`, sessionId, sessionId, seq);
|
|
740
|
+
if (first?.seq === null || first?.seq === undefined)
|
|
741
|
+
return;
|
|
742
|
+
if (Number(first.later) === 1) {
|
|
743
|
+
// The rows after it were linked before it: they are linked again, behind it.
|
|
744
|
+
await relinkFrom(executor, linking, sessionId, Number(first.seq));
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
const rows = await executor.all(`SELECT ${dialect.rowOrder()} AS id FROM ${entries} WHERE session_id = ? AND seq >= ? AND seq <= ? ORDER BY seq`, sessionId, Number(first.seq), seq);
|
|
748
|
+
await runInOrder(executor, rows.flatMap(({ id }) => statements.map((sql) => ({ sql, params: [id] }))));
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Links the rows session `sessionId` stores from seq `fromSeq` on again, behind the rows of the sources its segments
|
|
752
|
+
* name, and then the rows of every session that reads them through a segment and has a row linked after them: such a
|
|
753
|
+
* row took its parent's link, or its anchor, from the rows linked again (#6560).
|
|
754
|
+
*/
|
|
755
|
+
async function relinkFrom(executor, linking, sessionId, fromSeq) {
|
|
756
|
+
const { links, segments } = linking;
|
|
757
|
+
if (segments !== undefined) {
|
|
758
|
+
const pending = await executor.all(`SELECT seg.source_id, seg.to_seq FROM ${segments} AS seg WHERE seg.session_id = ? AND NOT EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = seg.source_id AND l.seq = seg.to_seq) ORDER BY seg.base_seq`, sessionId);
|
|
759
|
+
for (const segment of pending)
|
|
760
|
+
await linkThrough(executor, linking, segment.source_id, Number(segment.to_seq));
|
|
761
|
+
}
|
|
762
|
+
await relinkSessionEntries(executor, linking, sessionId, fromSeq);
|
|
763
|
+
if (segments === undefined)
|
|
764
|
+
return;
|
|
765
|
+
const readers = await executor.all(`SELECT seg.session_id, min(seg.base_seq + 1 + CASE WHEN seg.from_seq < ? THEN ? - seg.from_seq ELSE 0 END) AS first
|
|
766
|
+
FROM ${segments} AS seg WHERE seg.source_id = ? AND seg.to_seq >= ? GROUP BY seg.session_id ORDER BY seg.session_id`, fromSeq, fromSeq, sessionId, fromSeq);
|
|
767
|
+
for (const reader of readers) {
|
|
768
|
+
const linked = await executor.get(`SELECT 1 AS found FROM ${links} WHERE session_id = ? AND seq >= ? LIMIT 1`, reader.session_id, Number(reader.first));
|
|
769
|
+
if (linked !== undefined)
|
|
770
|
+
await relinkFrom(executor, linking, reader.session_id, Number(reader.first));
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* Indexes the stored entry at row order `id`, as the index's backfill meets it. The backfill goes in row order, but a
|
|
775
|
+
* fork that copied in the rows it read stores them after the entries it appended, and a fork moved onto another
|
|
776
|
+
* session's copy reads rows stored after its own (#6560): a row with a row before it, of its session or of a source
|
|
777
|
+
* its segments name, not linked yet, or with a row after it linked already, is linked by {@link linkThrough}, so every
|
|
778
|
+
* row is linked behind the rows before it in its view, as a save links it.
|
|
779
|
+
*/
|
|
780
|
+
async function linkStoredEntry(executor, linking, id) {
|
|
781
|
+
const { dialect, links, entries, segments, statements } = linking;
|
|
782
|
+
const pendingSource = segments === undefined
|
|
783
|
+
? "0"
|
|
784
|
+
: `CASE WHEN EXISTS (SELECT 1 FROM ${segments} AS seg WHERE seg.session_id = e.session_id AND seg.base_seq < e.seq AND NOT EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = seg.source_id AND l.seq = seg.to_seq)) THEN 1 ELSE 0 END`;
|
|
785
|
+
const row = await executor.get(`SELECT e.session_id, e.seq,
|
|
786
|
+
CASE WHEN EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = e.session_id AND l.seq = e.seq) THEN 1 ELSE 0 END AS linked,
|
|
787
|
+
CASE WHEN EXISTS (SELECT 1 FROM ${links} AS l WHERE l.session_id = e.session_id AND l.seq > e.seq) THEN 1 ELSE 0 END AS later,
|
|
788
|
+
(SELECT max(p.seq) FROM ${entries} AS p WHERE p.session_id = e.session_id AND p.seq < e.seq) AS previous,
|
|
789
|
+
(SELECT max(l.seq) FROM ${links} AS l WHERE l.session_id = e.session_id AND l.seq < e.seq) AS linked_before,
|
|
790
|
+
${pendingSource} AS pending_source
|
|
791
|
+
FROM ${entries} AS e WHERE ${dialect.rowOrder("e")} = ?`, id);
|
|
792
|
+
const inOrder = row === undefined ||
|
|
793
|
+
Number(row.linked) === 1 ||
|
|
794
|
+
(Number(row.later) === 0 &&
|
|
795
|
+
Number(row.pending_source) === 0 &&
|
|
796
|
+
(row.previous === null || (row.linked_before !== null && Number(row.linked_before) === Number(row.previous))));
|
|
797
|
+
if (inOrder)
|
|
798
|
+
for (const sql of statements)
|
|
799
|
+
await executor.run(sql, id);
|
|
800
|
+
else
|
|
801
|
+
await linkThrough(executor, linking, row.session_id, Number(row.seq));
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* The {@link SessionEntryLinks} of a session store under `prefix` whose fork segments table is `forkSegments` (#6560).
|
|
805
|
+
* Until the index's backfill of the session entries is done, which links the rows in seq order itself, `settle` only
|
|
806
|
+
* writes the segments.
|
|
807
|
+
*/
|
|
808
|
+
export function sessionEntryLinks(prefix, dialect, forkSegments) {
|
|
809
|
+
const t = snapshotIndexTables(prefix);
|
|
810
|
+
const source = indexSources(prefix, t, dialect, forkSegments).find((source) => source.name === "session-entries");
|
|
811
|
+
const linking = entryLinking(source, dialect, t.sessionLinks);
|
|
812
|
+
const complete = entriesIndexComplete(t.sources);
|
|
813
|
+
// The rows to check, from their links, which name each entry's id and its parent's, so no entry's JSON is parsed. A
|
|
814
|
+
// link without a parent is taken for a root: one whose parent is a value of another type, which no store writes, is
|
|
815
|
+
// linked broken, so the check finds it and the session is linked again row by row, from its JSON. A snapshot entry
|
|
816
|
+
// is its own anchor, as no other entry is.
|
|
817
|
+
const linked = `(SELECT l.session_id, l.seq, l.entry_id, l.parent_id, CASE WHEN l.parent_id IS NOT NULL THEN 'text' ELSE 'null' END AS parent_type, l.anchor_seq AS own_anchor FROM ${t.sessionLinks} AS l WHERE l.session_id = ? AND l.seq >= ?)`;
|
|
818
|
+
const check = forkLinksCheck({ links: t.sessionLinks, segments: forkSegments, refs: t.sessionRefs }, linked, "r.own_anchor = r.seq", complete);
|
|
819
|
+
return {
|
|
820
|
+
materialized: materializedForkLinks(t.sessionLinks, forkSegments, complete, dialect.types.int),
|
|
821
|
+
async settle(executor, sessionId, fromSeq, before) {
|
|
822
|
+
const [, verdict] = await Promise.all([
|
|
823
|
+
runInOrder(executor, before),
|
|
824
|
+
executor.get(check, sessionId, fromSeq, sessionId, fromSeq, sessionId, fromSeq),
|
|
825
|
+
]);
|
|
826
|
+
if (verdict === undefined)
|
|
827
|
+
return;
|
|
828
|
+
const children = Number(verdict.children) === 1;
|
|
829
|
+
if (verdict.seq !== null || children)
|
|
830
|
+
await relinkFrom(executor, linking, sessionId, children ? fromSeq : Number(verdict.seq));
|
|
831
|
+
if (verdict.seq !== null || children || Number(verdict.refs) === 1)
|
|
832
|
+
await executor.run(linking.relink.refsFrom, sessionId, fromSeq);
|
|
833
|
+
},
|
|
834
|
+
};
|
|
835
|
+
}
|
|
646
836
|
/**
|
|
647
837
|
* Creates a chunk table named `table` unless it exists. An ordinary table, whose primary key is an index of its own:
|
|
648
838
|
* a lookup reads that small index, then only the row it finds. A `WITHOUT ROWID` table, as earlier releases created,
|
|
@@ -695,7 +885,9 @@ async function addBlobChunks(transaction, t, dialect) {
|
|
|
695
885
|
* Creates the blob table and the tables of its reference index that are missing, reading what each step needs
|
|
696
886
|
* together, so on a SQLite file connection the setup waits for the connection's thread three times.
|
|
697
887
|
*/
|
|
698
|
-
async function createSnapshotIndexTables(transaction, t, prefix, dialect
|
|
888
|
+
async function createSnapshotIndexTables(transaction, t, prefix, dialect,
|
|
889
|
+
/** Statements that run with the tables' own, in the same request: such as a ledger record of what they create. */
|
|
890
|
+
after = []) {
|
|
699
891
|
const { int, text, blob } = dialect.types;
|
|
700
892
|
const strict = dialect.tableOptions;
|
|
701
893
|
const keyed = dialect.withoutRowidTableOptions;
|
|
@@ -713,7 +905,7 @@ async function createSnapshotIndexTables(transaction, t, prefix, dialect) {
|
|
|
713
905
|
CREATE TABLE IF NOT EXISTS ${t.sessionRefs} (session_id ${text} NOT NULL, seq ${int} NOT NULL, root ${text} NOT NULL, snapshot_id ${text} NOT NULL, prev_seq ${int}, restore_from ${text}, restore_to ${text}, degraded_from ${text}, degraded_since ${int}, PRIMARY KEY (session_id, seq))${keyed};
|
|
714
906
|
CREATE TABLE IF NOT EXISTS ${t.sessionLinks} (session_id ${text} NOT NULL, seq ${int} NOT NULL, entry_id ${text} NOT NULL, parent_id ${text}, anchor_seq ${int}, children ${int} NOT NULL, broken ${int} NOT NULL, PRIMARY KEY (session_id, seq))${strict};
|
|
715
907
|
CREATE INDEX IF NOT EXISTS ${t.sessionLinks}_entry ON ${t.sessionLinks} (session_id, entry_id);
|
|
716
|
-
|
|
908
|
+
${sessionLinksLeafIndex(t, dialect)};
|
|
717
909
|
CREATE INDEX IF NOT EXISTS ${t.sessionLinks}_broken ON ${t.sessionLinks} (session_id) WHERE broken = 1;
|
|
718
910
|
CREATE TABLE IF NOT EXISTS ${t.sessionRecords} (session_id ${text} NOT NULL, seq ${int} NOT NULL, snapshot_id ${text} NOT NULL, hash ${text} NOT NULL, PRIMARY KEY (session_id, seq, hash))${keyed};
|
|
719
911
|
CREATE INDEX IF NOT EXISTS ${t.sessionRecords}_hash ON ${t.sessionRecords} (hash);
|
|
@@ -722,6 +914,7 @@ async function createSnapshotIndexTables(transaction, t, prefix, dialect) {
|
|
|
722
914
|
CREATE TABLE IF NOT EXISTS ${t.collection} (id ${int} PRIMARY KEY CHECK (id = 1), claimed_at ${int}, holder ${text}, finished_at ${int}, deleted ${int}, error_code ${text})${strict};
|
|
723
915
|
INSERT INTO ${t.collection} (id) VALUES (1) ON CONFLICT DO NOTHING;
|
|
724
916
|
CREATE TABLE IF NOT EXISTS ${t.sources} (source ${text} PRIMARY KEY, watermark ${int} NOT NULL, backfilled_through ${int} NOT NULL)${keyed};
|
|
917
|
+
${after.map((statement) => `${statement};`).join("\n")}
|
|
725
918
|
`,
|
|
726
919
|
chunkTableDefinition(t.blobChunks, dialect),
|
|
727
920
|
], [...blobChunkProbes(transaction, t, dialect), ...sessionRefColumnProbes(transaction, t, dialect)]);
|
|
@@ -741,6 +934,124 @@ function blobMaintenanceIndexes(t) {
|
|
|
741
934
|
async function addBlobMaintenanceIndexes(transaction, t) {
|
|
742
935
|
await statementBatch(transaction, blobMaintenanceIndexes(t), []);
|
|
743
936
|
}
|
|
937
|
+
/**
|
|
938
|
+
* The ledger step, `schema:snapshot-links-hot`, after which the session links table has no index that names
|
|
939
|
+
* `children` on PostgreSQL ({@link hotSessionLinks}).
|
|
940
|
+
*/
|
|
941
|
+
const SESSION_LINKS_HOT_DOMAIN = "snapshot-links-hot";
|
|
942
|
+
function sessionLinksHotSchema(prefix) {
|
|
943
|
+
return { ledger: storageMigrationTable(prefix), domain: SESSION_LINKS_HOT_DOMAIN, revision: 1 };
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* The index the queries for the session tree's leaves read: on PostgreSQL every link with an anchor, whose leaves they
|
|
947
|
+
* pick by `children = 0` ({@link hotSessionLinks}); elsewhere only the leaves with an anchor.
|
|
948
|
+
*/
|
|
949
|
+
function sessionLinksLeafIndex(t, dialect) {
|
|
950
|
+
return dialect.name === "postgres"
|
|
951
|
+
? `CREATE INDEX IF NOT EXISTS ${t.sessionLinks}_anchored ON ${t.sessionLinks} (session_id, anchor_seq) WHERE anchor_seq IS NOT NULL`
|
|
952
|
+
: `CREATE INDEX IF NOT EXISTS ${t.sessionLinks}_leaves ON ${t.sessionLinks} (session_id, anchor_seq) WHERE children = 0 AND anchor_seq IS NOT NULL`;
|
|
953
|
+
}
|
|
954
|
+
/** The ledger record of {@link hotSessionLinks}, for a database whose links table this transaction created with it. */
|
|
955
|
+
function hotSessionLinksRecord(prefix, dialect) {
|
|
956
|
+
const { ledger, domain, revision } = sessionLinksHotSchema(prefix);
|
|
957
|
+
return `INSERT INTO ${ledger} (domain, version, applied_at) VALUES ('schema:${domain}', ${revision}, ${dialect.nowMs}) ON CONFLICT DO NOTHING`;
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* Makes the update each append writes to its parent's session link a HOT update on PostgreSQL: one that stays on its
|
|
961
|
+
* page and writes no index entry. Each append raises its parent link's `children`, and PostgreSQL updates a row in
|
|
962
|
+
* place only when no index names a changed column, its condition included, which `_leaves` (`WHERE children = 0`)
|
|
963
|
+
* did. So every append wrote the parent link's new version into each of the table's indexes. `_anchored` indexes the
|
|
964
|
+
* same rows without that condition, and the queries for leaves, which only collection runs, check `children = 0` on
|
|
965
|
+
* the rows it finds. Older builds read and write the table as before, and none of them creates `_leaves` again: on
|
|
966
|
+
* PostgreSQL the step that creates it runs once per database. Recorded in the ledger, so it runs once. SQLite keeps
|
|
967
|
+
* `_leaves`, as it updates rows in place whatever their indexes.
|
|
968
|
+
*/
|
|
969
|
+
async function hotSessionLinks(transaction, t, prefix, dialect) {
|
|
970
|
+
await ensureStorageSchema(transaction, dialect, sessionLinksHotSchema(prefix), async () => {
|
|
971
|
+
await transaction.exec(sessionLinksLeafIndex(t, dialect));
|
|
972
|
+
await transaction.exec(`DROP INDEX IF EXISTS ${t.sessionLinks}_leaves`);
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
/** This process's check of {@link hotSessionLinks} for each database, ledger and links table, while it holds. */
|
|
976
|
+
const hotSessionLinksChecks = new Map();
|
|
977
|
+
/**
|
|
978
|
+
* Runs {@link hotSessionLinks} on a PostgreSQL database whose ledger lacks it, in a transaction of its own. Nothing runs
|
|
979
|
+
* where the catalog the open read records it, or where this role does not own the links table: a runtime role without
|
|
980
|
+
* DDL opens as before, and `atomic storage migrate`, run as the owner, makes the change. A role that does not own the
|
|
981
|
+
* table finds that out once per process, as for the fillfactor steps.
|
|
982
|
+
*/
|
|
983
|
+
async function ensureHotSessionLinks(database, t, prefix) {
|
|
984
|
+
const dialect = dialectOf(database);
|
|
985
|
+
if (dialect.name !== "postgres" || database.readOnly === true)
|
|
986
|
+
return;
|
|
987
|
+
const schema = sessionLinksHotSchema(prefix);
|
|
988
|
+
if (await storageSchemaCurrent(database, schema))
|
|
989
|
+
return;
|
|
990
|
+
const identity = database.databaseIdentity?.();
|
|
991
|
+
if (identity === undefined) {
|
|
992
|
+
await checkHotSessionLinks(database, t, prefix);
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
995
|
+
const key = JSON.stringify([identity, schema.ledger, t.sessionLinks]);
|
|
996
|
+
let check = hotSessionLinksChecks.get(key);
|
|
997
|
+
if (check === undefined) {
|
|
998
|
+
const made = checkHotSessionLinks(database, t, prefix);
|
|
999
|
+
check = made;
|
|
1000
|
+
hotSessionLinksChecks.set(key, made);
|
|
1001
|
+
const forget = () => {
|
|
1002
|
+
if (hotSessionLinksChecks.get(key) === made)
|
|
1003
|
+
hotSessionLinksChecks.delete(key);
|
|
1004
|
+
};
|
|
1005
|
+
made.then((settled) => {
|
|
1006
|
+
if (!settled)
|
|
1007
|
+
forget();
|
|
1008
|
+
}, forget);
|
|
1009
|
+
}
|
|
1010
|
+
await check;
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* The largest links table, in bytes, an open builds {@link hotSessionLinks}'s index for in its own transaction, which
|
|
1014
|
+
* holds the table's writes for the build: about 150,000 links, a fraction of a second. A larger one is left to `atomic
|
|
1015
|
+
* storage migrate`, which builds the index without holding them ({@link SqlSnapshotBlobStore.buildHotSessionLinksIndex}).
|
|
1016
|
+
*/
|
|
1017
|
+
const HOT_SESSION_LINKS_OPEN_BUILD_BYTES = 16 * 1024 * 1024;
|
|
1018
|
+
/** How often {@link SqlSnapshotBlobStore.buildHotSessionLinksIndex} looks again at an index build another process runs. */
|
|
1019
|
+
const HOT_SESSION_LINKS_BUILD_POLL_MS = 500;
|
|
1020
|
+
/** The links table's owner, size and `_anchored` index, in one read; `undefined` when the table does not exist. */
|
|
1021
|
+
async function sessionLinksState(database, t, dialect) {
|
|
1022
|
+
const row = await database.get(`SELECT pg_catalog.pg_has_role(current_user, c.relowner, 'USAGE') AS owned, pg_catalog.pg_relation_size(c.oid) AS bytes,
|
|
1023
|
+
(SELECT x.indisvalid FROM pg_catalog.pg_index x JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid
|
|
1024
|
+
WHERE x.indrelid = c.oid AND i.relname = ?) AS anchored,
|
|
1025
|
+
EXISTS (SELECT 1 FROM pg_catalog.pg_stat_progress_create_index p WHERE p.relid = c.oid) AS building
|
|
1026
|
+
FROM pg_catalog.pg_class c WHERE c.relnamespace = current_schema()::regnamespace AND c.relname = ?`, dialect.identifier(`${t.sessionLinks}_anchored`), dialect.identifier(t.sessionLinks));
|
|
1027
|
+
if (row === undefined)
|
|
1028
|
+
return undefined;
|
|
1029
|
+
const yes = (value) => value === true || Number(value) === 1;
|
|
1030
|
+
return {
|
|
1031
|
+
owned: yes(row.owned),
|
|
1032
|
+
bytes: Number(row.bytes),
|
|
1033
|
+
anchored: row.anchored === null ? undefined : yes(row.anchored),
|
|
1034
|
+
building: yes(row.building),
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* Runs {@link hotSessionLinks} where this role owns a small links table; true when this process need not check again.
|
|
1039
|
+
* A large table, or one whose `_anchored` index a build of `atomic storage migrate` left unfinished or is making now,
|
|
1040
|
+
* is left to `atomic storage migrate`.
|
|
1041
|
+
*/
|
|
1042
|
+
async function checkHotSessionLinks(database, t, prefix) {
|
|
1043
|
+
const dialect = dialectOf(database);
|
|
1044
|
+
const found = await sessionLinksState(database, t, dialect);
|
|
1045
|
+
if (found === undefined)
|
|
1046
|
+
return false;
|
|
1047
|
+
if (!found.owned || found.bytes > HOT_SESSION_LINKS_OPEN_BUILD_BYTES || found.anchored === false || found.building)
|
|
1048
|
+
return true;
|
|
1049
|
+
await database.transaction((transaction) => hotSessionLinks(transaction, t, prefix, dialect), {
|
|
1050
|
+
retryTransientFailures: true,
|
|
1051
|
+
concurrency: { kind: "serial", domain: sessionLinksHotSchema(prefix).ledger },
|
|
1052
|
+
});
|
|
1053
|
+
return false;
|
|
1054
|
+
}
|
|
744
1055
|
/** The columns of {@link SnapshotIndexTables.sessionRefs} that later builds added, with their types. */
|
|
745
1056
|
const SESSION_REF_COLUMNS = ["prev_seq", "restore_from", "restore_to", "degraded_from", "degraded_since"];
|
|
746
1057
|
/** Whether the session references have each of {@link SESSION_REF_COLUMNS}, in its order. */
|
|
@@ -830,7 +1141,7 @@ async function installSource(transaction, dialect, t, source, reset) {
|
|
|
830
1141
|
}
|
|
831
1142
|
/**
|
|
832
1143
|
* Whether this build writes `source`'s {@link IndexSource.version} row only once its own backfill of the source is done:
|
|
833
|
-
* on SQLite
|
|
1144
|
+
* on SQLite, which builds before 0.9.88 also open (#5558).
|
|
834
1145
|
*/
|
|
835
1146
|
function withholdsVersion(dialect, source) {
|
|
836
1147
|
return dialect.name === "sqlite" && source.version !== undefined && source.own !== undefined;
|
|
@@ -868,7 +1179,7 @@ function sourceProgressRead(t) {
|
|
|
868
1179
|
async function readSourceStates(executor, dialect, t, sources, listRetired = false, present, also) {
|
|
869
1180
|
// `also` asks, in the same statement, which of other objects exist, as `also.found` tells.
|
|
870
1181
|
const names = [...sourceObjectNames(sources), ...(also?.names ?? [])];
|
|
871
|
-
// Builds before 0.9.88 open SQLite
|
|
1182
|
+
// Builds before 0.9.88 open SQLite databases only, so only there can a trigger of this build's name be
|
|
872
1183
|
// one that indexes less.
|
|
873
1184
|
const sqlite = dialect.name === "sqlite";
|
|
874
1185
|
const signatures = sqlite ? sources.flatMap((source) => source.signature ?? []) : [];
|
|
@@ -1033,9 +1344,27 @@ export class SqlSnapshotBlobStore {
|
|
|
1033
1344
|
: (await Promise.all(probes.map((probe) => database.get(probe.sql, ...probe.params)))).every((row) => row !== undefined);
|
|
1034
1345
|
// A versioned database always checks its ledger: a newer schema with the same tables is refused, and a step it
|
|
1035
1346
|
// lacks, such as the index triggers, runs even when every table exists.
|
|
1347
|
+
// Whether this open created the tables on PostgreSQL, and with them the links indexes of {@link hotSessionLinks}.
|
|
1348
|
+
let linksHot = false;
|
|
1036
1349
|
if (!current) {
|
|
1037
|
-
await applyStorageMigrations(database, SNAPSHOT_BLOB_DOMAIN, [
|
|
1038
|
-
{
|
|
1350
|
+
const migrated = await applyStorageMigrations(database, SNAPSHOT_BLOB_DOMAIN, [
|
|
1351
|
+
{
|
|
1352
|
+
version: 1,
|
|
1353
|
+
up: async (transaction, dialect) => {
|
|
1354
|
+
// On PostgreSQL the tables come with the links index of {@link hotSessionLinks}, without one an
|
|
1355
|
+
// earlier build made, recorded in the ledger in the same request: a new database takes no extra
|
|
1356
|
+
// round trip for it. Where forks share history, as a new database's do from its first open, the
|
|
1357
|
+
// guard that keeps what they inherit comes with them in that request too (fork-blob-guard.ts).
|
|
1358
|
+
const hot = dialect.name === "postgres";
|
|
1359
|
+
await createSnapshotIndexTables(transaction, t, prefix, dialect, [
|
|
1360
|
+
...(hot
|
|
1361
|
+
? [`DROP INDEX IF EXISTS ${t.sessionLinks}_leaves`, hotSessionLinksRecord(prefix, dialect)]
|
|
1362
|
+
: []),
|
|
1363
|
+
...((await shared) ? [forkInheritedBlobGuard(dialect, t, segments).replace(/;\s*$/, "")] : []),
|
|
1364
|
+
]);
|
|
1365
|
+
linksHot = hot;
|
|
1366
|
+
},
|
|
1367
|
+
},
|
|
1039
1368
|
// Where a ledger records the steps, it records the index triggers too, installed under the migration lock.
|
|
1040
1369
|
// Without one, installIndex below installs each source in a transaction of its own, as it always has.
|
|
1041
1370
|
...(dialect.versionedMigrations
|
|
@@ -1064,11 +1393,64 @@ export class SqlSnapshotBlobStore {
|
|
|
1064
1393
|
]
|
|
1065
1394
|
: []),
|
|
1066
1395
|
], { table: storageMigrationTable(prefix) });
|
|
1396
|
+
// The session store's open, which asks the catalog for the guard next, finds it without reading the schema again.
|
|
1397
|
+
if (migrated.applied.includes(1) && (await shared))
|
|
1398
|
+
noteStorageSchemaTables(database, [forkInheritedBlobGuardName(t.blobs)]);
|
|
1067
1399
|
}
|
|
1400
|
+
if (!linksHot)
|
|
1401
|
+
await ensureHotSessionLinks(database, t, prefix);
|
|
1068
1402
|
const store = new SqlSnapshotBlobStore(database, dialect, t, indexSources(prefix, t, dialect, (await shared) ? segments : undefined), segments);
|
|
1069
1403
|
await store.installIndex(undefined, false, await schemaCatalogOf(database));
|
|
1070
1404
|
return store;
|
|
1071
1405
|
}
|
|
1406
|
+
/**
|
|
1407
|
+
* Gives a PostgreSQL database's session links the index of {@link hotSessionLinks} without holding the table's writes,
|
|
1408
|
+
* as `atomic storage migrate` does where an open would not ({@link HOT_SESSION_LINKS_OPEN_BUILD_BYTES}). Each step
|
|
1409
|
+
* runs on its own, outside a transaction: `CREATE INDEX CONCURRENTLY` builds `_anchored`, `DROP INDEX CONCURRENTLY`
|
|
1410
|
+
* removes `_leaves`, and only then does the ledger record the step. A build that stopped part way, which leaves an
|
|
1411
|
+
* invalid `_anchored`, is dropped and made again; one another process is making is waited for. Nothing runs where the
|
|
1412
|
+
* ledger records the step, where the table does not exist yet (its first open creates it with the index), or where
|
|
1413
|
+
* this role does not own it. `database` should allow a statement as long as the build takes.
|
|
1414
|
+
*/
|
|
1415
|
+
static async buildHotSessionLinksIndex(database, prefix = "") {
|
|
1416
|
+
const dialect = dialectOf(database);
|
|
1417
|
+
if (dialect.name !== "postgres")
|
|
1418
|
+
return "current";
|
|
1419
|
+
const t = snapshotIndexTables(prefix);
|
|
1420
|
+
const schema = sessionLinksHotSchema(prefix);
|
|
1421
|
+
const recorded = async () => {
|
|
1422
|
+
const ledger = dialect.tableExists(schema.ledger);
|
|
1423
|
+
if ((await database.get(ledger.sql, ...ledger.params)) === undefined)
|
|
1424
|
+
return false;
|
|
1425
|
+
return ((await database.get(`SELECT 1 AS found FROM ${schema.ledger} WHERE domain = ? AND version >= ?`, `schema:${schema.domain}`, schema.revision)) !== undefined);
|
|
1426
|
+
};
|
|
1427
|
+
if (await recorded())
|
|
1428
|
+
return "current";
|
|
1429
|
+
for (;;) {
|
|
1430
|
+
const found = await sessionLinksState(database, t, dialect);
|
|
1431
|
+
if (found === undefined)
|
|
1432
|
+
return "absent";
|
|
1433
|
+
if (!found.owned)
|
|
1434
|
+
return "not-owner";
|
|
1435
|
+
if (found.building) {
|
|
1436
|
+
// Another process builds an index of the table, perhaps this one: its outcome decides what is left to do.
|
|
1437
|
+
await new Promise((resolve) => setTimeout(resolve, HOT_SESSION_LINKS_BUILD_POLL_MS));
|
|
1438
|
+
continue;
|
|
1439
|
+
}
|
|
1440
|
+
if (found.anchored === false)
|
|
1441
|
+
await database.exec(`DROP INDEX CONCURRENTLY IF EXISTS ${t.sessionLinks}_anchored`);
|
|
1442
|
+
if (found.anchored !== true)
|
|
1443
|
+
await database.exec(sessionLinksLeafIndex(t, dialect).replace("CREATE INDEX", "CREATE INDEX CONCURRENTLY"));
|
|
1444
|
+
break;
|
|
1445
|
+
}
|
|
1446
|
+
await database.exec(`DROP INDEX CONCURRENTLY IF EXISTS ${t.sessionLinks}_leaves`);
|
|
1447
|
+
// The index is in place, so the record runs no DDL, which would wait for the table's writes.
|
|
1448
|
+
await database.transaction((transaction) => ensureStorageSchema(transaction, dialect, schema, async () => { }), {
|
|
1449
|
+
retryTransientFailures: true,
|
|
1450
|
+
concurrency: { kind: "serial", domain: schema.ledger },
|
|
1451
|
+
});
|
|
1452
|
+
return "built";
|
|
1453
|
+
}
|
|
1072
1454
|
/** Runs only layout maintenance on the offline command's dedicated, exclusively locked SQLite file connection. */
|
|
1073
1455
|
static async moveChunksOffline(file, prefix = "") {
|
|
1074
1456
|
const tables = snapshotIndexTables(prefix);
|
|
@@ -1474,11 +1856,16 @@ export class SqlSnapshotBlobStore {
|
|
|
1474
1856
|
await transaction.run(sql, from, upper);
|
|
1475
1857
|
if (source.rowwise !== undefined) {
|
|
1476
1858
|
const rows = await transaction.all(`SELECT ${row} AS id FROM ${source.table} WHERE ${row} > ? AND ${row} <= ? ORDER BY ${row}`, from, upper);
|
|
1859
|
+
// The session entries are linked in each session's seq order, whatever order their rows are stored in (#6560).
|
|
1860
|
+
const linking = source.name === "session-entries" ? entryLinking(source, this.dialect, t.sessionLinks) : undefined;
|
|
1477
1861
|
for (const { id } of rows) {
|
|
1478
1862
|
// Stopping between rows rolls the whole batch back, progress included, so the pass stays resumable.
|
|
1479
1863
|
signal?.throwIfAborted();
|
|
1480
|
-
|
|
1481
|
-
await transaction
|
|
1864
|
+
if (linking !== undefined)
|
|
1865
|
+
await linkStoredEntry(transaction, linking, id);
|
|
1866
|
+
else
|
|
1867
|
+
for (const sql of source.rowwise)
|
|
1868
|
+
await transaction.run(sql, id);
|
|
1482
1869
|
}
|
|
1483
1870
|
}
|
|
1484
1871
|
// Indexing rows again behind the source's progress, for this build's own, never moves the progress back.
|
|
@@ -1628,6 +2015,12 @@ export class SqlSnapshotBlobStore {
|
|
|
1628
2015
|
* and the sessions that record its blobs now. A blob a session the sweep did not walk records, such as one created
|
|
1629
2016
|
* since, is kept; the next collection walks that session. Nothing in the transaction waits for a turn of the event
|
|
1630
2017
|
* loop (#5530).
|
|
2018
|
+
*
|
|
2019
|
+
* It runs as a whole-database transaction on purpose, so no other write runs beside it. With only the blob table's
|
|
2020
|
+
* lock it would not be safe: it decides which blobs sessions still use in one statement and deletes in the next. A
|
|
2021
|
+
* session write that records a blob meanwhile holds the blob's row only until it commits its reference; the delete
|
|
2022
|
+
* waits for it, then goes ahead without looking at the references again, and removes a blob a session has just
|
|
2023
|
+
* recorded. The same goes for the references retaining runs and carried work write.
|
|
1631
2024
|
*/
|
|
1632
2025
|
deleteUnretained(batch, minimumAge, options) {
|
|
1633
2026
|
const t = this.tables;
|
|
@@ -1957,7 +2350,7 @@ export class SqlSnapshotBlobStore {
|
|
|
1957
2350
|
Reflect.defineProperty(error, RENAME_BLOCKER, { value: { type: only.type, name: only.name } });
|
|
1958
2351
|
}
|
|
1959
2352
|
/**
|
|
1960
|
-
* Whether the file system of a SQLite
|
|
2353
|
+
* Whether the file system of a SQLite database file has room to copy what is left of the chunk table to the
|
|
1961
2354
|
* row layout (#5694): the copy grows the file by the bytes its free pages do not hold, and the write-ahead log can
|
|
1962
2355
|
* hold every page the copy writes until a checkpoint moves them into the file, with
|
|
1963
2356
|
* {@link SNAPSHOT_CHUNK_MOVE_HEADROOM_BYTES} left over; the database's own `freeBytes` says how much the file system
|
|
@@ -2161,7 +2554,7 @@ function __atomicOnDemandFailed(error, feature) {
|
|
|
2161
2554
|
return (async () => {
|
|
2162
2555
|
const root = new URL("../../", import.meta.url);
|
|
2163
2556
|
const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
|
|
2164
|
-
const key = `${root.href}#0.10.11-alpha.
|
|
2557
|
+
const key = `${root.href}#0.10.11-alpha.3`;
|
|
2165
2558
|
let release = releases.get(key);
|
|
2166
2559
|
if (release === undefined) {
|
|
2167
2560
|
const current = (async () => {
|
|
@@ -2189,7 +2582,7 @@ function __atomicOnDemandFailed(error, feature) {
|
|
|
2189
2582
|
} catch {
|
|
2190
2583
|
// No installation to read, as in a bundle of the package: the release the process runs decides.
|
|
2191
2584
|
}
|
|
2192
|
-
const updatedTo = typeof installed === "string" && installed !== "0.10.11-alpha.
|
|
2585
|
+
const updatedTo = typeof installed === "string" && installed !== "0.10.11-alpha.3" ? installed : running !== undefined && running.version !== "0.10.11-alpha.3" ? "0.10.11-alpha.3" : undefined;
|
|
2193
2586
|
if (updatedTo === undefined) throw error;
|
|
2194
2587
|
const application = typeof running?.name === "string" ? running.name : "atomic";
|
|
2195
2588
|
const restart = new Error(`${application} was updated to ${updatedTo} while this session was running; restart it to keep using ${feature}.`, {
|