@ref0/git 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access/private-refs.mjs +5 -4
- package/dist/contracts/forks.d.mts +3 -2
- package/dist/contracts/git.d.mts +23 -5
- package/dist/contracts/result.d.mts +7 -5
- package/dist/contracts/result.mjs +7 -5
- package/dist/contracts/sync.d.mts +11 -0
- package/dist/core/access.d.mts +1 -0
- package/dist/core/access.mjs +10 -11
- package/dist/core/asked.mjs +30 -0
- package/dist/core/events/deliver.d.mts +1 -0
- package/dist/core/events/deliver.mjs +5 -1
- package/dist/core/forks.mjs +39 -13
- package/dist/core/imports.mjs +9 -4
- package/dist/core/objects/reading.mjs +17 -9
- package/dist/core/parts.d.mts +2 -1
- package/dist/core/push.mjs +11 -8
- package/dist/core/refs.mjs +6 -3
- package/dist/core/registered-rows.d.mts +1 -0
- package/dist/core/registered-rows.mjs +7 -5
- package/dist/core/repack.mjs +5 -3
- package/dist/core/saved-caller-views.d.mts +18 -0
- package/dist/core/saved-caller-views.mjs +17 -4
- package/dist/core/saved-callers-public.d.mts +3 -3
- package/dist/core/saved-callers-public.mjs +3 -2
- package/dist/core/saved-callers.d.mts +7 -0
- package/dist/extend.d.mts +2 -1
- package/dist/extend.mjs +2 -1
- package/dist/http/push-uploads.mjs +6 -3
- package/dist/lfs/locks.mjs +14 -9
- package/dist/lfs/objects.mjs +27 -20
- package/dist/queue/calls.mjs +21 -1
- package/dist/rest/blobs.d.mts +15 -15
- package/dist/rest/commits.d.mts +191 -191
- package/dist/rest/files.d.mts +70 -70
- package/dist/rest/forks.d.mts +72 -72
- package/dist/rest/layer.mjs +8 -1
- package/dist/rest/queue.d.mts +212 -212
- package/dist/rest/refs.d.mts +148 -148
- package/dist/rest/repos.d.mts +47 -47
- package/dist/rest/tags.d.mts +76 -76
- package/dist/rest/tokens.d.mts +101 -101
- package/dist/rest/topics.d.mts +112 -112
- package/dist/rest/trees.d.mts +73 -73
- package/dist/rest/work.d.mts +39 -39
- package/dist/server/git-namespace.d.mts +3 -3
- package/dist/server/server.mjs +6 -4
- package/dist/storage/memory-budget.mjs +128 -6
- package/dist/storage/merge-cut.mjs +5 -4
- package/dist/storage/pack-reads.mjs +239 -27
- package/dist/storage/prune-seen.mjs +11 -6
- package/dist/storage/prune-walk.mjs +168 -68
- package/dist/storage/quarantine.mjs +2 -0
- package/dist/store/repo-record.d.mts +25 -0
- package/dist/store/repo-record.mjs +55 -1
- package/dist/sync/github.mjs +10 -1
- package/dist/sync/import.mjs +3 -2
- package/dist/sync/mirror.mjs +24 -17
- package/dist/sync/said.mjs +204 -0
- package/dist/sync/step.mjs +8 -8
- package/dist/sync/tries.mjs +34 -18
- package/dist/topics/advance.mjs +10 -3
- package/package.json +3 -3
|
@@ -7,8 +7,8 @@ import { readerFloors, readerMost } from "./budget.mjs";
|
|
|
7
7
|
import { readWhole } from "./calls.mjs";
|
|
8
8
|
import { putOnce } from "./index-build.mjs";
|
|
9
9
|
import { runKey } from "./layout.mjs";
|
|
10
|
-
import { pruneSeenBytes, upkeepMemoryOf, upkeepRuns, upkeepTooLarge } from "./memory-budget.mjs";
|
|
11
|
-
import { blockBytes, blocksHeld, indexBytes, packReader } from "./pack-reads.mjs";
|
|
10
|
+
import { pruneIndexFloor, pruneSeenBytes, upkeepMemoryOf, upkeepRuns, upkeepTooLarge } from "./memory-budget.mjs";
|
|
11
|
+
import { blockBytes, blocksHeld, indexBytes, isIndexReloaded, isIndexShort, packReader } from "./pack-reads.mjs";
|
|
12
12
|
import { SeenSaved, seenSet } from "./prune-seen.mjs";
|
|
13
13
|
import { StoredRuns, dedupeTableBytes, dropRuns, mergeHeld, mergeRuns, narrowed, narrowedCalls, runWriter, writerHeld } from "./runs.mjs";
|
|
14
14
|
import { countedReads } from "./walk.mjs";
|
|
@@ -196,14 +196,34 @@ const pruneWalk = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, star
|
|
|
196
196
|
const outsideMost = rows + named;
|
|
197
197
|
const namesBytes = (saved === void 0 ? named : history?.pending.rows ?? 0) * 70;
|
|
198
198
|
const seenBytes = saved?.phase === "trees" ? 0 : pruneSeenBytes(listed.packs, outsideMost);
|
|
199
|
+
const past = listed.packs.find((each) => indexBytes(each) > pruneIndexFloor);
|
|
200
|
+
if (past !== void 0) return yield* new PruneWalkTooLarge({ message: `pack ${past.id}'s index takes ${indexBytes(past)} bytes, past the ${pruneIndexFloor} a prune walk's reader holds` });
|
|
199
201
|
const indexes = listed.packs.reduce((sum, each) => sum + indexBytes(each), 0);
|
|
200
|
-
|
|
202
|
+
let loadNeeds = () => 3;
|
|
203
|
+
let shortBy;
|
|
204
|
+
let loads = 0;
|
|
205
|
+
const canLoad = () => {
|
|
206
|
+
const needs = loadNeeds();
|
|
207
|
+
loads += 1;
|
|
208
|
+
if (loads === 1 || fits(calls, needs)) return true;
|
|
209
|
+
shortBy = needs;
|
|
210
|
+
return false;
|
|
211
|
+
};
|
|
212
|
+
const room = {
|
|
213
|
+
bytes: Math.min(indexes, pruneIndexFloor),
|
|
214
|
+
unlisted: outsideMost,
|
|
215
|
+
canLoad
|
|
216
|
+
};
|
|
217
|
+
const evicts = room.bytes < indexes;
|
|
218
|
+
const unlistedBytes = outsideMost * 70;
|
|
219
|
+
const charge = pruneWalkHeld(sizes) + namesBytes + seenBytes + room.bytes + unlistedBytes;
|
|
201
220
|
if (charge - own > allotment.growable) return yield* new PruneWalkTooLarge({ message: `its walk charges ${charge} bytes with its packs' indexes, past the ${own + allotment.growable} its allotment holds: the repo is past what one prune walk holds` });
|
|
202
|
-
const heldBytes = namesBytes + seenBytes;
|
|
221
|
+
const heldBytes = namesBytes + seenBytes + unlistedBytes;
|
|
203
222
|
yield* Effect.acquireRelease(allotment.grow(heldBytes, upkeepTooLarge), () => Effect.sync(() => allotment.shrink(heldBytes)));
|
|
204
223
|
const reader = packReader({
|
|
205
224
|
...input,
|
|
206
|
-
memory
|
|
225
|
+
memory,
|
|
226
|
+
indexFloor: room
|
|
207
227
|
});
|
|
208
228
|
let held = 0;
|
|
209
229
|
yield* Effect.addFinalizer(() => Effect.sync(() => allotment.shrink(held)));
|
|
@@ -218,25 +238,43 @@ const pruneWalk = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, star
|
|
|
218
238
|
...reader,
|
|
219
239
|
roots
|
|
220
240
|
}, objects + 1e6, charged, void 0, release);
|
|
221
|
-
/**
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return false;
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
return at;
|
|
241
|
+
/**
|
|
242
|
+
* `lookup`'s answer, or `undefined` once it needs a pack whose index the reader's room let go
|
|
243
|
+
* of, or a load past `loadNeeds`, which ends the try where it is, as one short of calls does
|
|
244
|
+
* (#2230).
|
|
245
|
+
*/
|
|
246
|
+
const unlessReloaded = (lookup) => lookup.pipe(Effect.catchIf((error) => isIndexReloaded(error) || isIndexShort(error), () => Effect.succeed(void 0)));
|
|
247
|
+
/** A level stopped before `trees` on a lookup `unlessReloaded` ended: past the room or the calls. */
|
|
248
|
+
const stoppedOn = (trees) => shortBy === void 0 ? new WalkStopped({
|
|
249
|
+
trees,
|
|
250
|
+
needs: 0,
|
|
251
|
+
reloaded: true
|
|
252
|
+
}) : new WalkStopped({
|
|
253
|
+
trees,
|
|
254
|
+
needs: shortBy
|
|
239
255
|
});
|
|
256
|
+
/** `groups` as one list, and the end of each in it, so a batch takes from one group. */
|
|
257
|
+
const grouped = (groups) => {
|
|
258
|
+
const ends = [];
|
|
259
|
+
let end = 0;
|
|
260
|
+
for (const group of groups) {
|
|
261
|
+
end += group.length;
|
|
262
|
+
ends.push(end);
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
oids: groups.flat(),
|
|
266
|
+
ends
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* `ids` split in two, those to look up now and those after: a try's first alone while the room
|
|
271
|
+
* may let packs go, so its lookups need one pack's index, or every pack's once for an ID none
|
|
272
|
+
* holds, and the try moves. Many at once may let go of a pack they're in, which a try that
|
|
273
|
+
* moved ends on, to go on in the next (#2230).
|
|
274
|
+
*/
|
|
275
|
+
const alone = (ids) => !moved && evicts && ids.length > 1 ? [ids.slice(0, 1), ids.slice(1)] : [ids, []];
|
|
276
|
+
/** The end of the group `at` is in, of `ends`. */
|
|
277
|
+
const groupEnd = (ends, at) => ends.find((end) => end > at) ?? at;
|
|
240
278
|
/** Lets go of what `found` holds of `batch`, once each of it is put. */
|
|
241
279
|
const letGo = (found, batch) => {
|
|
242
280
|
for (const object of found.values()) reads.letGo(object);
|
|
@@ -346,6 +384,7 @@ const pruneWalk = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, star
|
|
|
346
384
|
let moved = false;
|
|
347
385
|
const most = calls === void 0 ? 0 : Math.min(calls.most.bucket, calls.most.subrequests);
|
|
348
386
|
const tooMany = (step, needs) => new PruneWalkTooLarge({ message: `${step} needs about ${needs} calls, past the ${most} a try makes` });
|
|
387
|
+
const pastRoom = (step) => new PruneWalkTooLarge({ message: `${step} needs more packs' indexes than the ${room.bytes} bytes its reader holds` });
|
|
349
388
|
let refs;
|
|
350
389
|
if (saved === void 0) {
|
|
351
390
|
const refsWriter = writer("refs", sizes.runBytes);
|
|
@@ -367,7 +406,7 @@ const pruneWalk = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, star
|
|
|
367
406
|
let prior;
|
|
368
407
|
let seenFrom;
|
|
369
408
|
if (history !== void 0) {
|
|
370
|
-
const rebuild = narrowedCalls(history.reached.lengths, rowBytes, sizes.runs, input.bucket.multipart).calls + narrowedCalls(history.frontier.lengths, rowBytes, sizes.runs, input.bucket.multipart).calls + mergeCalls(history.pending) + 1;
|
|
409
|
+
const rebuild = narrowedCalls(history.reached.lengths, rowBytes, sizes.runs, input.bucket.multipart).calls + narrowedCalls(history.frontier.lengths, rowBytes, sizes.runs, input.bucket.multipart).calls + mergeCalls(history.pending) + 1 + (history.seen.outside === 0 ? 0 : 3 * listed.packs.filter(({ id }) => !history.seen.packs.some((each) => each.id === id)).length);
|
|
371
410
|
if (!fits(calls, rebuild + 6)) return yield* tooMany("a history resume", rebuild + 6);
|
|
372
411
|
const bytes = yield* readWhole(input.bucket, history.seen.key);
|
|
373
412
|
if (bytes === void 0) return yield* Effect.fail(gitError("DATA_LOSS", `The walk's seen object ${history.seen.key} is gone`));
|
|
@@ -388,59 +427,107 @@ const pruneWalk = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, star
|
|
|
388
427
|
}
|
|
389
428
|
const seen = yield* seenSet(listed.packs, outsideMost, seenFrom === void 0 ? void 0 : {
|
|
390
429
|
...seenFrom,
|
|
391
|
-
place:
|
|
430
|
+
place: (oids) => reader.ranks(oids, new Set(seenFrom?.saved.packs.map(({ id }) => id)))
|
|
392
431
|
});
|
|
432
|
+
if (seenFrom !== void 0) reader.release();
|
|
433
|
+
loadNeeds = () => 8 + putCalls(names.length + parents.length);
|
|
393
434
|
const reached = writer("reached-0", sizes.runBytes);
|
|
394
435
|
const frontier = frontierWriter("frontier-0");
|
|
436
|
+
/** Where the history is, saved for the next try: its runs, the IDs yet to read, and its seen set. */
|
|
437
|
+
const savedHistory = Effect.fnUntraced(function* () {
|
|
438
|
+
const reachedRuns = yield* reached.finish;
|
|
439
|
+
const frontierRuns = yield* frontier.finish;
|
|
440
|
+
const pending = writer("pending", sizes.runBytes);
|
|
441
|
+
for (const oid of names) yield* put(pending, oidBytes(oid), tags.tree);
|
|
442
|
+
for (const oid of parents) yield* put(pending, oidBytes(oid), tags.reached);
|
|
443
|
+
const key = runKey(pack, `seen.${tried}`, 0);
|
|
444
|
+
const { layout, bytes } = seen.saved(key);
|
|
445
|
+
yield* putOnce(input.bucket, key, bytes);
|
|
446
|
+
return { more: {
|
|
447
|
+
phase: "history",
|
|
448
|
+
count: seen.size(),
|
|
449
|
+
seen: layout,
|
|
450
|
+
refs,
|
|
451
|
+
reached: after(prior?.reached, reachedRuns),
|
|
452
|
+
frontier: after(prior?.frontier, frontierRuns),
|
|
453
|
+
pending: yield* pending.finish,
|
|
454
|
+
known: knownRuns
|
|
455
|
+
} };
|
|
456
|
+
});
|
|
457
|
+
/** The try ended where it is: saved, or refused if it walked nothing. */
|
|
458
|
+
const stopHere = () => moved ? savedHistory() : Effect.fail(shortBy === void 0 ? pastRoom("a history batch") : tooMany("a history batch", shortBy));
|
|
459
|
+
/**
|
|
460
|
+
* The next IDs to read, the names' before the parents': those the first pack that holds some
|
|
461
|
+
* of them holds, as `nextPack` finds it, or all of them once no listed pack holds any;
|
|
462
|
+
* `undefined` once only packs the room let go of may hold what's left, which the next try
|
|
463
|
+
* reads.
|
|
464
|
+
*/
|
|
465
|
+
const nextLevel = Effect.fnUntraced(function* () {
|
|
466
|
+
for (const fromNames of [true, false]) {
|
|
467
|
+
const pool = fromNames ? names : parents;
|
|
468
|
+
if (pool.length === 0) continue;
|
|
469
|
+
const { placed, unlisted } = yield* reader.nextPack(pool);
|
|
470
|
+
if (placed.size === 0 && !unlisted) continue;
|
|
471
|
+
const level = unlisted ? [...new Set(pool)] : [...placed.keys()];
|
|
472
|
+
const rest = unlisted ? [] : pool.filter((oid) => !placed.has(oid));
|
|
473
|
+
if (fromNames) names = rest;
|
|
474
|
+
else parents = rest;
|
|
475
|
+
return {
|
|
476
|
+
fromNames,
|
|
477
|
+
level,
|
|
478
|
+
placed
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
});
|
|
395
482
|
while (names.length > 0 || parents.length > 0) {
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
483
|
+
const step = yield* unlessReloaded(nextLevel());
|
|
484
|
+
if (step === void 0) return yield* stopHere();
|
|
485
|
+
const { fromNames, level, placed } = step;
|
|
486
|
+
const back = (at) => {
|
|
487
|
+
if (fromNames) names = [...level.slice(at), ...names];
|
|
488
|
+
else parents = [...level.slice(at), ...parents];
|
|
489
|
+
};
|
|
400
490
|
for (let at = 0; at < level.length;) {
|
|
401
491
|
const left = level.length - at + names.length + parents.length;
|
|
402
|
-
const
|
|
492
|
+
const admission = yield* unlessReloaded(admitted(level.slice(at, at + 64), 5 + putCalls(left)));
|
|
493
|
+
if (admission === void 0) {
|
|
494
|
+
back(at);
|
|
495
|
+
return yield* stopHere();
|
|
496
|
+
}
|
|
497
|
+
const { count: admits, needs } = admission;
|
|
403
498
|
if (admits === 0) {
|
|
404
499
|
if (!moved) return yield* tooMany("a history batch", needs);
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
const pending = writer("pending", sizes.runBytes);
|
|
408
|
-
const rest = level.slice(at);
|
|
409
|
-
for (const oid of fromNames ? [...rest, ...names] : names) yield* put(pending, oidBytes(oid), tags.tree);
|
|
410
|
-
for (const oid of fromNames ? parents : [...rest, ...parents]) yield* put(pending, oidBytes(oid), tags.reached);
|
|
411
|
-
const key = runKey(pack, `seen.${tried}`, 0);
|
|
412
|
-
const { layout, bytes } = seen.saved(key);
|
|
413
|
-
yield* putOnce(input.bucket, key, bytes);
|
|
414
|
-
return { more: {
|
|
415
|
-
phase: "history",
|
|
416
|
-
count: seen.size(),
|
|
417
|
-
seen: layout,
|
|
418
|
-
refs,
|
|
419
|
-
reached: after(prior?.reached, reachedRuns),
|
|
420
|
-
frontier: after(prior?.frontier, frontierRuns),
|
|
421
|
-
pending: yield* pending.finish,
|
|
422
|
-
known: knownRuns
|
|
423
|
-
} };
|
|
500
|
+
back(at);
|
|
501
|
+
return yield* savedHistory();
|
|
424
502
|
}
|
|
425
|
-
moved = true;
|
|
426
503
|
const slice = level.slice(at, at + admits);
|
|
504
|
+
const looked = yield* unlessReloaded(Effect.gen(function* () {
|
|
505
|
+
const blobs = fromNames ? yield* reader.wholeBlobs(slice) : /* @__PURE__ */ new Set();
|
|
506
|
+
const unread = [...new Set(slice)].filter((oid) => !blobs.has(oid) && !seen.has(oid, placed.get(oid)));
|
|
507
|
+
return {
|
|
508
|
+
blobs,
|
|
509
|
+
unread,
|
|
510
|
+
found: unread.length === 0 ? /* @__PURE__ */ new Map() : yield* reads(unread)
|
|
511
|
+
};
|
|
512
|
+
}));
|
|
513
|
+
if (looked === void 0) {
|
|
514
|
+
back(at);
|
|
515
|
+
return yield* stopHere();
|
|
516
|
+
}
|
|
517
|
+
const { blobs, unread, found } = looked;
|
|
518
|
+
moved = true;
|
|
427
519
|
at += admits;
|
|
428
|
-
const blobs = fromNames ? yield* reader.wholeBlobs(slice) : /* @__PURE__ */ new Set();
|
|
429
|
-
const ranked = yield* ranksOf(slice);
|
|
430
|
-
const batch = [];
|
|
431
520
|
for (const oid of slice) {
|
|
432
|
-
const
|
|
433
|
-
const added = seen.add(oid, ranked.get(oid));
|
|
521
|
+
const added = seen.add(oid, placed.get(oid));
|
|
434
522
|
if (added === "full") return yield* Effect.fail(gitError("DATA_LOSS", `The walk reaches more than ${outsideMost} objects no listed pack holds: past its rows and refs`));
|
|
435
523
|
if (!added) continue;
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
524
|
+
const id = oidBytes(oid);
|
|
525
|
+
if (blobs.has(oid)) {
|
|
526
|
+
yield* put(reached, id, tags.reached);
|
|
527
|
+
continue;
|
|
528
|
+
}
|
|
441
529
|
const object = yield* foundOf(found, oid);
|
|
442
530
|
if (object === void 0) continue;
|
|
443
|
-
const id = oidBytes(oid);
|
|
444
531
|
if (object.type === "tree") {
|
|
445
532
|
yield* put(frontier, id, tags.tree);
|
|
446
533
|
continue;
|
|
@@ -450,7 +537,7 @@ const pruneWalk = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, star
|
|
|
450
537
|
if (object.type === "tag") names.push(...object.history);
|
|
451
538
|
else parents.push(...object.history);
|
|
452
539
|
}
|
|
453
|
-
if (
|
|
540
|
+
if (unread.length > 0) yield* letGo(found, unread);
|
|
454
541
|
}
|
|
455
542
|
}
|
|
456
543
|
runs = after(prior?.reached, yield* reached.finish);
|
|
@@ -465,6 +552,7 @@ const pruneWalk = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, star
|
|
|
465
552
|
const goesOn = within;
|
|
466
553
|
within = void 0;
|
|
467
554
|
const needs = reserve + 2 + saveCalls;
|
|
555
|
+
loadNeeds = () => 3 + reserve + saveCalls;
|
|
468
556
|
if (!fits(calls, needs)) {
|
|
469
557
|
if (!moved) return yield* tooMany(`level ${depth}`, needs);
|
|
470
558
|
return { more: {
|
|
@@ -481,17 +569,29 @@ const pruneWalk = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, star
|
|
|
481
569
|
let trees = [];
|
|
482
570
|
const last = goesOn === void 0 ? /* @__PURE__ */ new Uint8Array(20) : oidBytes(goesOn.last);
|
|
483
571
|
const readTrees = Effect.fnUntraced(function* () {
|
|
484
|
-
|
|
485
|
-
|
|
572
|
+
while (trees.length > 0) {
|
|
573
|
+
const [asked, rest] = alone(trees);
|
|
574
|
+
trees = rest;
|
|
575
|
+
yield* readSome(asked);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
const readSome = Effect.fnUntraced(function* (asked) {
|
|
579
|
+
const groups = yield* unlessReloaded(reader.inPackGroups(asked));
|
|
580
|
+
if (groups === void 0) return yield* stoppedOn(asked);
|
|
581
|
+
const { oids: ordered, ends } = grouped(groups);
|
|
582
|
+
const stoppedAt = (at) => stoppedOn(ordered.slice(at));
|
|
486
583
|
for (let at = 0; at < ordered.length;) {
|
|
487
|
-
const next = ordered.slice(at, at + 64);
|
|
488
|
-
const
|
|
584
|
+
const next = ordered.slice(at, Math.min(at + 64, groupEnd(ends, at)));
|
|
585
|
+
const admission = yield* unlessReloaded(admitted(next, reserve + saveCalls));
|
|
586
|
+
if (admission === void 0) return yield* stoppedAt(at);
|
|
587
|
+
const { count, needs } = admission;
|
|
489
588
|
if (count === 0) return yield* new WalkStopped({
|
|
490
589
|
trees: ordered.slice(at),
|
|
491
590
|
needs
|
|
492
591
|
});
|
|
493
592
|
const batch = next.slice(0, count);
|
|
494
|
-
const found = yield* reads(batch);
|
|
593
|
+
const found = yield* unlessReloaded(reads(batch));
|
|
594
|
+
if (found === void 0) return yield* stoppedAt(at);
|
|
495
595
|
for (const [index, oid] of batch.entries()) {
|
|
496
596
|
const object = yield* foundOf(found, oid);
|
|
497
597
|
if (object === void 0) continue;
|
|
@@ -536,7 +636,7 @@ const pruneWalk = /* @__PURE__ */ Effect.fnUntraced(function* (input, pack, star
|
|
|
536
636
|
});
|
|
537
637
|
const stopped = yield* Effect.as(walked, void 0).pipe(Effect.catchTag("WalkStopped", (stop) => Effect.succeed(stop)));
|
|
538
638
|
if (stopped !== void 0) {
|
|
539
|
-
if (!moved) return yield* tooMany(`a tree at level ${depth}`, stopped.needs);
|
|
639
|
+
if (!moved) return yield* stopped.reloaded === true ? pastRoom(`a tree at level ${depth}`) : tooMany(`a tree at level ${depth}`, stopped.needs);
|
|
540
640
|
const levelRuns = after(goesOn?.reached, yield* level.finish);
|
|
541
641
|
const frontierRuns = after(goesOn?.frontier, yield* frontier.finish);
|
|
542
642
|
const pending = writer(`trees-${depth}`, sizes.runBytes);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { bestEffort } from "../store/errors.mjs";
|
|
2
|
+
import { heldInTime } from "../store/repo-record.mjs";
|
|
2
3
|
import { newChangeId, repoScope } from "../store/scopes.mjs";
|
|
3
4
|
import { bucketDo, bucketPut } from "./calls.mjs";
|
|
4
5
|
import { isPackId, markerKey, newPackId, packFileKeys } from "./layout.mjs";
|
|
@@ -36,6 +37,7 @@ const openQuarantine = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
|
|
|
36
37
|
const { store, bucket, repo, at, prune } = input;
|
|
37
38
|
const pack = newPackId();
|
|
38
39
|
const due = removeAt(at, prune);
|
|
40
|
+
yield* heldInTime(`The push's pack for repo ${repo}`);
|
|
39
41
|
yield* store.add({
|
|
40
42
|
scope: repoScope(repo),
|
|
41
43
|
addition: {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import "../contracts/promises.mjs";
|
|
2
|
+
import "../contracts/access.mjs";
|
|
3
|
+
import { EffectiveLimits } from "../contracts/objects.mjs";
|
|
4
|
+
import "../contracts/ids.mjs";
|
|
5
|
+
import "../contracts/repos.mjs";
|
|
6
|
+
import "../contracts/store.mjs";
|
|
7
|
+
import "../protocol/objects/commit.mjs";
|
|
8
|
+
import "../contracts/result.mjs";
|
|
9
|
+
import "./records.mjs";
|
|
10
|
+
import * as Effect from "effect/Effect";
|
|
11
|
+
import "effect/Schema";
|
|
12
|
+
import { Addition, Count, JobInput, Key, Moment, Read, Row, Scope, Snapshot } from "@ref0/infra";
|
|
13
|
+
import "effect/Context";
|
|
14
|
+
import "effect/Types";
|
|
15
|
+
/**
|
|
16
|
+
* When a write to a repo's scope must begin its store call by, after a read at `heldAt` found the
|
|
17
|
+
* repo's record live: `heldAt` plus `fetchLimits.milliseconds`, less `jobLeaseMargin`. The repo
|
|
18
|
+
* was live at that read, so its delete came later, and its purge drops its scopes no sooner than
|
|
19
|
+
* `fetchLimits` past the delete, the record's `changedAt`: a call begun by then lands before the
|
|
20
|
+
* drop, with the lease margin for the call itself, as `git.repack`'s `remapLate` keeps it (#1911).
|
|
21
|
+
* It assumes the store call ends inside that margin: no store call is bounded below it yet (#2331).
|
|
22
|
+
*/
|
|
23
|
+
export declare const heldUntil: (heldAt: Moment, fetchLimits: EffectiveLimits) => Moment;
|
|
24
|
+
/** Whether a write may still begin its store call, by `heldUntil`'s `by`, at the clock's now. */
|
|
25
|
+
export declare const inTime: (by: Moment) => Effect.Effect<boolean>;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { noRepoRoots } from "../protocol/objects/commit.mjs";
|
|
2
2
|
import { checkChurn, decodeRecord, entryOf, project } from "./catalogue.mjs";
|
|
3
3
|
import { afterCommit } from "./call-count.mjs";
|
|
4
|
+
import { fail } from "../contracts/result.mjs";
|
|
4
5
|
import { afterWrites, decodeRow, storeCall } from "./errors.mjs";
|
|
5
6
|
import { listJobRow } from "./list-job.mjs";
|
|
6
7
|
import { LooseTally, RepoRootsRow, StatsTime } from "./records.mjs";
|
|
7
8
|
import { looseKey, maintainedKey, newChangeId, pushedKey, repoScope, selfKey } from "./scopes.mjs";
|
|
9
|
+
import * as Clock$1 from "effect/Clock";
|
|
8
10
|
import * as Effect from "effect/Effect";
|
|
11
|
+
import * as Schema from "effect/Schema";
|
|
12
|
+
import { jobLeaseMargin } from "@ref0/infra";
|
|
13
|
+
import * as Context from "effect/Context";
|
|
9
14
|
// src/store/repo-record.ts
|
|
10
15
|
/** A repo's record and its scope's rows, read at one version: `results[0]` is `self`. */
|
|
11
16
|
const readRecord = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, reads = [], counts = []) {
|
|
@@ -23,6 +28,55 @@ const rootsOf = (rows) => {
|
|
|
23
28
|
return Effect.map(decodeRow(RepoRootsRow, row, "The repo's roots"), ({ roots }) => new Set(roots));
|
|
24
29
|
};
|
|
25
30
|
/**
|
|
31
|
+
* When a write to a repo's scope must begin its store call by, after a read at `heldAt` found the
|
|
32
|
+
* repo's record live: `heldAt` plus `fetchLimits.milliseconds`, less `jobLeaseMargin`. The repo
|
|
33
|
+
* was live at that read, so its delete came later, and its purge drops its scopes no sooner than
|
|
34
|
+
* `fetchLimits` past the delete, the record's `changedAt`: a call begun by then lands before the
|
|
35
|
+
* drop, with the lease margin for the call itself, as `git.repack`'s `remapLate` keeps it (#1911).
|
|
36
|
+
* It assumes the store call ends inside that margin: no store call is bounded below it yet (#2331).
|
|
37
|
+
*/
|
|
38
|
+
const heldUntil = (heldAt, fetchLimits) => heldAt + fetchLimits.milliseconds - jobLeaseMargin;
|
|
39
|
+
/** Whether a write may still begin its store call, by `heldUntil`'s `by`, at the clock's now. */
|
|
40
|
+
const inTime = (by) => Effect.map(Clock$1.currentTimeMillis, (now) => now < by);
|
|
41
|
+
/**
|
|
42
|
+
* When the writes in scope must begin by, as `heldUntil` answered for the caller's own read of the
|
|
43
|
+
* repo's record: a push sets it around its receive, so the pack's quarantine row, an add at no
|
|
44
|
+
* version, is refused once the push waited past it, at its authorize or its memory's admission,
|
|
45
|
+
* as long as the repo's purge may take (#1911). `undefined` outside one, as for `git.repack`'s
|
|
46
|
+
* own packs, which the purge waits for.
|
|
47
|
+
*/
|
|
48
|
+
const HeldBy = Context.Reference("@ref0/git/HeldBy", { defaultValue: () => void 0 });
|
|
49
|
+
/** Fails `UNAVAILABLE` once the clock is at or past `HeldBy`, so a write that waited reads again. */
|
|
50
|
+
const heldInTime = (what) => Effect.flatMap(HeldBy, (by) => by === void 0 ? Effect.void : Effect.flatMap(inTime(by), (on) => on ? Effect.void : fail("UNAVAILABLE", `${what} came late: read the repo again`, { hint: "Push again" })));
|
|
51
|
+
/**
|
|
52
|
+
* A write to a repo's scope refused because the repo is gone: no record, or one deleted, so its
|
|
53
|
+
* purge may drop the scope, or has, and the write would make it again (#1911).
|
|
54
|
+
*/
|
|
55
|
+
var RepoGone = class extends Schema.TaggedError()("RepoGone", { repo: Schema.String }) {};
|
|
56
|
+
/** `store` as `heldAdd` calls it, each call a `storeCall`. */
|
|
57
|
+
const heldStore = (store) => ({
|
|
58
|
+
read: (scope, reads) => storeCall(() => store.read(scope, reads)),
|
|
59
|
+
add: (scope, addition) => storeCall(() => store.add(scope, addition))
|
|
60
|
+
});
|
|
61
|
+
/**
|
|
62
|
+
* `addition` to `repo`'s scope, an add at no version, only while the repo is live: it reads the
|
|
63
|
+
* record first and fails `RepoGone` when there's none or it's deleted, so a late write, a wake or
|
|
64
|
+
* a job after the delete never makes a purged scope again, nor on Turso its database. One whose
|
|
65
|
+
* read stalled past `heldUntil` is `UNAVAILABLE`, for a try that reads again. A wake, a job, an
|
|
66
|
+
* upload or a sync's cover made apart from the repo's own read goes through here, and a push's
|
|
67
|
+
* quarantine is held to its first read by `HeldBy`. The adds that don't are a fork create's cover
|
|
68
|
+
* rows, which come with its record, and a try's rows in its own scope, which its claim fences.
|
|
69
|
+
*/
|
|
70
|
+
const heldAdd = /* @__PURE__ */ Effect.fnUntraced(function* (store, repo, fetchLimits, addition) {
|
|
71
|
+
const scope = repoScope(repo);
|
|
72
|
+
const heldAt = yield* Clock$1.currentTimeMillis;
|
|
73
|
+
const snapshot = yield* store.read(scope, [selfKey]);
|
|
74
|
+
const record = yield* decodeRecord(snapshot.results[0]?.[0]);
|
|
75
|
+
if (record === void 0 || record.deleted === true) return yield* new RepoGone({ repo });
|
|
76
|
+
if (!(yield* inTime(heldUntil(heldAt, fetchLimits)))) return yield* fail("UNAVAILABLE", `The add to repo ${repo} came late: read it again`);
|
|
77
|
+
yield* store.add(scope, addition);
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
26
80
|
* The first of a repo write's two commits: its record, in its own scope, with `git.list` saved
|
|
27
81
|
* beside it, so the catalogue's projection happens even if the second never does.
|
|
28
82
|
*/
|
|
@@ -123,4 +177,4 @@ const repoStats = (record, refs, packs, times, readyBytes) => {
|
|
|
123
177
|
if (times.maintained !== void 0) stats.maintainedAt = times.maintained;
|
|
124
178
|
return stats;
|
|
125
179
|
};
|
|
126
|
-
export { commitRecord, decodeStats, looseRows, readRecord, repoStats, rootsOf, seenTimes, timeRow, writeRecord };
|
|
180
|
+
export { HeldBy, RepoGone, commitRecord, decodeStats, heldAdd, heldInTime, heldStore, heldUntil, inTime, looseRows, readRecord, repoStats, rootsOf, seenTimes, timeRow, writeRecord };
|
package/dist/sync/github.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { runnerIn } from "../store/crossing.mjs";
|
|
|
2
2
|
import { responseToWeb } from "./http.mjs";
|
|
3
3
|
import { fail, gitError } from "../contracts/result.mjs";
|
|
4
4
|
import { sameHash } from "../auth/token-text.mjs";
|
|
5
|
+
import { ProviderRefused, saidOf } from "./said.mjs";
|
|
5
6
|
import { hmacSha256 } from "../protocol/bytes/hmac-sha256.mjs";
|
|
6
7
|
import * as Clock$1 from "effect/Clock";
|
|
7
8
|
import * as Effect from "effect/Effect";
|
|
@@ -47,6 +48,11 @@ const tokenPermissions = (access) => ({
|
|
|
47
48
|
metadata: "read"
|
|
48
49
|
});
|
|
49
50
|
const ownerAndName = /^[\w.-]+\/[\w.-]+$/;
|
|
51
|
+
/**
|
|
52
|
+
* The fields of GitHub's JSON refusal kept: its `message` alone. `documentation_url` links a page
|
|
53
|
+
* of the docs, which says nothing of this failure, and is a URL, where userinfo could ride.
|
|
54
|
+
*/
|
|
55
|
+
const githubKept = ["message"];
|
|
50
56
|
/** A failure of the provider's own: its message names the call and the status, never a token. */
|
|
51
57
|
const failed = (call, status) => /* @__PURE__ */ new Error(status === void 0 ? `GitHub didn't answer to ${call}` : `GitHub answered ${status} to ${call}`);
|
|
52
58
|
/** The DER length of `size` bytes. */
|
|
@@ -220,7 +226,10 @@ const github = /* @__PURE__ */ Effect.fnUntraced(function* (options) {
|
|
|
220
226
|
const response = await fetch(request).catch(() => {
|
|
221
227
|
throw failed(call);
|
|
222
228
|
});
|
|
223
|
-
if (response.status !== 201)
|
|
229
|
+
if (response.status !== 201) {
|
|
230
|
+
const said = await saidOf(request, response, githubKept);
|
|
231
|
+
throw new ProviderRefused(failed(call, response.status).message, said);
|
|
232
|
+
}
|
|
224
233
|
const answer = decodeToken(await response.json().catch(() => void 0));
|
|
225
234
|
if (Option.isNone(answer)) throw failed(call, response.status);
|
|
226
235
|
return answer.value.token;
|
package/dist/sync/import.mjs
CHANGED
|
@@ -143,9 +143,10 @@ const cancelWith = /* @__PURE__ */ Effect.fnUntraced(function* (_bound, input) {
|
|
|
143
143
|
kind: "repo.update",
|
|
144
144
|
repo: input.repo
|
|
145
145
|
};
|
|
146
|
-
const
|
|
146
|
+
const opened = yield* openRepo(caller, operation, [], input.internalId, "first-read");
|
|
147
|
+
const { internalId } = opened;
|
|
147
148
|
const { store } = yield* CoreParts;
|
|
148
|
-
const read = yield* readImport(store, internalId);
|
|
149
|
+
const read = yield* readImport(store, internalId, opened);
|
|
149
150
|
if (read.row?.state !== "running") return yield* noImport(input.repo);
|
|
150
151
|
if (read.cancelled) return;
|
|
151
152
|
yield* storeCall(() => store.commit(repoScope(internalId), {
|
package/dist/sync/mirror.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { currentRepo } from "../store/job-try.mjs";
|
|
|
2
2
|
import { fail } from "../contracts/result.mjs";
|
|
3
3
|
import { contended, headOf, openRepo, repoAccess } from "../core/access.mjs";
|
|
4
4
|
import { kindsOf } from "../core/ancestry.mjs";
|
|
5
|
+
import { readAsked } from "../core/asked.mjs";
|
|
5
6
|
import { isRefName } from "../core/names.mjs";
|
|
6
7
|
import { unseenRef } from "../core/rules/check.mjs";
|
|
7
8
|
import { refViewIn } from "../core/ref-view.mjs";
|
|
@@ -16,7 +17,7 @@ import { MirrorRow } from "../core/mirror-rows.mjs";
|
|
|
16
17
|
import { collections, newChangeId, repoScope } from "../store/scopes.mjs";
|
|
17
18
|
import { asSync, mirrorLimits } from "./bound.mjs";
|
|
18
19
|
import { readImport } from "../core/imports.mjs";
|
|
19
|
-
import { fromRemote, httpOf, openedFor, remoteOf, syncObjects, tried, unknownProvider } from "./tries.mjs";
|
|
20
|
+
import { fromRemote, httpOf, keptFieldsOf, openedFor, remoteOf, syncObjects, tried, unknownProvider } from "./tries.mjs";
|
|
20
21
|
import { CoreParts, ObjectsParts, overStore } from "../core/parts.mjs";
|
|
21
22
|
import * as Clock$1 from "effect/Clock";
|
|
22
23
|
import * as Effect from "effect/Effect";
|
|
@@ -214,14 +215,14 @@ const goesOn = /* @__PURE__ */ Effect.fnUntraced(function* (listed, edit) {
|
|
|
214
215
|
if (update.kind !== "force") return true;
|
|
215
216
|
return (yield* kinds.exact(update)) === "fast-forward";
|
|
216
217
|
});
|
|
217
|
-
const upstreamOf = /* @__PURE__ */ Effect.fnUntraced(function* (http) {
|
|
218
|
+
const upstreamOf = /* @__PURE__ */ Effect.fnUntraced(function* (http, heard) {
|
|
218
219
|
const read = yield* Effect.result(receiveRefs(http));
|
|
219
220
|
if (Result.isSuccess(read)) return {
|
|
220
221
|
kind: "read",
|
|
221
222
|
refs: read.success
|
|
222
223
|
};
|
|
223
224
|
const { failure } = read;
|
|
224
|
-
if (!refusedCodes.has(failure.code)) return yield* Effect.fail(fromRemote("advertise")(failure));
|
|
225
|
+
if (!refusedCodes.has(failure.code)) return yield* Effect.fail(fromRemote("advertise", heard)(failure));
|
|
225
226
|
return { kind: "refused" };
|
|
226
227
|
});
|
|
227
228
|
/**
|
|
@@ -275,8 +276,8 @@ const pushStep = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, version,
|
|
|
275
276
|
const tip = opened?.refs.get(ref);
|
|
276
277
|
if (opened === void 0 || tip === void 0) return void 0;
|
|
277
278
|
const remote = yield* remoteOf(bound, mirror.destination, context.signal, "write");
|
|
278
|
-
const http = yield* httpOf(remote);
|
|
279
|
-
const upstream = yield* upstreamOf(http);
|
|
279
|
+
const { http, heard } = yield* httpOf(remote, keptFieldsOf(bound, mirror.destination));
|
|
280
|
+
const upstream = yield* upstreamOf(http, heard);
|
|
280
281
|
if (upstream.kind === "refused") return yield* paused(attempt, version, mirror, "refused");
|
|
281
282
|
const from = upstream.refs.refs.get(ref) ?? null;
|
|
282
283
|
if (from === tip) {
|
|
@@ -297,16 +298,19 @@ const pushStep = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, version,
|
|
|
297
298
|
const pushed = yield* Effect.result(sendPush(http, source, upstream.refs, [edit], {}));
|
|
298
299
|
if (Result.isFailure(pushed)) {
|
|
299
300
|
const { failure } = pushed;
|
|
300
|
-
if (!refusedCodes.has(failure.code)) return yield* Effect.fail(fromRemote("take a push")(failure));
|
|
301
|
+
if (!refusedCodes.has(failure.code)) return yield* Effect.fail(fromRemote("take a push", heard)(failure));
|
|
301
302
|
return yield* paused(attempt, version, mirror, "refused");
|
|
302
303
|
}
|
|
303
304
|
const [update] = pushed.success.updates;
|
|
304
305
|
if (update?.kind === "applied") return yield* pushedTo(attempt, version, mirror, tip);
|
|
305
|
-
return yield* refusedPush(attempt, version, mirror,
|
|
306
|
+
return yield* refusedPush(attempt, version, mirror, {
|
|
307
|
+
http,
|
|
308
|
+
heard
|
|
309
|
+
}, upstream.refs, ref);
|
|
306
310
|
});
|
|
307
311
|
/** A refused push: stale when the upstream's tip has moved since it was read, so read again. */
|
|
308
|
-
const refusedPush = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, version, mirror, http, first, ref) {
|
|
309
|
-
const reread = yield* upstreamOf(http);
|
|
312
|
+
const refusedPush = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, version, mirror, { http, heard }, first, ref) {
|
|
313
|
+
const reread = yield* upstreamOf(http, heard);
|
|
310
314
|
if (reread.kind === "read" && reread.refs.refs.get(ref) !== first.refs.get(ref)) return again;
|
|
311
315
|
return yield* paused(attempt, version, mirror, "refused");
|
|
312
316
|
});
|
|
@@ -359,19 +363,22 @@ const removeMirrorWith = /* @__PURE__ */ Effect.fnUntraced(function* (_bound, in
|
|
|
359
363
|
kind: "repo.update",
|
|
360
364
|
repo: input.repo
|
|
361
365
|
};
|
|
362
|
-
const
|
|
366
|
+
const opened = yield* openRepo(caller, operation, [], input.internalId, "first-read");
|
|
367
|
+
const { internalId, name, record } = opened;
|
|
363
368
|
const none = fail("NOT_FOUND", `'${input.repo}' has no mirror of '${ref}'`, { hint: "List the repo's mirrors with mirrors" });
|
|
364
|
-
if (!(yield* refViewIn(caller, repoAccess({
|
|
365
|
-
name,
|
|
366
|
-
record,
|
|
367
|
-
internalId
|
|
368
|
-
}))).sees(ref)) return yield* none;
|
|
369
369
|
const { store } = yield* CoreParts;
|
|
370
370
|
const scope = repoScope(internalId);
|
|
371
|
+
let refView;
|
|
371
372
|
for (let tries = 0; tries < 5; tries += 1) {
|
|
372
|
-
const
|
|
373
|
+
const asked = tries === 0 ? opened : void 0;
|
|
374
|
+
const read = yield* readAsked(store, internalId, [mirrorKey(ref)], [], asked);
|
|
375
|
+
if (refView === void 0) refView = yield* refViewIn(caller, repoAccess({
|
|
376
|
+
name,
|
|
377
|
+
record,
|
|
378
|
+
internalId
|
|
379
|
+
}));
|
|
373
380
|
const [[own] = []] = read.results;
|
|
374
|
-
if (own === void 0) return yield* none;
|
|
381
|
+
if (own === void 0 || !refView.sees(ref)) return yield* none;
|
|
375
382
|
if ((yield* storeCall(() => store.commit(scope, {
|
|
376
383
|
id: newChangeId(),
|
|
377
384
|
expect: read.version,
|