@ref0/git 0.14.0 → 0.20.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/auth/access-jwt.mjs +2 -2
- package/dist/auth/authorize.mjs +3 -3
- package/dist/auth/fences.d.mts +1 -2
- package/dist/auth/fences.mjs +3 -3
- package/dist/auth/grants.mjs +4 -4
- package/dist/auth/host-function.mjs +18 -1
- package/dist/auth/identify.d.mts +1 -1
- package/dist/auth/identify.mjs +3 -3
- package/dist/auth/token-cleanup.mjs +67 -0
- package/dist/auth/token-rows.mjs +1 -1
- package/dist/auth/token-text.mjs +9 -1
- package/dist/auth/tokens-base.d.mts +35 -0
- package/dist/auth/tokens-base.mjs +13 -0
- package/dist/auth/tokens-layer.d.mts +2 -27
- package/dist/auth/tokens-layer.mjs +6 -11
- package/dist/auth/tokens-public.d.mts +3 -3
- package/dist/auth/tokens.d.mts +7 -10
- package/dist/auth/tokens.mjs +9 -80
- package/dist/client/answer.mjs +21 -42
- package/dist/client/client.d.mts +2 -4
- package/dist/client/git-http.mjs +17 -7
- package/dist/client/local.mjs +14 -13
- package/dist/client/push-upload.mjs +9 -8
- package/dist/client/remote.mjs +8 -10
- package/dist/client/run-remote-helper.d.mts +1 -0
- package/dist/client/run-remote-helper.mjs +58 -24
- package/dist/client/slice-push.d.mts +1 -1
- package/dist/client/transport.mjs +105 -46
- package/dist/contracts/blobs.d.mts +55 -8
- package/dist/contracts/blobs.mjs +16 -2
- package/dist/contracts/call-allowance.d.mts +13 -0
- package/dist/contracts/call-allowance.mjs +44 -0
- package/dist/contracts/calls-spent.mjs +8 -3
- package/dist/contracts/client.d.mts +15 -16
- package/dist/contracts/commits.d.mts +24 -24
- package/dist/contracts/engine.d.mts +6 -1
- package/dist/contracts/engine.mjs +10 -1
- package/dist/contracts/files.d.mts +10 -10
- package/dist/contracts/forks.d.mts +17 -17
- package/dist/contracts/git-events.d.mts +29 -1
- package/dist/contracts/git-hooks.d.mts +1 -1
- package/dist/contracts/git.d.mts +21 -0
- package/dist/contracts/grants.d.mts +24 -4
- package/dist/contracts/handlers.d.mts +1 -1
- package/dist/contracts/lfs.d.mts +28 -2
- package/dist/contracts/merges.d.mts +3 -2
- package/dist/contracts/objects.d.mts +23 -25
- package/dist/contracts/queue.d.mts +40 -12
- package/dist/contracts/queue.mjs +3 -4
- package/dist/contracts/refs.d.mts +26 -23
- package/dist/contracts/remote.d.mts +6 -7
- package/dist/contracts/remote.mjs +4 -1
- package/dist/contracts/repos.d.mts +29 -138
- package/dist/contracts/repos.mjs +5 -3
- package/dist/contracts/result.d.mts +35 -16
- package/dist/contracts/result.mjs +35 -7
- package/dist/contracts/server.d.mts +25 -50
- package/dist/contracts/services.d.mts +1 -1
- package/dist/contracts/store.d.mts +6 -5
- package/dist/contracts/sync.d.mts +11 -7
- package/dist/contracts/sync.mjs +12 -2
- package/dist/contracts/tags.d.mts +10 -10
- package/dist/contracts/time.d.mts +3 -0
- package/dist/contracts/{promises.mjs → time.mjs} +1 -1
- package/dist/contracts/tokens.d.mts +15 -17
- package/dist/contracts/tokens.mjs +3 -2
- package/dist/contracts/topics.d.mts +1 -1
- package/dist/contracts/trees.d.mts +12 -12
- package/dist/contracts/work.d.mts +24 -13
- package/dist/core/access.d.mts +1 -2
- package/dist/core/access.mjs +20 -9
- package/dist/core/ancestry.d.mts +1 -0
- package/dist/core/asked.mjs +1 -1
- package/dist/core/call-names.mjs +6 -1
- package/dist/core/call-services.mjs +11 -3
- package/dist/core/events/deliver.d.mts +1 -2
- package/dist/core/events/deliver.mjs +43 -36
- package/dist/core/events/retired.mjs +119 -0
- package/dist/core/forks.mjs +928 -432
- package/dist/core/hooks/groups.mjs +1 -1
- package/dist/core/imports.mjs +29 -23
- package/dist/core/index-job.mjs +122 -34
- package/dist/core/index-lost.d.mts +1 -2
- package/dist/core/index-lost.mjs +2 -2
- package/dist/core/loose-tally.mjs +1 -1
- package/dist/core/objects/blobs.mjs +129 -3
- package/dist/core/objects/lines.mjs +2 -2
- package/dist/core/objects/merges.mjs +4 -1
- package/dist/core/objects/objects-layer.d.mts +1 -1
- package/dist/core/objects/objects-layer.mjs +3 -3
- package/dist/core/objects/reading.mjs +24 -13
- package/dist/core/objects/tags.mjs +4 -1
- package/dist/core/objects/trees.mjs +2 -2
- package/dist/core/objects/writing.mjs +2 -2
- package/dist/core/own-writes.mjs +1 -1
- package/dist/core/parts.d.mts +4 -5
- package/dist/core/parts.mjs +3 -8
- package/dist/core/promise.mjs +9 -12
- package/dist/core/purge.mjs +287 -83
- package/dist/core/push-decide.mjs +2 -0
- package/dist/core/push-files.d.mts +1 -1
- package/dist/core/push.mjs +58 -47
- package/dist/core/receipts.mjs +8 -3
- package/dist/core/ref-index-job.mjs +4 -4
- package/dist/core/ref-view.mjs +2 -2
- package/dist/core/refs.mjs +5 -5
- package/dist/core/registered-rows.mjs +2 -2
- package/dist/core/repack.mjs +36 -21
- package/dist/core/repo-info.mjs +3 -3
- package/dist/core/repos.mjs +21 -9
- package/dist/core/rules/commit-changes.d.mts +0 -1
- package/dist/core/saved-caller-views.d.mts +7 -2
- package/dist/core/saved-caller-views.mjs +2 -2
- package/dist/core/saved-callers.d.mts +19 -2
- package/dist/core/seam.d.mts +16 -26
- package/dist/core/seam.mjs +7 -28
- package/dist/core/tokens.mjs +1 -1
- package/dist/core/view.mjs +7 -15
- package/dist/core/work.mjs +59 -14
- package/dist/effect.d.mts +3 -12
- package/dist/effect.mjs +1 -10
- package/dist/engine/failures.mjs +2 -1
- package/dist/engine/reads.mjs +4 -4
- package/dist/event-streams/stream.d.mts +2 -2
- package/dist/event-streams/stream.mjs +37 -14
- package/dist/extend.d.mts +2 -3
- package/dist/extend.mjs +2 -1
- package/dist/http/answers.mjs +8 -5
- package/dist/http/core-parts.mjs +95 -79
- package/dist/http/handler.mjs +34 -7
- package/dist/http/node.d.mts +14 -1
- package/dist/http/node.mjs +56 -27
- package/dist/http/parts.d.mts +1 -0
- package/dist/http/push-upload-job.mjs +30 -26
- package/dist/http/push-uploads.mjs +36 -21
- package/dist/http/upload-pack.mjs +3 -3
- package/dist/index.d.mts +14 -14
- package/dist/index.mjs +2 -2
- package/dist/lfs/answer.mjs +37 -0
- package/dist/lfs/base.d.mts +2 -0
- package/dist/lfs/base.mjs +25 -1
- package/dist/lfs/copy.d.mts +21 -7
- package/dist/lfs/copy.mjs +89 -6
- package/dist/lfs/layer.d.mts +15 -1
- package/dist/lfs/layer.mjs +24 -11
- package/dist/lfs/locks.mjs +2 -2
- package/dist/lfs/objects.d.mts +1 -0
- package/dist/lfs/objects.mjs +87 -17
- package/dist/lfs/pointers.mjs +2 -2
- package/dist/lfs/rows.mjs +42 -8
- package/dist/lfs/upkeep.mjs +48 -14
- package/dist/lfs/wire.mjs +6 -31
- package/dist/merges/merges.mjs +2 -2
- package/dist/node.d.mts +2 -2
- package/dist/protocol/bytes/buffers.mjs +13 -5
- package/dist/protocol/bytes/reader.mjs +6 -1
- package/dist/protocol/bytes/streams.mjs +27 -1
- package/dist/protocol/diff/read.d.mts +4 -3
- package/dist/protocol/diff/read.mjs +8 -3
- package/dist/protocol/objects/lfs-pointer.d.mts +14 -2
- package/dist/protocol/objects/lfs-pointer.mjs +1 -3
- package/dist/protocol/objects/links-raw.mjs +24 -10
- package/dist/protocol/objects/tag.d.mts +1 -1
- package/dist/protocol/objects/tree.mjs +23 -6
- package/dist/protocol/packs/delta.d.mts +6 -3
- package/dist/protocol/packs/delta.mjs +96 -32
- package/dist/protocol/packs/idx.d.mts +2 -1
- package/dist/protocol/packs/idx.mjs +22 -3
- package/dist/protocol/packs/parts.d.mts +4 -1
- package/dist/protocol/packs/parts.mjs +10 -7
- package/dist/protocol/packs/reader.d.mts +5 -0
- package/dist/protocol/packs/reader.mjs +3 -2
- package/dist/protocol/packs/writer.mjs +26 -8
- package/dist/queue/advance.mjs +21 -24
- package/dist/queue/base.d.mts +55 -0
- package/dist/queue/base.mjs +44 -0
- package/dist/queue/calls.mjs +51 -54
- package/dist/queue/commit.mjs +1 -1
- package/dist/queue/host.d.mts +1 -15
- package/dist/queue/host.mjs +2 -7
- package/dist/queue/layer.d.mts +2 -1
- package/dist/queue/layer.mjs +10 -3
- package/dist/queue/limits.mjs +2 -0
- package/dist/queue/push-option.mjs +9 -24
- package/dist/queue/schedule.mjs +1 -1
- package/dist/queue/state.mjs +2 -10
- package/dist/queue/trim.mjs +5 -3
- package/dist/rest/blobs.mjs +29 -5
- package/dist/rest/caller.d.mts +4 -4271
- package/dist/rest/caller.mjs +4 -0
- package/dist/rest/client.d.mts +8 -5
- package/dist/rest/client.mjs +19 -2
- package/dist/rest/handlers.mjs +50 -5
- package/dist/rest/layer.d.mts +2 -2
- package/dist/rest/layer.mjs +5 -12
- package/dist/rest/me.d.mts +3 -432
- package/dist/server/check-fetch.mjs +3 -3
- package/dist/server/edge-node.d.mts +11 -8
- package/dist/server/edge-node.mjs +9 -6
- package/dist/server/edge.d.mts +21 -7
- package/dist/server/edge.mjs +32 -11
- package/dist/server/extension.mjs +1 -1
- package/dist/server/git-layer.d.mts +5 -5
- package/dist/server/git-layer.mjs +28 -22
- package/dist/server/git-namespace.d.mts +4 -3
- package/dist/server/git-namespace.mjs +3 -2
- package/dist/server/joined.d.mts +6 -18
- package/dist/server/joined.mjs +9 -36
- package/dist/server/lifecycle.mjs +18 -106
- package/dist/server/registry.mjs +24 -7
- package/dist/server/server.mjs +205 -346
- package/dist/signin/context.d.mts +1 -2
- package/dist/signin/layer.d.mts +1 -1
- package/dist/signin/layer.mjs +1 -1
- package/dist/storage/allotted.mjs +18 -3
- package/dist/storage/batch-upkeep.mjs +274 -0
- package/dist/storage/batches.d.mts +8 -0
- package/dist/storage/batches.mjs +344 -0
- package/dist/storage/calls.d.mts +1 -2
- package/dist/storage/calls.mjs +144 -158
- package/dist/storage/chunks.d.mts +9 -0
- package/dist/storage/chunks.mjs +297 -0
- package/dist/storage/clean-up.mjs +72 -9
- package/dist/storage/counted-bucket.mjs +4 -4
- package/dist/storage/fetch.d.mts +1 -0
- package/dist/storage/fetch.mjs +287 -210
- package/dist/storage/host-bucket.mjs +1 -2
- package/dist/storage/id-mix.mjs +19 -5
- package/dist/storage/index-bitmaps.mjs +9 -2
- package/dist/storage/index-build.d.mts +0 -1
- package/dist/storage/index-build.mjs +80 -23
- package/dist/storage/index-fetch.mjs +113 -72
- package/dist/storage/index-files.d.mts +3 -0
- package/dist/storage/index-files.mjs +10 -5
- package/dist/storage/index-graph.mjs +72 -22
- package/dist/storage/index-remap.mjs +200 -64
- package/dist/storage/index-whole.mjs +127 -0
- package/dist/storage/largest-files.mjs +1 -1
- package/dist/storage/layout.mjs +23 -0
- package/dist/storage/loose.d.mts +7 -4
- package/dist/storage/loose.mjs +212 -67
- package/dist/storage/memory-budget.mjs +16 -4
- package/dist/storage/merge-plan.mjs +3 -2
- package/dist/storage/merge-row.mjs +7 -1
- package/dist/storage/merge-stream.mjs +164 -25
- package/dist/storage/merge-walk.mjs +8 -4
- package/dist/storage/merge-write.mjs +1 -1
- package/dist/storage/merge.d.mts +1 -1
- package/dist/storage/merge.mjs +1 -1
- package/dist/storage/object-rows.d.mts +1 -0
- package/dist/storage/object-rows.mjs +385 -65
- package/dist/storage/oid-table.mjs +171 -0
- package/dist/storage/pack-order.mjs +8 -4
- package/dist/storage/pack-ranges.d.mts +1 -2
- package/dist/storage/pack-ranges.mjs +4 -5
- package/dist/storage/pack-reads.d.mts +2 -1
- package/dist/storage/pack-reads.mjs +158 -42
- package/dist/storage/pack-receive.d.mts +1 -1
- package/dist/storage/pack-receive.mjs +2 -2
- package/dist/storage/packs.d.mts +1 -1
- package/dist/storage/packs.mjs +136 -66
- package/dist/storage/placed-reads.mjs +1 -1
- package/dist/storage/plan-columns.d.mts +4 -0
- package/dist/storage/plan-columns.mjs +238 -0
- package/dist/storage/prune-keep.mjs +134 -41
- package/dist/storage/prune-walk.mjs +202 -62
- package/dist/storage/prune.mjs +194 -91
- package/dist/storage/push-allotment.mjs +91 -12
- package/dist/storage/push-uploads.mjs +4 -4
- package/dist/storage/pushed-commits.mjs +4 -2
- package/dist/storage/quarantine.d.mts +1 -1
- package/dist/storage/range-cache.mjs +125 -8
- package/dist/storage/ready.d.mts +1 -1
- package/dist/storage/ready.mjs +8 -6
- package/dist/storage/receive-bounds.mjs +23 -8
- package/dist/storage/repack-backlog.mjs +6 -3
- package/dist/storage/repack.d.mts +1 -1
- package/dist/storage/rows.d.mts +1 -1
- package/dist/storage/rows.mjs +1 -1
- package/dist/storage/runs.mjs +195 -43
- package/dist/storage/send-list.d.mts +1 -0
- package/dist/storage/send-list.mjs +54 -10
- package/dist/storage/single-flight.mjs +13 -7
- package/dist/storage/stream-whole.mjs +127 -26
- package/dist/storage/unpack.mjs +371 -79
- package/dist/storage/visible.mjs +2 -2
- package/dist/storage/walk.mjs +192 -38
- package/dist/storage/wants.mjs +5 -5
- package/dist/store/bodies.mjs +38 -0
- package/dist/store/call-count.d.mts +8 -12
- package/dist/store/call-count.mjs +34 -46
- package/dist/store/catalogue.d.mts +2 -2
- package/dist/store/catalogue.mjs +145 -35
- package/dist/store/crossing.mjs +1 -3
- package/dist/store/cursor-seal.d.mts +1 -2
- package/dist/store/cursor-seal.mjs +16 -6
- package/dist/store/door.mjs +183 -0
- package/dist/store/errors.d.mts +3 -4
- package/dist/store/errors.mjs +15 -33
- package/dist/store/git-store.mjs +25 -7
- package/dist/store/job-try.mjs +9 -32
- package/dist/store/list-job.mjs +44 -8
- package/dist/store/records.d.mts +3 -0
- package/dist/store/records.mjs +3 -0
- package/dist/store/repo-record.d.mts +1 -2
- package/dist/store/repo-record.mjs +32 -20
- package/dist/store/reservations.mjs +1 -1
- package/dist/store/scopes.mjs +11 -0
- package/dist/store/settle.mjs +4 -4
- package/dist/sync/github.mjs +3 -3
- package/dist/sync/import.mjs +31 -18
- package/dist/sync/lfs-batch.mjs +4 -5
- package/dist/sync/lfs-copy.mjs +17 -6
- package/dist/sync/mirror.mjs +34 -31
- package/dist/sync/said.mjs +16 -37
- package/dist/sync/step.mjs +33 -25
- package/dist/sync/tries.mjs +9 -9
- package/dist/topics/advance.mjs +10 -11
- package/dist/topics/base.d.mts +15 -0
- package/dist/topics/base.mjs +8 -0
- package/dist/topics/host.mjs +1 -1
- package/dist/topics/layer.d.mts +4 -9
- package/dist/topics/layer.mjs +2 -3
- package/dist/topics/members.mjs +4 -4
- package/dist/topics/public.d.mts +2 -1
- package/dist/topics/topic.mjs +2 -2
- package/package.json +5 -4
- package/dist/contracts/promises.d.mts +0 -39
- package/dist/core/call-names.d.mts +0 -3
- package/dist/core/clock.mjs +0 -18
- package/dist/lfs/calls.mjs +0 -26
- package/dist/rest/api.d.mts +0 -23
- package/dist/rest/blobs.d.mts +0 -833
- package/dist/rest/commits.d.mts +0 -3543
- package/dist/rest/errors.d.mts +0 -2124
- package/dist/rest/events.d.mts +0 -426
- package/dist/rest/files.d.mts +0 -1342
- package/dist/rest/forks.d.mts +0 -2160
- package/dist/rest/handlers.d.mts +0 -8
- package/dist/rest/merges.d.mts +0 -477
- package/dist/rest/queue.d.mts +0 -5917
- package/dist/rest/refs.d.mts +0 -2988
- package/dist/rest/repos.d.mts +0 -2567
- package/dist/rest/tags.d.mts +0 -1316
- package/dist/rest/tokens.d.mts +0 -2614
- package/dist/rest/topics.d.mts +0 -2224
- package/dist/rest/trees.d.mts +0 -1709
- package/dist/rest/work.d.mts +0 -1695
- package/dist/server/lifecycle.d.mts +0 -2
- package/dist/store/promises.d.mts +0 -11
- package/dist/store/promises.mjs +0 -327
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { fail } from "../contracts/result.mjs";
|
|
2
2
|
import { streamOf } from "../protocol/bytes/streams.mjs";
|
|
3
3
|
import { emptyTree, objectId, objectTypes } from "../protocol/objects/object.mjs";
|
|
4
|
+
import { decodeRow } from "../store/errors.mjs";
|
|
4
5
|
import { repoScope } from "../store/scopes.mjs";
|
|
6
|
+
import { SizeMarker, batchesOf, batchesRead, isBatchId, stagedKey, stagedOid, stagedPrefix, stagedRowsOf, stagedSizeKey } from "./batches.mjs";
|
|
7
|
+
import { ChunkReader, chunkedOf } from "./chunks.mjs";
|
|
5
8
|
import { objectCollections } from "./layout.mjs";
|
|
6
9
|
import * as Effect from "effect/Effect";
|
|
7
10
|
import * as Option from "effect/Option";
|
|
@@ -54,6 +57,7 @@ const objectRow = (object) => ({
|
|
|
54
57
|
*/
|
|
55
58
|
const objectOfRow = /* @__PURE__ */ Effect.fnUntraced(function* (row) {
|
|
56
59
|
const what = `Object ${row.id}`;
|
|
60
|
+
if (chunkedOf(row.value) !== void 0) return yield* fail("DATA_LOSS", `${what} is stored as chunks, which this read can't take whole`);
|
|
57
61
|
const stored = decodeObjectRow(row.value);
|
|
58
62
|
if (Option.isNone(stored)) return yield* fail("DATA_LOSS", `${what} is unreadable`);
|
|
59
63
|
const decoded = Base64.decode(stored.value.data);
|
|
@@ -78,6 +82,11 @@ const objectOfRow = /* @__PURE__ */ Effect.fnUntraced(function* (row) {
|
|
|
78
82
|
*/
|
|
79
83
|
const headerOfRow = /* @__PURE__ */ Effect.fnUntraced(function* (row) {
|
|
80
84
|
const what = `Object ${row.id}`;
|
|
85
|
+
const chunked = chunkedOf(row.value);
|
|
86
|
+
if (chunked !== void 0) return {
|
|
87
|
+
type: chunked.type,
|
|
88
|
+
size: chunked.size
|
|
89
|
+
};
|
|
81
90
|
const stored = decodeObjectRow(row.value);
|
|
82
91
|
if (Option.isNone(stored)) return yield* fail("DATA_LOSS", `${what} is unreadable`);
|
|
83
92
|
const { data } = stored.value;
|
|
@@ -96,10 +105,24 @@ const gitObjectOf = (object) => ({
|
|
|
96
105
|
bytes: streamOf(object.bytes.slice())
|
|
97
106
|
});
|
|
98
107
|
/**
|
|
99
|
-
* The object rows a receive's change puts, by ID, readable before the commit that writes them
|
|
100
|
-
* so a push's walk reads the new tips it
|
|
108
|
+
* The object rows a receive's change puts, by ID, readable before the commit that writes them,
|
|
109
|
+
* or those it staged as a batch the change publishes: so a push's walk reads the new tips it
|
|
110
|
+
* carries.
|
|
111
|
+
*/
|
|
112
|
+
const receivedRows = (change) => stagedRowsOf(change) ?? new Map((change?.put ?? []).flatMap((row) => row.collection === objectCollections.objects ? [[row.id, row]] : []));
|
|
113
|
+
/**
|
|
114
|
+
* How a staged push's own chunked rows are read before its commit, by the change it answered:
|
|
115
|
+
* its batch isn't published, so no reader of the repo finds them.
|
|
101
116
|
*/
|
|
102
|
-
const
|
|
117
|
+
const ownChunks = /* @__PURE__ */ new WeakMap();
|
|
118
|
+
/** `change`'s own chunked rows read through `reader`, as its push's walk reads them. */
|
|
119
|
+
const readsOwnChunks = (change, reader) => ownChunks.set(change, reader);
|
|
120
|
+
/** One of the rows `receivedRows` answers, read whole: one chunked, through its chunks. */
|
|
121
|
+
const receivedObject = (change, row) => {
|
|
122
|
+
const chunked = chunkedOf(row.value);
|
|
123
|
+
const reader = change === void 0 ? void 0 : ownChunks.get(change);
|
|
124
|
+
return chunked === void 0 || reader === void 0 ? objectOfRow(row) : reader(row.id, chunked).whole();
|
|
125
|
+
};
|
|
103
126
|
/**
|
|
104
127
|
* Object rows a store read refused as too large is cut into: as many of the largest as one answer
|
|
105
128
|
* holds, each row's key and version aside, so no read of them passes its 16 MiB.
|
|
@@ -112,18 +135,21 @@ const emptyTreeObject = {
|
|
|
112
135
|
bytes: /* @__PURE__ */ new Uint8Array(0)
|
|
113
136
|
};
|
|
114
137
|
const tooLargeRead = (error) => error.code === "RESOURCE_EXHAUSTED" && error.context?.["reason"] === "too-large";
|
|
138
|
+
const orTooLarge = (effect) => effect.pipe(Effect.catchIf(tooLargeRead, () => Effect.succeed(void 0)));
|
|
139
|
+
const listedBatches = (rows) => Effect.map(batchesOf(rows ?? []), (listed) => listed.map(({ batch }) => batch));
|
|
115
140
|
/**
|
|
116
|
-
* Each of `ids`'
|
|
117
|
-
* read at: `rowReadBatch` to a read, or `largeBatch` where those rows passed one answer's 16
|
|
118
|
-
* one read's rows are held, and the reads end once `each` answers `false`.
|
|
141
|
+
* Each of `ids`' `objects` rows the repo holds, a store read's answer at a time, with the version
|
|
142
|
+
* it's read at: `rowReadBatch` to a read, or `largeBatch` where those rows passed one answer's 16
|
|
143
|
+
* MiB. Only one read's rows are held, and the reads end once `each` answers `false`. Its staged
|
|
144
|
+
* batches are left out, so it answers only what `objects` holds.
|
|
119
145
|
*/
|
|
120
|
-
const
|
|
146
|
+
const eachObjectsRead = (store, repo, ids, each) => {
|
|
121
147
|
const read = (keys) => store.read({
|
|
122
148
|
scope: repoScope(repo),
|
|
123
149
|
reads: keys
|
|
124
150
|
});
|
|
125
151
|
const readAll = Effect.fnUntraced(function* (keys) {
|
|
126
|
-
const answer = yield* read(keys).pipe(
|
|
152
|
+
const answer = yield* read(keys).pipe(orTooLarge);
|
|
127
153
|
if (answer !== void 0) return yield* each(answer.results.flat(), answer.version);
|
|
128
154
|
for (let at = 0; at < keys.length; at += largeBatch) {
|
|
129
155
|
const cut = yield* read(keys.slice(at, at + largeBatch));
|
|
@@ -133,13 +159,186 @@ const eachRead = (store, repo, ids, each) => {
|
|
|
133
159
|
});
|
|
134
160
|
return Effect.gen(function* () {
|
|
135
161
|
const asked = [...new Set(ids)].filter((id) => id !== emptyTree);
|
|
136
|
-
for (let at = 0; at < asked.length; at += 100)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
162
|
+
for (let at = 0; at < asked.length; at += 100) if (!(yield* readAll(asked.slice(at, at + 100).map(objectKey)))) return;
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
/** A staged row as the `objects` row it stands for: its object's ID, its value as stored. */
|
|
166
|
+
const asObjectRow = (row) => ({
|
|
167
|
+
...objectKey(stagedOid(row.id)),
|
|
168
|
+
value: row.value
|
|
169
|
+
});
|
|
170
|
+
/**
|
|
171
|
+
* The value bytes packed into one staged body read at most (#2521): each row is at most 1 MiB, so
|
|
172
|
+
* every closed read holds > 13 MiB of values and stays under 16 MiB with its keys and envelope.
|
|
173
|
+
*/
|
|
174
|
+
const bodyPackBytes = 14680064;
|
|
175
|
+
/** The byte size a `stagedSizes` marker records: `DATA_LOSS` if unreadable or negative. */
|
|
176
|
+
const markerBytes = (row) => Effect.map(decodeRow(SizeMarker, row, `The size marker '${row.id}'`), ({ bytes }) => bytes);
|
|
177
|
+
/**
|
|
178
|
+
* Packs `hits` largest first into reads of at most `bodyPackBytes` of value bytes (always at least
|
|
179
|
+
* one key per read). Each closed read holds > 13 MiB of values, never two copies of one object.
|
|
180
|
+
*/
|
|
181
|
+
const packBodies = (hits) => {
|
|
182
|
+
const ordered = hits.toSorted((a, b) => b.bytes - a.bytes);
|
|
183
|
+
const packs = [];
|
|
184
|
+
let current = [];
|
|
185
|
+
let bytes = 0;
|
|
186
|
+
for (const hit of ordered) {
|
|
187
|
+
if (current.length > 0 && bytes + hit.bytes > 14680064) {
|
|
188
|
+
packs.push(current);
|
|
189
|
+
current = [];
|
|
190
|
+
bytes = 0;
|
|
142
191
|
}
|
|
192
|
+
current.push(hit);
|
|
193
|
+
bytes += hit.bytes;
|
|
194
|
+
}
|
|
195
|
+
if (current.length > 0) packs.push(current);
|
|
196
|
+
return packs;
|
|
197
|
+
};
|
|
198
|
+
/** The refusal of a read that discovered more than `newBatchReadsMost` new batches across its groups. */
|
|
199
|
+
const batchesMoved = () => fail("UNAVAILABLE", "Other pushes kept publishing large pushes during the read", {
|
|
200
|
+
hint: "Try again",
|
|
201
|
+
context: { reason: "too-many-writes" }
|
|
202
|
+
});
|
|
203
|
+
/**
|
|
204
|
+
* Each of `ids`' object rows the repo holds, in `objects` or in a published staged batch, handed to
|
|
205
|
+
* `each` a store read at a time: `rowReadBatch` IDs to a group, and the reads end once `each`
|
|
206
|
+
* answers `false`. An ID is missing only when its last read of `objects` missed and every batch
|
|
207
|
+
* that read listed was checked for it in a read that already listed that batch: a published
|
|
208
|
+
* batch's rows and size markers are fixed at its publication and leave it only into `objects`,
|
|
209
|
+
* which keeps them while any batch is listed, so the answer holds at that last read. Answers for
|
|
210
|
+
* different IDs may come from different reads. An ID in `objects` is answered from there, and one
|
|
211
|
+
* in several batches from the oldest.
|
|
212
|
+
*
|
|
213
|
+
* Each group runs:
|
|
214
|
+
* - A: `objects/<U>`, markers `stagedSizes/<k>/<u>` for batches `K` this reader already knows, and
|
|
215
|
+
* `batches`, in one snapshot (cut to `largeBatch` if `objects` overflows 16 MiB).
|
|
216
|
+
* - B: only when A or B lists batches `N` not yet checked for this group, `objects/<V>` for the
|
|
217
|
+
* still-open IDs, `N`'s markers, and `batches` in one snapshot, capped at `newBatchReadsMost`
|
|
218
|
+
* discoveries per reader before refusing `too-many-writes`.
|
|
219
|
+
* - Bodies: selected `stagedObjects/<b>/<oid>` keys packed by marker size into reads of at most
|
|
220
|
+
* `bodyPackBytes` (14 MiB), never two copies of one object.
|
|
221
|
+
* - Recovery: any body key gone (promoted or removed as a duplicate after the marker hit) is read
|
|
222
|
+
* in one call from `objects/<gone>` with `batches`.
|
|
223
|
+
*/
|
|
224
|
+
const eachRead = (store, repo, ids, each) => {
|
|
225
|
+
const scope = repoScope(repo);
|
|
226
|
+
const read = (reads) => store.read({
|
|
227
|
+
scope,
|
|
228
|
+
reads: [...reads]
|
|
229
|
+
});
|
|
230
|
+
const hand = (rows) => rows.length === 0 ? Effect.succeed(true) : each(rows);
|
|
231
|
+
const readSnapshot = Effect.fnUntraced(function* (oids, markerBatches) {
|
|
232
|
+
const markers = markerBatches.flatMap((batch) => oids.map((oid) => stagedSizeKey(batch, oid)));
|
|
233
|
+
const snapshot = yield* read([
|
|
234
|
+
...oids.map(objectKey),
|
|
235
|
+
batchesRead,
|
|
236
|
+
...markers
|
|
237
|
+
]);
|
|
238
|
+
const objectRows = snapshot.results.slice(0, oids.length).flat();
|
|
239
|
+
const listed = yield* listedBatches(snapshot.results[oids.length]);
|
|
240
|
+
const hit = new Set(objectRows.map(({ id }) => id));
|
|
241
|
+
const listedRank = new Map(listed.map((batch, rank) => [batch, rank]));
|
|
242
|
+
const selected = /* @__PURE__ */ new Map();
|
|
243
|
+
for (const [b, batch] of markerBatches.entries()) {
|
|
244
|
+
const rank = listedRank.get(batch);
|
|
245
|
+
if (rank === void 0) continue;
|
|
246
|
+
const offset = oids.length + 1 + b * oids.length;
|
|
247
|
+
for (const [i, oid] of oids.entries()) {
|
|
248
|
+
const row = snapshot.results[offset + i]?.[0];
|
|
249
|
+
if (row === void 0 || hit.has(oid)) continue;
|
|
250
|
+
const bytes = yield* markerBytes(row);
|
|
251
|
+
const current = selected.get(oid);
|
|
252
|
+
if (current === void 0 || rank < current.rank) selected.set(oid, {
|
|
253
|
+
oid,
|
|
254
|
+
batch,
|
|
255
|
+
bytes,
|
|
256
|
+
rank
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const misses = oids.filter((oid) => !hit.has(oid) && !selected.has(oid));
|
|
261
|
+
return {
|
|
262
|
+
objectRows,
|
|
263
|
+
listed,
|
|
264
|
+
selected: [...selected.values()],
|
|
265
|
+
misses
|
|
266
|
+
};
|
|
267
|
+
});
|
|
268
|
+
return Effect.gen(function* () {
|
|
269
|
+
const asked = [...new Set(ids)].filter((id) => id !== emptyTree);
|
|
270
|
+
let known = [];
|
|
271
|
+
let discoveries = 0;
|
|
272
|
+
const resolveCut = Effect.fnUntraced(function* (first, checkedInA, stagedHits) {
|
|
273
|
+
const take = Effect.fnUntraced(function* (snap) {
|
|
274
|
+
if (!(yield* hand(snap.objectRows))) return false;
|
|
275
|
+
for (const hit of snap.selected) if (!stagedHits.has(hit.oid)) stagedHits.set(hit.oid, hit);
|
|
276
|
+
return true;
|
|
277
|
+
});
|
|
278
|
+
if (!(yield* take(first))) return false;
|
|
279
|
+
const checked = new Set(checkedInA);
|
|
280
|
+
let open = first.misses;
|
|
281
|
+
let listed = first.listed;
|
|
282
|
+
known = listed;
|
|
283
|
+
while (open.length > 0) {
|
|
284
|
+
const fresh = listed.filter((batch) => !checked.has(batch));
|
|
285
|
+
if (fresh.length === 0) break;
|
|
286
|
+
if (discoveries >= 32) return yield* batchesMoved();
|
|
287
|
+
discoveries += 1;
|
|
288
|
+
const stepB = yield* readSnapshot(open, fresh).pipe(orTooLarge);
|
|
289
|
+
if (stepB !== void 0) {
|
|
290
|
+
if (!(yield* take(stepB))) return false;
|
|
291
|
+
open = stepB.misses;
|
|
292
|
+
listed = stepB.listed;
|
|
293
|
+
known = listed;
|
|
294
|
+
} else {
|
|
295
|
+
const nextOpen = [];
|
|
296
|
+
const nextListed = /* @__PURE__ */ new Set();
|
|
297
|
+
for (let at = 0; at < open.length; at += largeBatch) {
|
|
298
|
+
const cut = yield* readSnapshot(open.slice(at, at + largeBatch), fresh);
|
|
299
|
+
if (!(yield* take(cut))) return false;
|
|
300
|
+
nextOpen.push(...cut.misses);
|
|
301
|
+
for (const batch of cut.listed) nextListed.add(batch);
|
|
302
|
+
known = cut.listed;
|
|
303
|
+
}
|
|
304
|
+
open = nextOpen;
|
|
305
|
+
listed = [...nextListed];
|
|
306
|
+
}
|
|
307
|
+
for (const batch of fresh) checked.add(batch);
|
|
308
|
+
}
|
|
309
|
+
return true;
|
|
310
|
+
});
|
|
311
|
+
const resolveGroup = Effect.fnUntraced(function* (oids) {
|
|
312
|
+
const stagedHits = /* @__PURE__ */ new Map();
|
|
313
|
+
const checkedInA = known;
|
|
314
|
+
const whole = yield* readSnapshot(oids, checkedInA).pipe(orTooLarge);
|
|
315
|
+
if (whole !== void 0) {
|
|
316
|
+
if (!(yield* resolveCut(whole, checkedInA, stagedHits))) return false;
|
|
317
|
+
} else for (let at = 0; at < oids.length; at += largeBatch) {
|
|
318
|
+
const cutChecked = known;
|
|
319
|
+
const cut = yield* readSnapshot(oids.slice(at, at + largeBatch), cutChecked);
|
|
320
|
+
if (!(yield* resolveCut(cut, cutChecked, stagedHits))) return false;
|
|
321
|
+
}
|
|
322
|
+
for (const pack of packBodies([...stagedHits.values()])) {
|
|
323
|
+
const bodies = yield* read(pack.map(({ batch, oid }) => stagedKey(batch, oid)));
|
|
324
|
+
const found = [];
|
|
325
|
+
const gone = [];
|
|
326
|
+
for (const [index, hit] of pack.entries()) {
|
|
327
|
+
const row = bodies.results[index]?.[0];
|
|
328
|
+
if (row === void 0) gone.push(hit.oid);
|
|
329
|
+
else found.push(asObjectRow(row));
|
|
330
|
+
}
|
|
331
|
+
if (!(yield* hand(found))) return false;
|
|
332
|
+
if (gone.length > 0) {
|
|
333
|
+
const recovered = yield* read([...gone.map(objectKey), batchesRead]);
|
|
334
|
+
const recoveredRows = recovered.results.slice(0, gone.length).flat();
|
|
335
|
+
known = yield* listedBatches(recovered.results[gone.length]);
|
|
336
|
+
if (!(yield* hand(recoveredRows))) return false;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return true;
|
|
340
|
+
});
|
|
341
|
+
for (let at = 0; at < asked.length; at += 100) if (!(yield* resolveGroup(asked.slice(at, at + 100)))) return;
|
|
143
342
|
});
|
|
144
343
|
};
|
|
145
344
|
/** Each of `oids`' rows the repo holds, handed to `each` a store read at a time, as `eachRead` reads. */
|
|
@@ -155,7 +354,7 @@ const eachRow = (store, listed, oids, each) => eachRead(store, listed.repo, oids
|
|
|
155
354
|
const heldIdsAt = /* @__PURE__ */ Effect.fnUntraced(function* (store, repo, version, ids) {
|
|
156
355
|
const held = /* @__PURE__ */ new Set();
|
|
157
356
|
let moved = false;
|
|
158
|
-
yield*
|
|
357
|
+
yield* eachObjectsRead(store, repo, ids, (rows, at) => Effect.sync(() => {
|
|
159
358
|
moved = at !== version;
|
|
160
359
|
if (!moved) for (const { id } of rows) held.add(id);
|
|
161
360
|
return !moved;
|
|
@@ -166,7 +365,9 @@ const heldIdsAt = /* @__PURE__ */ Effect.fnUntraced(function* (store, repo, vers
|
|
|
166
365
|
* Each page of a repo's object rows, in ID order, handed to `each` before the next is read, every
|
|
167
366
|
* page read at `version`: `rowReadBatch` rows to a read, or `largeBatch` where those passed one
|
|
168
367
|
* answer's 16 MiB. `true` once every row is read; `false` once a page answers at another version,
|
|
169
|
-
* since the repo moved after the read it joins,
|
|
368
|
+
* since the repo moved after the read it joins, once `each` answers `false`, or once a page lists a
|
|
369
|
+
* published staged batch, whose rows `objects` doesn't hold yet: a whole-repo pass waits for
|
|
370
|
+
* upkeep to promote them, and a clone builds through the readers that read batches.
|
|
170
371
|
*/
|
|
171
372
|
const eachPageAt = /* @__PURE__ */ Effect.fnUntraced(function* (store, repo, version, each) {
|
|
172
373
|
const page = (after, limit) => {
|
|
@@ -177,53 +378,88 @@ const eachPageAt = /* @__PURE__ */ Effect.fnUntraced(function* (store, repo, ver
|
|
|
177
378
|
if (after !== void 0) read.after = after;
|
|
178
379
|
return Effect.map(store.read({
|
|
179
380
|
scope: repoScope(repo),
|
|
180
|
-
reads: [read]
|
|
381
|
+
reads: [read, batchesRead]
|
|
181
382
|
}), ({ version: at, results }) => ({
|
|
182
383
|
at,
|
|
183
384
|
rows: results[0] ?? [],
|
|
184
|
-
limit
|
|
385
|
+
limit,
|
|
386
|
+
batched: (results[1] ?? []).length > 0
|
|
185
387
|
}));
|
|
186
388
|
};
|
|
187
389
|
let after;
|
|
188
390
|
for (;;) {
|
|
189
|
-
const { at, rows, limit } = yield* page(after, 100).pipe(Effect.catchIf(tooLargeRead, () => page(after, largeBatch)));
|
|
190
|
-
if (at !== version || !(yield* each(rows))) return false;
|
|
391
|
+
const { at, rows, limit, batched } = yield* page(after, 100).pipe(Effect.catchIf(tooLargeRead, () => page(after, largeBatch)));
|
|
392
|
+
if (at !== version || batched || !(yield* each(rows))) return false;
|
|
191
393
|
const last = rows.at(-1);
|
|
192
394
|
if (last === void 0 || rows.length < limit) return true;
|
|
193
395
|
after = last.id;
|
|
194
396
|
}
|
|
195
397
|
});
|
|
398
|
+
/** A copy's cursor into `objects` from its first row, after every published batch's rows. */
|
|
399
|
+
const objectsFromStart = "-";
|
|
196
400
|
/**
|
|
197
401
|
* One page of `listed`'s object rows at its version, after `input.after`, read as `eachPageAt`
|
|
198
402
|
* reads each, and of those the rows `input.lacking` doesn't hold, read by the page's IDs as
|
|
199
|
-
* `heldIdsAt` reads them: `moved` once either repo answers at another version.
|
|
200
|
-
*
|
|
403
|
+
* `heldIdsAt` reads them: `moved` once either repo answers at another version. Each published
|
|
404
|
+
* staged batch's rows come first, oldest batch first, each as the `objects` row it stands for, then
|
|
405
|
+
* `objects`' own: every page is read at the copy's one version, so no row moves between them. An
|
|
406
|
+
* object held twice is copied twice, as one row. Its `next` is the page's last ID while the page
|
|
407
|
+
* is full, the next batch's or `objects`' start once a batch is read, and none once `objects` is.
|
|
201
408
|
*/
|
|
202
409
|
const copyRowsPage = /* @__PURE__ */ Effect.fnUntraced(function* (store, listed, input) {
|
|
203
|
-
const
|
|
410
|
+
const batchOf = (after) => {
|
|
411
|
+
const slash = after?.indexOf("/") ?? -1;
|
|
412
|
+
const named = after === void 0 || slash < 0 ? void 0 : after.slice(0, slash);
|
|
413
|
+
return named !== void 0 && isBatchId(named) ? named : void 0;
|
|
414
|
+
};
|
|
415
|
+
const inBatch = batchOf(input.after);
|
|
416
|
+
const readOf = (limit) => {
|
|
417
|
+
if (inBatch !== void 0) return {
|
|
418
|
+
collection: objectCollections.stagedObjects,
|
|
419
|
+
prefix: stagedPrefix(inBatch),
|
|
420
|
+
after: input.after ?? "",
|
|
421
|
+
limit
|
|
422
|
+
};
|
|
204
423
|
const read = {
|
|
205
424
|
collection: objectCollections.objects,
|
|
206
425
|
limit
|
|
207
426
|
};
|
|
208
|
-
if (input.after !== void 0) read.after = input.after;
|
|
209
|
-
return
|
|
210
|
-
scope: repoScope(listed.repo),
|
|
211
|
-
reads: [read]
|
|
212
|
-
}), ({ version: at, results }) => ({
|
|
213
|
-
at,
|
|
214
|
-
rows: results[0] ?? [],
|
|
215
|
-
limit
|
|
216
|
-
}));
|
|
427
|
+
if (input.after !== void 0 && input.after !== objectsFromStart) read.after = input.after;
|
|
428
|
+
return read;
|
|
217
429
|
};
|
|
430
|
+
const page = (limit) => Effect.map(store.read({
|
|
431
|
+
scope: repoScope(listed.repo),
|
|
432
|
+
reads: [readOf(limit), batchesRead]
|
|
433
|
+
}), ({ version: at, results }) => ({
|
|
434
|
+
at,
|
|
435
|
+
rows: results[0] ?? [],
|
|
436
|
+
batches: results[1] ?? [],
|
|
437
|
+
limit
|
|
438
|
+
}));
|
|
218
439
|
const read = yield* page(100).pipe(Effect.catchIf(tooLargeRead, () => page(largeBatch)));
|
|
219
440
|
if (read.at !== listed.version) return { moved: true };
|
|
220
|
-
const
|
|
221
|
-
|
|
441
|
+
const batches = (yield* batchesOf(read.batches)).map(({ batch }) => batch);
|
|
442
|
+
if (input.after === void 0 && batches[0] !== void 0) return yield* copyRowsPage(store, listed, {
|
|
443
|
+
...input,
|
|
444
|
+
after: stagedPrefix(batches[0])
|
|
445
|
+
});
|
|
446
|
+
const rows = read.rows.map(({ id, value }) => inBatch === void 0 ? {
|
|
447
|
+
collection: objectCollections.objects,
|
|
222
448
|
id,
|
|
223
449
|
value
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
450
|
+
} : {
|
|
451
|
+
collection: objectCollections.objects,
|
|
452
|
+
id: stagedOid(id),
|
|
453
|
+
value
|
|
454
|
+
});
|
|
455
|
+
const last = read.rows.at(-1);
|
|
456
|
+
const after = (() => {
|
|
457
|
+
if (last !== void 0 && read.rows.length === read.limit) return last.id;
|
|
458
|
+
if (inBatch === void 0) return void 0;
|
|
459
|
+
const following = batches[batches.indexOf(inBatch) + 1];
|
|
460
|
+
return following === void 0 ? objectsFromStart : stagedPrefix(following);
|
|
461
|
+
})();
|
|
462
|
+
const next = after === void 0 ? {} : { next: after };
|
|
227
463
|
const { lacking } = input;
|
|
228
464
|
if (lacking === void 0) return {
|
|
229
465
|
rows,
|
|
@@ -236,10 +472,31 @@ const copyRowsPage = /* @__PURE__ */ Effect.fnUntraced(function* (store, listed,
|
|
|
236
472
|
...next
|
|
237
473
|
};
|
|
238
474
|
});
|
|
239
|
-
/**
|
|
240
|
-
|
|
475
|
+
/**
|
|
476
|
+
* A chunked object's row found again in `objects`: a copy's chunks go only through duplicate
|
|
477
|
+
* removal, so `objects/<oid>` already holds the surviving manifest in one read (#2521).
|
|
478
|
+
*/
|
|
479
|
+
const chunkedAgain = (store, listed) => Effect.fnUntraced(function* (oid) {
|
|
480
|
+
const row = (yield* store.read({
|
|
481
|
+
scope: repoScope(listed.repo),
|
|
482
|
+
reads: [objectKey(oid)]
|
|
483
|
+
})).results[0]?.[0];
|
|
484
|
+
return row === void 0 ? void 0 : chunkedOf(row.value);
|
|
485
|
+
});
|
|
486
|
+
/** A reader of `oid`'s chunks, the repo's row naming them `chunked`. */
|
|
487
|
+
const chunkReaderOf = (store, listed, oid, chunked) => new ChunkReader(store, listed.repo, oid, chunked, chunkedAgain(store, listed));
|
|
488
|
+
/**
|
|
489
|
+
* A repo's object rows `oids` names, each handed on as it's read: the empty tree among them. One
|
|
490
|
+
* kept as chunks is read whole, `chunkReadMost` chunks a read, once `before` lets it.
|
|
491
|
+
*/
|
|
492
|
+
const eachHeldRow = (store, listed, before) => Effect.fnUntraced(function* (oids, each) {
|
|
241
493
|
if (oids.includes("4b825dc642cb6eb9a060e54bf8d69288fbee4904")) yield* each(emptyTreeObject);
|
|
242
|
-
yield* eachRow(store, listed, oids,
|
|
494
|
+
yield* eachRow(store, listed, oids, Effect.fnUntraced(function* (row) {
|
|
495
|
+
const chunked = chunkedOf(row.value);
|
|
496
|
+
if (chunked === void 0) return yield* Effect.flatMap(objectOfRow(row), each);
|
|
497
|
+
if (before !== void 0 && !(yield* before(row.id, chunked.size))) return;
|
|
498
|
+
yield* each(yield* chunkReaderOf(store, listed, row.id, chunked).whole());
|
|
499
|
+
}));
|
|
243
500
|
});
|
|
244
501
|
/** A repo's object rows by ID, read whole: those it holds, the empty tree among them. */
|
|
245
502
|
const heldRows = (store, listed) => Effect.fnUntraced(function* (oids) {
|
|
@@ -264,41 +521,104 @@ const rowHeaders = (store, listed) => Effect.fnUntraced(function* (oids) {
|
|
|
264
521
|
/** The size of each of `oids`' rows the repo holds, as `rowHeaders` reads it. */
|
|
265
522
|
const rowSizes = (store, listed) => (oids) => Effect.map(rowHeaders(store, listed)(oids), (headers) => new Map([...headers].map(([oid, { size }]) => [oid, size])));
|
|
266
523
|
/**
|
|
267
|
-
* The IDs of `repo`'s object rows that start with `prefix`, at most `count
|
|
268
|
-
* version they're read at:
|
|
269
|
-
*
|
|
524
|
+
* The IDs of `repo`'s object rows that start with `prefix`, at most `count` from each place it
|
|
525
|
+
* reads, lowest first, deduplicated, and the version they're read at: `objects` and every published
|
|
526
|
+
* staged batch's size markers, under `eachRead`'s rule. With no batch listed it's one store read,
|
|
527
|
+
* or pages of `largeBatch` where `objects` rows pass one answer's 16 MiB. With batches, each new
|
|
528
|
+
* batch is checked by its `stagedSizes` prefix beside `objects` and `batches`, capped at
|
|
529
|
+
* `newBatchReadsMost` discoveries. `version` is `undefined` once the answer took more than one
|
|
530
|
+
* snapshot.
|
|
270
531
|
*/
|
|
271
532
|
const rowsStartingWith = /* @__PURE__ */ Effect.fnUntraced(function* (store, repo, prefix, count) {
|
|
272
|
-
const
|
|
533
|
+
const scope = repoScope(repo);
|
|
534
|
+
const read = (reads) => store.read({
|
|
535
|
+
scope,
|
|
536
|
+
reads: [...reads]
|
|
537
|
+
});
|
|
538
|
+
const objectsRead = (limit, after) => {
|
|
273
539
|
const asked = {
|
|
274
540
|
collection: objectCollections.objects,
|
|
275
541
|
prefix,
|
|
276
542
|
limit
|
|
277
543
|
};
|
|
278
544
|
if (after !== void 0) asked.after = after;
|
|
279
|
-
return
|
|
280
|
-
scope: repoScope(repo),
|
|
281
|
-
reads: [asked]
|
|
282
|
-
});
|
|
545
|
+
return asked;
|
|
283
546
|
};
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
547
|
+
const markerRead = (batch) => ({
|
|
548
|
+
collection: objectCollections.stagedSizes,
|
|
549
|
+
prefix: `${stagedPrefix(batch)}${prefix}`,
|
|
550
|
+
limit: count
|
|
551
|
+
});
|
|
552
|
+
const inObjects = Effect.fnUntraced(function* () {
|
|
553
|
+
const whole = yield* read([objectsRead(count), batchesRead]).pipe(orTooLarge);
|
|
554
|
+
if (whole !== void 0) return {
|
|
555
|
+
oids: (whole.results[0] ?? []).map((row) => row.id),
|
|
556
|
+
listed: yield* listedBatches(whole.results[1]),
|
|
557
|
+
version: whole.version
|
|
558
|
+
};
|
|
559
|
+
const oids = [];
|
|
560
|
+
const listed = /* @__PURE__ */ new Set();
|
|
561
|
+
let after;
|
|
562
|
+
while (oids.length < count) {
|
|
563
|
+
const limit = Math.min(largeBatch, count - oids.length);
|
|
564
|
+
const page = yield* read([objectsRead(limit, after), batchesRead]);
|
|
565
|
+
const rows = page.results[0] ?? [];
|
|
566
|
+
oids.push(...rows.map((row) => row.id));
|
|
567
|
+
for (const batch of yield* listedBatches(page.results[1])) listed.add(batch);
|
|
568
|
+
if (rows.length < limit) break;
|
|
569
|
+
after = rows.at(-1)?.id;
|
|
570
|
+
}
|
|
571
|
+
return {
|
|
572
|
+
oids,
|
|
573
|
+
listed: [...listed],
|
|
574
|
+
version: void 0
|
|
575
|
+
};
|
|
576
|
+
});
|
|
577
|
+
const first = yield* inObjects();
|
|
578
|
+
if (first.listed.length === 0) return {
|
|
579
|
+
oids: first.oids,
|
|
580
|
+
version: first.version
|
|
288
581
|
};
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
582
|
+
const found = new Set(first.oids);
|
|
583
|
+
const checked = /* @__PURE__ */ new Set();
|
|
584
|
+
const answer = (version) => ({
|
|
585
|
+
oids: [...found].toSorted(),
|
|
586
|
+
version
|
|
587
|
+
});
|
|
588
|
+
let listed = first.listed;
|
|
589
|
+
let discoveries = 0;
|
|
590
|
+
for (;;) {
|
|
591
|
+
const fresh = listed.filter((batch) => !checked.has(batch));
|
|
592
|
+
if (fresh.length === 0) return answer(void 0);
|
|
593
|
+
if (discoveries >= 32) return yield* batchesMoved();
|
|
594
|
+
discoveries += 1;
|
|
595
|
+
const snapshot = yield* read([
|
|
596
|
+
objectsRead(count),
|
|
597
|
+
batchesRead,
|
|
598
|
+
...fresh.map(markerRead)
|
|
599
|
+
]).pipe(orTooLarge);
|
|
600
|
+
let now;
|
|
601
|
+
let version;
|
|
602
|
+
if (snapshot !== void 0) {
|
|
603
|
+
for (const row of snapshot.results[0] ?? []) found.add(row.id);
|
|
604
|
+
now = yield* listedBatches(snapshot.results[1]);
|
|
605
|
+
const nowSet = new Set(now);
|
|
606
|
+
for (const [i, batch] of fresh.entries()) {
|
|
607
|
+
if (!nowSet.has(batch)) continue;
|
|
608
|
+
for (const row of snapshot.results[i + 2] ?? []) found.add(stagedOid(row.id));
|
|
609
|
+
}
|
|
610
|
+
version = discoveries === 1 ? snapshot.version : void 0;
|
|
611
|
+
} else {
|
|
612
|
+
const markers = yield* read(fresh.map(markerRead));
|
|
613
|
+
for (const row of markers.results.flat()) found.add(stagedOid(row.id));
|
|
614
|
+
const paged = yield* inObjects();
|
|
615
|
+
for (const oid of paged.oids) found.add(oid);
|
|
616
|
+
now = paged.listed;
|
|
617
|
+
}
|
|
618
|
+
for (const batch of fresh) checked.add(batch);
|
|
619
|
+
if (now.every((batch) => checked.has(batch))) return answer(version);
|
|
620
|
+
listed = now;
|
|
297
621
|
}
|
|
298
|
-
return {
|
|
299
|
-
oids,
|
|
300
|
-
version: void 0
|
|
301
|
-
};
|
|
302
622
|
});
|
|
303
623
|
/** What `ObjectReader.startingWith` answers from the IDs each place found: each once, lowest first. */
|
|
304
624
|
const startingOf = (found, most) => {
|
|
@@ -308,4 +628,4 @@ const startingOf = (found, most) => {
|
|
|
308
628
|
more: all.length > most
|
|
309
629
|
};
|
|
310
630
|
};
|
|
311
|
-
export { ObjectRow, copyRowsPage, eachHeldRow, eachPageAt, emptyTreeObject, gitObjectOf, heldIdsAt, heldRows, largeBatch, noRows, objectKey, objectOfRow, objectRow, receivedRows, rowHeaders, rowSizes, rowValueBytes, rowsMoved, rowsStartingWith, startingOf, tooLargeRead };
|
|
631
|
+
export { ObjectRow, bodyPackBytes, copyRowsPage, eachHeldRow, eachPageAt, emptyTreeObject, gitObjectOf, headerOfRow, heldIdsAt, heldRows, largeBatch, noRows, objectKey, objectOfRow, objectRow, readsOwnChunks, receivedObject, receivedRows, rowHeaders, rowSizes, rowValueBytes, rowsMoved, rowsStartingWith, startingOf, tooLargeRead };
|