@ref0/git 0.20.0 → 0.25.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/access/private-refs.mjs +1 -1
- package/dist/auth/access-jwt.mjs +3 -3
- package/dist/auth/auth-namespace.d.mts +3 -3
- package/dist/auth/auth-namespace.mjs +3 -2
- package/dist/auth/auth.d.mts +3 -3
- package/dist/auth/auth.mjs +9 -8
- package/dist/auth/authorize.mjs +1 -1
- package/dist/auth/fences.d.mts +1 -1
- package/dist/auth/host-function.mjs +1 -1
- package/dist/auth/host-services.mjs +4 -6
- package/dist/auth/identify.d.mts +1 -1
- package/dist/auth/identify.mjs +6 -0
- package/dist/auth/token-cleanup.mjs +2 -2
- package/dist/auth/token-rows.mjs +6 -1
- package/dist/auth/token-text.mjs +1 -1
- package/dist/auth/tokens-base.d.mts +1 -1
- package/dist/auth/tokens.d.mts +1 -1
- package/dist/auth/tokens.mjs +1 -1
- package/dist/client/client.d.mts +15 -7
- package/dist/client/client.mjs +21 -12
- package/dist/client/git-http.mjs +1 -1
- package/dist/client/local.mjs +60 -24
- package/dist/client/negotiate.mjs +3 -3
- package/dist/client/push-upload.mjs +26 -10
- package/dist/client/remote.mjs +4 -3
- package/dist/client/run-remote-helper.d.mts +2 -2
- package/dist/client/run-remote-helper.mjs +6 -6
- package/dist/client/slice-push.d.mts +1 -1
- package/dist/client/transport.mjs +3 -3
- package/dist/contracts/blobs.d.mts +3 -3
- package/dist/contracts/blobs.mjs +1 -1
- package/dist/contracts/calls-spent.mjs +5 -33
- package/dist/contracts/client.d.mts +15 -14
- package/dist/contracts/commits.d.mts +4 -4
- package/dist/contracts/commits.mjs +1 -1
- package/dist/contracts/engine.d.mts +2 -2
- package/dist/contracts/events.d.mts +1 -1
- package/dist/contracts/events.mjs +1 -1
- package/dist/contracts/files.d.mts +4 -4
- package/dist/contracts/files.mjs +1 -1
- package/dist/contracts/forks.d.mts +4 -4
- package/dist/contracts/forks.mjs +1 -1
- package/dist/contracts/git-hooks.d.mts +1 -1
- package/dist/contracts/git.d.mts +9 -5
- package/dist/contracts/grants.d.mts +1 -1
- package/dist/contracts/merges.d.mts +1 -1
- package/dist/contracts/object-values.d.mts +1 -0
- package/dist/contracts/object-values.mjs +16 -1
- package/dist/contracts/objects.d.mts +20 -17
- package/dist/contracts/opaque.mjs +1 -1
- package/dist/contracts/operations.mjs +1 -1
- package/dist/contracts/queue.d.mts +208 -44
- package/dist/contracts/queue.mjs +5 -5
- package/dist/contracts/refs.d.mts +5 -5
- package/dist/contracts/refs.mjs +1 -1
- package/dist/contracts/remote.d.mts +3 -6
- package/dist/contracts/repos.d.mts +3 -3
- package/dist/contracts/repos.mjs +1 -1
- package/dist/contracts/result.d.mts +10 -7
- package/dist/contracts/result.mjs +8 -3
- package/dist/contracts/rules.d.mts +2 -2
- package/dist/contracts/server.d.mts +8 -10
- package/dist/contracts/services.d.mts +6 -9
- package/dist/contracts/services.mjs +1 -2
- package/dist/contracts/signin.d.mts +1 -1
- package/dist/contracts/store.d.mts +2 -2
- package/dist/contracts/sync.d.mts +63 -6
- package/dist/contracts/sync.mjs +3 -2
- package/dist/contracts/tags.d.mts +3 -3
- package/dist/contracts/tags.mjs +1 -1
- package/dist/contracts/tokens.d.mts +2 -2
- package/dist/contracts/tokens.mjs +1 -1
- package/dist/contracts/topics.d.mts +9 -9
- package/dist/contracts/trees.d.mts +4 -4
- package/dist/contracts/trees.mjs +1 -1
- package/dist/contracts/work.d.mts +4 -4
- package/dist/contracts/work.mjs +2 -2
- package/dist/core/access.d.mts +1 -1
- package/dist/core/ancestry.mjs +30 -34
- package/dist/core/{promise.mjs → call-groups.mjs} +7 -30
- package/dist/core/call-services.mjs +1 -1
- package/dist/core/events/deliver.d.mts +2 -2
- package/dist/core/events/deliver.mjs +3 -3
- package/dist/core/events/retired.mjs +1 -1
- package/dist/core/forks.mjs +5 -5
- package/dist/core/hooks/groups.mjs +2 -2
- package/dist/core/imports.mjs +101 -21
- package/dist/core/index-job.mjs +14 -9
- package/dist/core/index-lost.d.mts +1 -1
- package/dist/core/loose-tally.mjs +38 -15
- package/dist/core/merge-parts.d.mts +17 -4
- package/dist/core/merge-parts.mjs +7 -2
- package/dist/core/mirror-rows.mjs +31 -1
- package/dist/core/objects/blobs.mjs +8 -10
- package/dist/core/objects/files.mjs +20 -17
- package/dist/core/objects/objects-layer.mjs +1 -1
- package/dist/core/objects/peel.mjs +1 -7
- package/dist/core/objects/reading.mjs +19 -18
- package/dist/core/objects/tree-edits.mjs +1 -1
- package/dist/core/objects/trees.mjs +257 -58
- package/dist/core/objects/writing.mjs +3 -9
- package/dist/core/own-writes.mjs +1 -1
- package/dist/core/parts.d.mts +8 -1
- package/dist/core/parts.mjs +8 -4
- package/dist/core/purge.mjs +31 -18
- package/dist/core/push.d.mts +2 -2
- package/dist/core/push.mjs +125 -94
- package/dist/core/receipts.d.mts +2 -2
- package/dist/core/receipts.mjs +9 -2
- package/dist/core/ref-index-job.mjs +4 -4
- package/dist/core/ref-view.mjs +74 -31
- package/dist/core/refs.mjs +3 -3
- package/dist/core/repack.mjs +25 -30
- package/dist/core/repo-info.mjs +1 -1
- package/dist/core/repos.mjs +1 -1
- package/dist/core/rules/changes.mjs +18 -40
- package/dist/core/rules/check.mjs +6 -5
- package/dist/core/rules/commit-changes.mjs +3 -15
- package/dist/core/rules/context.d.mts +3 -3
- package/dist/core/rules/context.mjs +18 -14
- package/dist/core/rules/fetch.mjs +1 -1
- package/dist/core/rules/protect.mjs +30 -17
- package/dist/core/saved-caller-views.d.mts +1 -1
- package/dist/core/saved-caller-views.mjs +3 -3
- package/dist/core/saved-callers.d.mts +1 -1
- package/dist/core/saved-callers.mjs +1 -1
- package/dist/core/seam.d.mts +1 -2
- package/dist/core/view.d.mts +6 -3
- package/dist/core/view.mjs +11 -10
- package/dist/core/work.mjs +2 -2
- package/dist/engine/allotted-xdiff.mjs +3 -16
- package/dist/engine/combined.d.mts +3 -0
- package/dist/engine/combined.mjs +200 -185
- package/dist/engine/content.d.mts +2 -2
- package/dist/engine/content.mjs +1 -1
- package/dist/engine/merge.mjs +7 -9
- package/dist/engine/reads.d.mts +2 -2
- package/dist/engine/reads.mjs +22 -14
- package/dist/engine/xdiff.d.mts +1 -1
- package/dist/engine/xdiff.mjs +1 -1
- package/dist/event-streams/event-streams.d.mts +1 -1
- package/dist/event-streams/event-streams.mjs +1 -1
- package/dist/event-streams/stream.d.mts +2 -2
- package/dist/event-streams/stream.mjs +3 -3
- package/dist/extend.d.mts +2 -6
- package/dist/extend.mjs +1 -5
- package/dist/http/core-parts.mjs +83 -26
- package/dist/http/handler.mjs +54 -9
- package/dist/http/parts.d.mts +1 -0
- package/dist/http/push-upload-job.mjs +138 -24
- package/dist/http/push-uploads.mjs +2 -2
- package/dist/http/receive-pack.mjs +14 -53
- package/dist/http/request-snapshot.mjs +258 -0
- package/dist/http/upload-pack.mjs +23 -18
- package/dist/index.d.mts +29 -21
- package/dist/index.mjs +11 -2
- package/dist/lfs/base.d.mts +1 -1
- package/dist/lfs/copy.d.mts +49 -1
- package/dist/lfs/copy.mjs +135 -22
- package/dist/lfs/layer.d.mts +4 -3
- package/dist/lfs/layer.mjs +4 -5
- package/dist/lfs/locks.mjs +2 -2
- package/dist/lfs/objects.d.mts +1 -1
- package/dist/lfs/objects.mjs +3 -3
- package/dist/lfs/pointers.mjs +1 -1
- package/dist/lfs/rows.d.mts +1 -1
- package/dist/lfs/rows.mjs +11 -4
- package/dist/lfs/upkeep.mjs +40 -9
- package/dist/lfs/uploaded.mjs +1 -1
- package/dist/lfs/wire.mjs +1 -1
- package/dist/merges/merges.mjs +17 -2
- package/dist/protocol/bytes/buffers.d.mts +1 -1
- package/dist/protocol/bytes/buffers.mjs +1 -1
- package/dist/protocol/bytes/deflate.d.mts +1 -1
- package/dist/protocol/bytes/deflate.mjs +1 -1
- package/dist/protocol/bytes/inflate.d.mts +1 -1
- package/dist/protocol/bytes/inflate.mjs +1 -1
- package/dist/protocol/bytes/sha1.d.mts +1 -1
- package/dist/protocol/bytes/sha1.mjs +1 -1
- package/dist/protocol/diff/read.d.mts +2 -1
- package/dist/protocol/diff/read.mjs +102 -8
- package/dist/protocol/packs/graph.mjs +1 -1
- package/dist/protocol/packs/idx.d.mts +1 -1
- package/dist/protocol/packs/idx.mjs +1 -1
- package/dist/protocol/packs/parts.mjs +1 -1
- package/dist/protocol/packs/reader.d.mts +1 -1
- package/dist/protocol/packs/reader.mjs +1 -1
- package/dist/protocol/packs/write-error.d.mts +1 -1
- package/dist/protocol/packs/write-error.mjs +1 -1
- package/dist/protocol/packs/writer.mjs +3 -3
- package/dist/protocol/wire/advertisement.d.mts +1 -1
- package/dist/protocol/wire/advertisement.mjs +3 -2
- package/dist/protocol/wire/fetch.d.mts +1 -1
- package/dist/protocol/wire/fetch.mjs +1 -1
- package/dist/protocol/wire/lines.d.mts +9 -1
- package/dist/protocol/wire/lines.mjs +28 -1
- package/dist/protocol/wire/push-uploads.mjs +10 -7
- package/dist/protocol/wire/receive-pack.d.mts +1 -1
- package/dist/protocol/wire/receive-pack.mjs +1 -1
- package/dist/protocol/wire/report-status.d.mts +1 -1
- package/dist/protocol/wire/report-status.mjs +1 -1
- package/dist/protocol/wire/v2.d.mts +1 -1
- package/dist/protocol/wire/v2.mjs +1 -1
- package/dist/queue/advance.mjs +31 -24
- package/dist/queue/base.d.mts +5 -3
- package/dist/queue/calls.mjs +5 -5
- package/dist/queue/commit.mjs +1 -1
- package/dist/queue/host.d.mts +1 -1
- package/dist/queue/layer.d.mts +0 -1
- package/dist/queue/layer.mjs +9 -5
- package/dist/queue/schedule.mjs +1 -1
- package/dist/queue/search.mjs +1 -1
- package/dist/queue/state.mjs +1 -1
- package/dist/queue/trim.mjs +2 -2
- package/dist/rest/client.d.mts +1 -1
- package/dist/rest/client.mjs +6 -6
- package/dist/rest/errors.mjs +1 -1
- package/dist/rest/handler.mjs +2 -2
- package/dist/rest/handlers.mjs +16 -6
- package/dist/rest/layer.mjs +1 -1
- package/dist/rest/listen.mjs +2 -2
- package/dist/rest/refs.mjs +1 -1
- package/dist/server/edge.mjs +27 -3
- package/dist/server/git-layer.d.mts +1 -2
- package/dist/server/git-layer.mjs +4 -5
- package/dist/server/lifecycle.mjs +1 -1
- package/dist/server/registry.mjs +2 -8
- package/dist/server/server.mjs +62 -43
- package/dist/signin/context.d.mts +1 -1
- package/dist/signin/context.mjs +1 -1
- package/dist/signin/forms.mjs +1 -1
- package/dist/signin/grants.d.mts +2 -2
- package/dist/signin/grants.mjs +1 -1
- package/dist/signin/wire.mjs +1 -1
- package/dist/storage/allotted.mjs +4 -9
- package/dist/storage/batch-upkeep.mjs +31 -12
- package/dist/storage/batches.d.mts +2 -3
- package/dist/storage/batches.mjs +52 -49
- package/dist/storage/budget.mjs +23 -1
- package/dist/storage/calls.d.mts +1 -1
- package/dist/storage/calls.mjs +41 -43
- package/dist/storage/charged-cache.mjs +180 -0
- package/dist/storage/chunks.d.mts +3 -3
- package/dist/storage/chunks.mjs +121 -8
- package/dist/storage/counted-bucket.mjs +32 -10
- package/dist/storage/fetch-row-cache.d.mts +6 -0
- package/dist/storage/fetch-row-cache.mjs +211 -0
- package/dist/storage/fetch.d.mts +1 -0
- package/dist/storage/fetch.mjs +54 -242
- package/dist/storage/held-types.d.mts +0 -1
- package/dist/storage/host-bucket.mjs +9 -4
- package/dist/storage/index-bitmaps.mjs +77 -49
- package/dist/storage/index-build.d.mts +2 -3
- package/dist/storage/index-build.mjs +248 -48
- package/dist/storage/index-fetch.d.mts +3 -1
- package/dist/storage/index-fetch.mjs +60 -21
- package/dist/storage/index-graph.mjs +1 -1
- package/dist/storage/index-layers.mjs +55 -25
- package/dist/storage/index-reach.mjs +15 -22
- package/dist/storage/index-whole.d.mts +7 -0
- package/dist/storage/index-whole.mjs +145 -37
- package/dist/storage/largest-files.mjs +1 -7
- package/dist/storage/layout.mjs +17 -1
- package/dist/storage/lfs-pointers.mjs +1 -6
- package/dist/storage/link-join.mjs +55 -16
- package/dist/storage/list-source.d.mts +7 -0
- package/dist/storage/list-source.mjs +288 -0
- package/dist/storage/loose.d.mts +8 -8
- package/dist/storage/loose.mjs +157 -91
- package/dist/storage/memory-budget.mjs +226 -22
- package/dist/storage/merge-cut.mjs +9 -6
- package/dist/storage/merge-fence.mjs +1 -1
- package/dist/storage/merge-row.mjs +1 -1
- package/dist/storage/merge.d.mts +2 -3
- package/dist/storage/merge.mjs +2 -2
- package/dist/storage/object-rows.d.mts +3 -3
- package/dist/storage/object-rows.mjs +179 -38
- package/dist/storage/pack-order.mjs +97 -44
- package/dist/storage/pack-ranges.mjs +44 -16
- package/dist/storage/pack-reads.d.mts +5 -3
- package/dist/storage/pack-reads.mjs +236 -72
- package/dist/storage/pack-receive.d.mts +1 -2
- package/dist/storage/pack-receive.mjs +21 -17
- package/dist/storage/packs.d.mts +1 -1
- package/dist/storage/packs.mjs +477 -116
- package/dist/storage/placed-reads.mjs +33 -16
- package/dist/storage/prune-seen.mjs +1 -1
- package/dist/storage/prune-walk.mjs +1 -1
- package/dist/storage/prune.mjs +4 -31
- package/dist/storage/push-allotment.mjs +26 -14
- package/dist/storage/push-uploads.mjs +195 -57
- package/dist/storage/pushed-commits.mjs +20 -1
- package/dist/storage/quarantine.d.mts +2 -3
- package/dist/storage/range-cache.mjs +175 -40
- package/dist/storage/raw-ids.mjs +39 -10
- package/dist/storage/ready.d.mts +2 -3
- package/dist/storage/ready.mjs +114 -38
- package/dist/storage/receive-bounds.mjs +31 -9
- package/dist/storage/receive-cache.d.mts +7 -0
- package/dist/storage/receive-cache.mjs +147 -0
- package/dist/storage/receive-files.mjs +1 -1
- package/dist/storage/receive-links.mjs +1 -1
- package/dist/storage/receive-state.d.mts +2 -2
- package/dist/storage/receive-state.mjs +6 -8
- package/dist/storage/receive-steps.d.mts +20 -0
- package/dist/storage/receive-steps.mjs +298 -13
- package/dist/storage/repack-backlog.mjs +1 -6
- package/dist/storage/repack-contained.mjs +2 -2
- package/dist/storage/repack-job.mjs +1 -1
- package/dist/storage/repack.d.mts +2 -3
- package/dist/storage/repack.mjs +54 -9
- package/dist/storage/request-cache.mjs +57 -0
- package/dist/storage/roots.mjs +1 -24
- package/dist/storage/rows.d.mts +2 -2
- package/dist/storage/rows.mjs +1 -1
- package/dist/storage/runs.d.mts +2 -2
- package/dist/storage/runs.mjs +1 -1
- package/dist/storage/send-list.mjs +62 -25
- package/dist/storage/stream-whole.mjs +84 -63
- package/dist/storage/swap-walk.mjs +1 -1
- package/dist/storage/unpack.mjs +878 -450
- package/dist/storage/visible.mjs +110 -32
- package/dist/storage/walk.mjs +1 -0
- package/dist/storage/wants.mjs +22 -58
- package/dist/store/call-count.d.mts +2 -2
- package/dist/store/call-count.mjs +24 -11
- package/dist/store/catalogue.d.mts +1 -1
- package/dist/store/catalogue.mjs +19 -7
- package/dist/store/crossing.mjs +1 -7
- package/dist/store/cursor-seal.d.mts +1 -1
- package/dist/store/cursor-seal.mjs +1 -1
- package/dist/store/door.mjs +9 -4
- package/dist/store/errors.d.mts +2 -2
- package/dist/store/errors.mjs +107 -19
- package/dist/store/git-store.mjs +7 -2
- package/dist/store/job-try.mjs +90 -9
- package/dist/store/list-job.mjs +10 -34
- package/dist/store/outbox.d.mts +2 -2
- package/dist/store/outbox.mjs +2 -2
- package/dist/store/queue-jobs.mjs +6 -12
- package/dist/store/records.d.mts +2 -2
- package/dist/store/records.mjs +2 -2
- package/dist/store/ref-rows.d.mts +2 -2
- package/dist/store/ref-rows.mjs +2 -2
- package/dist/store/repo-record.d.mts +2 -2
- package/dist/store/repo-record.mjs +3 -3
- package/dist/store/request-snapshot.mjs +5 -0
- package/dist/store/reservations.mjs +2 -2
- package/dist/store/topic-jobs.mjs +5 -11
- package/dist/sync/bound.d.mts +3 -3
- package/dist/sync/bound.mjs +10 -7
- package/dist/sync/github.mjs +65 -67
- package/dist/sync/http.mjs +1 -1
- package/dist/sync/import.mjs +201 -66
- package/dist/sync/layer.d.mts +1 -1
- package/dist/sync/layer.mjs +6 -6
- package/dist/sync/lfs-batch.mjs +1 -1
- package/dist/sync/lfs-copy.mjs +175 -15
- package/dist/sync/mirror.mjs +5 -10
- package/dist/sync/said.mjs +1 -1
- package/dist/sync/step.mjs +268 -86
- package/dist/sync/tries.mjs +25 -6
- package/dist/sync.d.mts +2 -2
- package/dist/sync.mjs +2 -2
- package/dist/topics/advance.mjs +3 -3
- package/dist/topics/calls.mjs +1 -1
- package/dist/topics/layer.d.mts +15 -14
- package/dist/topics/members.mjs +1 -1
- package/dist/topics/topic.mjs +1 -1
- package/package.json +3 -13
- package/dist/auth/helpers.mjs +0 -17
- package/dist/auth.d.mts +0 -5
- package/dist/auth.mjs +0 -5
- package/dist/core/rules/commit-changes.d.mts +0 -12
- package/dist/effect.d.mts +0 -9
- package/dist/effect.mjs +0 -7
- package/dist/server/joined.d.mts +0 -70
- package/dist/server/joined.mjs +0 -41
package/dist/storage/batches.mjs
CHANGED
|
@@ -7,10 +7,10 @@ import { newChangeId, repoScope } from "../store/scopes.mjs";
|
|
|
7
7
|
import { objectCollections } from "./layout.mjs";
|
|
8
8
|
import { repackJobRow } from "./repack-job.mjs";
|
|
9
9
|
import { QuarantineRow, removeAt } from "./rows.mjs";
|
|
10
|
-
import * as Clock from "effect/Clock";
|
|
11
|
-
import * as Effect from "effect/Effect";
|
|
12
|
-
import * as Schema from "effect/Schema";
|
|
13
10
|
import { jobLeaseMargin, limits } from "@ref0/infra";
|
|
11
|
+
import * as Schema from "effect/Schema";
|
|
12
|
+
import * as Effect from "effect/Effect";
|
|
13
|
+
import * as Base64 from "effect/encoding/Base64";
|
|
14
14
|
// src/storage/batches.ts
|
|
15
15
|
const newBatchId = () => `b_${randomText(12)}`;
|
|
16
16
|
const isBatchId = (text) => /^b_[A-Za-z0-9_-]{16}$/.test(text);
|
|
@@ -64,6 +64,16 @@ const stagedSizeRow = (batch, oid, staged) => ({
|
|
|
64
64
|
...stagedSizeKey(batch, oid),
|
|
65
65
|
value: { bytes: rowBytes(staged) }
|
|
66
66
|
});
|
|
67
|
+
/** The raw bytes one spilled pending-delta part holds at most, matching `chunkRawBytes` under 1 MiB JSON. */
|
|
68
|
+
const deltaPartBytes = 768e3;
|
|
69
|
+
const stagedDeltaKey = (batch, seq, part) => ({
|
|
70
|
+
collection: objectCollections.stagedDeltas,
|
|
71
|
+
id: `${stagedPrefix(batch)}${seq}/${part}`
|
|
72
|
+
});
|
|
73
|
+
const stagedDeltaRow = (batch, seq, part, bytes) => ({
|
|
74
|
+
...stagedDeltaKey(batch, seq, part),
|
|
75
|
+
value: { data: Base64.encode(bytes) }
|
|
76
|
+
});
|
|
67
77
|
/** The object a staged row's ID names, after its batch's prefix. */
|
|
68
78
|
const stagedOid = (id) => id.slice(id.indexOf("/") + 1);
|
|
69
79
|
/** The read of a repo's published batches: one past `batchesMost`, so a longer list shows. */
|
|
@@ -135,10 +145,12 @@ const openBatch = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
|
|
|
135
145
|
});
|
|
136
146
|
/** The bytes one staging add carries at most, under a store call's 8 MiB with room for its keys. */
|
|
137
147
|
const stageBytes = fastPath.bytes;
|
|
138
|
-
const batchStager = (store, repo, opened) => {
|
|
148
|
+
const batchStager = (store, repo, opened, maxBytes = stageBytes, hooks) => {
|
|
139
149
|
const scope = repoScope(repo);
|
|
140
150
|
let put = [];
|
|
141
151
|
let bytes = 0;
|
|
152
|
+
const bufferedRows = /* @__PURE__ */ new Map();
|
|
153
|
+
const bufferedDeltas = /* @__PURE__ */ new Map();
|
|
142
154
|
const flush = Effect.fnUntraced(function* () {
|
|
143
155
|
if (put.length === 0) return;
|
|
144
156
|
const addition = yield* heldAddition(`The push's batch for repo ${repo}`, {
|
|
@@ -147,12 +159,16 @@ const batchStager = (store, repo, opened) => {
|
|
|
147
159
|
});
|
|
148
160
|
put = [];
|
|
149
161
|
bytes = 0;
|
|
150
|
-
|
|
162
|
+
bufferedRows.clear();
|
|
163
|
+
bufferedDeltas.clear();
|
|
164
|
+
const send = store.add({
|
|
151
165
|
scope,
|
|
152
166
|
addition
|
|
153
167
|
});
|
|
168
|
+
yield* hooks === void 0 ? send : hooks.flush(send);
|
|
154
169
|
});
|
|
155
170
|
return {
|
|
171
|
+
opened,
|
|
156
172
|
push: Effect.fnUntraced(function* (row) {
|
|
157
173
|
const staged = {
|
|
158
174
|
...stagedKey(opened.batch, row.id),
|
|
@@ -160,10 +176,23 @@ const batchStager = (store, repo, opened) => {
|
|
|
160
176
|
};
|
|
161
177
|
const marker = stagedSizeRow(opened.batch, row.id, staged);
|
|
162
178
|
const pairBytes = stagedBytes(staged) + stagedBytes(marker);
|
|
163
|
-
if (put.length > 0 && (put.length + 2 > limits.writes || bytes + pairBytes >
|
|
179
|
+
if (put.length > 0 && (put.length + 2 > limits.writes || bytes + pairBytes > maxBytes)) yield* flush();
|
|
180
|
+
if (hooks !== void 0) yield* hooks.reserve(pairBytes, put.length > 0, flush);
|
|
164
181
|
put.push(staged, marker);
|
|
165
182
|
bytes += pairBytes;
|
|
183
|
+
bufferedRows.set(row.id, row);
|
|
184
|
+
}),
|
|
185
|
+
pushDelta: Effect.fnUntraced(function* (seq, part, data) {
|
|
186
|
+
const delta = stagedDeltaRow(opened.batch, seq, part, data);
|
|
187
|
+
const deltaBytes = stagedBytes(delta);
|
|
188
|
+
if (put.length > 0 && (put.length + 1 > limits.writes || bytes + deltaBytes > maxBytes)) yield* flush();
|
|
189
|
+
if (hooks !== void 0) yield* hooks.reserve(deltaBytes + data.byteLength, put.length > 0, flush);
|
|
190
|
+
put.push(delta);
|
|
191
|
+
bytes += deltaBytes;
|
|
192
|
+
bufferedDeltas.set(`${seq}/${part}`, data);
|
|
166
193
|
}),
|
|
194
|
+
bufferedRow: (oid) => bufferedRows.get(oid),
|
|
195
|
+
bufferedDelta: (seq, part) => bufferedDeltas.get(`${seq}/${part}`),
|
|
167
196
|
flush
|
|
168
197
|
};
|
|
169
198
|
};
|
|
@@ -260,17 +289,14 @@ const abandonBatch = (store, repo, batch) => bestEffort(Effect.gen(function* ()
|
|
|
260
289
|
})).ok) return;
|
|
261
290
|
}
|
|
262
291
|
}));
|
|
292
|
+
const ownStaged = /* @__PURE__ */ new WeakMap();
|
|
293
|
+
/** On-demand access to a streamed staged push's own rows before its commit: none for other changes. */
|
|
294
|
+
const stagedOwnOf = (change) => change === void 0 ? void 0 : ownStaged.get(change);
|
|
263
295
|
/**
|
|
264
|
-
* The
|
|
265
|
-
*
|
|
266
|
-
* Keyed by the change, which a wrapper that passes the receive's answer on keeps.
|
|
267
|
-
*/
|
|
268
|
-
const ownRows = /* @__PURE__ */ new WeakMap();
|
|
269
|
-
/**
|
|
270
|
-
* The change that publishes `opened`: its `batches` row, and `moved`, its rows as the tally counts
|
|
271
|
-
* them, each physical row once. `rows`, the push's own, are kept for its reads before its commit.
|
|
296
|
+
* The change that publishes `opened`, with `moved` as its row tally and optional `own` for
|
|
297
|
+
* on-demand pre-commit reads when the push streamed through `batchStager`.
|
|
272
298
|
*/
|
|
273
|
-
const
|
|
299
|
+
const stagedPublication = (opened, moved, at, own) => {
|
|
274
300
|
const value = {
|
|
275
301
|
objects: moved.objects,
|
|
276
302
|
bytes: moved.bytes,
|
|
@@ -283,15 +309,11 @@ const publication = (opened, rows, moved, at) => {
|
|
|
283
309
|
}],
|
|
284
310
|
rows: moved
|
|
285
311
|
};
|
|
286
|
-
|
|
312
|
+
if (own !== void 0) ownStaged.set(change, own);
|
|
287
313
|
return change;
|
|
288
314
|
};
|
|
289
|
-
/** The `objects` rows a staged push's change keeps for its own reads: none for any other change. */
|
|
290
|
-
const stagedRowsOf = (change) => change === void 0 ? void 0 : ownRows.get(change);
|
|
291
315
|
/** What one row takes of a commit's bytes, as `fastPath.bytes` and a staging add count it. */
|
|
292
316
|
const stagedBytes = (row) => rowBytes(row) + row.id.length + 64;
|
|
293
|
-
/** Whether a receive's rows go to a batch: past one commit's `fastPath`. */
|
|
294
|
-
const isStaged = (rows) => rows.length > fastPath.rows || rows.reduce((sum, row) => sum + stagedBytes(row), 0) > fastPath.bytes;
|
|
295
317
|
/**
|
|
296
318
|
* `opened`'s quarantine row abandoned, keeping its `removeAt`, for a commit that publishes another
|
|
297
319
|
* batch in its place: upkeep sweeps its rows, and ends it only past `removeAt` and the skew.
|
|
@@ -304,35 +326,16 @@ const abandonedRow = (opened) => ({
|
|
|
304
326
|
}
|
|
305
327
|
});
|
|
306
328
|
/**
|
|
307
|
-
* A receive's
|
|
308
|
-
*
|
|
309
|
-
* fails or is interrupted abandons its batch before it answers. A receive that staged `chunks`
|
|
310
|
-
* already stages its rows beside them, in that batch, whatever their size; its caller abandons it.
|
|
329
|
+
* A streamed receive's push change: its inline rows when the stream stayed within `fastPath` and
|
|
330
|
+
* never opened a batch, or its published batch row with `own` when the stream staged to `opened`.
|
|
311
331
|
*/
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
if (!isStaged(rows)) return { change: {
|
|
321
|
-
put: [...rows],
|
|
322
|
-
rows: moved
|
|
323
|
-
} };
|
|
324
|
-
const at = yield* Clock.currentTimeMillis;
|
|
325
|
-
const opened = yield* openBatch({
|
|
326
|
-
store,
|
|
327
|
-
repo,
|
|
328
|
-
at
|
|
329
|
-
});
|
|
330
|
-
yield* stageRows(store, repo, opened, rows).pipe(Effect.onError(() => abandonBatch(store, repo, opened.batch)));
|
|
331
|
-
return {
|
|
332
|
-
change: publication(opened, rows, moved, at),
|
|
333
|
-
quarantine: opened.quarantine
|
|
334
|
-
};
|
|
335
|
-
});
|
|
332
|
+
const streamedChange = (opened, inlineRows, own, moved, at) => opened === void 0 ? { change: {
|
|
333
|
+
put: [...inlineRows],
|
|
334
|
+
rows: moved
|
|
335
|
+
} } : {
|
|
336
|
+
change: stagedPublication(opened, moved, at, own),
|
|
337
|
+
quarantine: opened.quarantine
|
|
338
|
+
};
|
|
336
339
|
/** The batch a receive staged, which its push's commit publishes: none for any other receive. */
|
|
337
340
|
const stagedBatchOf = (received) => {
|
|
338
341
|
const key = received?.quarantine;
|
|
@@ -341,4 +344,4 @@ const stagedBatchOf = (received) => {
|
|
|
341
344
|
};
|
|
342
345
|
/** Whether a receive staged a batch, so its push's commit holds the repo to `batchesMost`. */
|
|
343
346
|
const isStagedReceive = (received) => stagedBatchOf(received) !== void 0;
|
|
344
|
-
export { BatchRow, SizeMarker, abandonBatch, abandonedRow, awaitingUpkeep, batchKey, batchQuarantineKey, batchStager, batchesOf, batchesRead, fastPath, isBatchId,
|
|
347
|
+
export { BatchRow, SizeMarker, abandonBatch, abandonedRow, awaitingUpkeep, batchKey, batchQuarantineKey, batchStager, batchesOf, batchesRead, deltaPartBytes, fastPath, isBatchId, isStagedReceive, newBatchId, openBatch, promotionBytes, stageBytes, stageRows, stageRowsCalls, stageRowsCounter, stagedBatchOf, stagedBytes, stagedDeltaKey, stagedDeltaRow, stagedKey, stagedOid, stagedOwnOf, stagedPrefix, stagedPublication, stagedSizeKey, stagedSizeRow, storeSkew, streamedChange };
|
package/dist/storage/budget.mjs
CHANGED
|
@@ -122,8 +122,30 @@ packIndexerLimits.deltaBytes + packIndexerLimits.objectBytes + packIndexerLimits
|
|
|
122
122
|
/** What a fetch is allotted at its start: a writer meter of 1 MiB and a reader's floors. */
|
|
123
123
|
const fetchFloorBytes = mib + readerFloorBytes;
|
|
124
124
|
/**
|
|
125
|
+
* The most inflated bytes a `packs()` push may unpack into object rows, and the bound past which
|
|
126
|
+
* `git.repack` folds accumulated rows into a pack: 16 MiB.
|
|
127
|
+
*
|
|
128
|
+
* Derived from a 128 MB Worker's fetch allotment so two concurrent whole-plan clones fit at once:
|
|
129
|
+
* `allottableOf(defaultMemory)` is 103,284,736 B (98.50 MiB), half is 51,642,368 B (49.25 MiB),
|
|
130
|
+
* and less `fetchFloorBytes` (4,194,688 B) leaves 47,447,680 B (45.25 MiB) growable per fetch.
|
|
131
|
+
* `wholePlan` charges `2 * rowsBytes` (`≈ 8/3 × R` for base64 JSON rows), which allows
|
|
132
|
+
* `47,447,680 / (8 / 3) = 17,792,880 B` (16.97 MiB); rounded down to 16 MiB, one whole-plan clone
|
|
133
|
+
* takes ~46.67 MiB and two take ~93.33 MiB inside 98.50 MiB (5.17 MiB spare), while `rowsFirst` in
|
|
134
|
+
* `planned()` takes `2 × 16 MiB + 4 MiB = 36 MiB`. A push past this goes to `asPack`, while
|
|
135
|
+
* `UnpackOptions.maxBytes` keeps bounding wire bytes.
|
|
136
|
+
*/
|
|
137
|
+
const unpackInflatedMost = 16 * mib;
|
|
138
|
+
/**
|
|
125
139
|
* What pushes never admit or grow into, so a read's floors always fit beside them: one fetch's
|
|
126
140
|
* floors, 4 MiB and its block's 384 B cache entry. Caches grow into it while no read needs it.
|
|
127
141
|
*/
|
|
128
142
|
const readReserveBytes = fetchFloorBytes;
|
|
129
|
-
|
|
143
|
+
/**
|
|
144
|
+
* The most decoded/base64 object-row bytes one fetch request's row cache keeps between `heldHaves`,
|
|
145
|
+
* `planFetch`, and `rowsFirst` (#2899). Inline rows that fit both this byte cap and
|
|
146
|
+
* `fetchRowCacheEntries` are reused across those phases without re-reading the store; rows past
|
|
147
|
+
* either bound are skipped and read through from the store as before, and the cache clears before
|
|
148
|
+
* pack streaming starts.
|
|
149
|
+
*/
|
|
150
|
+
const fetchRowCacheBytes = 524288;
|
|
151
|
+
export { allottableOf, defaultMemory, fetchFloorBytes, fetchRowCacheBytes, headroomBytes, idleHeapBytes, openTreeBytes, openTreesFloorBytes, pushAdmissionOf, pushFloorsOf, pushPartBytes, pushReaderFloorsOf, pushRulesOf, readReserveBytes, readerFloorBytes, readerFloors, readerMost, receiveObjectsMostOf, unpackInflatedMost, uploadPartBytes };
|
package/dist/storage/calls.d.mts
CHANGED
|
@@ -3,8 +3,8 @@ import { Allotment, GitObject, ObjectHeader, ObjectHeadersInput, ObjectHeldInput
|
|
|
3
3
|
import { GitError } from "../contracts/result.mjs";
|
|
4
4
|
import { Listed } from "../contracts/store.mjs";
|
|
5
5
|
import "../store/call-count.mjs";
|
|
6
|
-
import * as Effect from "effect/Effect";
|
|
7
6
|
import "@ref0/infra";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
8
|
import "effect/Context";
|
|
9
9
|
import "effect/Scope";
|
|
10
10
|
/**
|
package/dist/storage/calls.mjs
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { allotmentWithin, objectsReadMost } from "../contracts/object-values.mjs";
|
|
2
2
|
import { gitError, isGitError } from "../contracts/result.mjs";
|
|
3
|
+
import { scopedReader as scopedReader$1 } from "../protocol/bytes/reader.mjs";
|
|
3
4
|
import { callScope, chargeCall, chargeCalls, committedNow, inCallScope, readScope } from "../store/call-count.mjs";
|
|
4
5
|
import { isServerClosed, tryClosing } from "../store/closed.mjs";
|
|
5
|
-
import { spentAt, tryUnlessSpent } from "../contracts/calls-spent.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import { afterWrites, fromInfra,
|
|
8
|
-
import * as Effect from "effect/Effect";
|
|
9
|
-
import * as Exit from "effect/Exit";
|
|
6
|
+
import { answerFailed, spentAt, tryUnlessSpent } from "../contracts/calls-spent.mjs";
|
|
7
|
+
import { runIn, runnerIn } from "../store/crossing.mjs";
|
|
8
|
+
import { afterWrites, fromInfra, thrownError } from "../store/errors.mjs";
|
|
10
9
|
import { CallLimit, Internal, Setup, Unavailable, isInfraError } from "@ref0/infra";
|
|
10
|
+
import * as Effect from "effect/Effect";
|
|
11
11
|
import * as Predicate from "effect/Predicate";
|
|
12
|
-
import * as Context from "effect/Context";
|
|
13
12
|
import * as Stream from "effect/Stream";
|
|
13
|
+
import * as Context from "effect/Context";
|
|
14
|
+
import * as Exit from "effect/Exit";
|
|
14
15
|
import * as Scope$1 from "effect/Scope";
|
|
15
16
|
import * as Deferred from "effect/Deferred";
|
|
16
17
|
// src/storage/calls.ts
|
|
@@ -69,13 +70,14 @@ const objectsCount = (count) => gitError("INVALID_ARGUMENT", `An objects read as
|
|
|
69
70
|
const objectReader = (given, scope) => {
|
|
70
71
|
let calls = given;
|
|
71
72
|
const open = (effect) => Effect.suspend(() => calls === void 0 ? Effect.fail(closedReader) : effect(calls));
|
|
73
|
+
const inReader = (input, effect) => inCallScope(effect, readScope(scope, input));
|
|
72
74
|
return {
|
|
73
|
-
read: (input) =>
|
|
74
|
-
sizes: (input) =>
|
|
75
|
-
headers: (input) =>
|
|
76
|
-
held: (input) =>
|
|
77
|
-
startingWith: (input) =>
|
|
78
|
-
objects: (input) =>
|
|
75
|
+
read: (input) => inReader(input, open((calls) => calls.object(input.oid, input.signal))),
|
|
76
|
+
sizes: (input) => inReader(input, open((calls) => calls.sizes(input.oids))),
|
|
77
|
+
headers: (input) => inReader(input, open((calls) => calls.headers(input.oids))),
|
|
78
|
+
held: (input) => inReader(input, open((calls) => calls.has(input.oids))),
|
|
79
|
+
startingWith: (input) => inReader(input, open((calls) => calls.startingWith(input.prefix, input.most))),
|
|
80
|
+
objects: (input) => inReader(input, input.oids.length === 0 || input.oids.length > 1024 ? Effect.fail(objectsCount(input.oids.length)) : open((calls) => calls.objects(input.oids, input.bytes))),
|
|
79
81
|
allotment: (most, refusal) => calls === void 0 ? allotmentWithin(0, closedReader) : calls.allotment(most, refusal),
|
|
80
82
|
close: () => {
|
|
81
83
|
const closing = calls;
|
|
@@ -89,19 +91,24 @@ const objectReader = (given, scope) => {
|
|
|
89
91
|
* failure and interrupt alike. Core opens a reader only through this, never with a bare
|
|
90
92
|
* `reader()`, so none outlives its request and keeps its read cache: `calls.test.ts` checks it.
|
|
91
93
|
*/
|
|
92
|
-
const scopedReader = (objects, listed, input) => Effect.acquireRelease(objects.reader(listed, input), (reader) => Effect.sync(() => reader.close()));
|
|
93
|
-
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
const scopedReader = (objects, listed, input) => Effect.acquireRelease(Effect.map(objects.reader(listed, input), spentStops), (reader) => Effect.sync(() => reader.close()));
|
|
95
|
+
/**
|
|
96
|
+
* `reader` with each read's refusal past a call bound the defect it is, as storage's own readers
|
|
97
|
+
* die on theirs: a host's reader may fail with one, and a caller that answers its own
|
|
98
|
+
* `RESOURCE_EXHAUSTED`, such as ancestry's walk limit, must never take a spent request for it.
|
|
99
|
+
*/
|
|
100
|
+
const spentStops = (reader) => ({
|
|
101
|
+
read: (input) => Effect.catch(reader.read(input), answerFailed),
|
|
102
|
+
sizes: (input) => Effect.catch(reader.sizes(input), answerFailed),
|
|
103
|
+
headers: (input) => Effect.catch(reader.headers(input), answerFailed),
|
|
104
|
+
held: (input) => Effect.catch(reader.held(input), answerFailed),
|
|
105
|
+
startingWith: (input) => Effect.catch(reader.startingWith(input), answerFailed),
|
|
106
|
+
objects: (input) => Effect.catch(reader.objects(input), answerFailed),
|
|
107
|
+
allotment: (most, refusal) => reader.allotment(most, refusal),
|
|
108
|
+
close: () => reader.close()
|
|
102
109
|
});
|
|
103
110
|
/** `use` on a reader of its own over `listed`, closed once `use` settles: a call with no walk. */
|
|
104
|
-
const once = (objects, listed, input, use) => Effect.scoped(Effect.flatMap(scopedReader(objects, listed, input),
|
|
111
|
+
const once = (objects, listed, input, use) => Effect.scoped(Effect.flatMap(scopedReader(objects, listed, input), use));
|
|
105
112
|
/**
|
|
106
113
|
* One read of `listed`'s objects, on a reader of its own, closed once the read settles. A body it
|
|
107
114
|
* hands on keeps the blocks it streams from until it ends.
|
|
@@ -151,7 +158,7 @@ const walkObjects = /* @__PURE__ */ Effect.fnUntraced(function* (objects, push)
|
|
|
151
158
|
const input = {};
|
|
152
159
|
if (listedOnly === true) input.listedOnly = true;
|
|
153
160
|
if (push !== void 0) input.push = push;
|
|
154
|
-
const reading = inCallScope(
|
|
161
|
+
const reading = inCallScope(scopedReader(objects, listed, input), calls);
|
|
155
162
|
return Effect.provideService(reading, Scope$1.Scope, scope).pipe(Effect.exit, Effect.flatMap((exit) => Deferred.done(opened, exit)), Effect.andThen(Deferred.await(opened)));
|
|
156
163
|
});
|
|
157
164
|
/** `call` in the walk's scope, wherever it's run: a rule's walk calls from a Promise of its own. */
|
|
@@ -461,25 +468,16 @@ const bucketBodyIn = (context, bucket, key, range) => {
|
|
|
461
468
|
}
|
|
462
469
|
}, { highWaterMark: 0 });
|
|
463
470
|
};
|
|
464
|
-
/**
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
* `read` of the bucket's stream of `key`, or of `range` of it, `undefined` when there's none: a
|
|
475
|
-
* reader that takes the bytes as they come, holding none past its chunk. Its failure is
|
|
476
|
-
* `bucketTry`'s. An interrupt or a failure cancels the bucket's read under it, even one `read`
|
|
477
|
-
* waits on, so no read outlives its caller.
|
|
478
|
-
*/
|
|
479
|
-
const bucketReading = (bucket, key, range, read) => Effect.uninterruptibleMask((restore) => Effect.flatMap(bucketStream(bucket, key, range), (body) => {
|
|
480
|
-
if (body === void 0) return restore(bucketTry(() => read(void 0)));
|
|
481
|
-
const reader = body.getReader();
|
|
482
|
-
return restore(bucketTry(() => read(bodyOf(reader)))).pipe(Effect.ensuring(Effect.sync(() => letGo(reader))));
|
|
471
|
+
/**
|
|
472
|
+
* `read` of a reader over the bucket's stream of `key`, or of `range` of it, `undefined` when
|
|
473
|
+
* there's none: a reader that takes the bytes as they come, holding none past its chunk. The scope
|
|
474
|
+
* owns both the bucket stream and the reader: on any exit, including early return, failure, or
|
|
475
|
+
* interrupt while a read is pending, it cancels the stream and releases the lock.
|
|
476
|
+
*/
|
|
477
|
+
const bucketReading = (bucket, key, range, read) => Effect.scoped(Effect.gen(function* () {
|
|
478
|
+
const body = yield* bucketStreamScoped(bucket, key, range);
|
|
479
|
+
if (body === void 0) return yield* read(void 0);
|
|
480
|
+
return yield* read(yield* scopedReader$1(body));
|
|
483
481
|
}));
|
|
484
482
|
/**
|
|
485
483
|
* A put of `bytes` to `key`, told its size, so the service charges all its calls as it starts. An
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// src/storage/charged-cache.ts
|
|
2
|
+
/** Unexported nominal brand so a bare `Map` or structural look-alike is unassignable to `ChargedCache`. */
|
|
3
|
+
const chargedCacheBrand = Symbol("ChargedCache");
|
|
4
|
+
/**
|
|
5
|
+
* Lightweight fixed-entry-cost, no-evict constructor on the same nominal `[chargedCacheBrand]`
|
|
6
|
+
* (used by `walkedVisible`, so thin bundles like `GitClient` do not carry LRU eviction or variable
|
|
7
|
+
* payload accounting).
|
|
8
|
+
*/
|
|
9
|
+
const chargedFixedCache = (charge, entryBytes, maxEntries, onEvict) => {
|
|
10
|
+
const map = /* @__PURE__ */ new Map();
|
|
11
|
+
let closed = false;
|
|
12
|
+
const lifetime = charge.lifetime;
|
|
13
|
+
charge.watch?.((targetBytes) => {
|
|
14
|
+
if (targetBytes <= 0) map.clear();
|
|
15
|
+
else for (const key of map.keys()) {
|
|
16
|
+
if (map.size * entryBytes <= targetBytes) break;
|
|
17
|
+
map.delete(key);
|
|
18
|
+
}
|
|
19
|
+
onEvict?.();
|
|
20
|
+
});
|
|
21
|
+
const clear = () => {
|
|
22
|
+
const held = map.size * entryBytes;
|
|
23
|
+
map.clear();
|
|
24
|
+
if (held > 0) charge.shrink(held);
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
[chargedCacheBrand]: lifetime,
|
|
28
|
+
lifetime,
|
|
29
|
+
get size() {
|
|
30
|
+
return map.size;
|
|
31
|
+
},
|
|
32
|
+
bytes: 0,
|
|
33
|
+
get chargedBytes() {
|
|
34
|
+
return map.size * entryBytes;
|
|
35
|
+
},
|
|
36
|
+
get: (key) => map.get(key),
|
|
37
|
+
has: (key) => map.has(key),
|
|
38
|
+
set: (key, value) => {
|
|
39
|
+
if (closed || charge.lifetime === "request" && charge.released?.() === true) return false;
|
|
40
|
+
if (map.has(key)) {
|
|
41
|
+
map.set(key, value);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (map.size >= maxEntries || entryBytes > 0 && !charge.tryGrow(entryBytes)) return false;
|
|
45
|
+
map.set(key, value);
|
|
46
|
+
return true;
|
|
47
|
+
},
|
|
48
|
+
delete: (key) => {
|
|
49
|
+
if (!map.delete(key)) return false;
|
|
50
|
+
if (entryBytes > 0) charge.shrink(entryBytes);
|
|
51
|
+
return true;
|
|
52
|
+
},
|
|
53
|
+
entries: () => map.entries(),
|
|
54
|
+
values: () => map.values(),
|
|
55
|
+
clear,
|
|
56
|
+
release: () => {
|
|
57
|
+
if (closed) return;
|
|
58
|
+
closed = true;
|
|
59
|
+
clear();
|
|
60
|
+
charge.close?.();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Builds a bounded, budget-charged cache with explicit lifetime (`'request'` or `'instance'`),
|
|
66
|
+
* automatic per-entry overhead accounting, LRU or no-evict policy, pressure eviction via
|
|
67
|
+
* `charge.watch`, and deterministic release.
|
|
68
|
+
*/
|
|
69
|
+
const chargedCache = (charge, options) => {
|
|
70
|
+
const { maxBytes, maxEntries, entryOverhead, weight, evict = "lru", onEvict } = options;
|
|
71
|
+
const map = /* @__PURE__ */ new Map();
|
|
72
|
+
let payloadBytes = 0;
|
|
73
|
+
let chargedBytes = 0;
|
|
74
|
+
let closed = false;
|
|
75
|
+
const isReleased = () => closed || charge.lifetime === "request" && charge.released?.() === true;
|
|
76
|
+
const drop = (key, entry) => {
|
|
77
|
+
map.delete(key);
|
|
78
|
+
payloadBytes -= entry.payload;
|
|
79
|
+
chargedBytes -= entry.charged;
|
|
80
|
+
return entry.charged;
|
|
81
|
+
};
|
|
82
|
+
charge.watch?.((targetBytes) => {
|
|
83
|
+
let evicted = false;
|
|
84
|
+
for (const [oldKey, oldEntry] of map) {
|
|
85
|
+
if (chargedBytes <= targetBytes) break;
|
|
86
|
+
drop(oldKey, oldEntry);
|
|
87
|
+
evicted = true;
|
|
88
|
+
}
|
|
89
|
+
if (evicted || targetBytes === 0) onEvict?.();
|
|
90
|
+
});
|
|
91
|
+
const set = (key, value) => {
|
|
92
|
+
if (isReleased()) return false;
|
|
93
|
+
const payload = Math.max(0, weight(value, key));
|
|
94
|
+
if (payload > maxBytes || maxEntries !== void 0 && maxEntries <= 0) return false;
|
|
95
|
+
const existing = map.get(key);
|
|
96
|
+
const nextCharged = payload + entryOverhead;
|
|
97
|
+
const deltaPayload = existing === void 0 ? payload : payload - existing.payload;
|
|
98
|
+
const deltaCharged = existing === void 0 ? nextCharged : nextCharged - existing.charged;
|
|
99
|
+
const deltaCount = existing === void 0 ? 1 : 0;
|
|
100
|
+
const overBounds = () => payloadBytes + deltaPayload > maxBytes || maxEntries !== void 0 && map.size + deltaCount > maxEntries;
|
|
101
|
+
let freed = 0;
|
|
102
|
+
if (evict === "lru") for (const [otherKey, otherEntry] of map) {
|
|
103
|
+
if (!overBounds()) break;
|
|
104
|
+
if (otherKey !== key) freed += drop(otherKey, otherEntry);
|
|
105
|
+
}
|
|
106
|
+
if (overBounds()) {
|
|
107
|
+
if (freed > 0) charge.shrink(freed);
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
const netCharged = deltaCharged - freed;
|
|
111
|
+
if (netCharged > 0 && !charge.tryGrow(netCharged)) {
|
|
112
|
+
if (freed > 0) charge.shrink(freed);
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
if (netCharged < 0) charge.shrink(-netCharged);
|
|
116
|
+
payloadBytes += deltaPayload;
|
|
117
|
+
chargedBytes += deltaCharged;
|
|
118
|
+
if (existing !== void 0) map.delete(key);
|
|
119
|
+
map.set(key, {
|
|
120
|
+
value,
|
|
121
|
+
payload,
|
|
122
|
+
charged: nextCharged
|
|
123
|
+
});
|
|
124
|
+
return true;
|
|
125
|
+
};
|
|
126
|
+
const clear = () => {
|
|
127
|
+
const held = chargedBytes;
|
|
128
|
+
map.clear();
|
|
129
|
+
payloadBytes = 0;
|
|
130
|
+
chargedBytes = 0;
|
|
131
|
+
if (held > 0) charge.shrink(held);
|
|
132
|
+
};
|
|
133
|
+
const release = () => {
|
|
134
|
+
if (closed) return;
|
|
135
|
+
closed = true;
|
|
136
|
+
clear();
|
|
137
|
+
charge.close?.();
|
|
138
|
+
};
|
|
139
|
+
const lifetime = charge.lifetime;
|
|
140
|
+
return {
|
|
141
|
+
[chargedCacheBrand]: lifetime,
|
|
142
|
+
lifetime,
|
|
143
|
+
get size() {
|
|
144
|
+
return map.size;
|
|
145
|
+
},
|
|
146
|
+
get bytes() {
|
|
147
|
+
return payloadBytes;
|
|
148
|
+
},
|
|
149
|
+
get chargedBytes() {
|
|
150
|
+
return chargedBytes;
|
|
151
|
+
},
|
|
152
|
+
get: (key) => {
|
|
153
|
+
const entry = map.get(key);
|
|
154
|
+
if (entry === void 0) return void 0;
|
|
155
|
+
if (evict === "lru") {
|
|
156
|
+
map.delete(key);
|
|
157
|
+
map.set(key, entry);
|
|
158
|
+
}
|
|
159
|
+
return entry.value;
|
|
160
|
+
},
|
|
161
|
+
has: (key) => map.has(key),
|
|
162
|
+
set,
|
|
163
|
+
delete: (key) => {
|
|
164
|
+
const existing = map.get(key);
|
|
165
|
+
if (existing === void 0) return false;
|
|
166
|
+
const freed = drop(key, existing);
|
|
167
|
+
if (freed > 0) charge.shrink(freed);
|
|
168
|
+
return true;
|
|
169
|
+
},
|
|
170
|
+
*entries() {
|
|
171
|
+
for (const [key, entry] of map) yield [key, entry.value];
|
|
172
|
+
},
|
|
173
|
+
*values() {
|
|
174
|
+
for (const entry of map.values()) yield entry.value;
|
|
175
|
+
},
|
|
176
|
+
clear,
|
|
177
|
+
release
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
export { chargedCache, chargedFixedCache };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "../contracts/ids.mjs";
|
|
2
2
|
import "../contracts/objects.mjs";
|
|
3
3
|
import "../contracts/result.mjs";
|
|
4
|
-
import "../contracts/services.mjs";
|
|
5
4
|
import "../contracts/store.mjs";
|
|
5
|
+
import "../store/call-count.mjs";
|
|
6
6
|
import "./batches.mjs";
|
|
7
|
-
import "
|
|
7
|
+
import { Key, Row } from "@ref0/infra";
|
|
8
8
|
import "effect/Schema";
|
|
9
|
-
import
|
|
9
|
+
import "effect/Effect";
|