@ref0/git 0.2.0 → 0.3.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/authorize.d.mts +1 -1
- package/dist/auth/fences.d.mts +1 -1
- package/dist/auth/host-function.mjs +2 -2
- package/dist/auth/identify.d.mts +1 -1
- package/dist/auth/tokens.d.mts +1 -1
- package/dist/client/client.mjs +2 -3
- package/dist/client/local.mjs +13 -3
- package/dist/contracts/calls-spent.mjs +3 -2
- package/dist/contracts/client.d.mts +2 -2
- package/dist/contracts/handlers.d.mts +2 -1
- package/dist/contracts/objects.d.mts +2 -2
- package/dist/contracts/promises.d.mts +13 -38
- package/dist/contracts/promises.mjs +13 -0
- package/dist/contracts/queue.d.mts +2 -1
- package/dist/contracts/result.d.mts +7 -0
- package/dist/contracts/server.d.mts +67 -40
- package/dist/contracts/sync.d.mts +1 -1
- package/dist/contracts/topics.d.mts +7 -1
- package/dist/core/access.d.mts +1 -1
- package/dist/core/call-names.d.mts +1 -0
- package/dist/core/call-names.mjs +93 -0
- package/dist/core/events/deliver.mjs +14 -7
- package/dist/core/events/stream.d.mts +1 -1
- package/dist/core/events/stream.mjs +8 -1
- package/dist/core/hooks/post-receive.mjs +15 -7
- package/dist/core/promise.mjs +28 -10
- package/dist/core/push.mjs +2 -1
- package/dist/core/seam.d.mts +2 -0
- package/dist/core/seam.mjs +19 -6
- package/dist/extend.d.mts +2 -1
- package/dist/extend.mjs +3 -1
- package/dist/index.d.mts +2 -2
- package/dist/lfs/objects.mjs +1 -1
- package/dist/lfs/rows.mjs +1 -1
- package/dist/queue/advance.mjs +2 -1
- package/dist/queue/host.d.mts +1 -1
- package/dist/queue/host.mjs +1 -1
- package/dist/queue/schedule.mjs +1 -1
- package/dist/rest/blobs.d.mts +15 -15
- package/dist/rest/client.mjs +2 -2
- package/dist/rest/commits.d.mts +91 -91
- package/dist/rest/errors.d.mts +2 -2
- package/dist/rest/errors.mjs +2 -2
- package/dist/rest/files.d.mts +81 -81
- package/dist/rest/handler.d.mts +1 -0
- package/dist/rest/handler.mjs +39 -16
- package/dist/rest/handlers.mjs +6 -6
- package/dist/rest/repos.d.mts +38 -38
- package/dist/rest/tags.d.mts +41 -41
- package/dist/rest/tokens.d.mts +145 -145
- package/dist/rest/work.d.mts +43 -43
- package/dist/server/extension.d.mts +6 -3
- package/dist/server/extension.mjs +39 -31
- package/dist/server/lifecycle.d.mts +3 -0
- package/dist/server/lifecycle.mjs +89 -0
- package/dist/server/routes.d.mts +7 -4
- package/dist/server/routes.mjs +12 -19
- package/dist/server/server.d.mts +8 -2
- package/dist/server/server.mjs +280 -104
- package/dist/signin/context.d.mts +1 -1
- package/dist/signin/grants.d.mts +1 -1
- package/dist/storage/bits.mjs +41 -0
- package/dist/storage/calls.d.mts +1 -1
- package/dist/storage/calls.mjs +2 -2
- package/dist/storage/fetch.d.mts +3 -1
- package/dist/storage/fetch.mjs +230 -24
- package/dist/storage/index-bitmaps.d.mts +1 -1
- package/dist/storage/index-build.d.mts +1 -1
- package/dist/storage/index-build.mjs +27 -13
- package/dist/storage/index-fetch.d.mts +1 -0
- package/dist/storage/index-fetch.mjs +103 -182
- package/dist/storage/index-graph.d.mts +1 -1
- package/dist/storage/loose.mjs +3 -2
- package/dist/storage/pack-order.d.mts +1 -1
- package/dist/storage/pack-order.mjs +3 -1
- package/dist/storage/pack-ranges.d.mts +1 -1
- package/dist/storage/pack-reads.d.mts +1 -1
- package/dist/storage/pack-reads.mjs +17 -0
- package/dist/storage/pack-receive.d.mts +2 -2
- package/dist/storage/pack-receive.mjs +1 -1
- package/dist/storage/packs.d.mts +2 -2
- package/dist/storage/packs.mjs +10 -7
- package/dist/storage/push-uploads.mjs +2 -1
- package/dist/storage/ready.d.mts +2 -2
- package/dist/storage/receive-links.mjs +1 -1
- package/dist/storage/repack.d.mts +2 -2
- package/dist/storage/rows.d.mts +2 -1
- package/dist/storage/rows.mjs +1 -1
- package/dist/storage/send-list.d.mts +8 -0
- package/dist/storage/send-list.mjs +319 -0
- package/dist/storage/shallow.d.mts +1 -2
- package/dist/storage/unpack.mjs +5 -3
- package/dist/storage/walk.d.mts +2 -1
- package/dist/storage/walk.mjs +14 -8
- package/dist/store/catalogue.d.mts +1 -1
- package/dist/store/closed.d.mts +21 -0
- package/dist/store/closed.mjs +34 -0
- package/dist/store/crossing.mjs +9 -6
- package/dist/store/cursor-seal.mjs +4 -1
- package/dist/store/errors.mjs +13 -7
- package/dist/store/outbox.mjs +4 -2
- package/dist/store/promises.d.mts +5 -0
- package/dist/store/promises.mjs +258 -0
- package/dist/sync/bound.mjs +9 -4
- package/dist/sync/jobs.d.mts +3 -3
- package/dist/sync/jobs.mjs +28 -25
- package/dist/sync/tries.mjs +2 -2
- package/dist/topics/advance.mjs +2 -1
- package/dist/topics/calls.mjs +3 -3
- package/dist/topics/host.d.mts +1 -1
- package/dist/topics/host.mjs +1 -1
- package/dist/topics/topic.mjs +22 -7
- package/package.json +2 -2
package/dist/storage/fetch.mjs
CHANGED
|
@@ -7,6 +7,10 @@ import { entryHeader, packStream, writePack } from "../protocol/packs/writer.mjs
|
|
|
7
7
|
import { untilAborted } from "../store/crossing.mjs";
|
|
8
8
|
import { fetchLess, gitError } from "../store/errors.mjs";
|
|
9
9
|
import { spentIn } from "../contracts/calls-spent.mjs";
|
|
10
|
+
import { hexOf } from "../protocol/bytes/hex.mjs";
|
|
11
|
+
import { isSet } from "./bits.mjs";
|
|
12
|
+
import { typeOfCode } from "./index-files.mjs";
|
|
13
|
+
import { ListCursor, entryAt, sizeOf } from "./send-list.mjs";
|
|
10
14
|
import { indexSendSet } from "./index-fetch.mjs";
|
|
11
15
|
import { planShallow } from "./shallow.mjs";
|
|
12
16
|
import { countedReads, fetchReadsOf, historyOf, lost, notHeld, unreadable, walk } from "./walk.mjs";
|
|
@@ -38,7 +42,10 @@ const limitNames = [
|
|
|
38
42
|
const pastLimits = (limits, fetchLimits) => {
|
|
39
43
|
const past = limitNames.find((name) => limits[name] > fetchLimits[name]);
|
|
40
44
|
if (past === void 0) return void 0;
|
|
41
|
-
return gitError("INVALID_ARGUMENT", `This fetch's limits ask for ${limits[past]} ${past}, past the server's
|
|
45
|
+
return gitError("INVALID_ARGUMENT", `This fetch's limits ask for ${limits[past]} ${past}, past the server's limit of ${fetchLimits[past]}`, {
|
|
46
|
+
hint: `Limit the fetch to ${fetchLimits[past]} ${past}`,
|
|
47
|
+
hostHint: "Raise createGitServer's fetchLimits"
|
|
48
|
+
});
|
|
42
49
|
};
|
|
43
50
|
/** What the pack writer holds at once: its buffers, its compressor, one object's body. */
|
|
44
51
|
const writerBytes = 16777216;
|
|
@@ -135,6 +142,175 @@ const plannedSource = (reads, plan, rows) => {
|
|
|
135
142
|
}
|
|
136
143
|
};
|
|
137
144
|
};
|
|
145
|
+
/** A pack entry's type, in its header's first byte: 1 to 4 for the kinds, 7 for a `REF_DELTA`. */
|
|
146
|
+
const entryTypes = {
|
|
147
|
+
commit: 1,
|
|
148
|
+
tree: 2,
|
|
149
|
+
blob: 3,
|
|
150
|
+
tag: 4
|
|
151
|
+
};
|
|
152
|
+
const refDeltaType = 7;
|
|
153
|
+
/**
|
|
154
|
+
* `copy`, refused with `DATA_LOSS` before its first range is handed over when its header's type
|
|
155
|
+
* isn't what the index says it is: `kind` for a whole entry, a `REF_DELTA` for a delta. A copied
|
|
156
|
+
* delta's header must name `base` too, the ID at the base position its `.bases` row gives,
|
|
157
|
+
* checked before the range that completes the header's ID is handed over.
|
|
158
|
+
*/
|
|
159
|
+
const typeChecked = (copy, entry, type, base) => {
|
|
160
|
+
const wrong = gitError("DATA_LOSS", `Object ${entry.oid} in pack ${entry.pack.id} isn't the entry the index's .types and .bases say`);
|
|
161
|
+
let head = /* @__PURE__ */ new Uint8Array(0);
|
|
162
|
+
let checked = true;
|
|
163
|
+
/** The base ID a `REF_DELTA`'s header names, past its type and size, once `bytes` hold it. */
|
|
164
|
+
const named = (bytes) => {
|
|
165
|
+
let at = 1;
|
|
166
|
+
while (at <= bytes.byteLength && ((bytes[at - 1] ?? 0) & 128) !== 0) at += 1;
|
|
167
|
+
return bytes.byteLength < at + 20 ? void 0 : hexOf(bytes.subarray(at, at + 20));
|
|
168
|
+
};
|
|
169
|
+
return {
|
|
170
|
+
bytes: copy.bytes,
|
|
171
|
+
read: (at) => Effect.flatMap(copy.read(at), (bytes) => {
|
|
172
|
+
if (at === 0 && ((bytes[0] ?? 0) >> 4 & 7) !== type) return Effect.fail(wrong);
|
|
173
|
+
if (at === 0) {
|
|
174
|
+
head = /* @__PURE__ */ new Uint8Array(0);
|
|
175
|
+
checked = base === void 0;
|
|
176
|
+
}
|
|
177
|
+
if (checked) return Effect.succeed(bytes);
|
|
178
|
+
head = Uint8Array.from([...head, ...bytes.subarray(0, 64 - head.byteLength)]);
|
|
179
|
+
const found = named(head);
|
|
180
|
+
if (found === void 0 && at + bytes.byteLength < copy.bytes) return Effect.succeed(bytes);
|
|
181
|
+
checked = true;
|
|
182
|
+
return found === base ? Effect.succeed(bytes) : Effect.fail(wrong);
|
|
183
|
+
})
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* The whole objects of `list` the writer reads at once from `cursor` on, as `plannedSource` reads
|
|
188
|
+
* its windows: those it doesn't copy, up to `windowBytes` of them or the one.
|
|
189
|
+
*/
|
|
190
|
+
const windowFrom = (cursor) => {
|
|
191
|
+
const { list } = cursor;
|
|
192
|
+
const window = [];
|
|
193
|
+
let bytes = 0;
|
|
194
|
+
for (const at = cursor.copy(); !at.done; at.next()) {
|
|
195
|
+
if (isSet(list.copied, at.ordinal)) continue;
|
|
196
|
+
const size = sizeOf(list, at.ordinal);
|
|
197
|
+
if (window.length > 0 && bytes + size > 1048576) break;
|
|
198
|
+
window.push({
|
|
199
|
+
ordinal: at.ordinal,
|
|
200
|
+
position: at.position,
|
|
201
|
+
pack: at.inPack
|
|
202
|
+
});
|
|
203
|
+
bytes += size;
|
|
204
|
+
}
|
|
205
|
+
return window;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* The stored entries the writer reads for `list`, in its order, as `writerCalls` forecasts a
|
|
209
|
+
* plan's: each copy's entry, and for each window of objects written whole, each one's entry and the
|
|
210
|
+
* bases down its chain, as the reader resolves it. None is held past `PackBlocks.gets`' count.
|
|
211
|
+
*/
|
|
212
|
+
function* listReads(list) {
|
|
213
|
+
let windowEnd = 0;
|
|
214
|
+
for (const cursor = new ListCursor(list); !cursor.done; cursor.next()) {
|
|
215
|
+
const pack = cursor.inPack;
|
|
216
|
+
if (isSet(list.copied, cursor.ordinal)) {
|
|
217
|
+
yield entryAt(pack, cursor.position);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (cursor.ordinal < windowEnd) continue;
|
|
221
|
+
const window = windowFrom(cursor);
|
|
222
|
+
windowEnd = (window.at(-1)?.ordinal ?? cursor.ordinal) + 1;
|
|
223
|
+
for (const each of window) for (let at = each.position, steps = 0; at !== void 0 && steps <= list.chains.size; at = list.chains.get(at), steps += 1) yield entryAt(each.pack, at);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* The bucket gets the writer makes for `list`'s objects, as `PackBlocks.gets` forecasts them, with
|
|
228
|
+
* no I/O: what `writerCalls` forecasts for a plan's, over the list's places (#522).
|
|
229
|
+
*/
|
|
230
|
+
const listCalls = (stored, list) => ({
|
|
231
|
+
bucket: stored.gets(listReads(list)),
|
|
232
|
+
store: 0
|
|
233
|
+
});
|
|
234
|
+
/**
|
|
235
|
+
* `list`'s objects as the writer takes them, a page at a time: each one's ID, kind and size from
|
|
236
|
+
* the index and the list, held for its page alone. A copy is its stored entry, its CRC-32 checked
|
|
237
|
+
* as it's read and its type against the index's; the rest are read whole a window at a time, as
|
|
238
|
+
* `plannedSource` reads them. Every read is a listed pack's, so the store is read no more.
|
|
239
|
+
*/
|
|
240
|
+
const listSource = (reads, list) => {
|
|
241
|
+
const cursor = new ListCursor(list);
|
|
242
|
+
let paged = /* @__PURE__ */ new Map();
|
|
243
|
+
let window = /* @__PURE__ */ new Map();
|
|
244
|
+
const load = Effect.fnUntraced(function* (from) {
|
|
245
|
+
const at = windowFrom(from).map(({ pack, position }) => {
|
|
246
|
+
const { oid, offset } = entryAt(pack, position);
|
|
247
|
+
return {
|
|
248
|
+
oid,
|
|
249
|
+
indexed: pack.indexed,
|
|
250
|
+
offset
|
|
251
|
+
};
|
|
252
|
+
});
|
|
253
|
+
if (reads.heldAt !== void 0) window = yield* reads.heldAt(at);
|
|
254
|
+
});
|
|
255
|
+
return {
|
|
256
|
+
count: list.count,
|
|
257
|
+
page: (_from, most) => Effect.sync(() => {
|
|
258
|
+
const page = [];
|
|
259
|
+
paged = /* @__PURE__ */ new Map();
|
|
260
|
+
for (; page.length < most && !cursor.done; cursor.next()) {
|
|
261
|
+
const { oid } = entryAt(cursor.inPack, cursor.position);
|
|
262
|
+
const kind = typeOfCode[list.kinds[cursor.ordinal] ?? 0] ?? "blob";
|
|
263
|
+
page.push({
|
|
264
|
+
oid,
|
|
265
|
+
kind,
|
|
266
|
+
size: sizeOf(list, cursor.ordinal)
|
|
267
|
+
});
|
|
268
|
+
paged.set(oid, cursor.copy());
|
|
269
|
+
}
|
|
270
|
+
return page;
|
|
271
|
+
}),
|
|
272
|
+
read: (object, at) => Effect.gen(function* () {
|
|
273
|
+
const placed = paged.get(object.oid);
|
|
274
|
+
if (!window.has(object.oid) && placed !== void 0) yield* load(placed);
|
|
275
|
+
const whole = window.get(object.oid);
|
|
276
|
+
if (whole === void 0) return yield* Effect.fail(gone(object.oid));
|
|
277
|
+
const bytes = whole.bytes.slice(at, at + rangeBytes);
|
|
278
|
+
if (at + bytes.byteLength >= whole.bytes.byteLength) {
|
|
279
|
+
const left = new Map(window);
|
|
280
|
+
left.delete(object.oid);
|
|
281
|
+
window = left;
|
|
282
|
+
}
|
|
283
|
+
return bytes;
|
|
284
|
+
}),
|
|
285
|
+
end: Effect.void,
|
|
286
|
+
copy: (object) => {
|
|
287
|
+
const placed = paged.get(object.oid);
|
|
288
|
+
if (placed === void 0 || reads.stored === void 0 || !isSet(list.copied, placed.ordinal)) return void 0;
|
|
289
|
+
const entry = entryAt(placed.inPack, placed.position);
|
|
290
|
+
const copy = checkedCopy(reads.stored, entry);
|
|
291
|
+
if (!isSet(list.deltas, placed.ordinal)) return typeChecked(copy, entry, entryTypes[object.kind]);
|
|
292
|
+
const base = entryAt(placed.inPack, list.bases[placed.ordinal] ?? 0).oid;
|
|
293
|
+
return typeChecked(copy, entry, refDeltaType, base);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
/** `first`'s objects, then `second`'s, as one source: a page across the seam takes from both. */
|
|
298
|
+
const joinedSources = (first, second) => {
|
|
299
|
+
let fromFirst = /* @__PURE__ */ new Set();
|
|
300
|
+
const of = (object) => fromFirst.has(object.oid) ? first : second;
|
|
301
|
+
return {
|
|
302
|
+
count: first.count + second.count,
|
|
303
|
+
page: (from, most) => Effect.gen(function* () {
|
|
304
|
+
const head = from < first.count ? yield* first.page(from, Math.min(most, first.count - from)) : [];
|
|
305
|
+
const tail = head.length < most ? yield* second.page(Math.max(0, from - first.count), most - head.length) : [];
|
|
306
|
+
fromFirst = new Set(head.map((object) => object.oid));
|
|
307
|
+
return [...head, ...tail];
|
|
308
|
+
}),
|
|
309
|
+
read: (object, at) => of(object).read(object, at),
|
|
310
|
+
end: Effect.andThen(first.end, second.end),
|
|
311
|
+
copy: (object) => of(object).copy?.(object)
|
|
312
|
+
};
|
|
313
|
+
};
|
|
138
314
|
/** A pack's objects from memory, in the order given. */
|
|
139
315
|
const memorySource = (objects) => {
|
|
140
316
|
const byOid = new Map(objects.map((object) => [object.oid, object]));
|
|
@@ -321,14 +497,30 @@ const contentBelow = Effect.fnUntraced(function* (read, roots, wanted, skip, fil
|
|
|
321
497
|
/**
|
|
322
498
|
* The annotated tags `include-tag` adds, of `tags`, the IDs the caller's `refs/tags/*` name: each
|
|
323
499
|
* tag, and each tag it tags in turn, when an object down its chain is in the pack and neither the
|
|
324
|
-
* pack nor the client holds it. A lightweight tag names no tag, so it adds none.
|
|
500
|
+
* pack nor the client holds it. A lightweight tag names no tag, so it adds none. A level at a time,
|
|
501
|
+
* it asks `sentOf` once of each ID it reaches, none of `skip`, what the client holds, and reads
|
|
502
|
+
* each it doesn't send once.
|
|
325
503
|
*/
|
|
326
|
-
const followedTags = Effect.fnUntraced(function* (read, tags,
|
|
327
|
-
const chains =
|
|
504
|
+
const followedTags = Effect.fnUntraced(function* (read, tags, skip, sentOf) {
|
|
505
|
+
const chains = /* @__PURE__ */ new Map();
|
|
506
|
+
const passed = new Set(skip);
|
|
507
|
+
const sent = /* @__PURE__ */ new Set();
|
|
508
|
+
for (let level = [...new Set(tags)].filter((oid) => !passed.has(oid)); level.length > 0;) {
|
|
509
|
+
for (const oid of yield* sentOf(level)) sent.add(oid);
|
|
510
|
+
const unread = level.filter((oid) => !sent.has(oid));
|
|
511
|
+
const found = unread.length === 0 ? /* @__PURE__ */ new Map() : yield* read(unread);
|
|
512
|
+
const next = /* @__PURE__ */ new Set();
|
|
513
|
+
for (const oid of level) passed.add(oid);
|
|
514
|
+
for (const object of found.values()) {
|
|
515
|
+
chains.set(object.oid, object);
|
|
516
|
+
if (object.type === "tag") for (const target of historyOf(object)) next.add(target);
|
|
517
|
+
}
|
|
518
|
+
level = [...next].filter((oid) => !passed.has(oid));
|
|
519
|
+
}
|
|
328
520
|
const added = /* @__PURE__ */ new Map();
|
|
329
521
|
for (const ref of new Set(tags)) {
|
|
330
522
|
const chain = [];
|
|
331
|
-
for (let object = chains.get(ref); object?.type === "tag";) {
|
|
523
|
+
for (let object = chains.get(ref); object?.type === "tag" && !sent.has(object.oid);) {
|
|
332
524
|
chain.push(object);
|
|
333
525
|
const [target] = historyOf(object);
|
|
334
526
|
if (target === void 0) break;
|
|
@@ -400,7 +592,7 @@ const planFetch = Effect.fnUntraced(function* (read, request, tags, objectsMost)
|
|
|
400
592
|
objects
|
|
401
593
|
};
|
|
402
594
|
const sent = new Set(objects.map((object) => object.oid));
|
|
403
|
-
const followed = yield* followedTags(read, tags,
|
|
595
|
+
const followed = yield* followedTags(read, tags, had, (oids) => Effect.succeed(new Set(oids.filter((oid) => sent.has(oid)))));
|
|
404
596
|
return {
|
|
405
597
|
deepened,
|
|
406
598
|
objects: [...objects, ...followed.map(packObjectOf)]
|
|
@@ -641,15 +833,13 @@ const objectsPlanned = Effect.fnUntraced(function* (read, request, tags, objects
|
|
|
641
833
|
tooMany: tooManyObjects(objectsMost)
|
|
642
834
|
});
|
|
643
835
|
if (sent === void 0) return yield* planFetch(read, request, tags, objectsMost);
|
|
836
|
+
const { list, rest, had, sentOf } = sent;
|
|
644
837
|
const deepened = yield* planShallow(read, request);
|
|
645
|
-
|
|
646
|
-
deepened,
|
|
647
|
-
objects: sent.objects
|
|
648
|
-
};
|
|
649
|
-
const followed = yield* followedTags(read, tags, new Set(sent.objects.map((object) => object.oid)), sent.had);
|
|
838
|
+
const followed = !request.includeTag || tags.length === 0 ? [] : yield* followedTags(read, tags, had, sentOf);
|
|
650
839
|
return {
|
|
651
840
|
deepened,
|
|
652
|
-
objects: [...
|
|
841
|
+
objects: [...rest, ...followed.map(packObjectOf)],
|
|
842
|
+
list
|
|
653
843
|
};
|
|
654
844
|
});
|
|
655
845
|
/**
|
|
@@ -662,14 +852,16 @@ const planFetchWithin = Effect.fnUntraced(function* (reads, input, within = {})
|
|
|
662
852
|
const { request, limits } = input;
|
|
663
853
|
const left = within.left ?? limits.milliseconds;
|
|
664
854
|
if (left <= 0) return yield* Effect.fail(planTooSlow(limits));
|
|
665
|
-
const { deepened, objects, copies, rows } = yield* Effect.gen(function* () {
|
|
855
|
+
const { deepened, objects, copies, rows, list } = yield* Effect.gen(function* () {
|
|
666
856
|
const clone = request.haves.length === 0;
|
|
667
857
|
const checked = callsChecked(within.calls, clone);
|
|
668
|
-
const read = countedReads(reads, within.readsMost ?? fetchReadsOf(limits), within.charge, checked);
|
|
669
|
-
const
|
|
858
|
+
const read = countedReads(reads, within.readsMost ?? fetchReadsOf(limits), within.charge, checked, within.release);
|
|
859
|
+
const planned = yield* objectsPlanned(read, request, input.tags ?? [], limits.objects, {
|
|
670
860
|
...within,
|
|
671
861
|
clone
|
|
672
862
|
});
|
|
863
|
+
const { deepened, objects } = planned;
|
|
864
|
+
const list = "list" in planned ? planned.list : void 0;
|
|
673
865
|
const stored = yield* reads.stored?.find(objects.map((object) => object.oid)) ?? Effect.succeed(/* @__PURE__ */ new Map());
|
|
674
866
|
const reused = reuse(inStoreOrder(objects, stored), stored);
|
|
675
867
|
const { calls } = within;
|
|
@@ -678,29 +870,40 @@ const planFetchWithin = Effect.fnUntraced(function* (reads, input, within = {})
|
|
|
678
870
|
const bases = calls === void 0 ? stored : yield* basesOf(reads, reused, stored);
|
|
679
871
|
const writer = yield* writerCalls(reads.stored, reused, bases);
|
|
680
872
|
rows = writer.rows;
|
|
681
|
-
if (calls !== void 0)
|
|
873
|
+
if (calls !== void 0) {
|
|
874
|
+
const listed = list === void 0 ? noCalls : listCalls(reads.stored, list);
|
|
875
|
+
const forecast = {
|
|
876
|
+
bucket: listed.bucket + writer.forecast.bucket,
|
|
877
|
+
store: listed.store + writer.forecast.store
|
|
878
|
+
};
|
|
879
|
+
yield* callsAhead(calls, forecast, clone);
|
|
880
|
+
}
|
|
682
881
|
}
|
|
683
882
|
return {
|
|
684
883
|
deepened,
|
|
685
884
|
rows,
|
|
885
|
+
list,
|
|
686
886
|
...reused
|
|
687
887
|
};
|
|
688
888
|
}).pipe(Effect.timeoutOrElse({
|
|
689
889
|
duration: left,
|
|
690
890
|
orElse: () => Effect.fail(planTooSlow(limits))
|
|
691
891
|
}));
|
|
692
|
-
const bytes = objects.reduce((sum, object) => sum + (copies.get(object.oid)?.bytes ?? object.size), 0);
|
|
693
|
-
|
|
892
|
+
const bytes = objects.reduce((sum, object) => sum + (copies.get(object.oid)?.bytes ?? object.size), list?.bytes ?? 0);
|
|
893
|
+
const count = objects.length + (list?.count ?? 0);
|
|
894
|
+
if (count > limits.objects || bytes > limits.bytes) return yield* Effect.fail(gitError("RESOURCE_EXHAUSTED", `This fetch needs ${count} objects, ${bytes} bytes: at most ${limits.objects}, ${limits.bytes}`, {
|
|
694
895
|
hint: "Fetch fewer refs at a time",
|
|
695
896
|
context: { reason: "fetch-plan-too-large" }
|
|
696
897
|
}));
|
|
697
|
-
|
|
898
|
+
const plan = {
|
|
698
899
|
deepened,
|
|
699
900
|
objects,
|
|
700
901
|
copies,
|
|
701
902
|
bytes,
|
|
702
903
|
rows
|
|
703
904
|
};
|
|
905
|
+
if (list !== void 0) plan.list = list;
|
|
906
|
+
return plan;
|
|
704
907
|
});
|
|
705
908
|
/**
|
|
706
909
|
* A plan's pack, its objects in one, written within `limits` in what's `left` of its time: each
|
|
@@ -708,19 +911,21 @@ const planFetchWithin = Effect.fnUntraced(function* (reads, input, within = {})
|
|
|
708
911
|
* read that fails then ends the stream, and so does the call's signal aborting.
|
|
709
912
|
*/
|
|
710
913
|
const packOfPlan = Effect.fnUntraced(function* (reads, plan, limits, writing, rows) {
|
|
711
|
-
const { deepened,
|
|
914
|
+
const { deepened, list } = plan;
|
|
915
|
+
const planned = plannedSource(reads, plan, rows);
|
|
916
|
+
const source = list === void 0 ? planned : joinedSources(listSource(reads, list), planned);
|
|
712
917
|
const meter = new BufferMeter(writerBytes);
|
|
713
918
|
const writeLimits = {
|
|
714
|
-
packBytes: limits.bytes +
|
|
919
|
+
packBytes: limits.bytes + source.count * 64 + 1024,
|
|
715
920
|
objectBytes: limits.bytes,
|
|
716
921
|
elapsedMillis: writing.left,
|
|
717
922
|
namedMillis: limits.milliseconds
|
|
718
923
|
};
|
|
719
|
-
const streamed = yield* packStream((output) => untilAborted(writePack(
|
|
924
|
+
const streamed = yield* packStream((output) => untilAborted(writePack(source, output, sha1Digest, writeLimits, meter), writing.signal).pipe(Effect.ensuring(writing.ended ?? Effect.void)), meter).pipe(Effect.mapError((error) => gitError("RESOURCE_EXHAUSTED", error.message, { context: { reason: "response-too-large" } })));
|
|
720
925
|
return {
|
|
721
926
|
shallow: deepened.shallow,
|
|
722
927
|
unshallow: deepened.unshallow,
|
|
723
|
-
objects:
|
|
928
|
+
objects: source.count,
|
|
724
929
|
pack: streamed.stream
|
|
725
930
|
};
|
|
726
931
|
});
|
|
@@ -743,7 +948,7 @@ const fetchTooLarge = gitError("RESOURCE_EXHAUSTED", "This fetch needs more obje
|
|
|
743
948
|
* packs stay for the bound's time: a fetch that first looked for a ready pack started then.
|
|
744
949
|
*/
|
|
745
950
|
const fetchPack = Effect.fnUntraced(function* (reads, input, fetchLimits, held = {}) {
|
|
746
|
-
const { started, ended, charge, calls, index } = held;
|
|
951
|
+
const { started, ended, charge, calls, index, release } = held;
|
|
747
952
|
const refused = pastLimits(input.limits, fetchLimits);
|
|
748
953
|
if (refused !== void 0) return yield* Effect.fail(refused);
|
|
749
954
|
const since = started ?? (yield* Clock.currentTimeMillis);
|
|
@@ -751,6 +956,7 @@ const fetchPack = Effect.fnUntraced(function* (reads, input, fetchLimits, held =
|
|
|
751
956
|
if (charge !== void 0) within.charge = charge;
|
|
752
957
|
if (calls !== void 0) within.calls = calls;
|
|
753
958
|
if (index !== void 0) within.index = index;
|
|
959
|
+
if (release !== void 0) within.release = release;
|
|
754
960
|
const plan = yield* planFetchWithin(reads, input, within);
|
|
755
961
|
const rows = reads.stored === void 0 ? void 0 : yield* rowsFirst(reads, plan, charge).pipe(Effect.timeoutOrElse({
|
|
756
962
|
duration: Math.max(0, yield* timeLeft(input.limits, since)),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "./index-bitmaps.mjs";
|
|
2
|
+
import "../contracts/promises.mjs";
|
|
2
3
|
import "../contracts/objects.mjs";
|
|
3
4
|
import "../contracts/services.mjs";
|
|
4
5
|
import "../contracts/store.mjs";
|
|
@@ -7,7 +8,6 @@ import "./fetch.mjs";
|
|
|
7
8
|
import "./index-graph.mjs";
|
|
8
9
|
import "./memory-budget.mjs";
|
|
9
10
|
import "./pack-order.mjs";
|
|
10
|
-
import "../contracts/promises.mjs";
|
|
11
11
|
import { Moment, Row } from "@ref0/infra";
|
|
12
12
|
import "effect/Effect";
|
|
13
13
|
import "effect/Schema";
|
|
@@ -18,7 +18,7 @@ import { joinBytes, joinLinks } from "./link-join.mjs";
|
|
|
18
18
|
import { outsideOn, readBusy } from "./memory-budget.mjs";
|
|
19
19
|
import { startPut } from "./merge.mjs";
|
|
20
20
|
import { eachPageAt, objectOfRow } from "./object-rows.mjs";
|
|
21
|
-
import { SliceLinks, SliceRefused, cutAtSpent, isSliceRefused, linksPastMemory, nothingSettled, readSlice, spentOf } from "./pack-order.mjs";
|
|
21
|
+
import { SliceLinks, SliceRefused, cutAtSpent, isSliceRefused, linksPastMemory, nothingSettled, readSlice, sliceRefusal, spentOf } from "./pack-order.mjs";
|
|
22
22
|
import { PackBlocks, packIndexerLimits, readWhole } from "./pack-reads.mjs";
|
|
23
23
|
import { rangeRanks, readExactly } from "./pack-ranges.mjs";
|
|
24
24
|
import { compareIds } from "./raw-ids.mjs";
|
|
@@ -351,15 +351,22 @@ const indexReadCallsAfter = (counts) => ({
|
|
|
351
351
|
store: 0
|
|
352
352
|
});
|
|
353
353
|
/**
|
|
354
|
+
* A refusal whose index row keeps its whole text, `message` then the host's step: the one text
|
|
355
|
+
* `lint/host-hints.test.ts` lets name the host's setup, since only the host's log and
|
|
356
|
+
* `GitObjects.index.status`, in process, read the row.
|
|
357
|
+
*/
|
|
358
|
+
const refusedRow = (message, hostHint, reason) => gitError("RESOURCE_EXHAUSTED", message, {
|
|
359
|
+
hostHint,
|
|
360
|
+
cause: new SliceRefused(`${message} ${hostHint}`),
|
|
361
|
+
context: { reason }
|
|
362
|
+
});
|
|
363
|
+
/**
|
|
354
364
|
* The refusal of a build whose read step needs `needs` calls of `kind` after its slice, at or past
|
|
355
365
|
* the try's `most` of them: no slice could read within the rest, so it refuses before any (#681).
|
|
356
366
|
*/
|
|
357
367
|
const reservePast = (kind, needs, most) => {
|
|
358
|
-
const message = `Indexing needs ${needs} ${kind === "bucket" ? "bucket calls" : "subrequests"} to join and write, more than the limit of ${most}
|
|
359
|
-
return
|
|
360
|
-
cause: new SliceRefused(message),
|
|
361
|
-
context: { reason: "too-many-store-calls" }
|
|
362
|
-
});
|
|
368
|
+
const message = `Indexing needs ${needs} ${kind === "bucket" ? "bucket calls" : "subrequests"} to join and write, more than the limit of ${most}.`;
|
|
369
|
+
return refusedRow(message, raiseCalls(kind), "too-many-store-calls");
|
|
363
370
|
};
|
|
364
371
|
/**
|
|
365
372
|
* The refusal of a read step whose join and puts ran out of the try's `most` calls past its
|
|
@@ -903,11 +910,8 @@ const mergeHeldMost = (merging) => {
|
|
|
903
910
|
* would come to the same, so its row waits as one for spent tries does, its layers kept.
|
|
904
911
|
*/
|
|
905
912
|
const mergePast = (needs, what, most, raise) => {
|
|
906
|
-
const message = `Merging the index's layers needs ${needs} ${what}, more than the limit of ${most}
|
|
907
|
-
return
|
|
908
|
-
cause: new SliceRefused(message),
|
|
909
|
-
context: { reason: what === "bytes" ? "too-large" : "too-many-store-calls" }
|
|
910
|
-
});
|
|
913
|
+
const message = `Merging the index's layers needs ${needs} ${what}, more than the limit of ${most}.`;
|
|
914
|
+
return refusedRow(message, raise, what === "bytes" ? "too-large" : "too-many-store-calls");
|
|
911
915
|
};
|
|
912
916
|
const raiseCalls = (kind) => `Raise \`callLimits.${kind}\` in \`cloudflare()\`'s options, up to the platform's cap.`;
|
|
913
917
|
/** A refusal when `needs` more calls are past what the try has left of its bound. */
|
|
@@ -1150,6 +1154,12 @@ const coveredPositions = (listed, data) => {
|
|
|
1150
1154
|
/** The rounds a row written by `input`'s try records: its round and those before it. */
|
|
1151
1155
|
const roundsAfter = (input) => (input.round ?? 0) + 1;
|
|
1152
1156
|
/**
|
|
1157
|
+
* Whether `data` is an update that adds nothing to the layers below it: no pack, row, commit or
|
|
1158
|
+
* bitmap. One starts when a try can't tell the row is up to date, as when a write beside it moves
|
|
1159
|
+
* the repo's version during its read, and finds at its commit that it was.
|
|
1160
|
+
*/
|
|
1161
|
+
const addsNothing = (data) => data.merge !== true && data.below.length > 0 && data.packs.length === 0 && data.rows === 0 && data.commits === 0 && data.bitmaps === 0;
|
|
1162
|
+
/**
|
|
1153
1163
|
* The commit step: the row, its layers those below the build and the build's own, over the packs
|
|
1154
1164
|
* it began with and its region.
|
|
1155
1165
|
*/
|
|
@@ -1357,6 +1367,10 @@ const indexStep = (parts, listed, input) => Effect.gen(function* () {
|
|
|
1357
1367
|
data: next
|
|
1358
1368
|
});
|
|
1359
1369
|
if (data.step === "region") yield* prune(data.build);
|
|
1370
|
+
if (data.step === "commit" && addsNothing(data)) {
|
|
1371
|
+
yield* prune();
|
|
1372
|
+
return prunedAt(input.at);
|
|
1373
|
+
}
|
|
1360
1374
|
if (data.step === "commit") return yield* commitStep(listed, data, input);
|
|
1361
1375
|
const allotment = yield* parts.budget.allot(floors.cache + floors.blocks, readBusy);
|
|
1362
1376
|
if (data.step === "region") return more(yield* regionStep(parts, listed, data, allotment));
|
|
@@ -1364,7 +1378,7 @@ const indexStep = (parts, listed, input) => Effect.gen(function* () {
|
|
|
1364
1378
|
if (data.step === "merge") {
|
|
1365
1379
|
const merged = yield* Effect.result(mergeStep(parts, listed, data, input, allotment));
|
|
1366
1380
|
if (Result.isSuccess(merged)) return more(merged.success);
|
|
1367
|
-
if (isSliceRefused(merged.failure)) return waiting(merged.failure
|
|
1381
|
+
if (isSliceRefused(merged.failure)) return waiting(sliceRefusal(merged.failure));
|
|
1368
1382
|
return yield* Effect.fail(merged.failure);
|
|
1369
1383
|
}
|
|
1370
1384
|
if (data.step === "graph") {
|
|
@@ -1386,7 +1400,7 @@ const indexStep = (parts, listed, input) => Effect.gen(function* () {
|
|
|
1386
1400
|
if (data.step === "read") {
|
|
1387
1401
|
const read = yield* Effect.result(readStep(parts, listed, data, allotment));
|
|
1388
1402
|
if (Result.isSuccess(read)) return more(read.success);
|
|
1389
|
-
if (isSliceRefused(read.failure)) return waiting(read.failure
|
|
1403
|
+
if (isSliceRefused(read.failure)) return waiting(sliceRefusal(read.failure));
|
|
1390
1404
|
return yield* Effect.fail(read.failure);
|
|
1391
1405
|
}
|
|
1392
1406
|
return more((yield* bitmapsStep(parts, listed, data, input, allotment)) ?? started(listed));
|