@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,7 +1,10 @@
|
|
|
1
|
-
import { gitError } from "../
|
|
1
|
+
import { gitError } from "../contracts/result.mjs";
|
|
2
|
+
import { RequestHolding } from "../store/call-count.mjs";
|
|
2
3
|
import { pushFloorsOf, readerFloors, readerMost } from "./budget.mjs";
|
|
3
4
|
import { packIndexerLimits } from "./pack-reads.mjs";
|
|
4
5
|
import { ReceivedPointers, lfsPointersMost, pageEntries } from "./lfs-pointers.mjs";
|
|
6
|
+
import { receiveRoomAdmitted } from "./receive-admission.mjs";
|
|
7
|
+
import { ReceiveRoom } from "./runs.mjs";
|
|
5
8
|
import { runnerIn } from "../store/crossing.mjs";
|
|
6
9
|
import * as Effect from "effect/Effect";
|
|
7
10
|
import * as Option from "effect/Option";
|
|
@@ -16,7 +19,7 @@ const headStuckMs = pushWaitMs / 2;
|
|
|
16
19
|
*/
|
|
17
20
|
const growWaitMs = 5e3;
|
|
18
21
|
/** The refusal a push gets when no room came within its wait, or its grow's. */
|
|
19
|
-
const pushBusy = gitError("UNAVAILABLE", "The server is busy with other pushes", {
|
|
22
|
+
const pushBusy = /* @__PURE__ */ gitError("UNAVAILABLE", "The server is busy with other pushes", {
|
|
20
23
|
hint: "Push again in a minute",
|
|
21
24
|
context: { reason: "busy" }
|
|
22
25
|
});
|
|
@@ -24,23 +27,59 @@ const pushBusy = gitError("UNAVAILABLE", "The server is busy with other pushes",
|
|
|
24
27
|
* The refusal a push gets when what it takes at once is past the whole budget, which no wait
|
|
25
28
|
* would make room for.
|
|
26
29
|
*/
|
|
27
|
-
const pushTooLarge = gitError("RESOURCE_EXHAUSTED", "This push takes more at once than fits in the server's memory", {
|
|
30
|
+
const pushTooLarge = /* @__PURE__ */ gitError("RESOURCE_EXHAUSTED", "This push takes more at once than fits in the server's memory", {
|
|
28
31
|
hint: "Push fewer commits at a time",
|
|
29
32
|
context: { reason: "too-large" }
|
|
30
33
|
});
|
|
31
34
|
/**
|
|
35
|
+
* A push's refusal when one entry needs more outside the indexer's cache than its isolate could
|
|
36
|
+
* ever give it beside the push: the entry's `need` and the `left` it could have beside the push's
|
|
37
|
+
* other objects, so a caller sees that a push of fewer objects leaves that entry more room.
|
|
38
|
+
*/
|
|
39
|
+
const pushEntryTooLarge = (objects) => (need, left) => {
|
|
40
|
+
const others = objects - 1;
|
|
41
|
+
const beside = others > 0 ? ` beside this push's other ${others.toLocaleString("en-US")} ${others === 1 ? "object" : "objects"}` : "";
|
|
42
|
+
return gitError("RESOURCE_EXHAUSTED", `An object in this push needs ${need.toLocaleString("en-US")} bytes of the server's memory at once, and ${Math.max(0, left).toLocaleString("en-US")} are left${beside}`, {
|
|
43
|
+
hint: "Push fewer commits at a time",
|
|
44
|
+
context: { reason: "too-large" }
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* A push's refusal when the repo's pack indexes its reads charge, beside what it holds of its
|
|
49
|
+
* own, pass what the server's memory could ever give it: the bytes of each, and that `most`, so a
|
|
50
|
+
* caller sees the repo's part, which a push of fewer commits leaves as it is.
|
|
51
|
+
*/
|
|
52
|
+
const pushIndexTooLarge = (index, own, most) => {
|
|
53
|
+
const bytes = (n) => n.toLocaleString("en-US");
|
|
54
|
+
return gitError("RESOURCE_EXHAUSTED", `This push needs ${bytes(index + own)} bytes of the server's memory at once, past the ${bytes(most)} it could have: ${bytes(index)} for the repo's pack indexes it reads, beside ${bytes(own)} of its own`, {
|
|
55
|
+
hint: "The repo's pack indexes count toward it, and push fewer commits at a time to leave them more",
|
|
56
|
+
context: {
|
|
57
|
+
reason: "too-large",
|
|
58
|
+
indexBytes: index,
|
|
59
|
+
pushBytes: own,
|
|
60
|
+
most
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
32
65
|
* A fetch's refusal when no room came within its wait, for its plan or its objects: Git shows a
|
|
33
66
|
* fetch's message alone, so the message says what to do.
|
|
34
67
|
*/
|
|
35
|
-
const fetchBusy = gitError("UNAVAILABLE", "The server is busy; fetch again in a minute", {
|
|
68
|
+
const fetchBusy = /* @__PURE__ */ gitError("UNAVAILABLE", "The server is busy; fetch again in a minute", {
|
|
36
69
|
hint: "Try again in a minute",
|
|
37
70
|
context: { reason: "busy" }
|
|
38
71
|
});
|
|
39
72
|
/** A reader's, a walk's or a diff's refusal when no room came within its wait. */
|
|
40
|
-
const readBusy = gitError("UNAVAILABLE", "The server is busy: try again in a minute", {
|
|
73
|
+
const readBusy = /* @__PURE__ */ gitError("UNAVAILABLE", "The server is busy: try again in a minute", {
|
|
41
74
|
hint: "Try again in a minute",
|
|
42
75
|
context: { reason: "busy" }
|
|
43
76
|
});
|
|
77
|
+
/**
|
|
78
|
+
* Maintenance's refusal when what one of its steps holds at once is past all it may hold, the
|
|
79
|
+
* budget less the read reserve, which no wait would make room for. Past only what's free while others hold the rest, the step waits
|
|
80
|
+
* as `readBusy` and comes back later (Q879's split, as Q888 asks of maintenance).
|
|
81
|
+
*/
|
|
82
|
+
const upkeepTooLarge = /* @__PURE__ */ gitError("RESOURCE_EXHAUSTED", "This repack step takes more at once than fits in the server's memory", { context: { reason: "too-large" } });
|
|
44
83
|
/** A cache's room within an operation's allotment, or the server's for its index cache. */
|
|
45
84
|
var Room = class {
|
|
46
85
|
#budget;
|
|
@@ -51,10 +90,19 @@ var Room = class {
|
|
|
51
90
|
/** What a shrink asks the cache to evict to. */
|
|
52
91
|
#evict = () => void 0;
|
|
53
92
|
closed = false;
|
|
54
|
-
|
|
93
|
+
/** The allotment it's within: none for the index cache's. */
|
|
94
|
+
owner;
|
|
95
|
+
/** Whether `growWithin` waits, refused with its allotment's busy. */
|
|
96
|
+
#waits;
|
|
97
|
+
/** Whether it's an index cache's room, which shrinks first and takes only what's free. */
|
|
98
|
+
index;
|
|
99
|
+
constructor(budget, floor, most, owner, waits = false, index = false) {
|
|
55
100
|
this.#budget = budget;
|
|
56
101
|
this.floor = floor;
|
|
57
102
|
this.most = Math.max(floor, most);
|
|
103
|
+
this.owner = owner;
|
|
104
|
+
this.#waits = waits;
|
|
105
|
+
this.index = index;
|
|
58
106
|
}
|
|
59
107
|
get bytes() {
|
|
60
108
|
return this.floor + this.extra;
|
|
@@ -63,6 +111,17 @@ var Room = class {
|
|
|
63
111
|
if (this.closed || this.bytes + bytes > this.most) return false;
|
|
64
112
|
return this.#budget.growRoom(this, bytes);
|
|
65
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* `grow`, waiting for the room when it's refused, for a block its cache let go and reads again:
|
|
116
|
+
* `true` once grown, or its allotment's busy past `growWaitMs`. `false` at once for a room that
|
|
117
|
+
* never waits, is closed or would pass its most, or whose own allotment, rooms and all, leaves
|
|
118
|
+
* too little of the budget for it: no other operation's end would make that room.
|
|
119
|
+
*/
|
|
120
|
+
growWithin(bytes) {
|
|
121
|
+
const owner = this.owner;
|
|
122
|
+
if (owner === void 0 || !this.#waits || this.closed || this.bytes + bytes > this.most || owner.held + bytes > this.#budget.total) return Effect.succeed(false);
|
|
123
|
+
return this.#budget.growWithin(this, bytes, owner);
|
|
124
|
+
}
|
|
66
125
|
watch(evict) {
|
|
67
126
|
this.#evict = evict;
|
|
68
127
|
}
|
|
@@ -71,6 +130,7 @@ var Room = class {
|
|
|
71
130
|
const freed = this.extra;
|
|
72
131
|
if (freed === 0) return 0;
|
|
73
132
|
this.extra = 0;
|
|
133
|
+
if (this.index) this.#budget.unwatchIndex(this);
|
|
74
134
|
this.#evict(this.floor);
|
|
75
135
|
return freed;
|
|
76
136
|
}
|
|
@@ -86,18 +146,21 @@ var MemoryAllotment = class MemoryAllotment {
|
|
|
86
146
|
push;
|
|
87
147
|
/** Its operation's refusal when a grow finds no room within its wait. */
|
|
88
148
|
busy;
|
|
149
|
+
/** The request whose `allot` this is: its grows let that request's kept reaches go first. */
|
|
150
|
+
owner;
|
|
89
151
|
#bytes;
|
|
90
152
|
#admitted;
|
|
91
153
|
#rooms = /* @__PURE__ */ new Set();
|
|
92
154
|
#released = false;
|
|
93
|
-
constructor(budget, bytes, push, busy, admitted = push ? bytes : 0) {
|
|
155
|
+
constructor(budget, bytes, push, busy, admitted = push ? bytes : 0, owner) {
|
|
94
156
|
this.#budget = budget;
|
|
95
157
|
this.#bytes = bytes;
|
|
96
158
|
this.#admitted = admitted;
|
|
97
159
|
this.push = push;
|
|
98
160
|
this.busy = busy;
|
|
161
|
+
this.owner = owner;
|
|
99
162
|
}
|
|
100
|
-
/** What a push's admission counts of it: its must-have and
|
|
163
|
+
/** What a push's admission counts of it: its must-have, floors and grows, or what it kept. */
|
|
101
164
|
get admitted() {
|
|
102
165
|
return this.#admitted;
|
|
103
166
|
}
|
|
@@ -105,13 +168,27 @@ var MemoryAllotment = class MemoryAllotment {
|
|
|
105
168
|
get bytes() {
|
|
106
169
|
return this.#bytes;
|
|
107
170
|
}
|
|
171
|
+
/** What it holds of the budget: its bytes and its rooms' growth. */
|
|
172
|
+
get held() {
|
|
173
|
+
let held = this.#bytes;
|
|
174
|
+
for (const room of this.#rooms) held += room.extra;
|
|
175
|
+
return held;
|
|
176
|
+
}
|
|
108
177
|
get released() {
|
|
109
178
|
return this.#released;
|
|
110
179
|
}
|
|
111
180
|
/**
|
|
181
|
+
* What it can still grow by, were nothing else allotted: its budget's total less what it holds,
|
|
182
|
+
* a push's less the reserve too. A grow past it is refused at once, with its `tooLarge` when
|
|
183
|
+
* given, since no wait makes room.
|
|
184
|
+
*/
|
|
185
|
+
get growable() {
|
|
186
|
+
return this.#budget.mostOf(this.push) - this.#bytes;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
112
189
|
* Grows it by `bytes`, at once when they fit once caches shrink, or within `growWaitMs`; then
|
|
113
|
-
* its `busy` refuses it. Bytes that couldn't fit the budget alone
|
|
114
|
-
* `tooLarge` when given.
|
|
190
|
+
* its `busy` refuses it. Bytes that couldn't fit the budget alone, a push's beside the reserve,
|
|
191
|
+
* are refused at once, with `tooLarge` when given.
|
|
115
192
|
*/
|
|
116
193
|
grow(bytes, tooLarge) {
|
|
117
194
|
return this.#budget.grow(this, bytes, this.busy, tooLarge);
|
|
@@ -120,12 +197,15 @@ var MemoryAllotment = class MemoryAllotment {
|
|
|
120
197
|
shrink(bytes) {
|
|
121
198
|
if (this.#released) return;
|
|
122
199
|
const given = Math.min(bytes, this.#bytes);
|
|
200
|
+
const admitted = this.push ? Math.min(given, this.#admitted) : 0;
|
|
123
201
|
this.#bytes -= given;
|
|
124
|
-
this.#
|
|
202
|
+
this.#admitted -= admitted;
|
|
203
|
+
this.#budget.returned(given, admitted);
|
|
125
204
|
}
|
|
126
|
-
/** Adds `bytes` granted by the budget. */
|
|
205
|
+
/** Adds `bytes` granted by the budget: a push's are admitted, as its grows count with pushes. */
|
|
127
206
|
added(bytes) {
|
|
128
207
|
this.#bytes += bytes;
|
|
208
|
+
if (this.push) this.#admitted += bytes;
|
|
129
209
|
}
|
|
130
210
|
/**
|
|
131
211
|
* Grows it by `bytes` only when they fit at once, with no wait: whether they did. A walk's
|
|
@@ -149,10 +229,12 @@ var MemoryAllotment = class MemoryAllotment {
|
|
|
149
229
|
}
|
|
150
230
|
/**
|
|
151
231
|
* A cache's room: `floor` within this allotment, already counted in it, and up to `most` when the
|
|
152
|
-
* budget has room to spare. It shrinks to its floor when another allotment needs the room.
|
|
232
|
+
* budget has room to spare. It shrinks to its floor when another allotment needs the room. With
|
|
233
|
+
* `waits`, its `growWithin` waits for room, refused with this allotment's busy, for a caller that
|
|
234
|
+
* retries that busy.
|
|
153
235
|
*/
|
|
154
|
-
room(floor, most) {
|
|
155
|
-
const room = new Room(this.#budget, floor, most);
|
|
236
|
+
room(floor, most, waits = false) {
|
|
237
|
+
const room = new Room(this.#budget, floor, most, this, waits);
|
|
156
238
|
if (this.#released) room.closed = true;
|
|
157
239
|
else {
|
|
158
240
|
this.#rooms.add(room);
|
|
@@ -160,6 +242,18 @@ var MemoryAllotment = class MemoryAllotment {
|
|
|
160
242
|
}
|
|
161
243
|
return room;
|
|
162
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Ends one of its rooms before it ends: what the room grew past its floor goes back, and its
|
|
247
|
+
* floor stays counted in this allotment until a shrink gives it back.
|
|
248
|
+
*/
|
|
249
|
+
endRoom(room) {
|
|
250
|
+
if (!(room instanceof Room) || !this.#rooms.delete(room)) return;
|
|
251
|
+
const extra = room.extra;
|
|
252
|
+
room.extra = 0;
|
|
253
|
+
room.closed = true;
|
|
254
|
+
this.#budget.unwatchRoom(room);
|
|
255
|
+
this.#budget.returned(extra, 0);
|
|
256
|
+
}
|
|
163
257
|
/** Ends it with its bytes handed to another allotment, as a grow's wait does: nothing goes back. */
|
|
164
258
|
adopted() {
|
|
165
259
|
this.#released = true;
|
|
@@ -184,10 +278,11 @@ var MemoryAllotment = class MemoryAllotment {
|
|
|
184
278
|
* from, so together they never take more than `total`. A push is admitted with its must-have and
|
|
185
279
|
* floors when they fit beside every admitted push within `total` less `reserve`, first-fit and
|
|
186
280
|
* oldest first, and none passes a push that has waited `headStuckMs`; it waits `pushWaitMs` at
|
|
187
|
-
* most. A fetch, a walk or a diff is allotted at once,
|
|
188
|
-
* stuck one, or waits `growWaitMs`. Caches are allotted
|
|
189
|
-
* shrinks to its floor, the index cache's first,
|
|
190
|
-
* It runs on one thread, so each step is
|
|
281
|
+
* most. Its grows fit there too, and count with it. A fetch, a walk or a diff is allotted at once,
|
|
282
|
+
* ahead of waiting pushes but never past a stuck one, or waits `growWaitMs`. Caches are allotted
|
|
283
|
+
* rooms between a floor and a most, and each shrinks to its floor, the index cache's first,
|
|
284
|
+
* whenever an allotment asks for more than is free. It runs on one thread, so each step is
|
|
285
|
+
* synchronous: the only awaits are the waits.
|
|
191
286
|
*/
|
|
192
287
|
var MemoryBudget = class {
|
|
193
288
|
total;
|
|
@@ -195,12 +290,24 @@ var MemoryBudget = class {
|
|
|
195
290
|
#allotted = 0;
|
|
196
291
|
#admitted = 0;
|
|
197
292
|
#rooms = /* @__PURE__ */ new Set();
|
|
293
|
+
/** The reaches requests keep, oldest first. */
|
|
294
|
+
#kept = /* @__PURE__ */ new Set();
|
|
198
295
|
#pushes = [];
|
|
199
296
|
#reads = [];
|
|
297
|
+
/**
|
|
298
|
+
* Upkeep's allotments, marked in `#allotOf`: they count with pushes, so `push` can't tell them
|
|
299
|
+
* apart. Their grows yield to pushes', and a refused grow's log line names them.
|
|
300
|
+
*/
|
|
301
|
+
#upkeeps = /* @__PURE__ */ new WeakSet();
|
|
200
302
|
/** Whether a wake runs, and whether one was asked for inside it. */
|
|
201
303
|
#waking = false;
|
|
202
304
|
#wakeAgain = false;
|
|
203
|
-
|
|
305
|
+
/**
|
|
306
|
+
* The index caches' rooms holding bytes, oldest first: one for each `open()` this budget serves.
|
|
307
|
+
* A room joins when it first grows and leaves when it shrinks, so a server dropped with its
|
|
308
|
+
* cache empty leaves nothing here.
|
|
309
|
+
*/
|
|
310
|
+
#indexes = /* @__PURE__ */ new Set();
|
|
204
311
|
/** The clock of the last operation that asked, so a release's wake reads the same time. */
|
|
205
312
|
#now = Date.now;
|
|
206
313
|
constructor(total, reserve) {
|
|
@@ -214,6 +321,26 @@ var MemoryBudget = class {
|
|
|
214
321
|
return effect();
|
|
215
322
|
});
|
|
216
323
|
}
|
|
324
|
+
/**
|
|
325
|
+
* `reach` kept until `unkeep`, or until `#fit` lets it go: `false`, with nothing kept, where its
|
|
326
|
+
* owner's kept reaches, this one's bytes now included, would pass a quarter of the budget. So a
|
|
327
|
+
* request keeps no new reach once its kept reaches pass a quarter, and its kept reaches can grow
|
|
328
|
+
* past that by their answers, all of which give way.
|
|
329
|
+
*/
|
|
330
|
+
keep(reach) {
|
|
331
|
+
let owned = reach.allotment.bytes;
|
|
332
|
+
for (const kept of this.#kept) if (kept.owner === reach.owner) owned += kept.allotment.bytes;
|
|
333
|
+
if (owned > this.total / 4) return false;
|
|
334
|
+
this.#kept.add(reach);
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
unkeep(reach) {
|
|
338
|
+
this.#kept.delete(reach);
|
|
339
|
+
}
|
|
340
|
+
/** A kept reach no ask uses now: what waits may fit by letting it go. */
|
|
341
|
+
reachIdle() {
|
|
342
|
+
this.#wake();
|
|
343
|
+
}
|
|
217
344
|
/** Every byte allotted, rooms' growth included. */
|
|
218
345
|
allotted() {
|
|
219
346
|
return this.#allotted;
|
|
@@ -222,12 +349,12 @@ var MemoryBudget = class {
|
|
|
222
349
|
admittedBytes() {
|
|
223
350
|
return this.#admitted;
|
|
224
351
|
}
|
|
225
|
-
/**
|
|
352
|
+
/**
|
|
353
|
+
* An index cache's room: a server's own, with no floor, which shrinks first. Each `open()` on
|
|
354
|
+
* one budget has its own, and one never takes another's bytes.
|
|
355
|
+
*/
|
|
226
356
|
indexRoom() {
|
|
227
|
-
|
|
228
|
-
this.#index = room;
|
|
229
|
-
this.#rooms.add(room);
|
|
230
|
-
return room;
|
|
357
|
+
return new Room(this, 0, this.total, void 0, false, true);
|
|
231
358
|
}
|
|
232
359
|
watchRoom(room) {
|
|
233
360
|
this.#rooms.add(room);
|
|
@@ -235,12 +362,95 @@ var MemoryBudget = class {
|
|
|
235
362
|
unwatchRoom(room) {
|
|
236
363
|
this.#rooms.delete(room);
|
|
237
364
|
}
|
|
238
|
-
/**
|
|
365
|
+
/** An index room shrunk to nothing. */
|
|
366
|
+
unwatchIndex(room) {
|
|
367
|
+
this.#indexes.delete(room);
|
|
368
|
+
this.#rooms.delete(room);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* A room's growth, from these in order: what's free; then the index caches', which no operation
|
|
372
|
+
* uses, let go only when that makes it fit. Never from a live operation's room or a kept reach:
|
|
373
|
+
* a request's kept reach is rebuilt by its next ask, and an allotment's grow, which rooms and
|
|
374
|
+
* kept reaches yield to, would take the room back, so each would evict what the other just
|
|
375
|
+
* read, back and forth. An index cache's own growth takes only what's free. So a warm isolate's
|
|
376
|
+
* leftover index cache doesn't keep a push's blocks at their floor, reading each block again
|
|
377
|
+
* (#1190). Refused while an operation waits, so the bytes freed go to it. A room refused its
|
|
378
|
+
* growth evicts to its floor.
|
|
379
|
+
*/
|
|
239
380
|
growRoom(room, bytes) {
|
|
240
|
-
if (this.#pushes.length > 0 || this.#reads.length > 0 || this.#
|
|
381
|
+
if (this.#pushes.length > 0 || this.#reads.length > 0 || this.#roomFree(room, false) < bytes) return false;
|
|
382
|
+
this.#roomGrows(room, bytes);
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* What `room` can grow by: what's free and, but for an index room, the index caches', and with `parked`, a room wait's,
|
|
387
|
+
* the growth of the rooms of operations parked on a grow too.
|
|
388
|
+
*/
|
|
389
|
+
#roomFree(room, parked) {
|
|
390
|
+
let free = this.total - this.#allotted;
|
|
391
|
+
if (!room.index) for (const index of this.#indexes) free += index.extra;
|
|
392
|
+
if (parked) for (const each of this.#parked(room)) free += each.extra;
|
|
393
|
+
return free;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* The rooms of operations parked on their allotment's grow, but `room`'s own: a parked operation
|
|
397
|
+
* reads through none of its caches till its grow lands, and then reads again what they let go,
|
|
398
|
+
* as after any shrink (#1197).
|
|
399
|
+
*/
|
|
400
|
+
*#parked(room) {
|
|
401
|
+
const parked = /* @__PURE__ */ new Set();
|
|
402
|
+
for (const waiter of this.#reads) if (!("room" in waiter) && waiter.grower !== void 0) parked.add(waiter.grower);
|
|
403
|
+
for (const each of this.#rooms) if (each.owner !== void 0 && each.owner !== room.owner && parked.has(each.owner)) yield each;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* `room` grown by `bytes` that `#roomFree` holds: the index caches let go first, oldest first,
|
|
407
|
+
* then parked operations' rooms, one at a time, only while they still need it. An index room
|
|
408
|
+
* takes only what's free.
|
|
409
|
+
*/
|
|
410
|
+
#roomGrows(room, bytes) {
|
|
411
|
+
for (const index of room.index ? [] : [...this.#indexes]) {
|
|
412
|
+
if (this.#allotted + bytes <= this.total) break;
|
|
413
|
+
this.#allotted -= index.shrink();
|
|
414
|
+
}
|
|
415
|
+
for (const each of this.#parked(room)) {
|
|
416
|
+
if (this.#allotted + bytes <= this.total) break;
|
|
417
|
+
this.#allotted -= each.shrink();
|
|
418
|
+
}
|
|
419
|
+
if (room.index && bytes > 0) {
|
|
420
|
+
this.#indexes.add(room);
|
|
421
|
+
this.#rooms.add(room);
|
|
422
|
+
}
|
|
241
423
|
room.extra += bytes;
|
|
242
424
|
this.#allotted += bytes;
|
|
243
|
-
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* `Room.growWithin`: `room` grown by `bytes` at once when they fit and no push is stuck, though
|
|
428
|
+
* others wait; else a wait in the reads' queue, in arrival order, `growWaitMs` at most, then
|
|
429
|
+
* `owner`'s busy. It takes what `growRoom` may, and the rooms of operations parked on their allotment's
|
|
430
|
+
* grow, never a running operation's room or a kept reach, and holds nothing while it waits. So
|
|
431
|
+
* an operation that holds what the wait needs finishes as it would with no wait: its allotment's
|
|
432
|
+
* grows don't queue behind it, its own room's wait is granted whenever its bytes fit, and once
|
|
433
|
+
* it parks on a grow that the waiter's admission holds back, its rooms let the waiter land and
|
|
434
|
+
* give that grow its room. A cache that thrashes its floor beside a running operation waits for
|
|
435
|
+
* it to end, and is refused busy rather than reading the same blocks until its calls run out
|
|
436
|
+
* (#1197).
|
|
437
|
+
*/
|
|
438
|
+
growWithin(room, bytes, owner) {
|
|
439
|
+
return this.#timed(() => {
|
|
440
|
+
if (this.#stuck(this.#now()) === void 0 && this.#roomFree(room, true) >= bytes) {
|
|
441
|
+
this.#roomGrows(room, bytes);
|
|
442
|
+
return Effect.succeed(true);
|
|
443
|
+
}
|
|
444
|
+
const waited = this.#queued(this.#reads, growWaitMs, (granted) => ({ waiter: {
|
|
445
|
+
room,
|
|
446
|
+
bytes,
|
|
447
|
+
granted
|
|
448
|
+
} }));
|
|
449
|
+
return Effect.flatMap(waited, Option.match({
|
|
450
|
+
onNone: () => Effect.fail(owner.busy),
|
|
451
|
+
onSome: Effect.succeed
|
|
452
|
+
}));
|
|
453
|
+
});
|
|
244
454
|
}
|
|
245
455
|
/** Bytes an allotment gave back, and the admitted bytes of a push that ended, then the queue's wake. */
|
|
246
456
|
returned(bytes, admitted) {
|
|
@@ -248,35 +458,79 @@ var MemoryBudget = class {
|
|
|
248
458
|
this.#admitted -= admitted;
|
|
249
459
|
this.#wake();
|
|
250
460
|
}
|
|
251
|
-
/**
|
|
252
|
-
|
|
461
|
+
/**
|
|
462
|
+
* Frees room for `bytes` by shrinking caches to their floors, the index caches' first, then by
|
|
463
|
+
* letting go of kept reaches no ask uses, `asker`'s own first, then the oldest.
|
|
464
|
+
*/
|
|
465
|
+
#fit(bytes, asker) {
|
|
253
466
|
if (this.#allotted + bytes <= this.total) return true;
|
|
254
|
-
const order = [...this.#rooms].sort((a, b) => Number(b
|
|
467
|
+
const order = [...this.#rooms].sort((a, b) => Number(b.index) - Number(a.index));
|
|
255
468
|
for (const room of order) {
|
|
256
469
|
this.#allotted -= room.shrink();
|
|
257
470
|
if (this.#allotted + bytes <= this.total) return true;
|
|
258
471
|
}
|
|
472
|
+
const kept = [...this.#kept].sort((a, b) => Number(b.owner === asker) - Number(a.owner === asker));
|
|
473
|
+
for (const reach of kept) {
|
|
474
|
+
if (!reach.idle()) continue;
|
|
475
|
+
this.#kept.delete(reach);
|
|
476
|
+
reach.dropped();
|
|
477
|
+
reach.allotment.release();
|
|
478
|
+
if (this.#allotted + bytes <= this.total) return true;
|
|
479
|
+
}
|
|
259
480
|
return false;
|
|
260
481
|
}
|
|
482
|
+
/**
|
|
483
|
+
* The queue's one order between pushes and upkeep (#1300): upkeep's `bytes`, an ask or a grow,
|
|
484
|
+
* yield while the pushes' grows that wait wouldn't all fit beside them, whichever asked first.
|
|
485
|
+
* So a push's grow is let in first, and upkeep's ask, waiting or new, never takes its room.
|
|
486
|
+
*/
|
|
487
|
+
#yieldsToPushes(bytes, upkeep) {
|
|
488
|
+
if (!upkeep) return false;
|
|
489
|
+
let waiting = 0;
|
|
490
|
+
for (const waiter of this.#reads) if (!("room" in waiter) && waiter.grower?.push === true && !this.#upkeeps.has(waiter.grower)) waiting += waiter.bytes;
|
|
491
|
+
return waiting > 0 && !this.#fits(bytes + waiting, true);
|
|
492
|
+
}
|
|
493
|
+
/** Whether `waiter` is upkeep's: an ask, which only upkeep makes counted with pushes, or a grow. */
|
|
494
|
+
#upkeepWaits(waiter) {
|
|
495
|
+
if ("room" in waiter || !waiter.push) return false;
|
|
496
|
+
return waiter.grower === void 0 || this.#upkeeps.has(waiter.grower);
|
|
497
|
+
}
|
|
261
498
|
/** The waiting push at the head when it has waited `headStuckMs`: nothing passes it. */
|
|
262
499
|
#stuck(now) {
|
|
263
500
|
const head = this.#pushes[0];
|
|
264
501
|
return head !== void 0 && now - head.since >= 3e4 ? head : void 0;
|
|
265
502
|
}
|
|
503
|
+
/** The most an allotment may hold: the whole budget, or a push's, all of it but the reserve. */
|
|
504
|
+
mostOf(push) {
|
|
505
|
+
return push ? this.total - this.reserve : this.total;
|
|
506
|
+
}
|
|
266
507
|
/** Whether a push's `bytes` fit beside the admitted pushes, the reserve left. */
|
|
267
|
-
#admits(bytes) {
|
|
268
|
-
return this.#admitted + bytes <= this.total - this.reserve && this.#fit(bytes);
|
|
508
|
+
#admits(bytes, asker) {
|
|
509
|
+
return this.#admitted + bytes <= this.total - this.reserve && this.#fit(bytes, asker);
|
|
269
510
|
}
|
|
270
|
-
|
|
271
|
-
|
|
511
|
+
/** Whether `bytes` fit now: a push's beside the admitted pushes, a read's once caches shrink. */
|
|
512
|
+
#fits(bytes, push, asker) {
|
|
513
|
+
return push ? this.#admits(bytes, asker) : this.#fit(bytes, asker);
|
|
514
|
+
}
|
|
515
|
+
#grant(bytes, push, busy = push ? pushBusy : readBusy, owner) {
|
|
516
|
+
const allotment = new MemoryAllotment(this, bytes, push, busy, void 0, owner);
|
|
272
517
|
this.#allotted += bytes;
|
|
273
518
|
if (push) this.#admitted += bytes;
|
|
519
|
+
this.#wakeRooms();
|
|
274
520
|
return allotment;
|
|
275
521
|
}
|
|
276
522
|
/**
|
|
523
|
+
* Wakes the queue when a room waits: a grant that shrank the caches to fit, each to its floor,
|
|
524
|
+
* may leave more free than it took, which only a room's wait, never letting a cache go, needed.
|
|
525
|
+
*/
|
|
526
|
+
#wakeRooms() {
|
|
527
|
+
if (this.#reads.some((waiter) => "room" in waiter)) this.#wake();
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
277
530
|
* The next waiter the queue's one rule lets in, or none: a stuck head when it fits, and nothing
|
|
278
|
-
* past it when it doesn't; else the oldest read that fits
|
|
279
|
-
* pushes
|
|
531
|
+
* past it when it doesn't; else the oldest read or grow that fits, a push's grow beside the
|
|
532
|
+
* admitted pushes, upkeep only once it yields to no push's grow; else the oldest push that fits.
|
|
533
|
+
* The pushes wait in arrival order, so once the head isn't stuck none behind it is.
|
|
280
534
|
*/
|
|
281
535
|
#next(now) {
|
|
282
536
|
const stuck = this.#stuck(now);
|
|
@@ -285,11 +539,11 @@ var MemoryBudget = class {
|
|
|
285
539
|
waiter: stuck,
|
|
286
540
|
push: true
|
|
287
541
|
} : void 0;
|
|
288
|
-
const read = this.#reads.find((waiter) => this.#
|
|
542
|
+
const read = this.#reads.find((waiter) => "room" in waiter ? waiter.room.closed || this.#roomFree(waiter.room, true) >= waiter.bytes : this.#fits(waiter.bytes, waiter.push, waiter.asker) && !this.#yieldsToPushes(waiter.bytes, this.#upkeepWaits(waiter)));
|
|
289
543
|
if (read !== void 0) return {
|
|
290
544
|
queue: this.#reads,
|
|
291
545
|
waiter: read,
|
|
292
|
-
push: false
|
|
546
|
+
push: "room" in read ? false : read.push
|
|
293
547
|
};
|
|
294
548
|
const push = this.#pushes.find((waiter) => this.#admits(waiter.bytes));
|
|
295
549
|
if (push !== void 0) return {
|
|
@@ -320,7 +574,11 @@ var MemoryBudget = class {
|
|
|
320
574
|
for (let next = this.#next(now); next !== void 0; next = this.#next(now)) {
|
|
321
575
|
const { queue, waiter, push } = next;
|
|
322
576
|
queue.splice(queue.indexOf(waiter), 1);
|
|
323
|
-
|
|
577
|
+
if ("room" in waiter) {
|
|
578
|
+
const open = !waiter.room.closed;
|
|
579
|
+
if (open) this.#roomGrows(waiter.room, waiter.bytes);
|
|
580
|
+
waiter.granted(open);
|
|
581
|
+
} else waiter.admitted(this.#grant(waiter.bytes, push, waiter.busy, waiter.asker));
|
|
324
582
|
}
|
|
325
583
|
} while (this.#wakeAgain);
|
|
326
584
|
} finally {
|
|
@@ -328,39 +586,64 @@ var MemoryBudget = class {
|
|
|
328
586
|
}
|
|
329
587
|
}
|
|
330
588
|
/**
|
|
331
|
-
* Waits in `queue`
|
|
589
|
+
* Waits in `queue` as the waiter `enter` makes, `ms` at most; `None` past it. A wait interrupted,
|
|
332
590
|
* by its timeout too, leaves the queue and wakes it, since the waiter may have held up others,
|
|
333
|
-
* and
|
|
591
|
+
* and runs its `left`.
|
|
334
592
|
*/
|
|
335
|
-
#
|
|
593
|
+
#queued(queue, ms, enter) {
|
|
336
594
|
return Effect.callback((resume) => {
|
|
337
|
-
|
|
338
|
-
const waiter = {
|
|
339
|
-
bytes,
|
|
340
|
-
busy,
|
|
341
|
-
since: this.#now(),
|
|
342
|
-
admitted: (allotment) => {
|
|
343
|
-
granted = allotment;
|
|
344
|
-
resume(Effect.succeed(allotment));
|
|
345
|
-
}
|
|
346
|
-
};
|
|
595
|
+
const { waiter, left } = enter((granted) => resume(Effect.succeed(granted)));
|
|
347
596
|
queue.push(waiter);
|
|
597
|
+
if (!("room" in waiter) && waiter.grower !== void 0) this.#wakeRooms();
|
|
348
598
|
return Effect.sync(() => {
|
|
349
599
|
const at = queue.indexOf(waiter);
|
|
350
600
|
if (at >= 0) {
|
|
351
601
|
queue.splice(at, 1);
|
|
352
602
|
this.#wake();
|
|
353
603
|
}
|
|
354
|
-
|
|
604
|
+
left?.();
|
|
355
605
|
});
|
|
356
606
|
}).pipe(Effect.timeoutOption(ms));
|
|
357
607
|
}
|
|
358
608
|
/**
|
|
359
|
-
*
|
|
360
|
-
*
|
|
609
|
+
* Waits in `queue` for an allotment of `bytes`, `ms` at most; `None` past it. A wait interrupted,
|
|
610
|
+
* by its timeout too, gives back an allotment granted it that it never took.
|
|
611
|
+
*/
|
|
612
|
+
#wait(queue, push, bytes, ms, busy, own, asker, grower) {
|
|
613
|
+
return this.#queued(queue, ms, (resume) => {
|
|
614
|
+
let granted;
|
|
615
|
+
return {
|
|
616
|
+
waiter: {
|
|
617
|
+
bytes,
|
|
618
|
+
push,
|
|
619
|
+
busy,
|
|
620
|
+
asker,
|
|
621
|
+
grower,
|
|
622
|
+
since: this.#now(),
|
|
623
|
+
admitted: (allotment) => {
|
|
624
|
+
granted = allotment;
|
|
625
|
+
own(allotment);
|
|
626
|
+
resume(allotment);
|
|
627
|
+
}
|
|
628
|
+
},
|
|
629
|
+
left: () => granted?.release()
|
|
630
|
+
};
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* An allotment released when the scope ends, on every exit. Its finalizer is added first, and
|
|
635
|
+
* `allotment` hands it what it grants in the step that grants it, by `own`, so its wait stays
|
|
636
|
+
* interruptible and no interrupt, after a grant or after a wait, leaves an allotment unowned.
|
|
361
637
|
*/
|
|
362
638
|
#scoped(allotment) {
|
|
363
|
-
return Effect.uninterruptibleMask((restore) =>
|
|
639
|
+
return Effect.uninterruptibleMask((restore) => {
|
|
640
|
+
let taken;
|
|
641
|
+
const own = (granted) => {
|
|
642
|
+
taken = granted;
|
|
643
|
+
return granted;
|
|
644
|
+
};
|
|
645
|
+
return Effect.andThen(Effect.addFinalizer(() => Effect.sync(() => taken?.release())), restore(this.#timed(() => allotment(own))));
|
|
646
|
+
});
|
|
364
647
|
}
|
|
365
648
|
/**
|
|
366
649
|
* A push's admission with `bytes`, its must-have and floors: at once when they fit beside the
|
|
@@ -369,10 +652,10 @@ var MemoryBudget = class {
|
|
|
369
652
|
* no wait makes room for, `pushTooLarge` at once. Released when the scope ends.
|
|
370
653
|
*/
|
|
371
654
|
admit(bytes) {
|
|
372
|
-
return this.#scoped(() => {
|
|
655
|
+
return this.#scoped((own) => {
|
|
373
656
|
if (bytes > this.total - this.reserve) return Effect.fail(pushTooLarge);
|
|
374
|
-
if (this.#stuck(this.#now()) === void 0 && this.#admits(bytes)) return Effect.succeed(this.#grant(bytes, true));
|
|
375
|
-
return this.#wait(this.#pushes, bytes, pushWaitMs).pipe(Effect.flatMap(Option.match({
|
|
657
|
+
if (this.#stuck(this.#now()) === void 0 && this.#admits(bytes)) return Effect.succeed(own(this.#grant(bytes, true)));
|
|
658
|
+
return this.#wait(this.#pushes, true, bytes, pushWaitMs, void 0, own).pipe(Effect.flatMap(Option.match({
|
|
376
659
|
onNone: () => Effect.fail(pushBusy),
|
|
377
660
|
onSome: Effect.succeed
|
|
378
661
|
})));
|
|
@@ -384,39 +667,85 @@ var MemoryBudget = class {
|
|
|
384
667
|
* Bytes past `total` are refused at once, `tooLarge` or `busy`. Released when the scope ends.
|
|
385
668
|
*/
|
|
386
669
|
allot(bytes, busy = readBusy, tooLarge) {
|
|
387
|
-
return
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
670
|
+
return Effect.flatMap(Effect.serviceOption(RequestHolding), (hold) => this.#allotOf(bytes, false, busy, tooLarge, Option.getOrUndefined(hold)));
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Upkeep's allotment of `bytes`, a maintenance step's or an index build's: upkeep honours the
|
|
674
|
+
* read reserve, as pushes do, so it grows as a push's does, beside the admitted pushes within
|
|
675
|
+
* `total` less `reserve` and counted with them, and a read's floors always fit beside it (Q895).
|
|
676
|
+
* It and each grow wait `growWaitMs` as a read's, then fail `busy`, as `bytes` past all it may
|
|
677
|
+
* hold does at once. Released when the scope ends.
|
|
678
|
+
*/
|
|
679
|
+
upkeep(bytes = 0, busy = readBusy) {
|
|
680
|
+
return this.#allotOf(bytes, true, busy);
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* `allot`'s and `upkeep`'s allotment of `bytes`: at once when they fit, no push is stuck at the
|
|
684
|
+
* head and, for upkeep, no push's grow waits that they'd take the room of; else within
|
|
685
|
+
* `growWaitMs`, then `busy`. With `push`, they fit as a push's grows do.
|
|
686
|
+
* Bytes past what it may ever hold are refused at once, `tooLarge` or `busy`.
|
|
687
|
+
*/
|
|
688
|
+
#allotOf(bytes, push, busy, tooLarge, asker) {
|
|
689
|
+
return this.#scoped((own) => {
|
|
690
|
+
if (bytes > this.mostOf(push)) return Effect.fail(tooLarge ?? busy);
|
|
691
|
+
const owned = (allotment) => {
|
|
692
|
+
if (push) this.#upkeeps.add(allotment);
|
|
693
|
+
return own(allotment);
|
|
694
|
+
};
|
|
695
|
+
if (this.#stuck(this.#now()) === void 0 && this.#fits(bytes, push, asker) && !this.#yieldsToPushes(bytes, push)) return Effect.succeed(owned(this.#grant(bytes, push, busy, asker)));
|
|
696
|
+
return this.#wait(this.#reads, push, bytes, growWaitMs, busy, owned, asker).pipe(Effect.flatMap(Option.match({
|
|
391
697
|
onNone: () => Effect.fail(busy),
|
|
392
698
|
onSome: Effect.succeed
|
|
393
699
|
})));
|
|
394
700
|
});
|
|
395
701
|
}
|
|
396
|
-
/**
|
|
702
|
+
/**
|
|
703
|
+
* `MemoryAllotment.tryGrow`: its bytes when they fit at once, caches shrunk, no push is stuck and,
|
|
704
|
+
* for upkeep, no push's grow waits that they'd take the room of. A push's fit beside the admitted pushes, the reserve left, and count with them, so a read's
|
|
705
|
+
* floors always fit beside every push's holdings.
|
|
706
|
+
*/
|
|
397
707
|
tryGrow(allotment, bytes) {
|
|
398
708
|
if (allotment.released || bytes <= 0) return true;
|
|
399
|
-
|
|
709
|
+
const fits = this.#fits(bytes, allotment.push, allotment.owner);
|
|
710
|
+
if (this.#stuck(this.#now()) !== void 0 || !fits) return false;
|
|
711
|
+
if (this.#yieldsToPushes(bytes, this.#upkeeps.has(allotment))) return false;
|
|
712
|
+
if (allotment.push) this.#admitted += bytes;
|
|
400
713
|
this.#allotted += bytes;
|
|
401
714
|
allotment.added(bytes);
|
|
715
|
+
this.#wakeRooms();
|
|
402
716
|
return true;
|
|
403
717
|
}
|
|
404
|
-
/**
|
|
718
|
+
/**
|
|
719
|
+
* `MemoryAllotment.grow`: its bytes waited for as a read's, then handed to `allotment`. A push's
|
|
720
|
+
* past all of the budget but the reserve, which no wait makes room for, are refused at once.
|
|
721
|
+
*/
|
|
405
722
|
grow(allotment, bytes, busy, tooLarge) {
|
|
406
723
|
return this.#timed(() => {
|
|
407
724
|
if (allotment.released || bytes <= 0) return Effect.void;
|
|
408
|
-
if (allotment.bytes + bytes > this.
|
|
725
|
+
if (allotment.bytes + bytes > this.mostOf(allotment.push)) return Effect.fail(tooLarge ?? busy);
|
|
409
726
|
if (this.tryGrow(allotment, bytes)) return Effect.void;
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
727
|
+
const adopt = (granted) => {
|
|
728
|
+
granted.adopted();
|
|
729
|
+
allotment.added(granted.bytes);
|
|
730
|
+
if (allotment.released) this.returned(granted.bytes, granted.admitted);
|
|
731
|
+
};
|
|
732
|
+
const { push, owner } = allotment;
|
|
733
|
+
return this.#wait(this.#reads, push, bytes, growWaitMs, void 0, adopt, owner, allotment).pipe(Effect.flatMap(Option.match({
|
|
734
|
+
onNone: () => Effect.andThen(this.#refusedGrow(allotment, bytes), Effect.fail(busy)),
|
|
735
|
+
onSome: () => Effect.void
|
|
736
|
+
})));
|
|
418
737
|
});
|
|
419
738
|
}
|
|
739
|
+
/**
|
|
740
|
+
* A grow refused busy, one line in the log with who asked and what was free as its wait ended,
|
|
741
|
+
* so a refusal beside upkeep shows as a pattern (#1300).
|
|
742
|
+
*/
|
|
743
|
+
#refusedGrow(allotment, bytes) {
|
|
744
|
+
const kind = this.#upkeeps.has(allotment) ? "upkeep" : allotment.push ? "push" : "read";
|
|
745
|
+
const free = this.total - this.#allotted;
|
|
746
|
+
const beside = this.total - this.reserve - this.#admitted;
|
|
747
|
+
return Effect.logWarning(`The ${kind} allotment's grow of ${bytes} B, holding ${allotment.bytes} B, was refused busy after ${growWaitMs} ms, with ${free} B of the budget's ${this.total} B free and ${beside} B beside the admitted pushes`);
|
|
748
|
+
}
|
|
420
749
|
};
|
|
421
750
|
/**
|
|
422
751
|
* `ObjectReader.allotment` on a reader's `allotment`: at most `most` bytes, `refusal` past it.
|
|
@@ -468,19 +797,100 @@ const allottedWithin = (allotment, most, refusal, context) => {
|
|
|
468
797
|
/**
|
|
469
798
|
* A reader's memory on `allotment`: its read cache and blocks as rooms that start at their floors
|
|
470
799
|
* and grow to their most while there's room, each pack's indexes charged as the allotment's
|
|
471
|
-
* growth,
|
|
472
|
-
*
|
|
800
|
+
* growth, refused at once past what it could have alone with `indexTooLarge` when given, and
|
|
801
|
+
* what a resolve holds outside the cache as its high-water, refused past the whole budget with
|
|
802
|
+
* `tooLarge` when given. Past only what's left beside others, either waits as a grow does. With
|
|
803
|
+
* `waits`, its blocks wait for room for a block read again, refused with the allotment's busy, for
|
|
804
|
+
* a caller that retries it: a push's, which Git retries.
|
|
473
805
|
*/
|
|
474
|
-
const readerMemoryOf = (allotment, { floors = readerFloors, most = readerMost, tooLarge } = {}) =>
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
806
|
+
const readerMemoryOf = (allotment, { floors = readerFloors, most = readerMost, tooLarge, indexTooLarge, waits = false } = {}) => {
|
|
807
|
+
let indexed = 0;
|
|
808
|
+
return {
|
|
809
|
+
cache: allotment.room(floors.cache, most.cache),
|
|
810
|
+
blocks: allotment.room(floors.blocks, most.blocks, waits),
|
|
811
|
+
index: (bytes) => {
|
|
812
|
+
if (indexTooLarge !== void 0 && bytes > allotment.growable) {
|
|
813
|
+
const own = Math.max(0, allotment.bytes - indexed);
|
|
814
|
+
return Effect.fail(indexTooLarge(indexed + bytes, own, allotment.bytes + allotment.growable));
|
|
815
|
+
}
|
|
816
|
+
return Effect.map(allotment.grow(bytes), () => {
|
|
817
|
+
indexed += bytes;
|
|
818
|
+
});
|
|
819
|
+
},
|
|
820
|
+
outside: outsideOn((bytes) => allotment.grow(bytes), tooLarge === void 0 ? void 0 : {
|
|
821
|
+
tooLarge,
|
|
822
|
+
growable: () => allotment.growable
|
|
823
|
+
})
|
|
824
|
+
};
|
|
825
|
+
};
|
|
826
|
+
/**
|
|
827
|
+
* An upkeep step's runs, cut and merged within the upkeep allotment: 4 MiB runs, read back 256 KiB
|
|
828
|
+
* at a time, 32 at once, so s1m's 7 runs of a pass merge without narrowing. A merge's hold counts
|
|
829
|
+
* them: its walk's chosen runs as `cursorHeld` does, its index pass's as `runsHeld` does.
|
|
830
|
+
*/
|
|
831
|
+
const upkeepRuns = {
|
|
832
|
+
runBytes: 4194304,
|
|
833
|
+
readBytes: 262144,
|
|
834
|
+
ways: 32
|
|
835
|
+
};
|
|
836
|
+
/**
|
|
837
|
+
* A maintenance reader's or merge's memory on the upkeep `allotment`, which counts nothing for it
|
|
838
|
+
* up front: the reader's floors, and `extra` besides, grown on it before its rooms are made, then
|
|
839
|
+
* each index it charges and what a resolve holds outside the cache. Each grow is refused as
|
|
840
|
+
* `upkeepTooLarge` past all the allotment may hold, and as its busy past its wait; its waits can
|
|
841
|
+
* be interrupted. All of it goes back when its scope ends, so a step's merges, one after another,
|
|
842
|
+
* never add up. Its blocks start at `blocks`, the reader's floor unless set, as a walk holds its
|
|
843
|
+
* 8 so it never rereads a block.
|
|
844
|
+
*/
|
|
845
|
+
const upkeepMemoryOf = (allotment, extra = 0, blocks = readerFloors.blocks) => Effect.suspend(() => {
|
|
846
|
+
const floors = readerFloors.cache + blocks + extra;
|
|
847
|
+
let grown = 0;
|
|
848
|
+
const grow = (bytes) => Effect.map(allotment.grow(bytes, upkeepTooLarge), () => {
|
|
849
|
+
grown += bytes;
|
|
850
|
+
});
|
|
851
|
+
return Effect.acquireRelease(Effect.map(allotment.grow(floors, upkeepTooLarge), () => ({
|
|
852
|
+
cache: allotment.room(readerFloors.cache, readerMost.cache),
|
|
853
|
+
blocks: allotment.room(blocks, readerMost.blocks, true),
|
|
854
|
+
index: grow,
|
|
855
|
+
outside: outsideOn(grow)
|
|
856
|
+
})), (memory) => Effect.sync(() => {
|
|
857
|
+
allotment.endRoom(memory.cache);
|
|
858
|
+
allotment.endRoom(memory.blocks);
|
|
859
|
+
allotment.shrink(floors + grown);
|
|
860
|
+
}), { interruptible: true });
|
|
479
861
|
});
|
|
480
862
|
/**
|
|
863
|
+
* A push's link join in its receive's `room` on `allotment`: what the join takes reuses what the
|
|
864
|
+
* room's sweeps and table gave back, and grows the allotment only past the most the room held.
|
|
865
|
+
* Growth past what the push could ever have is refused at once as the repo's pack indexes' part,
|
|
866
|
+
* by Q879's split, since no wait would fit it; past what's left beside others, it waits as the
|
|
867
|
+
* room's grow does, then `pushBusy`.
|
|
868
|
+
*/
|
|
869
|
+
const joinRoomOf = (allotment, room) => {
|
|
870
|
+
let joined = 0;
|
|
871
|
+
return {
|
|
872
|
+
take: (bytes) => {
|
|
873
|
+
const more = room.growth(bytes);
|
|
874
|
+
if (more > allotment.growable) {
|
|
875
|
+
const index = joined + bytes;
|
|
876
|
+
const most = allotment.bytes + allotment.growable;
|
|
877
|
+
return Effect.fail(pushIndexTooLarge(index, allotment.bytes + more - index, most));
|
|
878
|
+
}
|
|
879
|
+
joined += bytes;
|
|
880
|
+
return room.take(bytes) ?? Effect.void;
|
|
881
|
+
},
|
|
882
|
+
give: (bytes) => {
|
|
883
|
+
joined -= bytes;
|
|
884
|
+
room.give(bytes);
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
};
|
|
888
|
+
/**
|
|
481
889
|
* A push's memory on its admitted `allotment`, which already counts its floors: its blocks from
|
|
482
890
|
* their floor, a read cache from none, the indexer's base cache from its floor to its limit, and
|
|
483
|
-
* its
|
|
891
|
+
* its receive's room from what it was admitted with, grown as a push's grow is, its link join
|
|
892
|
+
* within it, and its reads' indexes too: within `growWaitMs`, then `pushBusy`, and `pushTooLarge`
|
|
893
|
+
* past the whole budget.
|
|
484
894
|
*/
|
|
485
895
|
const pushMemoryOf = (allotment, size) => {
|
|
486
896
|
const floors = pushFloorsOf(size);
|
|
@@ -489,28 +899,36 @@ const pushMemoryOf = (allotment, size) => {
|
|
|
489
899
|
cache: 0,
|
|
490
900
|
blocks: floors.blocks
|
|
491
901
|
},
|
|
492
|
-
tooLarge:
|
|
902
|
+
tooLarge: pushEntryTooLarge(size.objects),
|
|
903
|
+
indexTooLarge: pushIndexTooLarge,
|
|
904
|
+
waits: true
|
|
493
905
|
});
|
|
906
|
+
const room = new ReceiveRoom((bytes) => allotment.grow(bytes, pushTooLarge), receiveRoomAdmitted(size.objects), () => allotment.growable);
|
|
494
907
|
return {
|
|
495
908
|
reader,
|
|
496
909
|
cache: allotment.room(floors.cache, packIndexerLimits.cacheBytes),
|
|
497
|
-
memo: allotment.room(floors.memo, allotment.bytes),
|
|
498
910
|
pointers: new AllottedPointers(allotment),
|
|
499
|
-
outside: reader.outside
|
|
911
|
+
outside: reader.outside,
|
|
912
|
+
room,
|
|
913
|
+
join: joinRoomOf(allotment, room)
|
|
500
914
|
};
|
|
501
915
|
};
|
|
502
916
|
/**
|
|
503
|
-
* What an indexer takes outside its cache,
|
|
504
|
-
* most it grew to, waiting as
|
|
505
|
-
*
|
|
506
|
-
* ends, since the next large entry would need it again: a reader's resolves, a push's indexer,
|
|
507
|
-
*
|
|
917
|
+
* What an indexer takes outside its cache, through `grow`, an allotment's: grown to each ask that
|
|
918
|
+
* passes the most it grew to, waiting and refused as `grow` is, and with `refused`, refused at once
|
|
919
|
+
* past what its `growable` and its high-water leave. It keeps that high-water until the allotment
|
|
920
|
+
* ends, since the next large entry would need it again: a reader's resolves, a push's indexer, and
|
|
921
|
+
* an index build's slice.
|
|
508
922
|
*/
|
|
509
|
-
const outsideOn = (
|
|
923
|
+
const outsideOn = (grow, refused) => {
|
|
510
924
|
let grown = 0;
|
|
511
925
|
return (bytes) => {
|
|
512
926
|
if (bytes <= grown) return void 0;
|
|
513
|
-
|
|
927
|
+
if (refused !== void 0) {
|
|
928
|
+
const left = refused.growable() + grown;
|
|
929
|
+
if (bytes > left) return Effect.fail(refused.tooLarge(bytes, left));
|
|
930
|
+
}
|
|
931
|
+
return Effect.map(grow(bytes - grown), () => {
|
|
514
932
|
grown = Math.max(grown, bytes);
|
|
515
933
|
});
|
|
516
934
|
};
|
|
@@ -529,13 +947,23 @@ var AllottedPointers = class {
|
|
|
529
947
|
}
|
|
530
948
|
/** Lists the blob as `ReceivedPointers` does, then grows the allotment a page if it opened one. */
|
|
531
949
|
add(blob, bytes) {
|
|
532
|
-
return Effect.flatMap(this.#pointers.add(blob, bytes), () =>
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
950
|
+
return Effect.flatMap(this.#pointers.add(blob, bytes), () => this.#grown(this.#pointers.count));
|
|
951
|
+
}
|
|
952
|
+
/** The allotment grown for the pages of `count` pointers, before they're read into them. */
|
|
953
|
+
carrying(count) {
|
|
954
|
+
return Effect.forEach(Array.from({ length: Math.ceil(count / pageEntries) }), (_, page) => this.#grown(page * pageEntries + 1)).pipe(Effect.asVoid);
|
|
955
|
+
}
|
|
956
|
+
/** Lists a pointer an earlier step found, into a page `carrying` grew the allotment for. */
|
|
957
|
+
carried(record) {
|
|
958
|
+
this.#pointers.carried(record);
|
|
959
|
+
}
|
|
960
|
+
/** The allotment grown a page if `count` pointers open one past the pages it holds. */
|
|
961
|
+
#grown(count) {
|
|
962
|
+
const opened = this.#pages * pageEntries;
|
|
963
|
+
if (count <= opened) return Effect.void;
|
|
964
|
+
const page = Math.min(pageEntries, lfsPointersMost - opened) * 52;
|
|
965
|
+
return Effect.map(this.#allotment.grow(page), () => {
|
|
966
|
+
this.#pages += 1;
|
|
539
967
|
});
|
|
540
968
|
}
|
|
541
969
|
/** The pointers it found, sorted by blob: their `bytes` are what the push keeps past its answer. */
|
|
@@ -543,4 +971,4 @@ var AllottedPointers = class {
|
|
|
543
971
|
return this.#pointers.finish();
|
|
544
972
|
}
|
|
545
973
|
};
|
|
546
|
-
export { AllottedPointers, MemoryAllotment, MemoryBudget, allottedWithin, fetchBusy, growWaitMs, headStuckMs, outsideOn, pushBusy, pushMemoryOf, pushTooLarge, pushWaitMs, readBusy, readerMemoryOf };
|
|
974
|
+
export { AllottedPointers, MemoryAllotment, MemoryBudget, allottedWithin, fetchBusy, growWaitMs, headStuckMs, joinRoomOf, outsideOn, pushBusy, pushEntryTooLarge, pushIndexTooLarge, pushMemoryOf, pushTooLarge, pushWaitMs, readBusy, readerMemoryOf, upkeepMemoryOf, upkeepRuns, upkeepTooLarge };
|