@ref0/git 0.30.0 → 0.32.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.
@@ -969,6 +969,12 @@ export interface IndexTryInput extends CallInput {
969
969
  * it: the try's calls are part spent, so the next try makes its first step.
970
970
  */
971
971
  readonly lastCheck?: true;
972
+ /**
973
+ * The step's data is what the step before it answered in the same try, never data a settled
974
+ * try kept. A host may ignore it. A try lost earlier may still have written this step's files,
975
+ * so a step that skips a lookup for them keeps a safe path for one that's there (#2518).
976
+ */
977
+ readonly chained?: true;
972
978
  }
973
979
  /**
974
980
  * A try's end: another step due now, with the data to keep; the `index` row to commit, after
@@ -98,7 +98,8 @@ const refusalError = (refusal) => refusal === "spent" ? `git.index ran out of it
98
98
  * asked once more over a fresh read, with `lastCheck`, and its answer is the try's: no `moved`
99
99
  * leaves the job. A `chained` step, one after another in the same try, commits no refusal: its
100
100
  * calls are what the steps before it left, so its row ends `withheld`, and the try ends with the
101
- * step before it kept, for the next try to run first with the whole budget (#2525).
101
+ * step before it kept, for the next try to run first with the whole budget (#2525). Its step is
102
+ * told it's `chained`, as its data is the try's own (#2518).
102
103
  */
103
104
  const indexAttempt = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, internalId, data, signal, round, options = {}) {
104
105
  const { failed, chained } = options;
@@ -114,7 +115,8 @@ const indexAttempt = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store,
114
115
  round,
115
116
  failed,
116
117
  at,
117
- lastCheck
118
+ lastCheck,
119
+ chained
118
120
  });
119
121
  const stepOf = (asked) => Effect.flatMap(budgetedInput(asked.input), (input) => index.step(asked.listed, input));
120
122
  const first = yield* read();
@@ -256,6 +258,7 @@ const readTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, inter
256
258
  if (row !== void 0) input.row = row.value;
257
259
  if (roots.size > 0) input.roots = [...roots];
258
260
  if (of.lastCheck === true) input.lastCheck = true;
261
+ if (of.chained === true) input.chained = true;
259
262
  const [looseRow] = looseRows;
260
263
  return {
261
264
  record,
package/dist/lfs/copy.mjs CHANGED
@@ -195,10 +195,10 @@ const partsPut = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, partBytes,
195
195
  /** The copy over LFS's registration's rows and its bucket, each put inside `charge`, its `putCharge`. */
196
196
  const lfsCopy = (rows, bucket, charge) => {
197
197
  const partBytes = Math.max(Number.isFinite(bucket.multipart.partSize) ? bucket.multipart.partSize : 0, copyPartDefault);
198
- const put = (staging, body, size, oid) => Effect.scoped(Effect.andThen(charge(bucket.multipart, { size }), Effect.asVoid(Effect.uninterruptible(bucketDo(bucket.put(staging.key, body, {
198
+ const put = (staging, body, size, oid) => Effect.scoped(Effect.andThen(charge(bucket.multipart, { size }), Effect.asVoid(bucketDo(bucket.put(staging.key, body, {
199
199
  size,
200
200
  sha256: oid
201
- }))))));
201
+ })))));
202
202
  return {
203
203
  listed: (repo, oids) => listedOf(rows, repo, oids),
204
204
  stage: (repo, objects) => copyStages(rows, bucket, repo, objects),
@@ -16,6 +16,7 @@ import { CallBudget } from "../store/call-count.mjs";
16
16
  import { isLfsOid, lfsPointerText } from "../protocol/objects/lfs-pointer.mjs";
17
17
  import { ListedRow, UploadRow, largestObject, lfsCollections, linkLife, listedKey, listedRead, objectKey, stagingId, stagingKey, stagingRead, streamMost, uploadGrace, uploadKey, uploadRead } from "./rows.mjs";
18
18
  import { BatchRequest, VerifyRequest, batchMost, bodyOf, lfsAnswer } from "./wire.mjs";
19
+ import { askedOf } from "./ranges.mjs";
19
20
  import { uploadedRow } from "./uploaded.mjs";
20
21
  import { checkedAfterMost, pastMost, uploadPieceBytes } from "./upload-most.mjs";
21
22
  import { fail, gitError, httpStatus } from "../contracts/result.mjs";
@@ -481,10 +482,10 @@ const receive = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, oid) {
481
482
  if (staging === void 0) return yield* Effect.die(/* @__PURE__ */ new Error("One staging key asked, none made"));
482
483
  const { key } = staging;
483
484
  const sent = counted(call.request.body, upload.size);
484
- const put = yield* Effect.result(Effect.uninterruptible(bucketDo(bucket.put(key, sent.body, {
485
+ const put = yield* Effect.result(bucketDo(bucket.put(key, sent.body, {
485
486
  size: upload.size,
486
487
  sha256: oid
487
- }))));
488
+ })));
488
489
  if (Result.isFailure(put)) {
489
490
  if (sent.past()) return yield* Effect.fail(pastSize(upload.size));
490
491
  if (sent.size() < upload.size) return yield* Effect.fail(shortSize(upload.size, sent.size()));
@@ -630,7 +631,20 @@ const listStaged = /* @__PURE__ */ Effect.fnUntraced(function* (registered, call
630
631
  * rules are asked of it then, before the bucket's stream opens, and their refusal or failure is
631
632
  * the read's. `signal` aborted cancels the bucket's stream, opening or open.
632
633
  */
633
- const objectOf = /* @__PURE__ */ Effect.fnUntraced(function* (parts, read) {
634
+ const objectOf = (parts, read) => Effect.flatMap(askedObject(parts, read, () => whole), ({ oid, size, bytes }) => bytes === void 0 ? missingBytes(oid) : Effect.succeed({
635
+ oid,
636
+ size,
637
+ bytes
638
+ }));
639
+ /** A listed object whose bucket holds no bytes. */
640
+ const missingBytes = (oid) => fail("DATA_LOSS", `LFS object ${oid}'s bytes are missing`);
641
+ /** Asks the whole of an object, as `objectOf` does. */
642
+ const whole = { kind: "whole" };
643
+ /**
644
+ * `objectOf`'s read, of what `asked` makes of the object's size: its whole, a part, whose bytes
645
+ * alone the bucket's stream holds, or none, which opens no stream and answers no bytes.
646
+ */
647
+ const askedObject = /* @__PURE__ */ Effect.fnUntraced(function* (parts, read, asked) {
634
648
  const { oid, size, signal } = read;
635
649
  if (!isLfsOid(oid)) return yield* fail("NOT_FOUND", "Object does not exist");
636
650
  const repo = yield* openFor(read.caller, read.repo, false, read.internalId, "first-read");
@@ -646,11 +660,20 @@ const objectOf = /* @__PURE__ */ Effect.fnUntraced(function* (parts, read) {
646
660
  },
647
661
  request: read.request
648
662
  });
649
- const bytes = yield* Effect.uninterruptible(Effect.map(bucketStream(parts.bucket, listed.key), (stream) => stream === void 0 || signal === void 0 ? stream : bodyUntilAborted(stream, signal)));
650
- if (bytes === void 0) return yield* fail("DATA_LOSS", `LFS object ${oid}'s bytes are missing`);
663
+ const ask = asked(listed.size);
664
+ if (ask.kind === "none") return {
665
+ oid,
666
+ size: listed.size,
667
+ ask,
668
+ bytes: void 0
669
+ };
670
+ const range = ask.kind === "part" ? ask.range : void 0;
671
+ const bytes = yield* Effect.uninterruptible(Effect.map(bucketStream(parts.bucket, listed.key, range), (stream) => stream === void 0 || signal === void 0 ? stream : bodyUntilAborted(stream, signal)));
672
+ if (bytes === void 0) return yield* missingBytes(oid);
651
673
  return {
652
674
  oid,
653
675
  size: listed.size,
676
+ ask,
654
677
  bytes
655
678
  };
656
679
  });
@@ -727,22 +750,42 @@ const objectsOf = /* @__PURE__ */ Effect.fnUntraced(function* (parts, read) {
727
750
  });
728
751
  /**
729
752
  * `GET objects/<oid>`, a Worker download: a listed object's bytes, the repo's own or a source's,
730
- * as `objectOf` reads them. Its fetch rules are asked again, though the batch that gave the link
731
- * asked them: the link outlives that answer, and a signed bucket's link, which the bucket serves,
732
- * is asked only at the batch.
753
+ * as `objectOf` reads them, or the one range of them its `Range` asks, as a 206, so an import
754
+ * resuming a copy from its offset reads ref0 as it reads any other source. Its fetch rules are
755
+ * asked again, though the batch that gave the link asked them: the link outlives that answer, and
756
+ * a signed bucket's link, which the bucket serves, is asked only at the batch.
733
757
  */
734
758
  const send = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, oid) {
735
- const object = yield* objectOf(parts, {
759
+ const header = call.request.headers.get("range");
760
+ const object = yield* askedObject(parts, {
736
761
  caller: call.caller,
737
762
  repo: call.repo,
738
763
  oid,
739
764
  request: call.request
765
+ }, (size) => askedOf(header, size));
766
+ const { ask, size } = object;
767
+ if (ask.kind === "none") return new Response(null, {
768
+ status: 416,
769
+ headers: { "content-range": `bytes */${size}` }
740
770
  });
741
- return new Response(object.bytes, {
771
+ const headers = {
772
+ "content-type": "application/octet-stream",
773
+ "accept-ranges": "bytes"
774
+ };
775
+ if (ask.kind === "whole") return new Response(object.bytes, {
742
776
  status: 200,
743
777
  headers: {
744
- "content-type": "application/octet-stream",
745
- "content-length": String(object.size)
778
+ ...headers,
779
+ "content-length": String(size)
780
+ }
781
+ });
782
+ const { offset, length } = ask.range;
783
+ return new Response(object.bytes, {
784
+ status: 206,
785
+ headers: {
786
+ ...headers,
787
+ "content-length": String(length),
788
+ "content-range": `bytes ${offset}-${offset + length - 1}/${size}`
746
789
  }
747
790
  });
748
791
  });
@@ -0,0 +1,33 @@
1
+ // src/lfs/ranges.ts
2
+ const whole = { kind: "whole" };
3
+ const none = { kind: "none" };
4
+ /** One range of bytes: `bytes=<first>-[<last>]`, or a suffix, `bytes=-<length>`. */
5
+ const oneRange = /^bytes=(\d*)-(\d*)$/u;
6
+ /** `text`, digits alone, as a number, or undefined past the safe integers. */
7
+ const numberOf = (text) => {
8
+ const value = Number(text);
9
+ return Number.isSafeInteger(value) ? value : void 0;
10
+ };
11
+ /** The bytes from `first` to `last`, both counted, as a bucket's read takes them. */
12
+ const part = (first, last) => ({
13
+ kind: "part",
14
+ range: {
15
+ offset: first,
16
+ length: last - first + 1
17
+ }
18
+ });
19
+ /** What `header`, a request's `Range`, asks of an object of `size` bytes, as `Asked` says. */
20
+ const askedOf = (header, size) => {
21
+ const [, first = "", last = ""] = oneRange.exec(header?.trim() ?? "") ?? [];
22
+ if (first === "" && last === "") return whole;
23
+ if (first === "") {
24
+ const length = numberOf(last);
25
+ if (length === void 0) return whole;
26
+ return length === 0 || size === 0 ? none : part(Math.max(0, size - length), size - 1);
27
+ }
28
+ const start = numberOf(first);
29
+ const end = last === "" ? Number.POSITIVE_INFINITY : numberOf(last);
30
+ if (start === void 0 || end === void 0 || end < start) return whole;
31
+ return start >= size ? none : part(start, Math.min(end, size - 1));
32
+ };
33
+ export { askedOf };
@@ -483,14 +483,15 @@ const bucketReading = (bucket, key, range, read) => Effect.scoped(Effect.gen(fun
483
483
  }));
484
484
  /**
485
485
  * A put of `bytes` to `key`, told its size, so the service charges all its calls as it starts. An
486
- * interruption waits it out: a put left running could land after the push's clean-up deleted its
487
- * key, leaving bytes no row names. So an interrupt or a deadline doesn't stop it: it ends when its
488
- * store's own tries end. Aborting it wouldn't close that race, as a store may still land a request
489
- * it already took.
486
+ * interrupt or a deadline stops it as it stops any call: its store's request is aborted, or on R2,
487
+ * whose binding takes no signal, given up `r2PutSettleMost` on, so a stalled put ends its try
488
+ * within `jobLeaseMargin` of its timeout (#2999). A request its store already took can still land
489
+ * after the try's clean-up deleted its key: `dropRefused` leaves a `staged` row, so its pack's keys
490
+ * are deleted again `receiveStepGrace` on.
490
491
  */
491
492
  const bucketPut = (bucket, key, bytes) => {
492
493
  const parts = bytes instanceof Uint8Array ? [bytes] : bytes;
493
494
  const size = parts.reduce((sum, part) => sum + part.byteLength, 0);
494
- return Effect.uninterruptible(bucketDo(bucket.put(key, Stream.fromIterable(parts), { size })));
495
+ return bucketDo(bucket.put(key, Stream.fromIterable(parts), { size }));
495
496
  };
496
497
  export { bodyAcross, bodyOfBytes, bodyThrown, bucketBody, bucketBodyIn, bucketCall, bucketCharge, bucketDeleteMany, bucketDo, bucketFailed, bucketPut, bucketReading, bucketStream, bucketStreamScoped, bucketTry, cancelsBody, counting, deleteCharge, headersOnce, heldOnce, joined, madeOwned, objectReader, objectsOnce, oneShotReads, putCharge, putParts, readEach, readOnce, readWhole, retryCharge, scopedReader, scopedReceive, scopedReceiveStep, sizedPutCalls, sizesOnce, startingOnce, streamedPutCalls, walkObjects };
@@ -4,8 +4,8 @@ import { bucketDeleteMany, bucketDo } from "./calls.mjs";
4
4
  import { markerKey, markerPrefix, objectCollections } from "./layout.mjs";
5
5
  import { mergeKey } from "./merge-row.mjs";
6
6
  import { noRows } from "./object-rows.mjs";
7
- import { deletePackFiles } from "./quarantine.mjs";
8
- import { deleteStaged, receiveKey, stagedRow } from "./receive-steps.mjs";
7
+ import { deletePackFiles, stagedRow } from "./quarantine.mjs";
8
+ import { deleteStaged, receiveKey } from "./receive-steps.mjs";
9
9
  import { QuarantineRow, StagedRow, decodeHeld, decodeLeft, quarantineKey, quarantineRow, stagedKey } from "./rows.mjs";
10
10
  import * as Effect from "effect/Effect";
11
11
  /**
@@ -1455,7 +1455,10 @@ const bitmapsWritten = /* @__PURE__ */ Effect.fnUntraced(function* (parts, lower
1455
1455
  kept: Math.min(madeMost, madeAll)
1456
1456
  };
1457
1457
  if (below !== void 0) bitmapsInput.below = below;
1458
- if (tipsKey !== void 0) return yield* bitmapsCutTry(parts, files, data, bitmapsInput, tipsKey, allotment);
1458
+ if (tipsKey !== void 0) return yield* bitmapsCutTry(parts, files, data, bitmapsInput, {
1459
+ tipsKey,
1460
+ chained: input.chained === true
1461
+ }, allotment);
1459
1462
  const already = yield* storedSize(bucket, files.bitmaps);
1460
1463
  const written = already === void 0 ? yield* writeBitmaps(bitmapsInput) : yield* storedBitmaps(bucket, files.bitmaps, positions, already);
1461
1464
  if (written === void 0) return void 0;
@@ -1471,9 +1474,9 @@ const bitmapsWritten = /* @__PURE__ */ Effect.fnUntraced(function* (parts, lower
1471
1474
  * from where the last part ended, through the try's bound less `indexBitmapsCallsAfter`, then put
1472
1475
  * through the whole bound. Once the parts hold the order, the try joins them into `.bitmaps`. A
1473
1476
  * bitmap the bound cuts is left whole for the next try, and a try that makes none refuses, as the
1474
- * next would spend its calls at the same place.
1477
+ * next would spend its calls at the same place. `chained` says the step's data is its own try's.
1475
1478
  */
1476
- const bitmapsCutTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, files, data, input, tipsKey, allotment) {
1479
+ const bitmapsCutTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, files, data, input, { tipsKey, chained }, allotment) {
1477
1480
  const order = bitmapOrder(input.chosen);
1478
1481
  const ordered = orderKey(order);
1479
1482
  const cut = data.bitmapsCut?.order === ordered ? data.bitmapsCut : {
@@ -1484,7 +1487,7 @@ const bitmapsCutTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, files,
1484
1487
  if (cut.done >= order.length) return yield* bitmapsJoined(parts, files, data, cut, input.positions, allotment);
1485
1488
  yield* allotment.grow(partBytesMost);
1486
1489
  const key = files.bitmapsPart(cut.order, cut.parts.length);
1487
- const landed = yield* readWhole(parts.bucket, key);
1490
+ const landed = chained ? void 0 : yield* readWhole(parts.bucket, key);
1488
1491
  if (landed !== void 0) {
1489
1492
  const count = yield* partCount(key, landed);
1490
1493
  return {
@@ -1534,14 +1537,15 @@ const bitmapsCutTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, files,
1534
1537
  const callsFit = counted === void 0 || madeCalls === void 0 || directNeeds <= counted.most.bucket - madeCalls.bucket && directNeeds <= counted.most.subrequests - madeCalls.subrequests;
1535
1538
  const putBuffer = putHeldBytes(parts.bucket.multipart, { atMost });
1536
1539
  if (callsFit && (putBuffer === 0 || allotment.tryGrow(putBuffer))) return yield* Effect.ensuring(Effect.gen(function* () {
1537
- const already = yield* storedSize(parts.bucket, files.bitmaps);
1540
+ const already = chained ? void 0 : yield* storedSize(parts.bucket, files.bitmaps);
1538
1541
  const written = already === void 0 ? yield* Effect.scoped(Effect.gen(function* () {
1539
1542
  const bitmaps = partBitmaps(into.finish());
1540
1543
  if (bitmaps?.length !== into.count) return yield* Effect.fail(lost(`${files.bitmaps} part buffer is unreadable`));
1541
1544
  const put = yield* bitmapsPut(parts.bucket, files.bitmaps, input.positions, into.count);
1542
1545
  for (const bitmap of bitmaps) yield* put.addBytes(bitmap.position, bitmap.number, bitmap.bytes);
1543
1546
  return yield* put.finish;
1544
- })) : yield* storedBitmaps(parts.bucket, files.bitmaps, input.positions, already);
1547
+ })).pipe(Effect.catchIf(alreadyThere, () => Effect.succeed(void 0))) : yield* storedBitmaps(parts.bucket, files.bitmaps, input.positions, already);
1548
+ if (written === void 0) return data;
1545
1549
  const { bitmapsCut: _, ...rest } = data;
1546
1550
  return {
1547
1551
  ...rest,
@@ -2368,6 +2372,7 @@ const indexTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, limits, lis
2368
2372
  if (input.deleted !== void 0) step.deleted = input.deleted;
2369
2373
  if (input.failed !== void 0) step.failed = input.failed;
2370
2374
  if (input.lastCheck === true) step.lastCheck = true;
2375
+ if (input.chained === true) step.chained = true;
2371
2376
  const roots = new Set(input.roots ?? []);
2372
2377
  const ended = yield* indexStep({
2373
2378
  ...parts,
@@ -0,0 +1,286 @@
1
+ import { bucketBodyIn, joined } from "./calls.mjs";
2
+ import { replayPieceBytes } from "./range-cache.mjs";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Stream from "effect/Stream";
5
+ import * as Exit from "effect/Exit";
6
+ // src/storage/index-step-files.ts
7
+ /**
8
+ * The most a repo's index build keeps of its index files between its steps, 16 MiB. svelte's
9
+ * first build, 91,275 objects, reads about 10 MiB of them over its 10 chained steps, and about
10
+ * 5 s of its wall went to reading them again (#596). Pack bodies are never kept: the build reads
11
+ * about 150 MiB of those, past what a Durable Object's 128 MB could hold.
12
+ */
13
+ const indexStepFilesMost = 16777216;
14
+ /** A pack's own index file, as `packFiles` names it: `packs/<ID>.idx` and its kin. */
15
+ const packIndexFile = /^packs\/[^/]+\.(?:idx|pos|rev|graph|types)$/;
16
+ /**
17
+ * Whether a put of `key` is kept: an index file, under `index/`, or a pack's `.idx`, `.pos`,
18
+ * `.rev`, `.graph` or `.types`, as `packFiles` names them. Never a pack's bytes, nor a receive's
19
+ * keys under its pack's. Each is put once, with the same bytes by any try that puts it, so kept
20
+ * bytes are what the bucket holds until the key is removed.
21
+ */
22
+ const keepable = (key) => key.startsWith("index/") || packIndexFile.test(key);
23
+ /**
24
+ * Whether a read of `key` is kept: a pack's index file. A file under `index/` is kept only as a
25
+ * step puts it: one it didn't, an earlier layer's, `PackIndexes` holds whole where it's read whole.
26
+ */
27
+ const readKept = (key) => packIndexFile.test(key);
28
+ /**
29
+ * `kept`'s bytes from `from` to `to`, `replayPieceBytes` a piece, each its own copy read from them
30
+ * as it's pulled, so no reader changes another's. Bytes let go mid-way are no longer held here:
31
+ * the rest comes from `bucket`, read in `context` once pulled.
32
+ */
33
+ const replayed = (context, bucket, kept, from, to) => {
34
+ let at = from;
35
+ let rest;
36
+ return new ReadableStream({
37
+ pull: async (controller) => {
38
+ if (rest === void 0) {
39
+ const { bytes } = kept;
40
+ if (at === to) return controller.close();
41
+ if (bytes !== void 0) {
42
+ const end = Math.min(at + replayPieceBytes, to);
43
+ controller.enqueue(bytes.slice(at, end));
44
+ at = end;
45
+ return;
46
+ }
47
+ const range = {
48
+ offset: kept.offset + at,
49
+ length: to - at
50
+ };
51
+ rest = bucketBodyIn(context, bucket, kept.key, range).getReader();
52
+ }
53
+ const next = await rest.read();
54
+ if (next.done) controller.close();
55
+ else controller.enqueue(next.value);
56
+ },
57
+ cancel: (reason) => rest?.cancel(reason)
58
+ }, { highWaterMark: 0 });
59
+ };
60
+ /**
61
+ * The index files one repo's build reads and writes, kept between its steps within `most`, each
62
+ * charged to `charge`: a server's per-instance room (`instanceRoomOf`), which takes only what's
63
+ * free and gives way first, so what it keeps never holds back a live operation (#596).
64
+ *
65
+ * A step reads through `over`'s bucket. A read of a kept file, or of a range inside a kept one,
66
+ * answers from memory with no call. A put of an index file is kept as it lands, and a read of a
67
+ * pack's index file as its body is read to its end. The least recently used goes first past `most`,
68
+ * all of it when the room shrinks, and a removed key is let go. A step for another repo, or
69
+ * `clear`, lets everything go: the cache holds one build's files at a time.
70
+ */
71
+ var IndexStepFiles = class {
72
+ #charge;
73
+ most;
74
+ /** Least recently used first. */
75
+ #kept = /* @__PURE__ */ new Map();
76
+ #byKey = /* @__PURE__ */ new Map();
77
+ /** What kept entries are charged, and reads and puts under way that may keep theirs. */
78
+ #held = 0;
79
+ #filling = 0;
80
+ /** Each fill under way, by what lets its copies go: everything let go lets them go too. */
81
+ #fills = /* @__PURE__ */ new Set();
82
+ #repo;
83
+ constructor(charge, most = indexStepFilesMost) {
84
+ this.#charge = charge;
85
+ this.most = most;
86
+ charge.watch(() => this.#letGo(false));
87
+ }
88
+ /** What it holds now: kept entries and fills under way, as charged. */
89
+ get held() {
90
+ return this.#held + this.#filling;
91
+ }
92
+ /** `bucket`, for a step of `repo`'s build: a step of another repo's lets the last one's go. */
93
+ over(bucket, repo) {
94
+ if (this.#repo !== repo) {
95
+ this.#letGo(true);
96
+ this.#repo = repo;
97
+ }
98
+ return {
99
+ ...bucket,
100
+ read: (key, range) => Effect.suspend(() => {
101
+ if (!keepable(key)) return bucket.read(key, range);
102
+ const found = this.#replay(key, range);
103
+ if (found !== void 0) return Effect.map(Effect.context(), (context) => replayed(context, bucket, found.kept, found.from, found.to));
104
+ if (!readKept(key)) return bucket.read(key, range);
105
+ return Effect.map(bucket.read(key, range), (body) => this.#teed(key, range, body));
106
+ }),
107
+ put: (key, body, options) => Effect.suspend(() => {
108
+ if (!keepable(key)) return bucket.put(key, body, options);
109
+ const fill = this.#fill(options?.size);
110
+ if (fill === void 0) return bucket.put(key, body, options);
111
+ return bucket.put(key, Stream.map(body, fill.add), options).pipe(Effect.onExit((exit) => Effect.sync(() => Exit.isSuccess(exit) ? fill.end(key, void 0, exit.value.size) : fill.drop())));
112
+ }),
113
+ remove: (key) => Effect.andThen(Effect.sync(() => this.#forget(key)), bucket.remove(key)),
114
+ removeMany: (keys, options) => Effect.andThen(Effect.sync(() => keys.forEach((key) => this.#forget(key))), bucket.removeMany(keys, options))
115
+ };
116
+ }
117
+ /** Lets every kept file go, its charge given back: the build's end. */
118
+ clear() {
119
+ this.#letGo(true);
120
+ this.#repo = void 0;
121
+ }
122
+ /** The kept entry answering `range` of `key`, made the most recent, and where in it, or `undefined`. */
123
+ #replay(key, range) {
124
+ for (const kept of this.#byKey.get(key) ?? []) {
125
+ const from = (range?.offset ?? 0) - kept.offset;
126
+ const to = range === void 0 ? kept.size : from + range.length;
127
+ if (!(range === void 0 ? kept.whole : from >= 0 && to <= kept.size)) continue;
128
+ this.#kept.delete(kept.id);
129
+ this.#kept.set(kept.id, kept);
130
+ return {
131
+ kept,
132
+ from,
133
+ to
134
+ };
135
+ }
136
+ }
137
+ /** `body`, read through: kept once it ends at `range`'s length, or whole for no range. */
138
+ #teed(key, range, body) {
139
+ const fill = this.#fill(range?.length);
140
+ if (fill === void 0) return body;
141
+ const reader = body.getReader();
142
+ return new ReadableStream({
143
+ pull: async (controller) => {
144
+ const next = await reader.read().catch((cause) => {
145
+ fill.drop();
146
+ throw cause;
147
+ });
148
+ if (next.done) {
149
+ fill.end(key, range?.offset, range?.length);
150
+ return controller.close();
151
+ }
152
+ controller.enqueue(fill.add(next.value));
153
+ },
154
+ cancel: (reason) => {
155
+ fill.drop();
156
+ return reader.cancel(reason);
157
+ }
158
+ }, { highWaterMark: 0 });
159
+ }
160
+ /**
161
+ * One read's or put's bytes as they pass, charged as they come, or at once for a known `size`:
162
+ * `undefined` when even that doesn't fit. `add` copies each piece while it fits, into one block of
163
+ * a known `size`, `end` keeps them when they came to `size`, and `drop` lets them go. One that
164
+ * everything let go under keeps nothing, its copies gone at once and its charge given back with
165
+ * the rest.
166
+ */
167
+ #fill(size) {
168
+ let charged = 0;
169
+ let open = true;
170
+ let block;
171
+ let pieces;
172
+ let got = 0;
173
+ const abandon = () => {
174
+ open = false;
175
+ block = void 0;
176
+ pieces = void 0;
177
+ };
178
+ const charge = (bytes) => {
179
+ if (!this.#reserve(bytes)) return false;
180
+ charged += bytes;
181
+ return true;
182
+ };
183
+ const drop = () => {
184
+ if (!open) return;
185
+ abandon();
186
+ this.#fills.delete(abandon);
187
+ this.#filling -= charged;
188
+ this.#charge.shrink(charged);
189
+ };
190
+ if (!charge(320 + (size ?? 0))) return void 0;
191
+ if (size === void 0) pieces = [];
192
+ else block = new Uint8Array(size);
193
+ this.#fills.add(abandon);
194
+ return {
195
+ add: (piece) => {
196
+ if (!open) return piece;
197
+ const at = got;
198
+ got += piece.byteLength;
199
+ if (block !== void 0) {
200
+ if (got > block.byteLength) drop();
201
+ else block.set(piece, at);
202
+ } else if (!charge(piece.byteLength)) drop();
203
+ else pieces?.push(piece.slice());
204
+ return piece;
205
+ },
206
+ drop,
207
+ end: (key, offset, length) => {
208
+ if (!open) return;
209
+ if (length !== void 0 && got !== length || size !== void 0 && got !== size) return drop();
210
+ let bytes = block;
211
+ if (bytes === void 0) {
212
+ if (!charge(got)) return drop();
213
+ bytes = joined(pieces ?? []);
214
+ pieces = void 0;
215
+ charged -= got;
216
+ this.#filling -= got;
217
+ this.#charge.shrink(got);
218
+ }
219
+ abandon();
220
+ this.#fills.delete(abandon);
221
+ this.#filling -= charged;
222
+ this.#keep({
223
+ id: `${key}@${offset ?? "whole"}+${got}`,
224
+ key,
225
+ offset: offset ?? 0,
226
+ bytes,
227
+ size: got,
228
+ whole: offset === void 0,
229
+ cost: charged
230
+ });
231
+ }
232
+ };
233
+ }
234
+ /**
235
+ * Room for `bytes` more within `most`, the least recent let go first, then the charge's grow. What
236
+ * fills now can't make room, so bytes past `most` with it let nothing go.
237
+ */
238
+ #reserve(bytes) {
239
+ if (this.#filling + bytes > this.most) return false;
240
+ for (const [, oldest] of this.#kept) {
241
+ if (this.#held + this.#filling + bytes <= this.most) break;
242
+ this.#remove(oldest, true);
243
+ }
244
+ if (this.#held + this.#filling + bytes > this.most || !this.#charge.tryGrow(bytes)) return false;
245
+ this.#filling += bytes;
246
+ return true;
247
+ }
248
+ /** `kept`, its charge moved from filling to held: one already there with its ID is let go. */
249
+ #keep(kept) {
250
+ const prior = this.#kept.get(kept.id);
251
+ if (prior !== void 0) this.#remove(prior, true);
252
+ this.#kept.set(kept.id, kept);
253
+ this.#byKey.set(kept.key, [...this.#byKey.get(kept.key) ?? [], kept]);
254
+ this.#held += kept.cost;
255
+ }
256
+ /** `kept` let go: a replay of it under way reads the rest from the bucket. */
257
+ #remove(kept, release) {
258
+ if (!this.#kept.delete(kept.id)) return;
259
+ kept.bytes = void 0;
260
+ this.#held -= kept.cost;
261
+ if (release) this.#charge.shrink(kept.cost);
262
+ const left = (this.#byKey.get(kept.key) ?? []).filter((each) => each !== kept);
263
+ if (left.length === 0) this.#byKey.delete(kept.key);
264
+ else this.#byKey.set(kept.key, left);
265
+ }
266
+ /** `key`'s kept bytes let go, for a removed file. */
267
+ #forget(key) {
268
+ for (const kept of this.#byKey.get(key) ?? []) this.#remove(kept, true);
269
+ }
270
+ /**
271
+ * Everything let go, kept and filling, a fill's copies and a replay's bytes included, its charge
272
+ * given back unless a shrink took it.
273
+ */
274
+ #letGo(release) {
275
+ const charged = this.#held + this.#filling;
276
+ for (const abandon of this.#fills) abandon();
277
+ for (const kept of this.#kept.values()) kept.bytes = void 0;
278
+ this.#fills.clear();
279
+ this.#kept.clear();
280
+ this.#byKey.clear();
281
+ this.#held = 0;
282
+ this.#filling = 0;
283
+ if (release && charged > 0) this.#charge.shrink(charged);
284
+ }
285
+ };
286
+ export { IndexStepFiles, indexStepFilesMost };
@@ -82,7 +82,7 @@ const started = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, key, option
82
82
  const write = (bytes) => Effect.suspend(() => put.pollUnsafe() === void 0 ? Effect.andThen(Effect.raceFirst(Queue.offer(queue, bytes), ended), pulled) : ended);
83
83
  return {
84
84
  write,
85
- finish: Effect.uninterruptible(Effect.andThen(Queue.end(queue), Effect.asVoid(Fiber.join(put)))),
85
+ finish: Effect.andThen(Queue.end(queue), Effect.asVoid(Fiber.join(put))),
86
86
  abort
87
87
  };
88
88
  });
@@ -177,7 +177,8 @@ const writeRows = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
177
177
  bucket,
178
178
  indexes,
179
179
  repo,
180
- pack: opened.pack
180
+ pack: opened.pack,
181
+ at
181
182
  })));
182
183
  return {
183
184
  pack: {
@@ -147,6 +147,15 @@ const receivedObject = (change, row) => {
147
147
  */
148
148
  const wholePageRows = 1e3;
149
149
  /**
150
+ * Object rows one `rowHeaders` read asks for by key while its reader knows no staged batch: its A
151
+ * read then carries no size markers, so sizing a tree's 1,000 blobs is one store read rather than
152
+ * ten (#2974). A group too large for one answer, or one whose read lists a batch, is answered again
153
+ * as `rowReadBatch` groups, so step B never reads more than `rowReadBatch` IDs' markers. A header
154
+ * read keeps no row past its answer; a whole-object read stays at `rowReadBatch`, so a push's thin
155
+ * bases still stream a group at a time.
156
+ */
157
+ const headerReadRows = 1e3;
158
+ /**
150
159
  * Object rows a store read refused as too large is cut into: as many of the largest as one answer
151
160
  * holds, each row's key and version aside, so no read of them passes its 16 MiB.
152
161
  */
@@ -237,8 +246,10 @@ const batchesMoved = () => fail("UNAVAILABLE", "Other pushes kept publishing lar
237
246
  });
238
247
  /**
239
248
  * Each of `ids`' object rows the repo holds, in `objects` or in a published staged batch, handed to
240
- * `each` a store read at a time: `rowReadBatch` IDs to a group, and the reads end once `each`
241
- * answers `false`. An ID is missing only when its last read of `objects` missed and every batch
249
+ * `each` a store read at a time: `groupSize` IDs to a group while the reader knows no batch,
250
+ * `rowReadBatch` once it does, and the reads end once `each` answers `false`. A wide group's A
251
+ * read hands what `objects` holds, then answers its misses as `rowReadBatch` groups when it listed
252
+ * a batch, and the whole group as them when it was too large. An ID is missing only when its last read of `objects` missed and every batch
242
253
  * that read listed was checked for it in a read that already listed that batch: a published
243
254
  * batch's rows and size markers are fixed at its publication and leave it only into `objects`,
244
255
  * which keeps them while any batch is listed, so the answer holds at that last read. Answers for
@@ -256,7 +267,7 @@ const batchesMoved = () => fail("UNAVAILABLE", "Other pushes kept publishing lar
256
267
  * - Recovery: any body key gone (promoted or removed as a duplicate after the marker hit) is read
257
268
  * in one call from `objects/<gone>` with `batches`.
258
269
  */
259
- const eachRead = (store, repo, ids, each) => {
270
+ const eachRead = (store, repo, ids, each, groupSize = 100) => {
260
271
  const scope = repoScope(repo);
261
272
  const read = (reads) => store.read({
262
273
  scope,
@@ -373,14 +384,26 @@ const eachRead = (store, repo, ids, each) => {
373
384
  }
374
385
  return true;
375
386
  });
376
- for (let at = 0; at < asked.length; at += 100) if (!(yield* resolveGroup(asked.slice(at, at + 100)))) return;
387
+ const resolveWide = Effect.fnUntraced(function* (oids) {
388
+ const wide = yield* readSnapshot(oids, []).pipe(orTooLarge);
389
+ if (wide !== void 0 && !(yield* hand(wide.objectRows))) return false;
390
+ if (wide !== void 0) known = wide.listed;
391
+ const rest = wide === void 0 ? oids : known.length === 0 ? [] : wide.misses;
392
+ for (let at = 0; at < rest.length; at += 100) if (!(yield* resolveGroup(rest.slice(at, at + 100)))) return false;
393
+ return true;
394
+ });
395
+ for (let at = 0; at < asked.length;) {
396
+ const group = asked.slice(at, at + (known.length === 0 ? groupSize : 100));
397
+ at += group.length;
398
+ if (!(yield* group.length > 100 ? resolveWide(group) : resolveGroup(group))) return;
399
+ }
377
400
  });
378
401
  };
379
402
  /** Each of `oids`' rows the repo holds, handed to `each` a store read at a time, as `eachRead` reads. */
380
- const eachRow = (store, listed, oids, each) => eachRead(store, listed.repo, oids, Effect.fnUntraced(function* (rows) {
403
+ const eachRow = (store, listed, oids, each, groupSize = 100) => eachRead(store, listed.repo, oids, Effect.fnUntraced(function* (rows) {
381
404
  for (const row of rows) yield* each(row);
382
405
  return true;
383
- }));
406
+ }), groupSize);
384
407
  /**
385
408
  * Which of `ids` a repo holds as object rows, read by key as `eachRead` reads, each read at
386
409
  * `version`: `undefined` once one answers at another, since the repo moved after the read the
@@ -656,7 +679,7 @@ const rowHeaders = (store, listed, onRow, cache) => Effect.fnUntraced(function*
656
679
  if (cache !== void 0 && chunkedOf(row.value) === void 0) cache.putRaw(row, header);
657
680
  headers.set(row.id, header);
658
681
  onRow?.(row, header);
659
- }));
682
+ }), headerReadRows);
660
683
  return headers;
661
684
  });
662
685
  /** The size of each of `oids`' rows the repo holds, as `rowHeaders` reads it. */
@@ -769,4 +792,4 @@ const startingOf = (found, most) => {
769
792
  more: all.length > most
770
793
  };
771
794
  };
772
- export { ObjectRow, bodyPackBytes, copyRowsPage, eachHeldRow, eachPageAt, emptyTreeObject, gitObjectOf, headerOfRow, heldIdsAt, heldRows, largeBatch, noRows, objectKey, objectOfRow, objectRow, readStagedRows, readsOwnChunks, receivedObject, receivedRows, rowAt, rowHeaders, rowInflatedBytes, rowSizes, rowValueBytes, rowsInflatedBytes, rowsMoved, rowsStartingWith, startingOf, tooLargeRead, wholePageRows };
795
+ export { ObjectRow, bodyPackBytes, copyRowsPage, eachHeldRow, eachPageAt, emptyTreeObject, gitObjectOf, headerOfRow, headerReadRows, heldIdsAt, heldRows, largeBatch, noRows, objectKey, objectOfRow, objectRow, readStagedRows, readsOwnChunks, receivedObject, receivedRows, rowAt, rowHeaders, rowInflatedBytes, rowSizes, rowValueBytes, rowsInflatedBytes, rowsMoved, rowsStartingWith, startingOf, tooLargeRead, wholePageRows };
@@ -12,4 +12,5 @@ import "./pack-reads.mjs";
12
12
  import "./quarantine.mjs";
13
13
  import { Moment } from "@ref0/infra";
14
14
  import "effect/Effect";
15
+ import "effect/Clock";
15
16
  import "effect/Types";
@@ -286,14 +286,15 @@ const receivePack = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
286
286
  });
287
287
  /** `storePack` with a refused pack's runs, marker, files and row deleted. */
288
288
  const storeOrDrop = (input, opened) => {
289
- const { store, bucket, indexes, listed } = input;
290
- return Effect.scoped(storePack(input, opened)).pipe(Effect.onError(() => bestEffort(Effect.andThen(dropRuns(bucket, opened.pack), dropRefused({
289
+ const { store, bucket, indexes, listed, clock } = input;
290
+ return Effect.scoped(storePack(input, opened)).pipe(Effect.onError(() => bestEffort(Effect.andThen(dropRuns(bucket, opened.pack), Effect.suspend(() => dropRefused({
291
291
  store,
292
292
  bucket,
293
293
  indexes,
294
294
  repo: listed.repo,
295
- pack: opened.pack
296
- })))));
295
+ pack: opened.pack,
296
+ at: clock.currentTimeMillisUnsafe()
297
+ }))))));
297
298
  };
298
299
  /**
299
300
  * A step of `receivePack` under the quarantine `opened` for the run: the staged pack read on from
@@ -24,6 +24,7 @@ import { defaultRemapCpuMost, indexHolds } from "./index-remap.mjs";
24
24
  import { putHeldBytes } from "./put-holds.mjs";
25
25
  import { indexRowKey, isPackId, packFiles, prunePassKey } from "./layout.mjs";
26
26
  import { ReachCache, indexReach, reachCacheBytes, reachedRoots } from "./index-reach.mjs";
27
+ import { IndexStepFiles, indexStepFilesMost } from "./index-step-files.mjs";
27
28
  import { indexedVisible, setReachOf } from "./index-visible.mjs";
28
29
  import { PackIndexes, packReader, seedBytes } from "./pack-reads.mjs";
29
30
  import { maintainBatches, withBatchesDue } from "./batch-upkeep.mjs";
@@ -628,11 +629,15 @@ const packsWith = (options = {}, inner = {}) => {
628
629
  * with the scope.
629
630
  */
630
631
  const objectsAt = (listed, on, handles) => Effect.map(Effect.acquireRelease(openReader(listed, on, void 0, void 0, handles), (reader) => Effect.sync(() => reader.close())), (reader) => (oid) => reader.read({ oid }));
632
+ /** The tips' reaches a read walked, for tips with no stored bitmap yet. */
633
+ const reaches = new ReachCache(instanceRoomOf(budget, reachCacheBytes));
634
+ /** The index files a build's chained steps read again, kept from one step to the next (#596). */
635
+ const stepFiles = new IndexStepFiles(instanceRoomOf(budget, indexStepFilesMost));
631
636
  /** What a reach on the index reads through: a want check's, and a visible set's. */
632
637
  const reachParts = {
633
638
  bucket,
634
639
  budget,
635
- cache: new ReachCache(instanceRoomOf(budget, reachCacheBytes)),
640
+ cache: reaches,
636
641
  objects: (listed) => objectsAt(listed, { read: true }),
637
642
  indexes
638
643
  };
@@ -648,6 +653,7 @@ const packsWith = (options = {}, inner = {}) => {
648
653
  indexes,
649
654
  listed,
650
655
  at: clock.currentTimeMillisUnsafe(),
656
+ clock,
651
657
  prune,
652
658
  receive: input,
653
659
  memory,
@@ -790,6 +796,7 @@ const packsWith = (options = {}, inner = {}) => {
790
796
  staging: input.staging,
791
797
  sliceBytes: input.sliceBytes,
792
798
  partBytes: input.partBytes,
799
+ at: clock.currentTimeMillisUnsafe(),
793
800
  answer: {
794
801
  boundary: [],
795
802
  needs: [],
@@ -803,7 +810,8 @@ const packsWith = (options = {}, inner = {}) => {
803
810
  bucket,
804
811
  indexes,
805
812
  repo,
806
- pack
813
+ pack,
814
+ at: clock.currentTimeMillisUnsafe()
807
815
  })
808
816
  };
809
817
  /**
@@ -845,6 +853,7 @@ const packsWith = (options = {}, inner = {}) => {
845
853
  indexes,
846
854
  listed,
847
855
  at: clock.currentTimeMillisUnsafe(),
856
+ clock,
848
857
  prune,
849
858
  receive: {
850
859
  pack: new Blob([]).stream(),
@@ -1367,12 +1376,13 @@ const packsWith = (options = {}, inner = {}) => {
1367
1376
  ...visible === void 0 && { copyRows: (listed, input) => copyRowsPage(calls, listed, input) },
1368
1377
  index: {
1369
1378
  step: (listed, input) => {
1379
+ const kept = stepFiles.over(bucket, listed.repo);
1370
1380
  const raw = {
1371
1381
  store: base.store,
1372
- bucket
1382
+ bucket: kept
1373
1383
  };
1374
1384
  const unbounded = {
1375
- bucket,
1385
+ bucket: kept,
1376
1386
  store: base.store,
1377
1387
  budget,
1378
1388
  objects: (at, allotment, handles) => objectsAt(at, { upkeep: allotment }, handles)
@@ -1391,7 +1401,8 @@ const packsWith = (options = {}, inner = {}) => {
1391
1401
  }, listed, input).pipe(Effect.tap((answer) => answer.kind === "moved" && own !== void 0 ? countInto(own, "store", 1) : Effect.void));
1392
1402
  return own === void 0 ? step : Effect.provideService(step, CallBudget, own);
1393
1403
  };
1394
- return stepMost === void 0 ? counted(void 0) : Effect.flatMap(indexBudget(input, stepMost), counted);
1404
+ const step = stepMost === void 0 ? counted(void 0) : Effect.flatMap(indexBudget(input, stepMost), counted);
1405
+ return Effect.onExit(step, (exit) => Exit.isSuccess(exit) && exit.value.kind === "more" ? Effect.void : Effect.sync(() => stepFiles.clear()));
1395
1406
  },
1396
1407
  reach: (listed, input) => {
1397
1408
  const built = indexReach(reachParts, listed, input);
@@ -5,5 +5,6 @@ import "../contracts/ids.mjs";
5
5
  import "../contracts/store.mjs";
6
6
  import "./layout.mjs";
7
7
  import "./pack-reads.mjs";
8
+ import "./rows.mjs";
8
9
  import { JobInput, Key, Moment, Row } from "@ref0/infra";
9
10
  import "effect/Effect";
@@ -3,13 +3,29 @@ import { heldAddition } from "../store/repo-record.mjs";
3
3
  import { newChangeId, repoScope } from "../store/scopes.mjs";
4
4
  import { bucketDo, bucketPut } from "./calls.mjs";
5
5
  import { isPackId, markerKey, newPackId, packFileKeys } from "./layout.mjs";
6
+ import { receiveStepGrace } from "./receive-bounds.mjs";
6
7
  import { repackJobRow } from "./repack-job.mjs";
7
- import { QuarantineRow, decodeHeld, quarantineKey, quarantineRow, removeAt } from "./rows.mjs";
8
+ import { QuarantineRow, decodeHeld, quarantineKey, quarantineRow, removeAt, stagedKey } from "./rows.mjs";
8
9
  import { fail } from "../contracts/result.mjs";
9
10
  import * as Effect from "effect/Effect";
10
11
  // src/storage/quarantine.ts
11
12
  /** The marker that keeps `pack`'s bytes for `repo`: empty, under the pack's `by/`. */
12
13
  const putMarker = (bucket, pack, repo) => bucketPut(bucket, markerKey(pack, repo), /* @__PURE__ */ new Uint8Array(0));
14
+ /**
15
+ * `pack`'s `staged` row, for the keys a landing, an end or a drop of its receive left, due
16
+ * `receiveStepGrace` after `at`, and its files unless it `landed`. `at` is no earlier than any read
17
+ * of the receive's open quarantine by a step still running: a landing's or a drop's is its own
18
+ * try's, which another try's step read before, since its claim came after that try's lease, and
19
+ * `dropRefused`'s is its write's start or later, after its try's claim. Clean-up's is its own
20
+ * try's, after the commit that abandoned the quarantine, which no step read open past.
21
+ */
22
+ const stagedRow = (pack, at, landed = false) => ({
23
+ ...stagedKey(pack),
24
+ value: landed ? {
25
+ removeAt: at + receiveStepGrace,
26
+ landed
27
+ } : { removeAt: at + receiveStepGrace }
28
+ });
13
29
  /** How many markers a fork puts at once. */
14
30
  const sharing = 8;
15
31
  /** A marker for `repo` that's there already is the one a share would put. */
@@ -106,22 +122,31 @@ const whileOpen = /* @__PURE__ */ Effect.fnUntraced(function* ({ store, repo, pa
106
122
  }
107
123
  });
108
124
  /**
109
- * After a receive or a merge failed, its kept indexes let go, then its marker, files and
110
- * `quarantine` row deleted before its refusal is answered, marker first, as clean-up orders them,
111
- * so a refused write keeps nothing. A row clean-up abandoned meanwhile is clean-up's to delete. A
112
- * delete that fails, or other commits that keep moving the repo, leave the row for clean-up to end
113
- * at its `removeAt`. Its own failure is dropped: the write's is the one its caller sees.
125
+ * After a receive or a merge failed, its kept indexes let go, then its marker and files deleted
126
+ * before its refusal is answered, marker first, as clean-up orders them, so a refused write keeps
127
+ * nothing. Its `quarantine` row then gives way to a `staged` row, with `git.repack` due when it is:
128
+ * a put the write's interrupt gave up on, on R2 whose binding takes no signal, can still land after
129
+ * these deletes, and clean-up deletes the pack's files and prefix again `receiveStepGrace` on
130
+ * (#2999). Its marker was put before any of them. A row clean-up abandoned meanwhile is clean-up's
131
+ * to end, as it puts its own `staged` row. A delete that fails, or other commits that keep moving
132
+ * the repo, leave the row for clean-up to end at its `removeAt`. Its own failure is dropped: the
133
+ * write's is the one its caller sees.
114
134
  */
115
135
  const dropRefused = (input) => bestEffort(Effect.gen(function* () {
116
- const { store, bucket, repo, pack } = input;
136
+ const { store, bucket, repo, pack, at } = input;
117
137
  input.indexes.forget(pack);
118
138
  const keys = [markerKey(pack, repo), ...packFileKeys(pack)];
119
139
  yield* Effect.forEach(keys, (key) => bucketDo(bucket.remove(key)), { discard: true });
140
+ const staged = stagedRow(pack, at);
120
141
  yield* whileOpen({
121
142
  store,
122
143
  repo,
123
144
  pack
124
- }, { delete: [quarantineKey(pack)] });
145
+ }, {
146
+ put: [staged],
147
+ delete: [quarantineKey(pack)],
148
+ jobs: [repackJobRow(staged.value.removeAt)]
149
+ });
125
150
  }));
126
151
  /**
127
152
  * A push that ends with no commit that listed its pack commits its own `quarantine` row
@@ -139,4 +164,4 @@ const abandonOwn = ({ at, repackJobRow: repackAt, ...input }) => bestEffort(whil
139
164
  })],
140
165
  jobs: [repackAt(at)]
141
166
  }));
142
- export { abandonOwn, deletePackFiles, dropRefused, openQuarantine, putMarker, quarantineOf, quarantineState, sharePacks, stillOpen };
167
+ export { abandonOwn, deletePackFiles, dropRefused, openQuarantine, putMarker, quarantineOf, quarantineState, sharePacks, stagedRow, stillOpen };
@@ -109,7 +109,9 @@ const importTryTimeout = "13 minutes";
109
109
  * `staged` row's wait, from the landing, the end or the drop that left them. A step puts them
110
110
  * only inside an import's try, which the queue aborts at `importTryTimeout`, or a push upload's,
111
111
  * which it aborts sooner, at `jobTryTimeout`, after its claim and its read of its quarantine, so
112
- * it's bound by how long the longer of those tries' calls can run:
112
+ * it's bound by how long the longer of those tries' calls can run. A refused merge's `staged` row
113
+ * waits from its try's start, and a refused push's from its drop, as its request has no try to
114
+ * end its puts, so each waits out the puts it gave up on too (#2999):
113
115
  * - On Cloudflare, an alarm's `alarmWallTime`, 15 minutes from before the claim. R2's calls
114
116
  * through its binding take no signal, so one started before the try's timeout runs on, but
115
117
  * the alarm's end stops it.
@@ -7,8 +7,7 @@ import "./pack-receive.mjs";
7
7
  import "./pack-reads.mjs";
8
8
  import "./quarantine.mjs";
9
9
  import "./layout.mjs";
10
- import "./rows.mjs";
11
- import { Key, Moment, Row } from "@ref0/infra";
10
+ import { Key, Moment } from "@ref0/infra";
12
11
  import * as Schema from "effect/Schema";
13
12
  import "effect/Effect";
14
13
  /** One uploaded multipart receipt kept across staging tries, matching infra's `ListedPart`. */
@@ -12,12 +12,12 @@ import { putOnce } from "./index-build.mjs";
12
12
  import { packPutOptions, startPut } from "./merge.mjs";
13
13
  import { storeStep } from "./pack-receive.mjs";
14
14
  import { pushUploadMost } from "./push-uploads.mjs";
15
- import { deletePackFiles, dropRefused, openQuarantine, quarantineOf, quarantineState } from "./quarantine.mjs";
15
+ import { deletePackFiles, dropRefused, openQuarantine, quarantineOf, quarantineState, stagedRow } from "./quarantine.mjs";
16
16
  import { putStepState, readStepState, stepStateKeys } from "./receive-state.mjs";
17
17
  import { isPackId, markerPrefix, objectCollections, packFiles, receivePrefix } from "./layout.mjs";
18
18
  import { fileBytesMost } from "./file-limits.mjs";
19
19
  import { receiveCpuShare, receiveDropPage, receiveStepFloor, receiveStepGrace } from "./receive-bounds.mjs";
20
- import { decodeHeld, quarantineKey, stagedKey } from "./rows.mjs";
20
+ import { decodeHeld, quarantineKey } from "./rows.mjs";
21
21
  import * as Schema from "effect/Schema";
22
22
  import * as Effect from "effect/Effect";
23
23
  import * as Predicate from "effect/Predicate";
@@ -91,20 +91,6 @@ const commitStep = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
91
91
  return "lost";
92
92
  });
93
93
  /**
94
- * `pack`'s `staged` row, for the keys a landing, an end or a drop of its receive left, due
95
- * `receiveStepGrace` after `at`, and its files unless it `landed`. `at` is no earlier than any read of the receive's open quarantine
96
- * by a step still running: a landing's or a drop's is its own try's, which another try's step
97
- * read before, since its claim came after that try's lease. Clean-up's is its own try's, after the
98
- * commit that abandoned the quarantine, which no step read open past.
99
- */
100
- const stagedRow = (pack, at, landed = false) => ({
101
- ...stagedKey(pack),
102
- value: landed ? {
103
- removeAt: at + receiveStepGrace,
104
- landed
105
- } : { removeAt: at + receiveStepGrace }
106
- });
107
- /**
108
94
  * Every key under `pack`'s prefix but its markers, a page at a time, each page's through one
109
95
  * `bucketDeleteMany`, so its calls are charged as its batches are: its runs, its answer and its
110
96
  * steps' keys.
@@ -358,7 +344,8 @@ const stageReceiveStep = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
358
344
  bucket,
359
345
  indexes: input.indexes,
360
346
  repo,
361
- pack
347
+ pack,
348
+ at: input.at
362
349
  });
363
350
  return yield* failed;
364
351
  });
@@ -390,7 +377,8 @@ const stageReceiveStep = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
390
377
  bucket,
391
378
  indexes: input.indexes,
392
379
  repo,
393
- pack
380
+ pack,
381
+ at: input.at
394
382
  });
395
383
  return yield* stageGone(`A staged pack's multipart upload is gone at ${packKey}`);
396
384
  });
@@ -460,7 +448,8 @@ const stageReceiveStep = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
460
448
  bucket,
461
449
  indexes: input.indexes,
462
450
  repo,
463
- pack
451
+ pack,
452
+ at: input.at
464
453
  }) : Effect.void));
465
454
  const answer = {
466
455
  ...input.answer,
@@ -699,4 +688,4 @@ const receiveStep = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
699
688
  yield* bestEffort(bucketDeleteMany(bucket, Object.values(keys)));
700
689
  return ended;
701
690
  });
702
- export { ReceiveAnswer, ReceiveRow, StagePart, StageProgress, answerKey, commitStep, deleteStaged, dropReceive, newAttempt, openStageReceive, putAnswer, readAnswer, readReceive, receiveKey, receiveStep, stageReceive, stageReceiveStep, stageStepKey, stageStepOf, stagedRow, stepEntryMostOf, stepInflatedMostOf, stepShareOf, streamStepsMost };
691
+ export { ReceiveAnswer, ReceiveRow, StagePart, StageProgress, answerKey, commitStep, deleteStaged, dropReceive, newAttempt, openStageReceive, putAnswer, readAnswer, readReceive, receiveKey, receiveStep, stageReceive, stageReceiveStep, stageStepKey, stageStepOf, stepEntryMostOf, stepInflatedMostOf, stepShareOf, streamStepsMost };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ref0/git",
3
- "version": "0.30.0",
3
+ "version": "0.32.0",
4
4
  "private": false,
5
5
  "description": "Git hosting as a library: a server, a client and their merges",
6
6
  "license": "Apache-2.0",
@@ -51,11 +51,11 @@
51
51
  }
52
52
  },
53
53
  "dependencies": {
54
- "@ref0/infra": "0.30.0"
54
+ "@ref0/infra": "0.32.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@effect/vitest": "4.1.7",
58
- "@ref0/xdiff-wasm": "0.30.0",
58
+ "@ref0/xdiff-wasm": "0.32.0",
59
59
  "effect": "4.1.7",
60
60
  "vite-plus": "1.8.0",
61
61
  "vitest": "5.1.1",