@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/fetch.mjs
CHANGED
|
@@ -2,23 +2,19 @@ import { gitError } from "../contracts/result.mjs";
|
|
|
2
2
|
import { BufferMeter } from "../protocol/bytes/buffers.mjs";
|
|
3
3
|
import { crc32Update } from "../protocol/bytes/crc32.mjs";
|
|
4
4
|
import { deflatedMost } from "../protocol/bytes/deflate.mjs";
|
|
5
|
+
import { hexOf } from "../protocol/bytes/hex.mjs";
|
|
5
6
|
import { Sha1 } from "../protocol/bytes/sha1.mjs";
|
|
6
7
|
import { emptyTree } from "../protocol/objects/object.mjs";
|
|
7
8
|
import { entryHeader, packStream, writePack } from "../protocol/packs/writer.mjs";
|
|
8
9
|
import { untilAborted } from "../store/crossing.mjs";
|
|
9
10
|
import { fetchLess } from "../store/errors.mjs";
|
|
10
11
|
import { catchSpent, ownSpentOf } from "../contracts/calls-spent.mjs";
|
|
11
|
-
import { hexOf } from "../protocol/bytes/hex.mjs";
|
|
12
|
-
import "./pack-reads.mjs";
|
|
13
|
-
import { isSet } from "./bits.mjs";
|
|
14
12
|
import { entryHolds, planColumns } from "./plan-columns.mjs";
|
|
15
|
-
import { typeOfCode } from "./index-files.mjs";
|
|
16
|
-
import { ListCursor, sizeOf } from "./send-list.mjs";
|
|
17
13
|
import { oidSet } from "./oid-table.mjs";
|
|
18
14
|
import { planShallow, withRootsSent } from "./shallow.mjs";
|
|
19
15
|
import { countedReads, fetchReadsOf, historyOf, lost, noIds, notHeld, unreadable, walk } from "./walk.mjs";
|
|
20
|
-
import * as Clock from "effect/Clock";
|
|
21
16
|
import * as Effect from "effect/Effect";
|
|
17
|
+
import * as Clock from "effect/Clock";
|
|
22
18
|
// src/storage/fetch.ts
|
|
23
19
|
/**
|
|
24
20
|
* `Git.layer`'s `fetchLimits` when it names none: a clone of a large repo fits within them.
|
|
@@ -121,6 +117,11 @@ const plannedSource = (reads, plan, rows) => {
|
|
|
121
117
|
const ordinal = columns.sentAt(at);
|
|
122
118
|
if (columns.copiedAt(ordinal)) continue;
|
|
123
119
|
const each = size[ordinal] ?? 0;
|
|
120
|
+
const kind = columns.kindAt(ordinal);
|
|
121
|
+
if (kind !== void 0 && reads.ranged?.handles({
|
|
122
|
+
kind,
|
|
123
|
+
size: each
|
|
124
|
+
}) === true) continue;
|
|
124
125
|
if (oids.length > 0 && bytes + each > 1048576) break;
|
|
125
126
|
oids.push(columns.oidAt(ordinal));
|
|
126
127
|
bytes += each;
|
|
@@ -145,6 +146,11 @@ const plannedSource = (reads, plan, rows) => {
|
|
|
145
146
|
count,
|
|
146
147
|
page: (from, most) => Effect.sync(() => Array.from({ length: Math.max(0, Math.min(most, count - from)) }, (_, at) => columns.sent(from + at))),
|
|
147
148
|
read: Effect.fnUntraced(function* (object, at) {
|
|
149
|
+
if (reads.ranged?.handles(object) === true) {
|
|
150
|
+
const piece = yield* reads.ranged.read(object.oid, at);
|
|
151
|
+
if (piece === void 0) return yield* Effect.fail(gone(object.oid));
|
|
152
|
+
return piece;
|
|
153
|
+
}
|
|
148
154
|
if (!window.has(object.oid)) yield* load(object.oid);
|
|
149
155
|
const whole = window.get(object.oid);
|
|
150
156
|
if (whole === void 0) return yield* Effect.fail(gone(object.oid));
|
|
@@ -165,234 +171,6 @@ const plannedSource = (reads, plan, rows) => {
|
|
|
165
171
|
}
|
|
166
172
|
};
|
|
167
173
|
};
|
|
168
|
-
/** A pack entry's type, in its header's first byte: 1 to 4 for the kinds, 7 for a `REF_DELTA`. */
|
|
169
|
-
const entryTypes = {
|
|
170
|
-
commit: 1,
|
|
171
|
-
tree: 2,
|
|
172
|
-
blob: 3,
|
|
173
|
-
tag: 4
|
|
174
|
-
};
|
|
175
|
-
const refDeltaType = 7;
|
|
176
|
-
/**
|
|
177
|
-
* `copy`, refused with `DATA_LOSS` before its first range is handed over when its header's type
|
|
178
|
-
* isn't what the index says it is: `kind` for a whole entry, a `REF_DELTA` for a delta. A copied
|
|
179
|
-
* delta's header must name `base` too, the ID at the base position its `.bases` row gives,
|
|
180
|
-
* checked before the range that completes the header's ID is handed over.
|
|
181
|
-
*/
|
|
182
|
-
const typeChecked = (copy, entry, type, base) => {
|
|
183
|
-
const wrong = gitError("DATA_LOSS", `Object ${entry.oid} in pack ${entry.pack.id} isn't the entry the index's .types and .bases say`);
|
|
184
|
-
let head = /* @__PURE__ */ new Uint8Array(0);
|
|
185
|
-
let checked = true;
|
|
186
|
-
/** The base ID a `REF_DELTA`'s header names, past its type and size, once `bytes` hold it. */
|
|
187
|
-
const named = (bytes) => {
|
|
188
|
-
let at = 1;
|
|
189
|
-
while (at <= bytes.byteLength && ((bytes[at - 1] ?? 0) & 128) !== 0) at += 1;
|
|
190
|
-
return bytes.byteLength < at + 20 ? void 0 : hexOf(bytes.subarray(at, at + 20));
|
|
191
|
-
};
|
|
192
|
-
return {
|
|
193
|
-
bytes: copy.bytes,
|
|
194
|
-
read: (at) => Effect.flatMap(copy.read(at), (bytes) => {
|
|
195
|
-
if (at === 0 && ((bytes[0] ?? 0) >> 4 & 7) !== type) return Effect.fail(wrong);
|
|
196
|
-
if (at === 0) {
|
|
197
|
-
head = /* @__PURE__ */ new Uint8Array(0);
|
|
198
|
-
checked = base === void 0;
|
|
199
|
-
}
|
|
200
|
-
if (checked) return Effect.succeed(bytes);
|
|
201
|
-
head = Uint8Array.from([...head, ...bytes.subarray(0, 64 - head.byteLength)]);
|
|
202
|
-
const found = named(head);
|
|
203
|
-
if (found === void 0 && at + bytes.byteLength < copy.bytes) return Effect.succeed(bytes);
|
|
204
|
-
checked = true;
|
|
205
|
-
return found === base ? Effect.succeed(bytes) : Effect.fail(wrong);
|
|
206
|
-
})
|
|
207
|
-
};
|
|
208
|
-
};
|
|
209
|
-
/**
|
|
210
|
-
* The whole objects of `list` the writer reads at once from `cursor` on, as `plannedSource` reads
|
|
211
|
-
* its windows: those it doesn't copy, up to `windowBytes` of them or the one.
|
|
212
|
-
*/
|
|
213
|
-
const windowFrom = (cursor) => {
|
|
214
|
-
const { list } = cursor;
|
|
215
|
-
const window = [];
|
|
216
|
-
let bytes = 0;
|
|
217
|
-
for (const at = cursor.copy(); !at.done; at.next()) {
|
|
218
|
-
if (isSet(list.copied, at.ordinal)) continue;
|
|
219
|
-
const size = sizeOf(list, at.ordinal);
|
|
220
|
-
if (window.length > 0 && bytes + size > 1048576) break;
|
|
221
|
-
window.push({
|
|
222
|
-
ordinal: at.ordinal,
|
|
223
|
-
position: at.position,
|
|
224
|
-
pack: at.inPack
|
|
225
|
-
});
|
|
226
|
-
bytes += size;
|
|
227
|
-
}
|
|
228
|
-
return window;
|
|
229
|
-
};
|
|
230
|
-
/**
|
|
231
|
-
* The stored entries the writer reads through the reader's blocks for `list`, in its order, as
|
|
232
|
-
* `writerCalls` forecasts a plan's: for each window of objects written whole, each one's entry and
|
|
233
|
-
* the bases down its chain, as the reader resolves it. Its copies are read through `listRuns`.
|
|
234
|
-
* None is held past `PackBlocks.gets`' count.
|
|
235
|
-
*/
|
|
236
|
-
function* listReads(list) {
|
|
237
|
-
let windowEnd = 0;
|
|
238
|
-
for (const cursor = new ListCursor(list); !cursor.done; cursor.next()) {
|
|
239
|
-
if (isSet(list.copied, cursor.ordinal) || cursor.ordinal < windowEnd) continue;
|
|
240
|
-
const window = windowFrom(cursor);
|
|
241
|
-
windowEnd = (window.at(-1)?.ordinal ?? cursor.ordinal) + 1;
|
|
242
|
-
for (const each of window) for (let at = each.position, steps = 0; at !== void 0 && steps <= list.chains.size; at = list.chains.get(at), steps += 1) yield each.pack.at(at);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* `list`'s copies as runs, in its order: each copy joins the run before it when it's in the same
|
|
247
|
-
* pack and starts at most `blockBytes` past that run's end, the gap read and let go. So each run
|
|
248
|
-
* starts in a block no run before it reads, and runs are never more gets than the blocks the
|
|
249
|
-
* copies' bytes span. A full clone of one pack is one run (#647).
|
|
250
|
-
*/
|
|
251
|
-
function* listRuns(list) {
|
|
252
|
-
let run;
|
|
253
|
-
let pack = -1;
|
|
254
|
-
for (const cursor = new ListCursor(list); !cursor.done; cursor.next()) {
|
|
255
|
-
if (!isSet(list.copied, cursor.ordinal)) continue;
|
|
256
|
-
const entry = cursor.inPack.at(cursor.position);
|
|
257
|
-
const end = entry.offset + entry.bytes;
|
|
258
|
-
if (run !== void 0 && cursor.pack === pack && entry.offset <= run.to + 1048576) {
|
|
259
|
-
run.to = end;
|
|
260
|
-
run.last = cursor.ordinal;
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
if (run !== void 0) yield run;
|
|
264
|
-
pack = cursor.pack;
|
|
265
|
-
run = {
|
|
266
|
-
pack: entry.pack,
|
|
267
|
-
from: entry.offset,
|
|
268
|
-
to: end,
|
|
269
|
-
first: cursor.ordinal,
|
|
270
|
-
last: cursor.ordinal
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
if (run !== void 0) yield run;
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* The bucket gets the writer makes for `list`'s objects, with no I/O: one a run of its copies, and
|
|
277
|
-
* its windows' reads as `PackBlocks.gets` forecasts them, as `writerCalls` forecasts a plan's
|
|
278
|
-
* (#522).
|
|
279
|
-
*/
|
|
280
|
-
const listCalls = (stored, list) => {
|
|
281
|
-
let runs = 0;
|
|
282
|
-
for (const _run of listRuns(list)) runs += 1;
|
|
283
|
-
return {
|
|
284
|
-
bucket: runs + stored.gets(listReads(list)),
|
|
285
|
-
store: 0
|
|
286
|
-
};
|
|
287
|
-
};
|
|
288
|
-
/**
|
|
289
|
-
* `list`'s objects as the writer takes them, a page at a time: each one's ID, kind and size from
|
|
290
|
-
* the index and the list, held for its page alone. A copy is its stored entry, read through its
|
|
291
|
-
* run's one ranged get, its CRC-32 checked as it's read and its type against the index's; the rest
|
|
292
|
-
* are read whole a window at a time, as `plannedSource` reads them. Every read is a listed pack's,
|
|
293
|
-
* so the store is read no more. A second write, from the first object again, reads its runs again.
|
|
294
|
-
*/
|
|
295
|
-
const listSource = (reads, list) => {
|
|
296
|
-
let cursor = new ListCursor(list);
|
|
297
|
-
let paged = /* @__PURE__ */ new Map();
|
|
298
|
-
let window = /* @__PURE__ */ new Map();
|
|
299
|
-
let runs = listRuns(list);
|
|
300
|
-
let run;
|
|
301
|
-
let reading;
|
|
302
|
-
const closeRun = Effect.suspend(() => {
|
|
303
|
-
const open = reading;
|
|
304
|
-
reading = void 0;
|
|
305
|
-
return open?.close ?? Effect.void;
|
|
306
|
-
});
|
|
307
|
-
const load = Effect.fnUntraced(function* (from) {
|
|
308
|
-
const at = windowFrom(from).map(({ pack, position }) => {
|
|
309
|
-
const { oid, offset } = pack.at(position);
|
|
310
|
-
return {
|
|
311
|
-
oid,
|
|
312
|
-
lookup: pack.lookup,
|
|
313
|
-
offset
|
|
314
|
-
};
|
|
315
|
-
});
|
|
316
|
-
if (reads.heldAt !== void 0) window = yield* reads.heldAt(at);
|
|
317
|
-
});
|
|
318
|
-
/**
|
|
319
|
-
* The copy at `ordinal`'s bytes from `at`, through its run: a run is opened as the writer reaches
|
|
320
|
-
* it, and another from the entry on only for a read behind the one open.
|
|
321
|
-
*/
|
|
322
|
-
const copied = Effect.fnUntraced(function* (stored, ordinal, entry, at) {
|
|
323
|
-
while (run === void 0 || run.last < ordinal) {
|
|
324
|
-
yield* closeRun;
|
|
325
|
-
const next = runs.next();
|
|
326
|
-
if (next.done === true) return yield* Effect.die(/* @__PURE__ */ new Error(`no run of the list holds its copy ${ordinal}`));
|
|
327
|
-
run = next.value;
|
|
328
|
-
}
|
|
329
|
-
if (ordinal < run.first) return yield* Effect.die(/* @__PURE__ */ new Error(`the list's copy ${ordinal} is read before its run`));
|
|
330
|
-
const offset = entry.offset + at;
|
|
331
|
-
const open = reading !== void 0 && reading.reads(offset);
|
|
332
|
-
if (!open && stored.kept(entry.pack, offset)) return yield* stored.read(entry, at);
|
|
333
|
-
if (reading === void 0 || !open) {
|
|
334
|
-
yield* closeRun;
|
|
335
|
-
reading = stored.run(run.pack, offset, run.to);
|
|
336
|
-
}
|
|
337
|
-
return yield* reading.read(offset, entry.offset + entry.bytes);
|
|
338
|
-
});
|
|
339
|
-
return {
|
|
340
|
-
count: list.count,
|
|
341
|
-
page: Effect.fnUntraced(function* (from, most) {
|
|
342
|
-
if (from === 0 && cursor.ordinal > 0) {
|
|
343
|
-
yield* closeRun;
|
|
344
|
-
cursor = new ListCursor(list);
|
|
345
|
-
window = /* @__PURE__ */ new Map();
|
|
346
|
-
runs = listRuns(list);
|
|
347
|
-
run = void 0;
|
|
348
|
-
}
|
|
349
|
-
if (from !== cursor.ordinal) return yield* Effect.die(/* @__PURE__ */ new Error(`the list pages in order: ${from} isn't its next`));
|
|
350
|
-
const page = [];
|
|
351
|
-
paged = /* @__PURE__ */ new Map();
|
|
352
|
-
for (; page.length < most && !cursor.done; cursor.next()) {
|
|
353
|
-
const { oid } = cursor.inPack.at(cursor.position);
|
|
354
|
-
const kind = typeOfCode[list.kinds[cursor.ordinal] ?? 0] ?? "blob";
|
|
355
|
-
const size = sizeOf(list, cursor.ordinal);
|
|
356
|
-
page.push(isSet(list.copied, cursor.ordinal) ? {
|
|
357
|
-
oid,
|
|
358
|
-
kind,
|
|
359
|
-
storedBytes: size
|
|
360
|
-
} : {
|
|
361
|
-
oid,
|
|
362
|
-
kind,
|
|
363
|
-
size
|
|
364
|
-
});
|
|
365
|
-
paged.set(oid, cursor.copy());
|
|
366
|
-
}
|
|
367
|
-
return page;
|
|
368
|
-
}),
|
|
369
|
-
read: Effect.fnUntraced(function* (object, at) {
|
|
370
|
-
const placed = paged.get(object.oid);
|
|
371
|
-
if (!window.has(object.oid) && placed !== void 0) yield* load(placed);
|
|
372
|
-
const whole = window.get(object.oid);
|
|
373
|
-
if (whole === void 0) return yield* Effect.fail(gone(object.oid));
|
|
374
|
-
const bytes = whole.bytes.slice(at, at + rangeBytes);
|
|
375
|
-
if (at + bytes.byteLength >= whole.bytes.byteLength) {
|
|
376
|
-
const left = new Map(window);
|
|
377
|
-
left.delete(object.oid);
|
|
378
|
-
window = left;
|
|
379
|
-
}
|
|
380
|
-
return bytes;
|
|
381
|
-
}),
|
|
382
|
-
end: closeRun,
|
|
383
|
-
close: closeRun,
|
|
384
|
-
copy: (object) => {
|
|
385
|
-
const placed = paged.get(object.oid);
|
|
386
|
-
const { stored } = reads;
|
|
387
|
-
if (placed === void 0 || stored === void 0 || !isSet(list.copied, placed.ordinal)) return void 0;
|
|
388
|
-
const entry = placed.inPack.at(placed.position);
|
|
389
|
-
const copy = checkedCopy(entry, (at) => copied(stored, placed.ordinal, entry, at));
|
|
390
|
-
if (!isSet(list.deltas, placed.ordinal)) return typeChecked(copy, entry, entryTypes[object.kind]);
|
|
391
|
-
const base = placed.inPack.at(list.bases[placed.ordinal] ?? 0).oid;
|
|
392
|
-
return typeChecked(copy, entry, refDeltaType, base);
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
};
|
|
396
174
|
/** `first`'s objects, then `second`'s, as one source: a page across the seam takes from both. */
|
|
397
175
|
const joinedSources = (first, second) => {
|
|
398
176
|
let fromFirst = /* @__PURE__ */ new Set();
|
|
@@ -420,7 +198,7 @@ const memorySource = (objects) => {
|
|
|
420
198
|
kind: object.type,
|
|
421
199
|
size: object.bytes.byteLength
|
|
422
200
|
}))),
|
|
423
|
-
read: (object, at) => Effect.sync(() => byOid.get(object.oid)?.bytes.slice(at, at +
|
|
201
|
+
read: (object, at) => Effect.sync(() => byOid.get(object.oid)?.bytes.slice(at, at + 1048576) ?? /* @__PURE__ */ new Uint8Array(0)),
|
|
424
202
|
end: Effect.void
|
|
425
203
|
};
|
|
426
204
|
};
|
|
@@ -650,7 +428,18 @@ const planFetch = /* @__PURE__ */ Effect.fnUntraced(function* (read, request, ta
|
|
|
650
428
|
for (let at = 0; at < parents.length; at += 20) if (hadAt(parents, at)) edges.addBytes(parents, at);
|
|
651
429
|
}
|
|
652
430
|
const edgeTrees = [];
|
|
653
|
-
|
|
431
|
+
const unreadEdges = [];
|
|
432
|
+
for (const oid of edges.values()) {
|
|
433
|
+
const have = haves.get(oid);
|
|
434
|
+
if (have !== void 0) {
|
|
435
|
+
if (have.tree !== void 0) edgeTrees.push(have.tree);
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
unreadEdges.push(oid);
|
|
439
|
+
}
|
|
440
|
+
if (unreadEdges.length > 0) {
|
|
441
|
+
for (const commit of (yield* read(unreadEdges)).values()) if (commit.tree !== void 0) edgeTrees.push(commit.tree);
|
|
442
|
+
}
|
|
654
443
|
const byId = request.wants.some((oid) => {
|
|
655
444
|
const type = history.typeOf(oid);
|
|
656
445
|
return type === "tree" || type === "blob";
|
|
@@ -944,10 +733,29 @@ const writerCalls = /* @__PURE__ */ Effect.fnUntraced(function* (stored, columns
|
|
|
944
733
|
}
|
|
945
734
|
}
|
|
946
735
|
const rows = Array.from(whole).filter((ordinal) => packed[ordinal] !== 1).map((ordinal) => columns.oidAt(ordinal)).filter((oid) => oid !== emptyTree);
|
|
736
|
+
const sizeOf = (oid) => size[columns.find(oid) ?? columns.size] ?? 0;
|
|
737
|
+
let store;
|
|
738
|
+
if (rows.length === 0) store = 0;
|
|
739
|
+
else if (stored?.cachedRow !== void 0 && stored.pinCachedRows !== void 0) {
|
|
740
|
+
const rowBytes = rows.reduce((sum, oid) => sum + sizeOf(oid), 0);
|
|
741
|
+
if (stored.pinCachedRows(2 * rowBytes)) {
|
|
742
|
+
store = 0;
|
|
743
|
+
for (let at = 0; at < rows.length; at += 100) {
|
|
744
|
+
const end = Math.min(rows.length, at + 100);
|
|
745
|
+
for (let i = at; i < end; i += 1) {
|
|
746
|
+
const oid = rows[i];
|
|
747
|
+
if (oid !== void 0 && !stored.cachedRow(oid)) {
|
|
748
|
+
store += 1;
|
|
749
|
+
break;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
} else store = Math.ceil(rows.length / 100);
|
|
754
|
+
} else store = Math.ceil(rows.length / 100);
|
|
947
755
|
return {
|
|
948
756
|
forecast: {
|
|
949
757
|
bucket: stored?.gets(readsInTurn()) ?? 0,
|
|
950
|
-
store
|
|
758
|
+
store
|
|
951
759
|
},
|
|
952
760
|
rows
|
|
953
761
|
};
|
|
@@ -1081,7 +889,7 @@ const planFetchWithin = /* @__PURE__ */ Effect.fnUntraced(function* (reads, inpu
|
|
|
1081
889
|
const writer = yield* writerCalls(restRead.stored, columns);
|
|
1082
890
|
rows = writer.rows;
|
|
1083
891
|
if (calls !== void 0) {
|
|
1084
|
-
const listed = list === void 0 ? noCalls :
|
|
892
|
+
const listed = list === void 0 || within.index === void 0 ? noCalls : within.index.calls(reads.stored, list);
|
|
1085
893
|
forecast = {
|
|
1086
894
|
bucket: listed.bucket + writer.forecast.bucket,
|
|
1087
895
|
store: listed.store + writer.forecast.store
|
|
@@ -1113,7 +921,11 @@ const planFetchWithin = /* @__PURE__ */ Effect.fnUntraced(function* (reads, inpu
|
|
|
1113
921
|
bytes,
|
|
1114
922
|
rows
|
|
1115
923
|
};
|
|
1116
|
-
if (list !== void 0)
|
|
924
|
+
if (list !== void 0) {
|
|
925
|
+
plan.list = list;
|
|
926
|
+
const { index } = within;
|
|
927
|
+
if (index !== void 0) plan.listSource = (from) => index.sourceOf(from, list);
|
|
928
|
+
}
|
|
1117
929
|
if (unplaced !== void 0) plan.unplaced = unplaced;
|
|
1118
930
|
return plan;
|
|
1119
931
|
});
|
|
@@ -1123,9 +935,9 @@ const planFetchWithin = /* @__PURE__ */ Effect.fnUntraced(function* (reads, inpu
|
|
|
1123
935
|
* read that fails then ends the stream, and so does the call's signal aborting.
|
|
1124
936
|
*/
|
|
1125
937
|
const packOfPlan = /* @__PURE__ */ Effect.fnUntraced(function* (reads, plan, limits, writing, rows) {
|
|
1126
|
-
const { deepened
|
|
938
|
+
const { deepened } = plan;
|
|
1127
939
|
const planned = plannedSource(restReads(reads, plan.unplaced), plan, rows);
|
|
1128
|
-
const listed =
|
|
940
|
+
const listed = plan.listSource?.(reads);
|
|
1129
941
|
const source = listed === void 0 ? planned : joinedSources(listed, planned);
|
|
1130
942
|
const meter = new BufferMeter(writerBytes);
|
|
1131
943
|
const writeLimits = {
|
|
@@ -1220,4 +1032,4 @@ const rowsFirst = /* @__PURE__ */ Effect.fnUntraced(function* (reads, plan, char
|
|
|
1220
1032
|
}
|
|
1221
1033
|
return rows;
|
|
1222
1034
|
});
|
|
1223
|
-
export { awaitingIndex, callsAhead, checkedCopy, defaultFetchLimits, fetchPack, fetchTooLarge,
|
|
1035
|
+
export { awaitingIndex, callsAhead, checkedCopy, defaultFetchLimits, fetchPack, fetchTooLarge, gone, memoryPack, packOfPlan, pastLimits, planFetchWithin, planTooSlow, rangeBytes, refusedWhenSpent, requestSpent, timeLeft, tooManyCalls, unreadPackMs, windowBytes };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { spentAt } from "../contracts/calls-spent.mjs";
|
|
2
2
|
import { isServerClosed } from "../store/closed.mjs";
|
|
3
3
|
import { bucketFailed } from "./calls.mjs";
|
|
4
|
-
import * as Effect from "effect/Effect";
|
|
5
4
|
import { Unavailable } from "@ref0/infra";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
6
|
// src/storage/host-bucket.ts
|
|
7
7
|
/**
|
|
8
8
|
* A host bucket's own defect as `Unavailable`, which `bucketDo` answers `UNAVAILABLE`, "The bucket
|
|
@@ -13,8 +13,9 @@ const hostFailure = (cause) => isServerClosed(cause) || spentAt(cause) !== void
|
|
|
13
13
|
cause
|
|
14
14
|
}));
|
|
15
15
|
/**
|
|
16
|
-
* The host's bucket as `packs().open` takes it, each call's defect a failure: a host's
|
|
17
|
-
*
|
|
16
|
+
* The host's bucket as `packs().open` takes it, each call's defect a failure: a host's own
|
|
17
|
+
* `Bucket` service may die with what it likes, as an adapter's call over a promise does with any
|
|
18
|
+
* rejection that isn't an infra error.
|
|
18
19
|
*/
|
|
19
20
|
const hostFailures = (bucket) => ({
|
|
20
21
|
...bucket,
|
|
@@ -22,7 +23,11 @@ const hostFailures = (bucket) => ({
|
|
|
22
23
|
read: (key, range) => Effect.catchDefect(bucket.read(key, range), hostFailure),
|
|
23
24
|
remove: (key) => Effect.catchDefect(bucket.remove(key), hostFailure),
|
|
24
25
|
removeMany: (keys, options) => Effect.catchDefect(bucket.removeMany(keys, options), hostFailure),
|
|
25
|
-
list: (prefix, page) => Effect.catchDefect(bucket.list(prefix, page), hostFailure)
|
|
26
|
+
list: (prefix, page) => Effect.catchDefect(bucket.list(prefix, page), hostFailure),
|
|
27
|
+
beginPut: (key) => Effect.catchDefect(bucket.beginPut(key), hostFailure),
|
|
28
|
+
putPart: (key, token, part, body) => Effect.catchDefect(bucket.putPart(key, token, part, body), hostFailure),
|
|
29
|
+
completePut: (key, token, parts, options) => Effect.catchDefect(bucket.completePut(key, token, parts, options), hostFailure),
|
|
30
|
+
abortPut: (key, token) => Effect.catchDefect(bucket.abortPut(key, token), hostFailure)
|
|
26
31
|
});
|
|
27
32
|
/** The host's links, each call's defect a failure, as `hostFailures` says. */
|
|
28
33
|
const hostLinks = (links) => ({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { gitError } from "../contracts/result.mjs";
|
|
2
2
|
import { Sha1 } from "../protocol/bytes/sha1.mjs";
|
|
3
|
-
import { bucketDo, bucketReading, readWhole } from "./calls.mjs";
|
|
3
|
+
import { bucketDo, bucketReading, bucketTry, readWhole } from "./calls.mjs";
|
|
4
4
|
import { bitmapOf, bitmapWords, ewahExtent, ewahOf, mostDirty, orEwah } from "./ewah.mjs";
|
|
5
5
|
import "./link-join.mjs";
|
|
6
6
|
import { uploadPartBytes } from "./budget.mjs";
|
|
@@ -74,11 +74,15 @@ const noRootPositions = /* @__PURE__ */ new Set();
|
|
|
74
74
|
*/
|
|
75
75
|
const edgesFileOf = (key, first, positions, links, targets, roots = noRootPositions) => {
|
|
76
76
|
const sources = links.sources;
|
|
77
|
-
const
|
|
77
|
+
const hasRoots = roots.size > 0;
|
|
78
|
+
const targetCount = targets.length;
|
|
78
79
|
let count = 0;
|
|
79
80
|
for (let source = 0; source < sources; source += 1) {
|
|
80
|
-
const
|
|
81
|
-
|
|
81
|
+
const from = links.linkStart(source);
|
|
82
|
+
const to = links.linkEnd(source);
|
|
83
|
+
if (!(hasRoots && roots.has(links.positionOf(source)))) {
|
|
84
|
+
for (let at = from; at < to; at += 1) if (at < targetCount && targets[at] !== 4294967295) count += 1;
|
|
85
|
+
} else for (let at = from; at < to; at += 1) if (at < targetCount && targets[at] !== 4294967295 && !links.mayLack(source, at - from)) count += 1;
|
|
82
86
|
}
|
|
83
87
|
const bytes = new Uint8Array(edgesHeaderBytes + sources * 8 + 4 + count * 4);
|
|
84
88
|
const view = new DataView(bytes.buffer);
|
|
@@ -91,16 +95,37 @@ const edgesFileOf = (key, first, positions, links, targets, roots = noRootPositi
|
|
|
91
95
|
const starts = edgesHeaderBytes + sources * 4;
|
|
92
96
|
const ends = starts + (sources + 1) * 4;
|
|
93
97
|
let link = 0;
|
|
94
|
-
for (let source = 0; source < sources; source += 1) {
|
|
98
|
+
if (count === links.size) for (let source = 0; source < sources; source += 1) {
|
|
95
99
|
view.setUint32(edgesHeaderBytes + source * 4, links.positionOf(source));
|
|
96
100
|
view.setUint32(starts + source * 4, link);
|
|
97
|
-
const
|
|
101
|
+
const from = links.linkStart(source);
|
|
102
|
+
const to = links.linkEnd(source);
|
|
98
103
|
for (let at = from; at < to; at += 1) {
|
|
99
|
-
if (!kept(source, at, from)) continue;
|
|
100
104
|
view.setUint32(ends + link * 4, targets[at] ?? 4294967295);
|
|
101
105
|
link += 1;
|
|
102
106
|
}
|
|
103
107
|
}
|
|
108
|
+
else for (let source = 0; source < sources; source += 1) {
|
|
109
|
+
const position = links.positionOf(source);
|
|
110
|
+
view.setUint32(edgesHeaderBytes + source * 4, position);
|
|
111
|
+
view.setUint32(starts + source * 4, link);
|
|
112
|
+
const from = links.linkStart(source);
|
|
113
|
+
const to = links.linkEnd(source);
|
|
114
|
+
if (!(hasRoots && roots.has(position))) for (let at = from; at < to; at += 1) {
|
|
115
|
+
if (at >= targetCount) continue;
|
|
116
|
+
const target = targets[at] ?? 4294967295;
|
|
117
|
+
if (target === 4294967295) continue;
|
|
118
|
+
view.setUint32(ends + link * 4, target);
|
|
119
|
+
link += 1;
|
|
120
|
+
}
|
|
121
|
+
else for (let at = from; at < to; at += 1) {
|
|
122
|
+
if (at >= targetCount) continue;
|
|
123
|
+
const target = targets[at] ?? 4294967295;
|
|
124
|
+
if (target === 4294967295 || links.mayLack(source, at - from)) continue;
|
|
125
|
+
view.setUint32(ends + link * 4, target);
|
|
126
|
+
link += 1;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
104
129
|
view.setUint32(starts + sources * 4, link);
|
|
105
130
|
return {
|
|
106
131
|
slice: {
|
|
@@ -649,12 +674,20 @@ const runsOf = (entries, mostBytes = Number.POSITIVE_INFINITY) => {
|
|
|
649
674
|
const runsMost = (table, count, mostBytes = Number.POSITIVE_INFINITY) => Math.min(count, 1 + Math.floor(table / runGapBytes) + (mostBytes === Number.POSITIVE_INFINITY ? 0 : Math.floor(2 * table / mostBytes)));
|
|
650
675
|
/** The `.bitmaps` at `key`, of `positions` and `count` bitmaps, its table at `table`. */
|
|
651
676
|
const openBitmaps = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, key, written) {
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
677
|
+
const checkHead = (head) => {
|
|
678
|
+
const view = new DataView(head.buffer, head.byteOffset, head.byteLength);
|
|
679
|
+
return bitmapsMagic.some((byte, at) => head[at] !== byte) || view.getUint32(4) !== 1 || view.getUint32(8) !== written.positions || view.getUint32(12) !== written.count ? Effect.fail(lost(`${key} isn't the ${written.count} bitmaps of ${written.positions}`)) : Effect.void;
|
|
680
|
+
};
|
|
681
|
+
if (written.table < 16) {
|
|
682
|
+
yield* checkHead(yield* readExactly(bucket, key, 0, 16));
|
|
683
|
+
return yield* Effect.fail(lost(`${key}'s table at ${written.table} is inside its header`));
|
|
684
|
+
}
|
|
685
|
+
const [head, table] = yield* Effect.all([
|
|
686
|
+
readExactly(bucket, key, 0, 16),
|
|
687
|
+
readExactly(bucket, key, written.table, written.count * 20),
|
|
688
|
+
readExactly(bucket, key, written.table + written.count * 20, 20)
|
|
689
|
+
], { concurrency: "unbounded" });
|
|
690
|
+
yield* checkHead(head);
|
|
658
691
|
const fields = wordsOf(table, 0, written.count * 5);
|
|
659
692
|
const entries = Array.from({ length: written.count }, (_, at) => ({
|
|
660
693
|
position: fields[at * 5] ?? 0,
|
|
@@ -698,48 +731,43 @@ const openBitmaps = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, key, wr
|
|
|
698
731
|
offset: from,
|
|
699
732
|
length: last.offset + last.length - from
|
|
700
733
|
};
|
|
701
|
-
return bucketReading(bucket, key, range,
|
|
702
|
-
if (
|
|
703
|
-
const reader = body.getReader();
|
|
734
|
+
return bucketReading(bucket, key, range, Effect.fnUntraced(function* (reader) {
|
|
735
|
+
if (reader === void 0) return lost(`${key} is missing its bytes from ${from}`);
|
|
704
736
|
let at = from;
|
|
705
737
|
let next = 0;
|
|
706
738
|
let held;
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
held.set(chunk.subarray(offset, offset + length), taken);
|
|
726
|
-
}
|
|
727
|
-
at += length;
|
|
728
|
-
offset += length;
|
|
729
|
-
if (at < entry.offset + entry.length) continue;
|
|
730
|
-
const bytes = whole ? chunk.subarray(offset - length, offset) : held;
|
|
731
|
-
held = void 0;
|
|
732
|
-
next += 1;
|
|
733
|
-
const ewah = bytes === void 0 ? void 0 : wordsOf(bytes, 0, entry.length / 4);
|
|
734
|
-
if (ewah === void 0 || !fits(ewah)) return unread(entry);
|
|
735
|
-
orEwah(ewah, into);
|
|
739
|
+
for (let read = yield* bucketTry(() => reader.read()); !read.done; read = yield* bucketTry(() => reader.read())) {
|
|
740
|
+
const chunk = read.value;
|
|
741
|
+
let offset = 0;
|
|
742
|
+
while (offset < chunk.length) {
|
|
743
|
+
const entry = run[next];
|
|
744
|
+
if (entry === void 0) return void 0;
|
|
745
|
+
if (at < entry.offset) {
|
|
746
|
+
const skip = Math.min(entry.offset - at, chunk.length - offset);
|
|
747
|
+
at += skip;
|
|
748
|
+
offset += skip;
|
|
749
|
+
continue;
|
|
750
|
+
}
|
|
751
|
+
const taken = at - entry.offset;
|
|
752
|
+
const length = Math.min(entry.length - taken, chunk.length - offset);
|
|
753
|
+
const whole = taken === 0 && length === entry.length;
|
|
754
|
+
if (!whole) {
|
|
755
|
+
held ??= new Uint8Array(entry.length);
|
|
756
|
+
held.set(chunk.subarray(offset, offset + length), taken);
|
|
736
757
|
}
|
|
758
|
+
at += length;
|
|
759
|
+
offset += length;
|
|
760
|
+
if (at < entry.offset + entry.length) continue;
|
|
761
|
+
const bytes = whole ? chunk.subarray(offset - length, offset) : held;
|
|
762
|
+
held = void 0;
|
|
763
|
+
next += 1;
|
|
764
|
+
const ewah = bytes === void 0 ? void 0 : wordsOf(bytes, 0, entry.length / 4);
|
|
765
|
+
if (ewah === void 0 || !fits(ewah)) return unread(entry);
|
|
766
|
+
orEwah(ewah, into);
|
|
737
767
|
}
|
|
738
|
-
return run[next] === void 0 ? void 0 : lost(`${key} is missing its bytes from ${at}`);
|
|
739
|
-
} finally {
|
|
740
|
-
await reader.cancel();
|
|
741
768
|
}
|
|
742
|
-
|
|
769
|
+
return run[next] === void 0 ? void 0 : lost(`${key} is missing its bytes from ${at}`);
|
|
770
|
+
}));
|
|
743
771
|
};
|
|
744
772
|
const orEntries = Effect.fnUntraced(function* (entries, into, atOnce) {
|
|
745
773
|
if (into.length < words) return yield* Effect.fail(lost(`${key}'s bitmaps are past what they're ORed into`));
|
|
@@ -2,7 +2,6 @@ import "../contracts/result.mjs";
|
|
|
2
2
|
import "./index-bitmaps.mjs";
|
|
3
3
|
import "../contracts/ids.mjs";
|
|
4
4
|
import "../contracts/objects.mjs";
|
|
5
|
-
import "../contracts/services.mjs";
|
|
6
5
|
import "../contracts/store.mjs";
|
|
7
6
|
import "../protocol/objects/commit.mjs";
|
|
8
7
|
import "../store/call-count.mjs";
|
|
@@ -12,8 +11,8 @@ import "./index-layers.mjs";
|
|
|
12
11
|
import "./layout.mjs";
|
|
13
12
|
import "./memory-budget.mjs";
|
|
14
13
|
import "./pack-order.mjs";
|
|
14
|
+
import { Moment, Row } from "@ref0/infra";
|
|
15
|
+
import "effect/Schema";
|
|
15
16
|
import "effect/Effect";
|
|
16
17
|
import "effect/Option";
|
|
17
|
-
import "effect/Schema";
|
|
18
|
-
import { Moment, Row } from "@ref0/infra";
|
|
19
18
|
import "effect/Scope";
|