@ref0/git 0.3.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.mjs +12 -0
- package/dist/access/private-refs.d.mts +12 -9
- package/dist/access/private-refs.mjs +70 -48
- package/dist/auth/access-jwt.mjs +7 -7
- package/dist/auth/auth.d.mts +41 -0
- package/dist/auth/auth.mjs +39 -0
- package/dist/auth/authorize.mjs +65 -83
- package/dist/auth/bridge.mjs +30 -0
- package/dist/auth/fences.d.mts +22 -2
- package/dist/auth/fences.mjs +3 -3
- package/dist/auth/grants.d.mts +25 -0
- package/dist/auth/grants.mjs +29 -34
- package/dist/auth/helpers.mjs +4 -4
- package/dist/auth/host-function.d.mts +9 -2
- package/dist/auth/host-function.mjs +35 -8
- package/dist/auth/identify.d.mts +7 -2
- package/dist/auth/identify.mjs +9 -11
- package/dist/auth/namespaces.d.mts +3 -0
- package/dist/auth/policy.d.mts +57 -0
- package/dist/auth/policy.mjs +56 -0
- package/dist/auth/token-rows.mjs +6 -6
- package/dist/auth/token-text.mjs +16 -4
- package/dist/auth/tokens.d.mts +3 -0
- package/dist/auth/tokens.mjs +63 -24
- package/dist/auth.d.mts +2 -1
- package/dist/auth.mjs +2 -1
- package/dist/client/answer.mjs +49 -11
- package/dist/client/client.d.mts +2 -2
- package/dist/client/client.mjs +3 -3
- package/dist/client/git-http.d.mts +6 -0
- package/dist/client/git-http.mjs +23 -36
- package/dist/client/helper-node.d.mts +12 -0
- package/dist/client/helper-node.mjs +108 -5
- package/dist/client/local.mjs +96 -99
- package/dist/client/negotiate.mjs +10 -8
- package/dist/client/push-upload.d.mts +14 -0
- package/dist/client/push-upload.mjs +12 -12
- package/dist/client/remote-helper.mjs +22 -20
- package/dist/client/remote.mjs +28 -22
- package/dist/client/run-remote-helper.d.mts +40 -16
- package/dist/client/run-remote-helper.mjs +147 -154
- package/dist/client/scrub.d.mts +8 -2
- package/dist/client/scrub.mjs +76 -4
- package/dist/client/slice-push.d.mts +77 -0
- package/dist/client/slice-push.mjs +169 -0
- package/dist/client/slice-report.mjs +188 -0
- package/dist/client/slices.d.mts +44 -0
- package/dist/client/slices.mjs +131 -0
- package/dist/client/transport.d.mts +1 -0
- package/dist/client/transport.mjs +30 -26
- package/dist/contracts/access.d.mts +41 -10
- package/dist/contracts/actors.d.mts +28 -10
- package/dist/contracts/actors.mjs +17 -0
- package/dist/contracts/authorize.d.mts +81 -0
- package/dist/contracts/authorize.mjs +25 -0
- package/dist/contracts/blobs.d.mts +48 -15
- package/dist/contracts/blobs.mjs +30 -0
- package/dist/contracts/calls-spent.d.mts +1 -0
- package/dist/contracts/calls-spent.mjs +58 -18
- package/dist/contracts/client.d.mts +14 -16
- package/dist/contracts/commits.d.mts +558 -76
- package/dist/contracts/commits.mjs +147 -0
- package/dist/contracts/engine.d.mts +91 -55
- package/dist/contracts/engine.mjs +103 -0
- package/dist/contracts/events.d.mts +1410 -206
- package/dist/contracts/events.mjs +496 -0
- package/dist/contracts/files.d.mts +295 -50
- package/dist/contracts/files.mjs +100 -0
- package/dist/contracts/forks.d.mts +306 -25
- package/dist/contracts/forks.mjs +39 -0
- package/dist/contracts/git.d.mts +172 -0
- package/dist/contracts/git.mjs +23 -0
- package/dist/contracts/grants.d.mts +7 -2
- package/dist/contracts/ids.d.mts +23 -8
- package/dist/contracts/ids.mjs +40 -5
- package/dist/contracts/lfs.d.mts +12 -4
- package/dist/contracts/merges.d.mts +68 -16
- package/dist/contracts/merges.mjs +27 -0
- package/dist/contracts/namespaces.d.mts +14 -0
- package/dist/contracts/object-values.d.mts +96 -0
- package/dist/contracts/object-values.mjs +104 -0
- package/dist/contracts/objects.d.mts +329 -88
- package/dist/contracts/operations.d.mts +24 -16
- package/dist/contracts/promises.d.mts +10 -11
- package/dist/contracts/push-uploads.d.mts +40 -25
- package/dist/contracts/push-uploads.mjs +54 -0
- package/dist/contracts/queue.d.mts +454 -141
- package/dist/contracts/queue.mjs +197 -0
- package/dist/contracts/refs.d.mts +248 -45
- package/dist/contracts/refs.mjs +117 -0
- package/dist/contracts/repo-records.d.mts +34 -0
- package/dist/contracts/repo-records.mjs +18 -0
- package/dist/contracts/repos.d.mts +411 -58
- package/dist/contracts/repos.mjs +136 -0
- package/dist/contracts/result.d.mts +339 -69
- package/dist/contracts/result.mjs +355 -5
- package/dist/contracts/rules.d.mts +60 -48
- package/dist/contracts/rules.mjs +9 -0
- package/dist/contracts/server.d.mts +124 -51
- package/dist/contracts/services.d.mts +15 -24
- package/dist/contracts/services.mjs +5 -9
- package/dist/contracts/signin.d.mts +64 -31
- package/dist/contracts/signin.mjs +18 -0
- package/dist/contracts/store.d.mts +45 -5
- package/dist/contracts/store.mjs +31 -0
- package/dist/contracts/sync.d.mts +81 -46
- package/dist/contracts/sync.mjs +41 -2
- package/dist/contracts/tags.d.mts +204 -22
- package/dist/contracts/tags.mjs +51 -1
- package/dist/contracts/tokens.d.mts +32 -7
- package/dist/contracts/tokens.mjs +31 -1
- package/dist/contracts/topics.d.mts +123 -67
- package/dist/contracts/topics.mjs +109 -0
- package/dist/contracts/trees.d.mts +132 -52
- package/dist/contracts/trees.mjs +105 -0
- package/dist/contracts/work.d.mts +128 -21
- package/dist/contracts/work.mjs +69 -0
- package/dist/core/access.d.mts +25 -14
- package/dist/core/access.mjs +93 -108
- package/dist/core/ancestry.mjs +86 -18
- package/dist/core/call-names.d.mts +3 -1
- package/dist/core/call-names.mjs +1 -0
- package/dist/core/call-services.mjs +73 -0
- package/dist/core/changes.d.mts +31 -0
- package/dist/core/changes.mjs +5 -0
- package/dist/core/claim-rows.d.mts +4 -0
- package/dist/core/claim-rows.mjs +53 -0
- package/dist/core/clock.mjs +3 -3
- package/dist/core/events/deliver.d.mts +12 -0
- package/dist/core/events/deliver.mjs +454 -146
- package/dist/core/events/seen.mjs +138 -0
- package/dist/core/forks.mjs +435 -161
- package/dist/core/hooks/order.d.mts +9 -0
- package/dist/core/hooks/order.mjs +25 -0
- package/dist/core/hooks/post-receive.mjs +33 -29
- package/dist/core/hooks/pre-receive.d.mts +8 -1
- package/dist/core/hooks/pre-receive.mjs +8 -6
- package/dist/core/imports.mjs +212 -0
- package/dist/core/index-job.mjs +152 -53
- package/dist/core/merge-parts.d.mts +30 -0
- package/dist/core/merge-parts.mjs +31 -0
- package/dist/core/names.mjs +4 -16
- package/dist/core/namespaces.d.mts +2 -0
- package/dist/core/objects/blobs.mjs +4 -4
- package/dist/core/objects/commit-writes.mjs +19 -17
- package/dist/core/objects/commits.mjs +12 -12
- package/dist/core/objects/files.mjs +10 -11
- package/dist/core/objects/lines.mjs +15 -32
- package/dist/core/objects/merges.mjs +4 -4
- package/dist/core/objects/objects-layer.d.mts +21 -0
- package/dist/core/objects/objects-layer.mjs +47 -0
- package/dist/core/objects/objects-namespace.d.mts +6 -0
- package/dist/core/objects/objects-namespace.mjs +13 -0
- package/dist/core/objects/objects.d.mts +49 -0
- package/dist/core/objects/objects.mjs +18 -0
- package/dist/core/objects/peel.mjs +3 -3
- package/dist/core/objects/reading.mjs +135 -40
- package/dist/core/objects/tags.mjs +7 -7
- package/dist/core/objects/tree-edits.mjs +40 -27
- package/dist/core/objects/trees.mjs +23 -18
- package/dist/core/objects/writing.mjs +43 -44
- package/dist/core/own-writes.mjs +3 -3
- package/dist/core/parts.d.mts +131 -0
- package/dist/core/parts.mjs +59 -0
- package/dist/core/promise.mjs +13 -9
- package/dist/core/publish.mjs +27 -17
- package/dist/core/purge.d.mts +8 -0
- package/dist/core/purge.mjs +237 -0
- package/dist/core/push-decide.mjs +116 -29
- package/dist/core/push.mjs +352 -171
- package/dist/core/receipts.d.mts +4 -3
- package/dist/core/receipts.mjs +20 -12
- package/dist/core/ref-conflicts.mjs +70 -4
- package/dist/core/ref-index-job.mjs +176 -0
- package/dist/core/ref-index.d.mts +26 -0
- package/dist/core/ref-index.mjs +156 -0
- package/dist/core/ref-view.mjs +171 -0
- package/dist/core/refs.mjs +318 -98
- package/dist/core/repack.d.mts +11 -0
- package/dist/core/repack.mjs +264 -136
- package/dist/core/repo-info.mjs +99 -0
- package/dist/core/repos.mjs +114 -80
- package/dist/core/rules/changes.mjs +48 -20
- package/dist/core/rules/check.mjs +36 -28
- package/dist/core/rules/commit-changes.d.mts +13 -0
- package/dist/core/rules/commit-changes.mjs +100 -91
- package/dist/core/rules/context.d.mts +67 -8
- package/dist/core/rules/context.mjs +88 -51
- package/dist/core/rules/facts.mjs +1 -1
- package/dist/core/rules/fetch.mjs +24 -26
- package/dist/core/rules/files.d.mts +13 -0
- package/dist/core/rules/files.mjs +27 -28
- package/dist/core/rules/namespace.d.mts +2 -0
- package/dist/core/rules/patterns.mjs +29 -5
- package/dist/core/rules/protect.d.mts +12 -6
- package/dist/core/rules/protect.mjs +22 -20
- package/dist/core/rules/rules-layer.d.mts +17 -0
- package/dist/core/rules/rules-layer.mjs +26 -0
- package/dist/core/rules/rules.d.mts +8 -0
- package/dist/core/rules/rules.mjs +16 -0
- package/dist/core/rules/service.mjs +18 -0
- package/dist/core/seam.d.mts +60 -10
- package/dist/core/seam.mjs +25 -15
- package/dist/core/still-takes.mjs +75 -0
- package/dist/core/tokens.mjs +29 -23
- package/dist/core/view.d.mts +106 -6
- package/dist/core/view.mjs +215 -114
- package/dist/core/work.mjs +40 -14
- package/dist/effect.d.mts +3 -4
- package/dist/effect.mjs +2 -3
- package/dist/engine/allotted-xdiff.d.mts +1 -0
- package/dist/engine/allotted-xdiff.mjs +1 -1
- package/dist/engine/attributes.mjs +1 -1
- package/dist/engine/combined.d.mts +18 -0
- package/dist/engine/combined.mjs +39 -44
- package/dist/engine/commits.mjs +5 -4
- package/dist/engine/content.d.mts +3 -2
- package/dist/engine/content.mjs +2 -2
- package/dist/engine/failures.d.mts +2 -2
- package/dist/engine/failures.mjs +2 -9
- package/dist/engine/merge-base-walk.d.mts +3 -2
- package/dist/engine/merge-base-walk.mjs +1 -1
- package/dist/engine/merge-bases.mjs +3 -2
- package/dist/engine/merge.mjs +568 -566
- package/dist/engine/parts.d.mts +3 -2
- package/dist/engine/parts.mjs +40 -7
- package/dist/engine/reads.d.mts +1 -0
- package/dist/engine/reads.mjs +5 -5
- package/dist/engine/walk.mjs +23 -24
- package/dist/engine/xdiff.d.mts +2 -33
- package/dist/engine/xdiff.mjs +6 -3
- package/dist/event-streams/event-streams.d.mts +25 -0
- package/dist/event-streams/event-streams.mjs +22 -0
- package/dist/event-streams/namespace.d.mts +2 -0
- package/dist/event-streams/stream.d.mts +42 -0
- package/dist/{core/events → event-streams}/stream.mjs +106 -49
- package/dist/extend.d.mts +5 -2
- package/dist/http/answers.mjs +8 -4
- package/dist/http/bodies.mjs +84 -56
- package/dist/http/core-parts.mjs +222 -68
- package/dist/http/handler.d.mts +2 -0
- package/dist/http/handler.mjs +19 -13
- package/dist/http/node.d.mts +2 -23
- package/dist/http/node.mjs +10 -6
- package/dist/http/parts.d.mts +13 -0
- package/dist/http/push-uploads.d.mts +17 -0
- package/dist/http/push-uploads.mjs +94 -87
- package/dist/http/receive-pack.mjs +165 -29
- package/dist/http/upload-pack.mjs +106 -81
- package/dist/index.d.mts +52 -28
- package/dist/index.mjs +31 -7
- package/dist/lfs/base.d.mts +32 -0
- package/dist/lfs/base.mjs +8 -0
- package/dist/lfs/calls.mjs +21 -12
- package/dist/lfs/layer.d.mts +27 -0
- package/dist/lfs/layer.mjs +64 -0
- package/dist/lfs/locks.mjs +36 -46
- package/dist/lfs/namespace.d.mts +2 -0
- package/dist/lfs/objects.d.mts +26 -0
- package/dist/lfs/objects.mjs +83 -94
- package/dist/lfs/pointers.mjs +13 -11
- package/dist/lfs/public.d.mts +5 -0
- package/dist/lfs/public.mjs +8 -0
- package/dist/lfs/purge.mjs +44 -0
- package/dist/lfs/rows.mjs +30 -18
- package/dist/lfs/service.d.mts +14 -0
- package/dist/lfs/service.mjs +26 -28
- package/dist/lfs/upkeep.mjs +39 -54
- package/dist/lfs/wire.mjs +80 -38
- package/dist/merges/merges.d.mts +20 -0
- package/dist/merges/merges.mjs +32 -0
- package/dist/merges/namespace.d.mts +2 -0
- package/dist/merges/public.d.mts +6 -0
- package/dist/merges/public.mjs +10 -0
- package/dist/node.d.mts +3 -3
- package/dist/node.mjs +1 -3
- package/dist/protocol/bytes/buffers.d.mts +9 -3
- package/dist/protocol/bytes/buffers.mjs +11 -5
- package/dist/protocol/bytes/deflate.d.mts +7 -5
- package/dist/protocol/bytes/deflate.mjs +59 -23
- package/dist/protocol/bytes/inflate.d.mts +4 -3
- package/dist/protocol/bytes/inflate.mjs +61 -26
- package/dist/protocol/bytes/reader.mjs +61 -0
- package/dist/protocol/bytes/sha1-hasher.d.mts +3 -1
- package/dist/protocol/bytes/sha1-hasher.mjs +13 -3
- package/dist/protocol/bytes/sha1.d.mts +1 -1
- package/dist/protocol/bytes/sha1.mjs +5 -5
- package/dist/protocol/bytes/streams.mjs +16 -6
- package/dist/protocol/diff/patch.d.mts +4 -0
- package/dist/protocol/diff/patch.mjs +1 -1
- package/dist/protocol/diff/paths.mjs +1 -1
- package/dist/protocol/diff/read.d.mts +1 -1
- package/dist/protocol/diff/read.mjs +102 -90
- package/dist/protocol/framing/pkt-line.d.mts +1 -0
- package/dist/protocol/framing/pkt-line.mjs +40 -6
- package/dist/protocol/objects/checked-blobs.d.mts +1 -0
- package/dist/protocol/objects/fsck.mjs +7 -1
- package/dist/protocol/objects/held.mjs +5 -11
- package/dist/protocol/objects/ident.mjs +1 -1
- package/dist/protocol/objects/object-rules.mjs +15 -7
- package/dist/protocol/objects/object.d.mts +6 -2
- package/dist/protocol/objects/object.mjs +5 -2
- package/dist/protocol/objects/tag.d.mts +3 -1
- package/dist/protocol/objects/tag.mjs +27 -1
- package/dist/protocol/objects/tree.mjs +1 -1
- package/dist/protocol/packs/delta.d.mts +1 -1
- package/dist/protocol/packs/delta.mjs +2 -2
- package/dist/protocol/packs/graph.mjs +55 -56
- package/dist/protocol/packs/idx.d.mts +4 -2
- package/dist/protocol/packs/idx.mjs +156 -63
- package/dist/protocol/packs/indexer.d.mts +22 -4
- package/dist/protocol/packs/indexer.mjs +14 -35
- package/dist/protocol/packs/parts.mjs +5 -5
- package/dist/protocol/packs/pos.mjs +12 -5
- package/dist/protocol/packs/reader.d.mts +19 -12
- package/dist/protocol/packs/reader.mjs +252 -25
- package/dist/protocol/packs/rev.d.mts +1 -1
- package/dist/protocol/packs/rev.mjs +42 -24
- package/dist/protocol/packs/types-file.mjs +85 -0
- package/dist/protocol/packs/write-error.d.mts +1 -1
- package/dist/protocol/packs/write-error.mjs +2 -2
- package/dist/protocol/packs/writer.d.mts +40 -15
- package/dist/protocol/packs/writer.mjs +142 -49
- package/dist/protocol/wire/advertisement.d.mts +34 -15
- package/dist/protocol/wire/advertisement.mjs +135 -35
- package/dist/protocol/wire/fetch.d.mts +57 -19
- package/dist/protocol/wire/fetch.mjs +57 -26
- package/dist/protocol/wire/json.mjs +25 -0
- package/dist/protocol/wire/lines.d.mts +22 -0
- package/dist/protocol/wire/lines.mjs +51 -26
- package/dist/protocol/wire/push-limits.d.mts +6 -0
- package/dist/protocol/wire/push-limits.mjs +88 -0
- package/dist/protocol/wire/push-uploads.mjs +3 -28
- package/dist/protocol/wire/receive-pack.d.mts +30 -14
- package/dist/protocol/wire/receive-pack.mjs +29 -2
- package/dist/protocol/wire/report-status.d.mts +30 -11
- package/dist/protocol/wire/report-status.mjs +21 -2
- package/dist/protocol/wire/v2.d.mts +45 -29
- package/dist/protocol/wire/v2.mjs +95 -18
- package/dist/protocol.d.mts +4 -3
- package/dist/protocol.mjs +7 -6
- package/dist/queue/advance.mjs +240 -148
- package/dist/queue/callers.mjs +12 -9
- package/dist/queue/calls.mjs +315 -157
- package/dist/queue/commit.mjs +86 -35
- package/dist/queue/host.d.mts +39 -12
- package/dist/queue/host.mjs +36 -38
- package/dist/queue/lanes.mjs +1 -1
- package/dist/queue/layer.d.mts +16 -0
- package/dist/queue/layer.mjs +60 -0
- package/dist/queue/limits.mjs +43 -2
- package/dist/queue/namespace.d.mts +2 -0
- package/dist/queue/pages.mjs +1 -1
- package/dist/queue/public.d.mts +6 -0
- package/dist/queue/public.mjs +21 -0
- package/dist/queue/push-option.mjs +49 -30
- package/dist/queue/rows.mjs +38 -21
- package/dist/queue/schedule.mjs +22 -22
- package/dist/queue/search.mjs +8 -7
- package/dist/queue/state.mjs +68 -18
- package/dist/queue/steps.mjs +16 -7
- package/dist/queue/trim.mjs +284 -0
- package/dist/remote-helper.d.mts +5 -2
- package/dist/remote-helper.mjs +5 -2
- package/dist/rest/api.d.mts +1 -1
- package/dist/rest/blobs.d.mts +799 -32
- package/dist/rest/blobs.mjs +4 -4
- package/dist/rest/caller.d.mts +4163 -36
- package/dist/rest/caller.mjs +2 -2
- package/dist/rest/client.mjs +80 -70
- package/dist/rest/commits.d.mts +3261 -190
- package/dist/rest/commits.mjs +18 -64
- package/dist/rest/errors.d.mts +2082 -22
- package/dist/rest/errors.mjs +46 -89
- package/dist/rest/events.d.mts +394 -11
- package/dist/rest/events.mjs +13 -9
- package/dist/rest/files.d.mts +1265 -114
- package/dist/rest/files.mjs +11 -42
- package/dist/rest/forks.d.mts +2045 -102
- package/dist/rest/forks.mjs +10 -13
- package/dist/rest/handler.d.mts +3 -0
- package/dist/rest/handler.mjs +35 -19
- package/dist/rest/handlers.mjs +53 -60
- package/dist/rest/layer.d.mts +14 -0
- package/dist/rest/layer.mjs +52 -0
- package/dist/rest/listen.d.mts +5 -8
- package/dist/rest/listen.mjs +23 -29
- package/dist/rest/me.d.mts +393 -10
- package/dist/rest/me.mjs +2 -2
- package/dist/rest/merges.d.mts +399 -16
- package/dist/rest/merges.mjs +3 -17
- package/dist/rest/namespace.d.mts +2 -0
- package/dist/rest/paths.mjs +1 -0
- package/dist/rest/queue.d.mts +5658 -283
- package/dist/rest/queue.mjs +15 -130
- package/dist/rest/refs.d.mts +2869 -142
- package/dist/rest/refs.mjs +19 -39
- package/dist/rest/repos.d.mts +2421 -93
- package/dist/rest/repos.mjs +10 -33
- package/dist/rest/tags.d.mts +1220 -69
- package/dist/rest/tags.mjs +6 -34
- package/dist/rest/tokens.d.mts +2358 -55
- package/dist/rest/tokens.mjs +7 -4
- package/dist/rest/topics.d.mts +2053 -106
- package/dist/rest/topics.mjs +23 -71
- package/dist/rest/trees.d.mts +1616 -81
- package/dist/rest/trees.mjs +16 -57
- package/dist/rest/wire.d.mts +404 -0
- package/dist/rest/wire.mjs +32 -46
- package/dist/rest/work.d.mts +1204 -63
- package/dist/rest/work.mjs +7 -51
- package/dist/rest.d.mts +3 -3
- package/dist/server/edge-node.d.mts +20 -0
- package/dist/server/edge-node.mjs +20 -0
- package/dist/server/edge.d.mts +10 -0
- package/dist/server/edge.mjs +23 -0
- package/dist/server/extension.d.mts +6 -2
- package/dist/server/extension.mjs +54 -30
- package/dist/server/git-layer.d.mts +34 -0
- package/dist/server/git-layer.mjs +118 -0
- package/dist/server/git-namespace.d.mts +7 -0
- package/dist/server/git-namespace.mjs +18 -0
- package/dist/server/lifecycle.d.mts +1 -2
- package/dist/server/lifecycle.mjs +8 -15
- package/dist/server/namespaces.d.mts +2 -0
- package/dist/server/registry.d.mts +12 -0
- package/dist/server/registry.mjs +218 -0
- package/dist/server/route-match.mjs +88 -0
- package/dist/server/routes.d.mts +12 -8
- package/dist/server/routes.mjs +27 -18
- package/dist/server/server.d.mts +22 -0
- package/dist/server/server.mjs +335 -210
- package/dist/server/uploads.d.mts +14 -0
- package/dist/server/uploads.mjs +15 -0
- package/dist/signin/codes.mjs +9 -6
- package/dist/signin/context.d.mts +1 -0
- package/dist/signin/context.mjs +4 -4
- package/dist/signin/device.mjs +8 -8
- package/dist/signin/forms.mjs +11 -29
- package/dist/signin/grants.d.mts +4 -2
- package/dist/signin/grants.mjs +20 -19
- package/dist/signin/route.mjs +2 -2
- package/dist/signin/web.mjs +7 -7
- package/dist/signin/wire.mjs +6 -6
- package/dist/storage/budget.mjs +51 -18
- package/dist/storage/calls.d.mts +28 -11
- package/dist/storage/calls.mjs +354 -117
- package/dist/storage/clean-up.mjs +121 -46
- package/dist/storage/counted-bucket.mjs +115 -0
- package/dist/storage/fetch.d.mts +2 -0
- package/dist/storage/fetch.mjs +243 -100
- package/dist/storage/fsck.mjs +56 -7
- package/dist/storage/held-types.d.mts +7 -0
- package/dist/storage/held-types.mjs +263 -0
- package/dist/storage/host-bucket.mjs +43 -0
- package/dist/storage/id-mix.d.mts +1 -0
- package/dist/storage/id-mix.mjs +55 -0
- package/dist/storage/index-bitmaps.d.mts +2 -1
- package/dist/storage/index-bitmaps.mjs +233 -101
- package/dist/storage/index-build.d.mts +6 -2
- package/dist/storage/index-build.mjs +650 -164
- package/dist/storage/index-fetch.d.mts +3 -1
- package/dist/storage/index-fetch.mjs +297 -195
- package/dist/storage/index-files.mjs +25 -27
- package/dist/storage/index-graph.d.mts +2 -1
- package/dist/storage/index-graph.mjs +127 -91
- package/dist/storage/index-layers.d.mts +11 -0
- package/dist/storage/index-layers.mjs +258 -78
- package/dist/storage/index-reach.mjs +181 -75
- package/dist/storage/index-remap.mjs +74 -32
- package/dist/storage/index-shallow.mjs +311 -0
- package/dist/storage/index-visible.mjs +168 -0
- package/dist/storage/layout.d.mts +1 -0
- package/dist/storage/layout.mjs +44 -8
- package/dist/storage/lfs-pointers.d.mts +3 -1
- package/dist/storage/lfs-pointers.mjs +25 -9
- package/dist/storage/link-join.d.mts +4 -0
- package/dist/storage/link-join.mjs +50 -12
- package/dist/storage/links.mjs +89 -4
- package/dist/storage/listed-ids.mjs +10 -0
- package/dist/storage/loose.d.mts +11 -4
- package/dist/storage/loose.mjs +102 -69
- package/dist/storage/memory-budget.d.mts +5 -0
- package/dist/storage/memory-budget.mjs +530 -102
- package/dist/storage/merge-choose.mjs +258 -0
- package/dist/storage/merge-cut.mjs +47 -0
- package/dist/storage/merge-fence.mjs +89 -0
- package/dist/storage/merge-index.mjs +347 -0
- package/dist/storage/merge-most.mjs +202 -0
- package/dist/storage/merge-plan.mjs +171 -0
- package/dist/storage/merge-row.mjs +258 -0
- package/dist/storage/merge-stream.mjs +497 -0
- package/dist/storage/merge-walk.mjs +199 -0
- package/dist/storage/merge-write.mjs +129 -0
- package/dist/storage/merge.d.mts +10 -0
- package/dist/storage/merge.mjs +82 -306
- package/dist/storage/object-rows.d.mts +4 -2
- package/dist/storage/object-rows.mjs +101 -17
- package/dist/storage/pack-order.d.mts +1 -1
- package/dist/storage/pack-order.mjs +69 -54
- package/dist/storage/pack-ranges.d.mts +1 -1
- package/dist/storage/pack-ranges.mjs +396 -60
- package/dist/storage/pack-reads.d.mts +6 -2
- package/dist/storage/pack-reads.mjs +598 -126
- package/dist/storage/pack-receive.d.mts +5 -0
- package/dist/storage/pack-receive.mjs +820 -237
- package/dist/storage/packs-memory.d.mts +25 -0
- package/dist/storage/packs-memory.mjs +49 -0
- package/dist/storage/packs.d.mts +7 -5
- package/dist/storage/packs.mjs +554 -213
- package/dist/storage/placed-reads.mjs +205 -0
- package/dist/storage/prune-keep.mjs +164 -0
- package/dist/storage/prune-walk.mjs +578 -0
- package/dist/storage/prune.mjs +739 -332
- package/dist/storage/push-allotment.mjs +3 -3
- package/dist/storage/push-uploads.mjs +31 -26
- package/dist/storage/pushed-commits.mjs +8 -9
- package/dist/storage/quarantine.d.mts +10 -0
- package/dist/storage/quarantine.mjs +71 -29
- package/dist/storage/range-cache.mjs +71 -0
- package/dist/storage/raw-ids.mjs +20 -1
- package/dist/storage/ready.d.mts +4 -2
- package/dist/storage/ready.mjs +109 -48
- package/dist/storage/receive-admission.mjs +67 -0
- package/dist/storage/receive-bounds.d.mts +1 -0
- package/dist/storage/receive-bounds.mjs +202 -0
- package/dist/storage/receive-files.mjs +248 -0
- package/dist/storage/receive-links.mjs +281 -244
- package/dist/storage/receive-state.d.mts +9 -0
- package/dist/storage/receive-state.mjs +150 -0
- package/dist/storage/receive-steps.mjs +344 -0
- package/dist/storage/receive-sweep.mjs +160 -0
- package/dist/storage/receive-table.d.mts +3 -0
- package/dist/storage/receive-table.mjs +197 -0
- package/dist/storage/repack-backlog.mjs +70 -0
- package/dist/storage/repack-contained.mjs +269 -0
- package/dist/storage/repack-job.d.mts +3 -0
- package/dist/storage/repack-job.mjs +27 -17
- package/dist/storage/repack.d.mts +4 -4
- package/dist/storage/repack.mjs +156 -77
- package/dist/storage/roots.mjs +23 -7
- package/dist/storage/rows.d.mts +4 -2
- package/dist/storage/rows.mjs +81 -9
- package/dist/storage/runs.d.mts +8 -0
- package/dist/storage/runs.mjs +731 -0
- package/dist/storage/send-list.d.mts +2 -1
- package/dist/storage/send-list.mjs +261 -76
- package/dist/storage/shallow.d.mts +3 -2
- package/dist/storage/shallow.mjs +7 -7
- package/dist/storage/single-flight.mjs +47 -0
- package/dist/storage/stream-whole.mjs +121 -54
- package/dist/storage/swap-walk.mjs +188 -0
- package/dist/storage/unpack.mjs +52 -23
- package/dist/storage/visible.mjs +58 -39
- package/dist/storage/walk.d.mts +2 -0
- package/dist/storage/walk.mjs +20 -7
- package/dist/storage/wants.mjs +185 -33
- package/dist/storage/written-bases.mjs +172 -0
- package/dist/store/call-count.d.mts +69 -4
- package/dist/store/call-count.mjs +193 -51
- package/dist/store/catalogue.d.mts +17 -3
- package/dist/store/catalogue.mjs +135 -48
- package/dist/store/crossing.mjs +2 -4
- package/dist/store/cursor-seal.d.mts +12 -1
- package/dist/store/cursor-seal.mjs +7 -6
- package/dist/store/errors.d.mts +2 -2
- package/dist/store/errors.mjs +112 -24
- package/dist/store/git-store.mjs +21 -2
- package/dist/store/job-try.mjs +26 -0
- package/dist/store/list-job.mjs +23 -17
- package/dist/store/outbox.d.mts +15 -5
- package/dist/store/outbox.mjs +143 -39
- package/dist/store/promises.d.mts +8 -2
- package/dist/store/promises.mjs +129 -85
- package/dist/store/queue-jobs.mjs +34 -13
- package/dist/store/records.d.mts +64 -1
- package/dist/store/records.mjs +101 -32
- package/dist/store/ref-rows.d.mts +18 -2
- package/dist/store/ref-rows.mjs +62 -5
- package/dist/store/repo-record.mjs +11 -9
- package/dist/store/reservations.mjs +9 -8
- package/dist/store/scopes.mjs +13 -11
- package/dist/store/settle.mjs +1 -1
- package/dist/store/topic-jobs.mjs +4 -4
- package/dist/sync/bound.d.mts +5 -3
- package/dist/sync/bound.mjs +32 -3
- package/dist/sync/github.mjs +7 -7
- package/dist/sync/import.d.mts +2 -0
- package/dist/sync/import.mjs +46 -50
- package/dist/sync/jobs.mjs +15 -23
- package/dist/sync/mirror.d.mts +6 -2
- package/dist/sync/mirror.mjs +122 -45
- package/dist/sync/publish.d.mts +1 -0
- package/dist/sync/publish.mjs +22 -19
- package/dist/sync/step.mjs +443 -71
- package/dist/sync/tries.mjs +50 -32
- package/dist/sync.d.mts +3 -3
- package/dist/sync.mjs +2 -2
- package/dist/topics/advance.mjs +103 -86
- package/dist/topics/calls.mjs +97 -67
- package/dist/topics/directory.mjs +31 -11
- package/dist/topics/host.d.mts +0 -1
- package/dist/topics/host.mjs +2 -12
- package/dist/topics/members.mjs +30 -24
- package/dist/topics/rows.mjs +10 -9
- package/dist/topics/topic.mjs +20 -9
- package/package.json +8 -15
- package/dist/auth/authorize.d.mts +0 -5
- package/dist/contracts/objects.mjs +0 -54
- package/dist/core/events/stream.d.mts +0 -19
- package/dist/core/rules/define.d.mts +0 -5
- package/dist/core/rules/define.mjs +0 -13
- package/dist/core/rules/fetch.d.mts +0 -5
- package/dist/core/sight.mjs +0 -99
- package/dist/engine/engine.d.mts +0 -25
- package/dist/engine/engine.mjs +0 -49
- package/dist/engine/xdiff/NOTICE.md +0 -63
- package/dist/engine/xdiff/compiled.d.mts +0 -7
- package/dist/engine/xdiff/compiled.mjs +0 -9
- package/dist/engine/xdiff/embedded.mjs +0 -4
- package/dist/engine/xdiff/node.d.mts +0 -7
- package/dist/engine/xdiff/node.mjs +0 -10
- package/dist/engine/xdiff/upstream/LGPL-2.1 +0 -511
- package/dist/engine/xdiff/xdiff.wasm +0 -0
- package/dist/engine.d.mts +0 -3
- package/dist/engine.mjs +0 -3
- package/dist/lfs/repo.mjs +0 -42
- package/dist/storage/distinct-ids.mjs +0 -39
- package/dist/storage/held-memo.mjs +0 -188
- package/dist/storage/index-remap.d.mts +0 -8
- package/dist/sync/records.mjs +0 -73
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
import { millis } from "../../contracts/promises.mjs";
|
|
2
|
+
import { isInternalId } from "../../contracts/ids.mjs";
|
|
3
|
+
import { fail, gitError } from "../../contracts/result.mjs";
|
|
4
|
+
import { isWellFormed, utf8 } from "../../protocol/bytes/text.mjs";
|
|
2
5
|
import { decodeRecord } from "../../store/catalogue.mjs";
|
|
3
6
|
import { settleName } from "../../store/settle.mjs";
|
|
4
|
-
import { decodeRow,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
+
import { decodeRow, storeCall } from "../../store/errors.mjs";
|
|
8
|
+
import { Delivered, FailedTry, Follower, appendEvents, cursorId, cursorRead, decodeEvents, decodeOutbox, deliveryCursorId, eventBytes, eventId, eventLimits, failedKeyOf, failedPrefix, headKey, outboxCollections, outboxReads, repoEnvelope, shownEvent } from "../../store/outbox.mjs";
|
|
9
|
+
import { madeJob, settledCall } from "../../store/job-try.mjs";
|
|
7
10
|
import { newChangeId, repoScope, scopeRepo, selfKey } from "../../store/scopes.mjs";
|
|
8
|
-
import {
|
|
9
|
-
import * as Effect from "effect/Effect";
|
|
11
|
+
import { CurrentJob, Job, isInfraError, limits } from "@ref0/infra";
|
|
10
12
|
import * as Schema from "effect/Schema";
|
|
13
|
+
import * as Effect from "effect/Effect";
|
|
11
14
|
import * as Predicate from "effect/Predicate";
|
|
12
15
|
// src/core/events/deliver.ts
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
/** What each delivery's job name starts with: `git.deliver.<name>`. */
|
|
17
|
+
const deliverJobPrefix = "git.deliver.";
|
|
18
|
+
/** `delivery`'s job, `git.deliver.<delivery>`: one a scope, beside each other delivery's. */
|
|
19
|
+
const deliverJobName = (delivery) => `${deliverJobPrefix}${delivery}`;
|
|
20
|
+
/** The delivery a job named `name` runs, or `undefined` for a job no delivery's. */
|
|
21
|
+
const deliveryOf = (name) => name.startsWith(deliverJobPrefix) && name.length > 12 ? name.slice(12) : void 0;
|
|
22
|
+
/** One row per scope and delivery, so its events go one batch at a time, in `seq` order. */
|
|
15
23
|
const deliverJobKey = "deliver";
|
|
16
|
-
const DeliverData = Schema.Struct({});
|
|
17
|
-
|
|
24
|
+
const DeliverData = /* @__PURE__ */ Schema.Struct({});
|
|
25
|
+
/** The delivery a server ships with: its host's `events`. */
|
|
26
|
+
const eventsDelivery = "events";
|
|
18
27
|
/** How long a delivered event is kept for replay, unless the kept budget trims it first. */
|
|
19
28
|
const keptFor = 864e5;
|
|
20
29
|
/** How long a scope waits before it looks again at a scope that held its name's sequence. */
|
|
@@ -35,6 +44,11 @@ const defaultDeliverRetry = {
|
|
|
35
44
|
};
|
|
36
45
|
/** The host's `events`, as one shape. */
|
|
37
46
|
const eventDelivery = (events) => Predicate.isFunction(events) ? { handler: events } : events;
|
|
47
|
+
/** The deliveries a server runs for the host's `events`: the one, `events`, until D2 adds more. */
|
|
48
|
+
const deliveriesOf = (events) => [{
|
|
49
|
+
...eventDelivery(events),
|
|
50
|
+
name: eventsDelivery
|
|
51
|
+
}];
|
|
38
52
|
/** A read infra refused because its answer passed 16 MiB. */
|
|
39
53
|
const tooLarge = (error) => error.code === "RESOURCE_EXHAUSTED" && error.context?.reason === "too-large";
|
|
40
54
|
/**
|
|
@@ -49,6 +63,78 @@ const readEvents = (store, scope, reads, limit) => {
|
|
|
49
63
|
})));
|
|
50
64
|
return read(limit).pipe(Effect.catchIf(tooLarge, () => read(largeReadRows)));
|
|
51
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* Where a delivery stands in a scope it has no cursor row in yet: the retained beginning, just
|
|
68
|
+
* before the oldest event kept, whose earlier events' bytes the head counts as trimmed, since a
|
|
69
|
+
* trim deletes the oldest first. With none kept, past the last. One read, of one event.
|
|
70
|
+
*/
|
|
71
|
+
const retainedStart = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, head) {
|
|
72
|
+
const read = {
|
|
73
|
+
collection: outboxCollections.events,
|
|
74
|
+
limit: 1
|
|
75
|
+
};
|
|
76
|
+
const snapshot = yield* storeCall(() => store.read(scope, [read]));
|
|
77
|
+
const [oldest] = yield* decodeEvents(snapshot.results[0] ?? []);
|
|
78
|
+
return oldest === void 0 ? {
|
|
79
|
+
seq: head.next - 1,
|
|
80
|
+
bytes: head.bytes
|
|
81
|
+
} : {
|
|
82
|
+
seq: oldest.seq - 1,
|
|
83
|
+
bytes: head.trimmed
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
/** A cursor row, read by `cursorRead`, or none: a delivery that hasn't moved in the scope yet. */
|
|
87
|
+
const decodeCursor = (rows) => {
|
|
88
|
+
const [row] = rows ?? [];
|
|
89
|
+
return row === void 0 ? Effect.succeed(void 0) : decodeRow(Delivered, row, "The delivery cursor");
|
|
90
|
+
};
|
|
91
|
+
/** A delivery's cursor in `scope`, from its `cursorRead` rows, or its retained beginning. */
|
|
92
|
+
const cursorOf = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, head, rows) {
|
|
93
|
+
const cursor = yield* decodeCursor(rows);
|
|
94
|
+
if (cursor !== void 0) return cursor;
|
|
95
|
+
return yield* retainedStart(store, scope, head);
|
|
96
|
+
});
|
|
97
|
+
/** Each delivery's cursor, from their `cursorRead`s' results, in the order the reads named them. */
|
|
98
|
+
const decodeCursors = /* @__PURE__ */ Effect.fnUntraced(function* (deliveries, results) {
|
|
99
|
+
const cursors = /* @__PURE__ */ new Map();
|
|
100
|
+
for (const [index, delivery] of deliveries.entries()) cursors.set(delivery, yield* decodeCursor(results[index]));
|
|
101
|
+
return cursors;
|
|
102
|
+
});
|
|
103
|
+
/** The slowest of `places`, or `undefined` when one is missing: a delivery that hasn't moved. */
|
|
104
|
+
const slowest = (places) => {
|
|
105
|
+
let least;
|
|
106
|
+
for (const place of places) {
|
|
107
|
+
if (place === void 0) return void 0;
|
|
108
|
+
if (least === void 0 || place.seq < least.seq) least = place;
|
|
109
|
+
}
|
|
110
|
+
return least;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Moves `delivery`'s cursor to `value`, in a new row, and then the low-water mark to the slowest
|
|
114
|
+
* active delivery, when each has a cursor and the slowest has passed the mark, as `read` showed
|
|
115
|
+
* them. A low-water row that a crash between the two leaves behind only holds more: the next move
|
|
116
|
+
* writes it. Answers the low-water mark after.
|
|
117
|
+
*/
|
|
118
|
+
const moveCursor = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, delivery, value, read) {
|
|
119
|
+
const own = read.cursors.get(delivery);
|
|
120
|
+
const moved = own === void 0 || own.seq < value.seq ? value : own;
|
|
121
|
+
const id = deliveryCursorId(delivery, value.seq);
|
|
122
|
+
if (moved === value) yield* addCursor(store, scope, {
|
|
123
|
+
collection: outboxCollections.cursors,
|
|
124
|
+
id,
|
|
125
|
+
value
|
|
126
|
+
});
|
|
127
|
+
const places = [...read.cursors].map(([name, at]) => name === delivery ? moved : at);
|
|
128
|
+
const floor = slowest(places);
|
|
129
|
+
if (floor === void 0 || floor.seq <= read.delivered.seq) return read.delivered;
|
|
130
|
+
const mark = {
|
|
131
|
+
collection: outboxCollections.delivered,
|
|
132
|
+
id: cursorId(floor.seq),
|
|
133
|
+
value: floor
|
|
134
|
+
};
|
|
135
|
+
yield* addCursor(store, scope, mark);
|
|
136
|
+
return floor;
|
|
137
|
+
});
|
|
52
138
|
const again = (at) => ({
|
|
53
139
|
kind: "settle",
|
|
54
140
|
outcome: at === void 0 ? { kind: "more" } : {
|
|
@@ -61,28 +147,42 @@ const settle = (outcome) => ({
|
|
|
61
147
|
outcome
|
|
62
148
|
});
|
|
63
149
|
/**
|
|
64
|
-
* Which of the scopes that held this scope's names' sequences before still owe theirs
|
|
65
|
-
* hasn't
|
|
66
|
-
* until a retry delivers them or a discard skips them, so a
|
|
67
|
-
*
|
|
150
|
+
* Which of the scopes that held this scope's names' sequences before still owe theirs to this
|
|
151
|
+
* try's delivery: each whose cursor for it hasn't reached where this one goes on. One whose
|
|
152
|
+
* delivery failed still owes them, until a retry delivers them or a discard skips them, so a
|
|
153
|
+
* name's `seq` only goes up, for each delivery. Drops from `after` only those every delivery is
|
|
154
|
+
* past, by the earlier scope's low-water mark, and answers the first `seq` here they hold for this
|
|
155
|
+
* delivery, or `undefined` when none does.
|
|
68
156
|
*/
|
|
69
|
-
const followed = Effect.fnUntraced(function* (parts, store, scope, version, head) {
|
|
157
|
+
const followed = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, scope, version, head) {
|
|
70
158
|
const { after } = head;
|
|
71
159
|
if (after === void 0) return void 0;
|
|
72
160
|
const owing = [];
|
|
161
|
+
const kept = [];
|
|
162
|
+
const waiter = scopeRepo(scope);
|
|
73
163
|
for (const follows of after) {
|
|
74
164
|
const before = repoScope(follows.internalId);
|
|
75
|
-
const
|
|
165
|
+
const reads = [...outboxReads, cursorRead(parts.delivery)];
|
|
166
|
+
const snapshot = yield* storeCall(() => parts.store.read(before, reads));
|
|
76
167
|
const outbox = yield* decodeOutbox(snapshot.results);
|
|
168
|
+
const cursor = yield* cursorOf(parts.store, before, outbox.head, snapshot.results[2]);
|
|
77
169
|
const owed = Math.min(follows.seq, outbox.head.next - 1);
|
|
78
|
-
if (
|
|
170
|
+
if (cursor.seq < owed) owing.push(follows);
|
|
171
|
+
if (cursor.seq < owed || outbox.delivered.seq < owed) kept.push(follows);
|
|
172
|
+
if (owing.at(-1) !== follows || waiter === void 0) continue;
|
|
173
|
+
const row = {
|
|
174
|
+
collection: outboxCollections.followers,
|
|
175
|
+
id: waiter,
|
|
176
|
+
value: { seq: owed }
|
|
177
|
+
};
|
|
178
|
+
yield* addNew(parts.store, before, row);
|
|
79
179
|
}
|
|
80
|
-
if (
|
|
180
|
+
if (kept.length < after.length) {
|
|
81
181
|
const left = {
|
|
82
182
|
...head,
|
|
83
|
-
after:
|
|
183
|
+
after: kept
|
|
84
184
|
};
|
|
85
|
-
if (
|
|
185
|
+
if (kept.length === 0) delete left.after;
|
|
86
186
|
const change = {
|
|
87
187
|
id: newChangeId(),
|
|
88
188
|
expect: version,
|
|
@@ -95,14 +195,79 @@ const followed = Effect.fnUntraced(function* (parts, store, scope, version, head
|
|
|
95
195
|
}
|
|
96
196
|
return owing.length === 0 ? void 0 : Math.min(...owing.map((follows) => follows.from));
|
|
97
197
|
});
|
|
198
|
+
/** What a try reads of the scopes that wait on its events, beside its outbox. */
|
|
199
|
+
const followersRead = {
|
|
200
|
+
collection: outboxCollections.followers,
|
|
201
|
+
limit: 20
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Makes each delivery's job due now in each scope whose `followers` row, `snapshot`'s last result, has a
|
|
205
|
+
* `seq` the low-water mark at `delivered` has passed, so every delivery has, then deletes their
|
|
206
|
+
* rows in one commit at its version: one that loses leaves them for the next send, which wakes
|
|
207
|
+
* them again. A waiter a slower delivery still holds looks again after `followWait`.
|
|
208
|
+
*/
|
|
209
|
+
const wakeFollowers = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, scope, snapshot, delivered) {
|
|
210
|
+
const woken = [];
|
|
211
|
+
for (const row of snapshot.results.at(-1) ?? []) {
|
|
212
|
+
const { id } = row;
|
|
213
|
+
const { seq } = yield* decodeRow(Follower, row, `The follower '${id}'`);
|
|
214
|
+
if (seq > delivered.seq) continue;
|
|
215
|
+
if (isInternalId(id)) yield* storeCall(() => parts.store.add(repoScope(id), { jobs: [...parts.wake()] }));
|
|
216
|
+
woken.push({
|
|
217
|
+
collection: row.collection,
|
|
218
|
+
id
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
if (woken.length === 0) return;
|
|
222
|
+
const change = {
|
|
223
|
+
id: newChangeId(),
|
|
224
|
+
expect: snapshot.version,
|
|
225
|
+
delete: woken
|
|
226
|
+
};
|
|
227
|
+
yield* storeCall(() => store.commit(scope, change));
|
|
228
|
+
});
|
|
229
|
+
/**
|
|
230
|
+
* Moves the low-water mark up to the slowest active cursor, and wakes the followers it passes, for
|
|
231
|
+
* a drained try whose own cursor is past the mark: a try that stopped between `moveCursor`'s two
|
|
232
|
+
* writes left it behind, and no send is left to move it.
|
|
233
|
+
*/
|
|
234
|
+
const settleMark = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, scope) {
|
|
235
|
+
const reads = [
|
|
236
|
+
...outboxReads,
|
|
237
|
+
...parts.deliveries.map(cursorRead),
|
|
238
|
+
followersRead
|
|
239
|
+
];
|
|
240
|
+
const snapshot = yield* storeCall(() => store.read(scope, reads));
|
|
241
|
+
const { delivered } = yield* decodeOutbox(snapshot.results);
|
|
242
|
+
const cursors = yield* decodeCursors(parts.deliveries, snapshot.results.slice(2));
|
|
243
|
+
const own = cursors.get(parts.delivery);
|
|
244
|
+
if (own === void 0) return;
|
|
245
|
+
const mark = yield* moveCursor(store, scope, parts.delivery, own, {
|
|
246
|
+
delivered,
|
|
247
|
+
cursors
|
|
248
|
+
});
|
|
249
|
+
yield* wakeFollowers(parts, store, scope, snapshot, mark);
|
|
250
|
+
});
|
|
98
251
|
/**
|
|
99
|
-
* Deletes what
|
|
100
|
-
* past the kept budget whatever their age, with the
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
252
|
+
* Deletes what every active delivery has passed and is old: each event behind the slowest cursor
|
|
253
|
+
* older than `keptFor`, and the oldest past the kept budget whatever their age, with the low-water
|
|
254
|
+
* and cursor rows behind each newest, and a removed delivery's cursor and `failed` rows, at most
|
|
255
|
+
* `trimBatch` of each. A delivery with no cursor yet holds every event. Answers the bytes of events
|
|
256
|
+
* it deleted, and `at`: now when `delivery` has events left to send or there's more to trim; when
|
|
257
|
+
* the oldest event left is due to be trimmed; or `undefined` when none is left, or a slower
|
|
258
|
+
* delivery holds it, whose own tries trim once they pass it. `lost` says a write since its read
|
|
259
|
+
* beat its commit, so it trimmed nothing and should run again.
|
|
104
260
|
*/
|
|
105
|
-
const trim = Effect.fnUntraced(function* (store, scope, now) {
|
|
261
|
+
const trim = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, scope, now) {
|
|
262
|
+
const { delivery, deliveries } = parts;
|
|
263
|
+
const sweep = [{
|
|
264
|
+
collection: outboxCollections.cursors,
|
|
265
|
+
limit: 1001
|
|
266
|
+
}, {
|
|
267
|
+
collection: outboxCollections.outbox,
|
|
268
|
+
prefix: failedPrefix,
|
|
269
|
+
limit: 1001
|
|
270
|
+
}];
|
|
106
271
|
const reads = (limit) => [
|
|
107
272
|
{
|
|
108
273
|
collection: headKey.collection,
|
|
@@ -115,22 +280,35 @@ const trim = Effect.fnUntraced(function* (store, scope, now) {
|
|
|
115
280
|
{
|
|
116
281
|
collection: outboxCollections.events,
|
|
117
282
|
limit
|
|
118
|
-
}
|
|
283
|
+
},
|
|
284
|
+
...deliveries.map(cursorRead),
|
|
285
|
+
...sweep
|
|
119
286
|
];
|
|
120
287
|
const { snapshot, limit } = yield* readEvents(store, scope, reads, trimBatch);
|
|
121
|
-
const [headRows = [],
|
|
122
|
-
const
|
|
288
|
+
const [headRows = [], markRows = [], eventRows = []] = snapshot.results;
|
|
289
|
+
const newest = snapshot.results.slice(3, 3 + deliveries.length);
|
|
290
|
+
const [cursorRows = [], failedRows = []] = snapshot.results.slice(3 + deliveries.length);
|
|
291
|
+
const { head } = yield* decodeOutbox([headRows, markRows]);
|
|
123
292
|
const events = yield* decodeEvents(eventRows);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
293
|
+
const cursors = yield* decodeCursors(deliveries, newest);
|
|
294
|
+
const floor = slowest([...cursors.values()]);
|
|
295
|
+
const own = cursors.get(delivery);
|
|
296
|
+
const keep = new Set(newest.flatMap((rows) => rows.slice(0, 1).map((row) => row.id)));
|
|
297
|
+
const failing = new Set(deliveries.map((name) => failedKeyOf(name).id));
|
|
298
|
+
const gone = [
|
|
299
|
+
...markRows.slice(1),
|
|
300
|
+
...cursorRows.filter((row) => !keep.has(row.id)),
|
|
301
|
+
...failedRows.filter((row) => !failing.has(row.id))
|
|
302
|
+
].map(({ collection, id }) => ({
|
|
127
303
|
collection,
|
|
128
304
|
id
|
|
129
305
|
}));
|
|
306
|
+
let kept = floor === void 0 ? 0 : floor.bytes - head.trimmed;
|
|
307
|
+
let trimmed = 0;
|
|
130
308
|
let left;
|
|
131
309
|
for (const event of events) {
|
|
132
310
|
const old = event.at + 864e5 <= now || kept > eventLimits.kept;
|
|
133
|
-
if (event.seq >
|
|
311
|
+
if (floor === void 0 || event.seq > floor.seq || !old) {
|
|
134
312
|
left = event;
|
|
135
313
|
break;
|
|
136
314
|
}
|
|
@@ -164,11 +342,21 @@ const trim = Effect.fnUntraced(function* (store, scope, now) {
|
|
|
164
342
|
lost: true
|
|
165
343
|
};
|
|
166
344
|
}
|
|
167
|
-
if (left !== void 0)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
345
|
+
if (left !== void 0) {
|
|
346
|
+
if (own === void 0 || left.seq > own.seq) return {
|
|
347
|
+
trimmed,
|
|
348
|
+
at: now
|
|
349
|
+
};
|
|
350
|
+
if (floor === void 0 || left.seq > floor.seq) return {
|
|
351
|
+
trimmed,
|
|
352
|
+
at: void 0
|
|
353
|
+
};
|
|
354
|
+
return {
|
|
355
|
+
trimmed,
|
|
356
|
+
at: left.at + keptFor
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
const more = events.length === limit || markRows.length > trimBatch || cursorRows.length > trimBatch || failedRows.length > trimBatch;
|
|
172
360
|
return {
|
|
173
361
|
trimmed,
|
|
174
362
|
at: more ? now : void 0
|
|
@@ -185,30 +373,57 @@ const drainCeiling = eventLimits.undelivered + eventLimits.kept;
|
|
|
185
373
|
* (Q399).
|
|
186
374
|
*/
|
|
187
375
|
const trimsFirst = (head, delivered) => delivered.bytes - head.trimmed > eventLimits.kept && head.bytes - head.trimmed > drainCeiling;
|
|
376
|
+
/** How many times a try reads its scope while each read settles a name first. */
|
|
377
|
+
const settleReads = 2;
|
|
378
|
+
/**
|
|
379
|
+
* Reads the scope's outbox, with `delivery`'s cursor, once its name is settled: a create's or a
|
|
380
|
+
* rename's first try settles it, reads again and goes on, so it sends in the same try (#1506).
|
|
381
|
+
* Answers `undefined` when each of `settleReads` reads found a name to settle, a write racing the
|
|
382
|
+
* settle, for the next try.
|
|
383
|
+
*/
|
|
384
|
+
const readSettled = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, delivery) {
|
|
385
|
+
for (let reads = 0; reads < settleReads; reads += 1) {
|
|
386
|
+
const all = [
|
|
387
|
+
selfKey,
|
|
388
|
+
...outboxReads,
|
|
389
|
+
cursorRead(delivery)
|
|
390
|
+
];
|
|
391
|
+
const snapshot = yield* storeCall(() => store.read(scope, all));
|
|
392
|
+
const record = yield* decodeRecord(snapshot.results[0]?.[0]);
|
|
393
|
+
const { head, delivered } = yield* decodeOutbox(snapshot.results.slice(1));
|
|
394
|
+
const read = {
|
|
395
|
+
version: snapshot.version,
|
|
396
|
+
head,
|
|
397
|
+
record
|
|
398
|
+
};
|
|
399
|
+
if (yield* settleName(store, scope, read)) continue;
|
|
400
|
+
return {
|
|
401
|
+
snapshot,
|
|
402
|
+
head,
|
|
403
|
+
delivered,
|
|
404
|
+
cursor: yield* cursorOf(store, scope, head, snapshot.results[3])
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
});
|
|
188
408
|
/**
|
|
189
409
|
* A try's first part: settles what holds delivery back, and past `drainCeiling` trims, a step at a
|
|
190
410
|
* time, before it sends, until the scope is back under it or keeps only the kept budget delivered.
|
|
191
411
|
* Then it reads the next batch past the cursor. Drained, it trims past the kept budget and
|
|
192
412
|
* past `keptFor`, and settles at the oldest event's trim, or done when none is left.
|
|
193
413
|
*/
|
|
194
|
-
const prepare = Effect.fnUntraced(function* (parts, job, store) {
|
|
414
|
+
const prepare = /* @__PURE__ */ Effect.fnUntraced(function* (parts, job, store) {
|
|
195
415
|
const { scope } = job;
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
const { head, delivered } =
|
|
199
|
-
if (yield* settleName(store, scope, {
|
|
200
|
-
version: snapshot.version,
|
|
201
|
-
head,
|
|
202
|
-
record
|
|
203
|
-
})) return again();
|
|
416
|
+
const settled = yield* readSettled(store, scope, parts.delivery);
|
|
417
|
+
if (settled === void 0) return again();
|
|
418
|
+
const { snapshot, head, delivered, cursor } = settled;
|
|
204
419
|
if (trimsFirst(head, delivered)) {
|
|
205
|
-
const { trimmed, lost } = yield* trim(store, scope, yield* parts.now);
|
|
420
|
+
const { trimmed, lost } = yield* trim(parts, store, scope, yield* parts.now);
|
|
206
421
|
if (trimmed > 0 || lost === true) return again();
|
|
207
422
|
}
|
|
208
423
|
const held = yield* followed(parts, store, scope, snapshot.version, head);
|
|
209
424
|
const waited = again((yield* parts.now) + followWait);
|
|
210
|
-
if (held !== void 0 && held <=
|
|
211
|
-
const after = eventId(
|
|
425
|
+
if (held !== void 0 && held <= cursor.seq + 1) return waited;
|
|
426
|
+
const after = eventId(cursor.seq);
|
|
212
427
|
const reads = (limit) => [{
|
|
213
428
|
collection: outboxCollections.events,
|
|
214
429
|
after,
|
|
@@ -222,69 +437,104 @@ const prepare = Effect.fnUntraced(function* (parts, job, store) {
|
|
|
222
437
|
const sent = events.slice(0, limit - 1);
|
|
223
438
|
return {
|
|
224
439
|
kind: "send",
|
|
225
|
-
cursor
|
|
440
|
+
cursor,
|
|
226
441
|
events: sent,
|
|
227
442
|
last: fetched.length < limit && sent.length === events.length
|
|
228
443
|
};
|
|
229
444
|
}
|
|
230
445
|
if (held !== void 0) return waited;
|
|
231
446
|
if (fetched.length > 0) return again();
|
|
232
|
-
|
|
447
|
+
if (cursor.seq > delivered.seq) yield* settleMark(parts, store, scope);
|
|
448
|
+
const { at } = yield* trim(parts, store, scope, yield* parts.now);
|
|
233
449
|
return settle(at === void 0 ? void 0 : {
|
|
234
450
|
kind: "more",
|
|
235
451
|
at
|
|
236
452
|
});
|
|
237
453
|
});
|
|
238
454
|
/**
|
|
239
|
-
* A try's last part, once the host took the batch: the cursor moves past it, in a new
|
|
240
|
-
* try's claim fences, so a stale try moves nothing
|
|
241
|
-
* already moved it. A batch that sent the last event
|
|
242
|
-
* `
|
|
455
|
+
* A try's last part, once the host took the batch: the delivery's cursor moves past it, in a new
|
|
456
|
+
* row the try's claim fences, so a stale try moves nothing, and the low-water mark with it when
|
|
457
|
+
* it was the slowest. A skip a discard recorded at the same `seq` already moved it. A batch that sent the head's last event trims and settles as a drained
|
|
458
|
+
* `prepare` would, when `sentLast` holds. Otherwise one that sent the last event it read trims
|
|
459
|
+
* past the kept budget, up to `trimBatch`, and each try after trims on. Steady traffic whose batches outweigh the smaller
|
|
243
460
|
* events a trim removes can hold kept past the budget while it lasts, under `drainCeiling`. Past
|
|
244
461
|
* `drainCeiling`, the next try's first part trims before it sends more.
|
|
245
462
|
*/
|
|
246
|
-
const advance = Effect.fnUntraced(function* (parts, job, store, batch) {
|
|
463
|
+
const advance = /* @__PURE__ */ Effect.fnUntraced(function* (parts, job, store, batch) {
|
|
247
464
|
const { scope } = job;
|
|
248
465
|
const last = batch.events.at(-1);
|
|
249
466
|
const again = { kind: "more" };
|
|
250
467
|
if (last === void 0) return again;
|
|
251
|
-
const
|
|
468
|
+
const { deliveries } = parts;
|
|
469
|
+
const reads = [
|
|
470
|
+
...outboxReads,
|
|
471
|
+
...deliveries.map(cursorRead),
|
|
472
|
+
followersRead
|
|
473
|
+
];
|
|
474
|
+
const snapshot = yield* storeCall(() => store.read(scope, reads));
|
|
252
475
|
const outbox = yield* decodeOutbox(snapshot.results);
|
|
476
|
+
const cursors = yield* decodeCursors(deliveries, snapshot.results.slice(2));
|
|
477
|
+
const own = cursors.get(parts.delivery);
|
|
253
478
|
const bytes = batch.events.reduce((sum, event) => sum + eventBytes(event), batch.cursor.bytes);
|
|
254
479
|
const value = {
|
|
255
480
|
seq: last.seq,
|
|
256
481
|
bytes
|
|
257
482
|
};
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
value
|
|
483
|
+
const read = {
|
|
484
|
+
delivered: outbox.delivered,
|
|
485
|
+
cursors
|
|
262
486
|
};
|
|
263
|
-
|
|
264
|
-
|
|
487
|
+
const mark = yield* moveCursor(store, scope, parts.delivery, value, read);
|
|
488
|
+
yield* wakeFollowers(parts, store, scope, snapshot, mark);
|
|
489
|
+
if (sentLast(outbox, own, last, mark)) {
|
|
490
|
+
const { at } = yield* trim(parts, store, scope, yield* parts.now);
|
|
491
|
+
return at === void 0 ? void 0 : {
|
|
492
|
+
kind: "more",
|
|
493
|
+
at
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
if (batch.last && mark.bytes - outbox.head.trimmed > eventLimits.kept) yield* trim(parts, store, scope, yield* parts.now);
|
|
265
497
|
return again;
|
|
266
498
|
});
|
|
499
|
+
/**
|
|
500
|
+
* Whether the try that sent `last` leaves its scope so the next try's `prepare` would only trim
|
|
501
|
+
* and settle, as `outbox` and the delivery's cursor `own`, read before it moved and the low-water
|
|
502
|
+
* mark moved to `mark`, show. Then the try trims and settles itself, with the same answer, and
|
|
503
|
+
* saves the next try (#1506). Any doubt is `false`, and the next try runs. Each part is a step
|
|
504
|
+
* `prepare` would take first, or one that finds more:
|
|
505
|
+
* - the cursor moves to the head's last event, so a read past it finds no event to send;
|
|
506
|
+
* - no name waits to be settled, which `settleName` would write first;
|
|
507
|
+
* - no scope it follows, which `followed` would read, and which may hold it;
|
|
508
|
+
* - not `trimsFirst`, which would trim a step and run again before it reads.
|
|
509
|
+
* A write since the read adds events and saves the job while this try holds it, so the queue runs
|
|
510
|
+
* it again by the earlier of the save and the settle's `at`, as it does for a drained `prepare`.
|
|
511
|
+
*/
|
|
512
|
+
const sentLast = (outbox, own, last, mark) => (own === void 0 || own.seq < last.seq) && outbox.head.next === last.seq + 1 && outbox.head.unconfirmed === void 0 && outbox.head.after === void 0 && !trimsFirst(outbox.head, mark);
|
|
513
|
+
/** Adds a row, unless one is there by its key: then that one stays. */
|
|
514
|
+
const addNew = (store, scope, row) => storeCall(() => store.add(scope, { put: [row] })).pipe(Effect.catchIf((error) => error.code === "ALREADY_EXISTS", () => Effect.void));
|
|
267
515
|
/** Adds a cursor row: one already at its `seq`, a discard's skip, moved the cursor there first. */
|
|
268
|
-
const addCursor = (store, scope, row) =>
|
|
516
|
+
const addCursor = (store, scope, row) => addNew(store, scope, row);
|
|
269
517
|
/**
|
|
270
518
|
* Whether `note` is of a try after `job`'s: a later claim in the scope has a higher `claim`, even
|
|
271
519
|
* once the row is deleted and added again.
|
|
272
520
|
*/
|
|
273
521
|
const newerThan = (note, job) => note.claim > job.claim;
|
|
274
|
-
/** Drops the
|
|
522
|
+
/** Drops the note when it's `job`'s try's or an older one's, whose `onFailure` has run. */
|
|
275
523
|
const dropNote = (sending, job) => {
|
|
276
524
|
const note = sending.get(job.scope);
|
|
277
525
|
if (note !== void 0 && !newerThan(note, job)) sending.delete(job.scope);
|
|
278
526
|
};
|
|
279
527
|
/**
|
|
280
|
-
*
|
|
528
|
+
* A delivery's try, in one scope: up to 100 events past its cursor, to the host's `events`. A
|
|
281
529
|
* throw or a timeout sends the same batch again, so later events wait behind one that fails; once
|
|
282
530
|
* the host took it, the cursor moves past it. When none is left to send, the try trims and sleeps
|
|
283
531
|
* until the oldest event kept is due to go. `sending` notes the batch while the host has it.
|
|
284
532
|
*/
|
|
285
|
-
const
|
|
533
|
+
const deliverTry = (parts, sending) => Effect.fnUntraced(function* () {
|
|
534
|
+
const job = yield* CurrentJob.current;
|
|
535
|
+
const store = yield* CurrentJob.store;
|
|
286
536
|
dropNote(sending, job);
|
|
287
|
-
const prepared =
|
|
537
|
+
const prepared = yield* prepare(parts, job, store);
|
|
288
538
|
if (prepared.kind === "settle") return prepared.outcome;
|
|
289
539
|
const seq = prepared.events[0]?.seq;
|
|
290
540
|
dropNote(sending, job);
|
|
@@ -292,40 +542,45 @@ const deliverHandler = (parts, sending) => async (job, context) => {
|
|
|
292
542
|
claim: job.claim,
|
|
293
543
|
seq
|
|
294
544
|
});
|
|
295
|
-
|
|
296
|
-
|
|
545
|
+
const events = prepared.events.map(shownEvent);
|
|
546
|
+
const signal = yield* CurrentJob.signal;
|
|
547
|
+
yield* settledCall(async () => parts.handler({
|
|
548
|
+
events,
|
|
297
549
|
attempt: job.attempt,
|
|
298
|
-
signal
|
|
299
|
-
});
|
|
550
|
+
signal
|
|
551
|
+
}));
|
|
300
552
|
dropNote(sending, job);
|
|
301
|
-
return
|
|
302
|
-
};
|
|
553
|
+
return yield* advance(parts, job, store, prepared);
|
|
554
|
+
});
|
|
303
555
|
/**
|
|
304
|
-
*
|
|
305
|
-
* or none. A claim out of tries runs no try, so its `onFailure` finds a note of an older
|
|
306
|
-
* none, and names no event.
|
|
556
|
+
* `delivery`'s `failed` row for `job`'s last try: the batch `sending` noted for that try, by its
|
|
557
|
+
* `claim`, or none. A claim out of tries runs no try, so its `onFailure` finds a note of an older
|
|
558
|
+
* try, or none, and names no event.
|
|
307
559
|
*/
|
|
308
|
-
const failedTry = (sending, job) => {
|
|
560
|
+
const failedTry = (sending, delivery, job) => {
|
|
309
561
|
const noted = sending.get(job.scope);
|
|
310
562
|
dropNote(sending, job);
|
|
311
|
-
|
|
563
|
+
const value = noted?.claim === job.claim ? {
|
|
312
564
|
claim: noted.claim,
|
|
313
565
|
seq: noted.seq
|
|
314
566
|
} : { claim: job.claim };
|
|
567
|
+
return {
|
|
568
|
+
...failedKeyOf(delivery),
|
|
569
|
+
value
|
|
570
|
+
};
|
|
315
571
|
};
|
|
316
572
|
/**
|
|
317
573
|
* Writes `repo.work.failed` when one of a repo's jobs fails its last try, behind the events it
|
|
318
|
-
* held. It passes the events budget. A failed
|
|
319
|
-
* which would run the job it reports again
|
|
320
|
-
*
|
|
574
|
+
* held. It passes the events budget. A failed delivery's job saves every delivery's job but its
|
|
575
|
+
* own, which would run the job it reports again: the queue keeps any other failed job failed, so
|
|
576
|
+
* each stays as its own tries left it. It passes `tried`, which names the event its last try sent,
|
|
577
|
+
* for the `failed` row a discard skips by, in the same commit. It writes through the
|
|
578
|
+
* try's `context.store`, fenced by its claim, so a failure whose lease has ended writes nothing.
|
|
321
579
|
*/
|
|
322
|
-
const workFailed = (
|
|
323
|
-
const write = Effect.fnUntraced(function* (job, failure) {
|
|
580
|
+
const workFailed = (log, now, tried) => {
|
|
581
|
+
const write = Effect.fnUntraced(function* (job, failure, store) {
|
|
324
582
|
if (scopeRepo(job.scope) === void 0) return;
|
|
325
|
-
const failed = tried === void 0 ? [] : [
|
|
326
|
-
...failedKey,
|
|
327
|
-
value: tried(job)
|
|
328
|
-
}];
|
|
583
|
+
const failed = tried === void 0 ? [] : [tried(job)];
|
|
329
584
|
for (let attempt = 0; attempt < failedTries; attempt += 1) {
|
|
330
585
|
const snapshot = yield* storeCall(() => store.read(job.scope, [selfKey, ...outboxReads]));
|
|
331
586
|
const record = yield* decodeRecord(snapshot.results[0]?.[0]);
|
|
@@ -352,7 +607,7 @@ const workFailed = (store, log, now, tried) => {
|
|
|
352
607
|
exempt: true
|
|
353
608
|
};
|
|
354
609
|
const appended = yield* appendEvents(log, outbox, [event], options);
|
|
355
|
-
const jobs =
|
|
610
|
+
const jobs = appended.jobs.filter((saved) => !sameJob(saved, job));
|
|
356
611
|
const change = {
|
|
357
612
|
id: newChangeId(),
|
|
358
613
|
expect: snapshot.version,
|
|
@@ -366,26 +621,29 @@ const workFailed = (store, log, now, tried) => {
|
|
|
366
621
|
}))).ok) return;
|
|
367
622
|
}
|
|
368
623
|
});
|
|
369
|
-
|
|
370
|
-
return handler;
|
|
624
|
+
return (_data, failure) => Effect.flatMap(Effect.all([CurrentJob.current, CurrentJob.store]), ([job, store]) => write(job, failure, store));
|
|
371
625
|
};
|
|
372
|
-
/** Whether `
|
|
373
|
-
const
|
|
626
|
+
/** Whether `a` and `b` are one job of a scope: its name and its key. */
|
|
627
|
+
const sameJob = (a, b) => a.name === b.name && a.key === b.key;
|
|
628
|
+
/** Whether `job` is a scope's job of a delivery, `git.deliver.<name>`. */
|
|
629
|
+
const isDeliverJob = (job) => deliveryOf(job.name) !== void 0 && job.key === "deliver";
|
|
374
630
|
/**
|
|
375
|
-
* A discard's event that has gone since it read the cursor: delivery passed it, by a retry, and
|
|
376
|
-
* trim deleted it, so there is nothing to skip. A trim deletes only
|
|
377
|
-
* that the cursor hasn't passed is `DATA_LOSS`.
|
|
631
|
+
* A discard's event that has gone since it read the cursor: `delivery` passed it, by a retry, and
|
|
632
|
+
* a trim deleted it, so there is nothing to skip. A trim deletes only events every delivery has
|
|
633
|
+
* passed, so one gone that the cursor hasn't passed is `DATA_LOSS`.
|
|
378
634
|
*/
|
|
379
|
-
const passed = Effect.fnUntraced(function* (store, scope, seq) {
|
|
380
|
-
const snapshot = yield* storeCall(() => store.read(scope, [...outboxReads]));
|
|
381
|
-
const {
|
|
382
|
-
if (
|
|
635
|
+
const passed = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, delivery, seq) {
|
|
636
|
+
const snapshot = yield* storeCall(() => store.read(scope, [...outboxReads, cursorRead(delivery)]));
|
|
637
|
+
const { head } = yield* decodeOutbox(snapshot.results);
|
|
638
|
+
if ((yield* cursorOf(store, scope, head, snapshot.results[2])).seq < seq) return yield* fail("DATA_LOSS", `The event ${seq} has gone`);
|
|
383
639
|
});
|
|
384
640
|
/** A retry that found the job no longer failed: a discard sent at once, or a retry, ran first. */
|
|
385
641
|
const notFailed = (error) => error.code === "FAILED_PRECONDITION" && isInfraError(error.cause) && error.cause.reason === "not-failed" || error.code === "NOT_FOUND";
|
|
386
642
|
/**
|
|
387
|
-
* A discard of
|
|
388
|
-
*
|
|
643
|
+
* A discard of `target`, a delivery's failed job, of the active `deliveries`: a skip of its
|
|
644
|
+
* delivery's cursor past the event its last try sent, with the low-water mark when it was the
|
|
645
|
+
* slowest, then that job due again for the rest. Every other delivery's job, failed or not, and
|
|
646
|
+
* its cursor, stay as they are. The queue makes a failed job due only by its own `retry`, so the two are
|
|
389
647
|
* separate writes. The skip is the cursor row past the cursor, added only when the `failed` row
|
|
390
648
|
* `workFailed` wrote names the try the job lists, by its `claim`, and that event: a try can fail
|
|
391
649
|
* before it sends one, and a row from an older failure names an older claim, even one in the same
|
|
@@ -393,18 +651,31 @@ const notFailed = (error) => error.code === "FAILED_PRECONDITION" && isInfraErro
|
|
|
393
651
|
* discard sent again finds the cursor past that event, or the job no longer failed, so it skips
|
|
394
652
|
* once. `verification/Discards.tla` checks it.
|
|
395
653
|
*/
|
|
396
|
-
const skipFailed = Effect.fnUntraced(function* (store, jobs, scope) {
|
|
397
|
-
const
|
|
654
|
+
const skipFailed = /* @__PURE__ */ Effect.fnUntraced(function* (store, jobs, scope, target, deliveries) {
|
|
655
|
+
const delivery = deliveryOf(target.name);
|
|
656
|
+
if (delivery === void 0 || !deliveries.includes(delivery)) return;
|
|
657
|
+
const request = {
|
|
658
|
+
state: "failed",
|
|
659
|
+
name: target.name
|
|
660
|
+
};
|
|
661
|
+
const failed = (yield* storeCall(() => jobs.list(scope, request))).items.find((item) => sameJob(item, target));
|
|
398
662
|
if (failed === void 0) return;
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
663
|
+
const failedRow = failedKeyOf(delivery);
|
|
664
|
+
const reads = [
|
|
665
|
+
...outboxReads,
|
|
666
|
+
{
|
|
667
|
+
collection: failedRow.collection,
|
|
668
|
+
id: failedRow.id
|
|
669
|
+
},
|
|
670
|
+
...deliveries.map(cursorRead)
|
|
671
|
+
];
|
|
403
672
|
const snapshot = yield* storeCall(() => store.read(scope, reads));
|
|
404
|
-
const { delivered } = yield* decodeOutbox(snapshot.results);
|
|
673
|
+
const { head, delivered } = yield* decodeOutbox(snapshot.results);
|
|
405
674
|
const [row] = snapshot.results[2] ?? [];
|
|
406
675
|
const tried = row === void 0 ? void 0 : yield* decodeRow(FailedTry, row, "The failed try");
|
|
407
|
-
const
|
|
676
|
+
const cursors = yield* decodeCursors(deliveries, snapshot.results.slice(3));
|
|
677
|
+
const cursor = cursors.get(delivery) ?? (yield* retainedStart(store, scope, head));
|
|
678
|
+
const seq = cursor.seq + 1;
|
|
408
679
|
if (tried?.seq === seq && tried.claim === failed.claim) {
|
|
409
680
|
const read = {
|
|
410
681
|
collection: outboxCollections.events,
|
|
@@ -412,64 +683,101 @@ const skipFailed = Effect.fnUntraced(function* (store, jobs, scope) {
|
|
|
412
683
|
};
|
|
413
684
|
const next = yield* storeCall(() => store.read(scope, [read]));
|
|
414
685
|
const [event] = yield* decodeEvents(next.results[0] ?? []);
|
|
415
|
-
if (event === void 0) yield* passed(store, scope, seq);
|
|
686
|
+
if (event === void 0) yield* passed(store, scope, delivery, seq);
|
|
416
687
|
else {
|
|
417
688
|
const value = {
|
|
418
689
|
seq,
|
|
419
|
-
bytes:
|
|
690
|
+
bytes: cursor.bytes + eventBytes(event)
|
|
420
691
|
};
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
};
|
|
426
|
-
yield* addCursor(store, scope, cursor);
|
|
692
|
+
yield* moveCursor(store, scope, delivery, value, {
|
|
693
|
+
delivered,
|
|
694
|
+
cursors
|
|
695
|
+
});
|
|
427
696
|
}
|
|
428
697
|
}
|
|
429
698
|
const job = {
|
|
430
|
-
name:
|
|
431
|
-
key:
|
|
699
|
+
name: failed.name,
|
|
700
|
+
key: failed.key
|
|
432
701
|
};
|
|
433
702
|
yield* storeCall(() => jobs.retry(scope, job)).pipe(Effect.catchIf(notFailed, () => Effect.void));
|
|
434
703
|
});
|
|
435
704
|
/** The longest a host's `events.timeout` may be: a Git job's longest try (Q188). */
|
|
436
705
|
const longestDelivery = 78e4;
|
|
437
706
|
/**
|
|
438
|
-
* Throws for an `events.timeout` past a Git job's longest try,
|
|
439
|
-
* options before its runtime is built.
|
|
707
|
+
* Throws an `INVALID_ARGUMENT` `GitError` for an `events.timeout` past a Git job's longest try,
|
|
708
|
+
* as `createGitServer` checks its options before its runtime is built.
|
|
440
709
|
*/
|
|
441
710
|
const checkDeliveryTimeout = ({ timeout }) => {
|
|
442
711
|
if (timeout === void 0 || millis(timeout) <= longestDelivery) return;
|
|
443
712
|
const message = `events.timeout is at most '13 minutes', the longest a Git job may run, not '${String(timeout)}'`;
|
|
444
|
-
throw
|
|
713
|
+
throw gitError("INVALID_ARGUMENT", message);
|
|
445
714
|
};
|
|
446
715
|
/**
|
|
447
|
-
*
|
|
448
|
-
*
|
|
716
|
+
* Throws an `INVALID_ARGUMENT` `GitError` unless there are 1 to `deliveryLimit` deliveries, each
|
|
717
|
+
* named, with no name twice, each job name within a job name's 256 bytes as UTF-8 and holding no
|
|
718
|
+
* U+0000 or lone surrogate, and each timeout within `checkDeliveryTimeout`'s. A store that writes a
|
|
719
|
+
* lone surrogate as U+FFFD would give two such names one cursor.
|
|
449
720
|
*/
|
|
450
|
-
const
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
721
|
+
const checkDeliveries = (deliveries) => {
|
|
722
|
+
const names = new Set(deliveries.map((delivery) => delivery.name));
|
|
723
|
+
if (deliveries.length === 0 || deliveries.length > 16) {
|
|
724
|
+
const message = `A server runs 1 to 16 deliveries, not ${deliveries.length}`;
|
|
725
|
+
throw gitError("INVALID_ARGUMENT", message);
|
|
726
|
+
}
|
|
727
|
+
if (names.size < deliveries.length) throw gitError("INVALID_ARGUMENT", "Each delivery has a name of its own");
|
|
728
|
+
for (const delivery of deliveries) {
|
|
729
|
+
const name = deliverJobName(delivery.name);
|
|
730
|
+
if (delivery.name === "" || name.includes("\0") || !isWellFormed(name) || utf8(name).length > limits.nameBytes) {
|
|
731
|
+
const message = `A delivery's name is set, holds no U+0000 or lone surrogate, and keeps '${deliverJobPrefix}<name>' within ${limits.nameBytes} bytes as UTF-8`;
|
|
732
|
+
throw gitError("INVALID_ARGUMENT", message);
|
|
733
|
+
}
|
|
734
|
+
checkDeliveryTimeout(delivery);
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
/**
|
|
738
|
+
* A job for each of `parts.deliveries`, `git.deliver.<name>`, over its host's handler: tried again
|
|
739
|
+
* as its `retry` says, or for three days at most an hour apart, within its own `timeout`, with its
|
|
740
|
+
* own cursor. Its last failure writes `repo.work.failed`, which waits behind it, and makes each
|
|
741
|
+
* other delivery's job due. The deliveries are checked before any job is made.
|
|
742
|
+
*/
|
|
743
|
+
const deliverJobs = (parts) => {
|
|
744
|
+
checkDeliveries(parts.deliveries);
|
|
745
|
+
const names = parts.deliveries.map((delivery) => delivery.name);
|
|
746
|
+
const log = {
|
|
747
|
+
deliveries: names,
|
|
748
|
+
deliverJobs: () => definitions.map((definition) => definition.job({
|
|
749
|
+
key: deliverJobKey,
|
|
750
|
+
data: {}
|
|
751
|
+
}))
|
|
465
752
|
};
|
|
466
|
-
const
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
753
|
+
const definitions = parts.deliveries.map((delivery) => {
|
|
754
|
+
const sending = /* @__PURE__ */ new Map();
|
|
755
|
+
const { timeout } = delivery;
|
|
756
|
+
const policy = {
|
|
757
|
+
payload: DeliverData,
|
|
758
|
+
retry: delivery.retry ?? defaultDeliverRetry
|
|
759
|
+
};
|
|
760
|
+
const DeliverJob = Job.make(deliverJobName(delivery.name), timeout === void 0 ? policy : {
|
|
761
|
+
...policy,
|
|
762
|
+
timeout: millis(timeout)
|
|
763
|
+
});
|
|
764
|
+
const tryParts = {
|
|
765
|
+
...parts,
|
|
766
|
+
delivery: delivery.name,
|
|
767
|
+
deliveries: names
|
|
768
|
+
};
|
|
769
|
+
const handler = deliverTry({
|
|
770
|
+
...tryParts,
|
|
771
|
+
handler: delivery.handler,
|
|
772
|
+
wake: log.deliverJobs
|
|
773
|
+
}, sending);
|
|
774
|
+
const tried = (job) => failedTry(sending, delivery.name, job);
|
|
775
|
+
const onFailure = workFailed(log, parts.now, tried);
|
|
776
|
+
return madeJob(DeliverJob.definition(handler, { onFailure }));
|
|
777
|
+
});
|
|
470
778
|
return {
|
|
471
|
-
|
|
779
|
+
definitions,
|
|
472
780
|
log
|
|
473
781
|
};
|
|
474
782
|
};
|
|
475
|
-
export {
|
|
783
|
+
export { DeliverData, checkDeliveries, checkDeliveryTimeout, defaultDeliverRetry, deliverJobKey, deliverJobName, deliverJobs, deliverTry, deliveriesOf, drainCeiling, eventDelivery, eventsDelivery, isDeliverJob, keptFor, notFailed, skipFailed, workFailed };
|