@ref0/git 0.14.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/access-jwt.mjs +2 -2
- package/dist/auth/authorize.mjs +3 -3
- package/dist/auth/fences.d.mts +1 -2
- package/dist/auth/fences.mjs +3 -3
- package/dist/auth/grants.mjs +4 -4
- package/dist/auth/host-function.mjs +18 -1
- package/dist/auth/identify.d.mts +1 -1
- package/dist/auth/identify.mjs +3 -3
- package/dist/auth/token-cleanup.mjs +67 -0
- package/dist/auth/token-rows.mjs +1 -1
- package/dist/auth/token-text.mjs +9 -1
- package/dist/auth/tokens-base.d.mts +35 -0
- package/dist/auth/tokens-base.mjs +13 -0
- package/dist/auth/tokens-layer.d.mts +2 -27
- package/dist/auth/tokens-layer.mjs +6 -11
- package/dist/auth/tokens-public.d.mts +3 -3
- package/dist/auth/tokens.d.mts +7 -10
- package/dist/auth/tokens.mjs +9 -80
- package/dist/client/answer.mjs +21 -42
- package/dist/client/client.d.mts +2 -4
- package/dist/client/git-http.mjs +17 -7
- package/dist/client/local.mjs +14 -13
- package/dist/client/push-upload.mjs +9 -8
- package/dist/client/remote.mjs +8 -10
- package/dist/client/run-remote-helper.d.mts +1 -0
- package/dist/client/run-remote-helper.mjs +58 -24
- package/dist/client/slice-push.d.mts +1 -1
- package/dist/client/transport.mjs +105 -46
- package/dist/contracts/blobs.d.mts +55 -8
- package/dist/contracts/blobs.mjs +16 -2
- package/dist/contracts/call-allowance.d.mts +13 -0
- package/dist/contracts/call-allowance.mjs +44 -0
- package/dist/contracts/calls-spent.mjs +8 -3
- package/dist/contracts/client.d.mts +15 -16
- package/dist/contracts/commits.d.mts +24 -24
- package/dist/contracts/engine.d.mts +6 -1
- package/dist/contracts/engine.mjs +10 -1
- package/dist/contracts/files.d.mts +10 -10
- package/dist/contracts/forks.d.mts +17 -17
- package/dist/contracts/git-events.d.mts +29 -1
- package/dist/contracts/git-hooks.d.mts +1 -1
- package/dist/contracts/git.d.mts +21 -0
- package/dist/contracts/grants.d.mts +24 -4
- package/dist/contracts/handlers.d.mts +1 -1
- package/dist/contracts/lfs.d.mts +28 -2
- package/dist/contracts/merges.d.mts +3 -2
- package/dist/contracts/objects.d.mts +23 -25
- package/dist/contracts/queue.d.mts +40 -12
- package/dist/contracts/queue.mjs +3 -4
- package/dist/contracts/refs.d.mts +26 -23
- package/dist/contracts/remote.d.mts +6 -7
- package/dist/contracts/remote.mjs +4 -1
- package/dist/contracts/repos.d.mts +29 -138
- package/dist/contracts/repos.mjs +5 -3
- package/dist/contracts/result.d.mts +35 -16
- package/dist/contracts/result.mjs +35 -7
- package/dist/contracts/server.d.mts +25 -50
- package/dist/contracts/services.d.mts +1 -1
- package/dist/contracts/store.d.mts +6 -5
- package/dist/contracts/sync.d.mts +11 -7
- package/dist/contracts/sync.mjs +12 -2
- package/dist/contracts/tags.d.mts +10 -10
- package/dist/contracts/time.d.mts +3 -0
- package/dist/contracts/{promises.mjs → time.mjs} +1 -1
- package/dist/contracts/tokens.d.mts +15 -17
- package/dist/contracts/tokens.mjs +3 -2
- package/dist/contracts/topics.d.mts +1 -1
- package/dist/contracts/trees.d.mts +12 -12
- package/dist/contracts/work.d.mts +24 -13
- package/dist/core/access.d.mts +1 -2
- package/dist/core/access.mjs +20 -9
- package/dist/core/ancestry.d.mts +1 -0
- package/dist/core/asked.mjs +1 -1
- package/dist/core/call-names.mjs +6 -1
- package/dist/core/call-services.mjs +11 -3
- package/dist/core/events/deliver.d.mts +1 -2
- package/dist/core/events/deliver.mjs +43 -36
- package/dist/core/events/retired.mjs +119 -0
- package/dist/core/forks.mjs +928 -432
- package/dist/core/hooks/groups.mjs +1 -1
- package/dist/core/imports.mjs +29 -23
- package/dist/core/index-job.mjs +122 -34
- package/dist/core/index-lost.d.mts +1 -2
- package/dist/core/index-lost.mjs +2 -2
- package/dist/core/loose-tally.mjs +1 -1
- package/dist/core/objects/blobs.mjs +129 -3
- package/dist/core/objects/lines.mjs +2 -2
- package/dist/core/objects/merges.mjs +4 -1
- package/dist/core/objects/objects-layer.d.mts +1 -1
- package/dist/core/objects/objects-layer.mjs +3 -3
- package/dist/core/objects/reading.mjs +24 -13
- package/dist/core/objects/tags.mjs +4 -1
- package/dist/core/objects/trees.mjs +2 -2
- package/dist/core/objects/writing.mjs +2 -2
- package/dist/core/own-writes.mjs +1 -1
- package/dist/core/parts.d.mts +4 -5
- package/dist/core/parts.mjs +3 -8
- package/dist/core/promise.mjs +9 -12
- package/dist/core/purge.mjs +287 -83
- package/dist/core/push-decide.mjs +2 -0
- package/dist/core/push-files.d.mts +1 -1
- package/dist/core/push.mjs +58 -47
- package/dist/core/receipts.mjs +8 -3
- package/dist/core/ref-index-job.mjs +4 -4
- package/dist/core/ref-view.mjs +2 -2
- package/dist/core/refs.mjs +5 -5
- package/dist/core/registered-rows.mjs +2 -2
- package/dist/core/repack.mjs +36 -21
- package/dist/core/repo-info.mjs +3 -3
- package/dist/core/repos.mjs +21 -9
- package/dist/core/rules/commit-changes.d.mts +0 -1
- package/dist/core/saved-caller-views.d.mts +7 -2
- package/dist/core/saved-caller-views.mjs +2 -2
- package/dist/core/saved-callers.d.mts +19 -2
- package/dist/core/seam.d.mts +16 -26
- package/dist/core/seam.mjs +7 -28
- package/dist/core/tokens.mjs +1 -1
- package/dist/core/view.mjs +7 -15
- package/dist/core/work.mjs +59 -14
- package/dist/effect.d.mts +3 -12
- package/dist/effect.mjs +1 -10
- package/dist/engine/failures.mjs +2 -1
- package/dist/engine/reads.mjs +4 -4
- package/dist/event-streams/stream.d.mts +2 -2
- package/dist/event-streams/stream.mjs +37 -14
- package/dist/extend.d.mts +2 -3
- package/dist/extend.mjs +2 -1
- package/dist/http/answers.mjs +8 -5
- package/dist/http/core-parts.mjs +95 -79
- package/dist/http/handler.mjs +34 -7
- package/dist/http/node.d.mts +14 -1
- package/dist/http/node.mjs +56 -27
- package/dist/http/parts.d.mts +1 -0
- package/dist/http/push-upload-job.mjs +30 -26
- package/dist/http/push-uploads.mjs +36 -21
- package/dist/http/upload-pack.mjs +3 -3
- package/dist/index.d.mts +14 -14
- package/dist/index.mjs +2 -2
- package/dist/lfs/answer.mjs +37 -0
- package/dist/lfs/base.d.mts +2 -0
- package/dist/lfs/base.mjs +25 -1
- package/dist/lfs/copy.d.mts +21 -7
- package/dist/lfs/copy.mjs +89 -6
- package/dist/lfs/layer.d.mts +15 -1
- package/dist/lfs/layer.mjs +24 -11
- package/dist/lfs/locks.mjs +2 -2
- package/dist/lfs/objects.d.mts +1 -0
- package/dist/lfs/objects.mjs +87 -17
- package/dist/lfs/pointers.mjs +2 -2
- package/dist/lfs/rows.mjs +42 -8
- package/dist/lfs/upkeep.mjs +48 -14
- package/dist/lfs/wire.mjs +6 -31
- package/dist/merges/merges.mjs +2 -2
- package/dist/node.d.mts +2 -2
- package/dist/protocol/bytes/buffers.mjs +13 -5
- package/dist/protocol/bytes/reader.mjs +6 -1
- package/dist/protocol/bytes/streams.mjs +27 -1
- package/dist/protocol/diff/read.d.mts +4 -3
- package/dist/protocol/diff/read.mjs +8 -3
- package/dist/protocol/objects/lfs-pointer.d.mts +14 -2
- package/dist/protocol/objects/lfs-pointer.mjs +1 -3
- package/dist/protocol/objects/links-raw.mjs +24 -10
- package/dist/protocol/objects/tag.d.mts +1 -1
- package/dist/protocol/objects/tree.mjs +23 -6
- package/dist/protocol/packs/delta.d.mts +6 -3
- package/dist/protocol/packs/delta.mjs +96 -32
- package/dist/protocol/packs/idx.d.mts +2 -1
- package/dist/protocol/packs/idx.mjs +22 -3
- package/dist/protocol/packs/parts.d.mts +4 -1
- package/dist/protocol/packs/parts.mjs +10 -7
- package/dist/protocol/packs/reader.d.mts +5 -0
- package/dist/protocol/packs/reader.mjs +3 -2
- package/dist/protocol/packs/writer.mjs +26 -8
- package/dist/queue/advance.mjs +21 -24
- package/dist/queue/base.d.mts +55 -0
- package/dist/queue/base.mjs +44 -0
- package/dist/queue/calls.mjs +51 -54
- package/dist/queue/commit.mjs +1 -1
- package/dist/queue/host.d.mts +1 -15
- package/dist/queue/host.mjs +2 -7
- package/dist/queue/layer.d.mts +2 -1
- package/dist/queue/layer.mjs +10 -3
- package/dist/queue/limits.mjs +2 -0
- package/dist/queue/push-option.mjs +9 -24
- package/dist/queue/schedule.mjs +1 -1
- package/dist/queue/state.mjs +2 -10
- package/dist/queue/trim.mjs +5 -3
- package/dist/rest/blobs.mjs +29 -5
- package/dist/rest/caller.d.mts +4 -4271
- package/dist/rest/caller.mjs +4 -0
- package/dist/rest/client.d.mts +8 -5
- package/dist/rest/client.mjs +19 -2
- package/dist/rest/handlers.mjs +50 -5
- package/dist/rest/layer.d.mts +2 -2
- package/dist/rest/layer.mjs +5 -12
- package/dist/rest/me.d.mts +3 -432
- package/dist/server/check-fetch.mjs +3 -3
- package/dist/server/edge-node.d.mts +11 -8
- package/dist/server/edge-node.mjs +9 -6
- package/dist/server/edge.d.mts +21 -7
- package/dist/server/edge.mjs +32 -11
- package/dist/server/extension.mjs +1 -1
- package/dist/server/git-layer.d.mts +5 -5
- package/dist/server/git-layer.mjs +28 -22
- package/dist/server/git-namespace.d.mts +4 -3
- package/dist/server/git-namespace.mjs +3 -2
- package/dist/server/joined.d.mts +6 -18
- package/dist/server/joined.mjs +9 -36
- package/dist/server/lifecycle.mjs +18 -106
- package/dist/server/registry.mjs +24 -7
- package/dist/server/server.mjs +205 -346
- package/dist/signin/context.d.mts +1 -2
- package/dist/signin/layer.d.mts +1 -1
- package/dist/signin/layer.mjs +1 -1
- package/dist/storage/allotted.mjs +18 -3
- package/dist/storage/batch-upkeep.mjs +274 -0
- package/dist/storage/batches.d.mts +8 -0
- package/dist/storage/batches.mjs +344 -0
- package/dist/storage/calls.d.mts +1 -2
- package/dist/storage/calls.mjs +144 -158
- package/dist/storage/chunks.d.mts +9 -0
- package/dist/storage/chunks.mjs +297 -0
- package/dist/storage/clean-up.mjs +72 -9
- package/dist/storage/counted-bucket.mjs +4 -4
- package/dist/storage/fetch.d.mts +1 -0
- package/dist/storage/fetch.mjs +287 -210
- package/dist/storage/host-bucket.mjs +1 -2
- package/dist/storage/id-mix.mjs +19 -5
- package/dist/storage/index-bitmaps.mjs +9 -2
- package/dist/storage/index-build.d.mts +0 -1
- package/dist/storage/index-build.mjs +80 -23
- package/dist/storage/index-fetch.mjs +113 -72
- package/dist/storage/index-files.d.mts +3 -0
- package/dist/storage/index-files.mjs +10 -5
- package/dist/storage/index-graph.mjs +72 -22
- package/dist/storage/index-remap.mjs +200 -64
- package/dist/storage/index-whole.mjs +127 -0
- package/dist/storage/largest-files.mjs +1 -1
- package/dist/storage/layout.mjs +23 -0
- package/dist/storage/loose.d.mts +7 -4
- package/dist/storage/loose.mjs +212 -67
- package/dist/storage/memory-budget.mjs +16 -4
- package/dist/storage/merge-plan.mjs +3 -2
- package/dist/storage/merge-row.mjs +7 -1
- package/dist/storage/merge-stream.mjs +164 -25
- package/dist/storage/merge-walk.mjs +8 -4
- package/dist/storage/merge-write.mjs +1 -1
- package/dist/storage/merge.d.mts +1 -1
- package/dist/storage/merge.mjs +1 -1
- package/dist/storage/object-rows.d.mts +1 -0
- package/dist/storage/object-rows.mjs +385 -65
- package/dist/storage/oid-table.mjs +171 -0
- package/dist/storage/pack-order.mjs +8 -4
- package/dist/storage/pack-ranges.d.mts +1 -2
- package/dist/storage/pack-ranges.mjs +4 -5
- package/dist/storage/pack-reads.d.mts +2 -1
- package/dist/storage/pack-reads.mjs +158 -42
- package/dist/storage/pack-receive.d.mts +1 -1
- package/dist/storage/pack-receive.mjs +2 -2
- package/dist/storage/packs.d.mts +1 -1
- package/dist/storage/packs.mjs +136 -66
- package/dist/storage/placed-reads.mjs +1 -1
- package/dist/storage/plan-columns.d.mts +4 -0
- package/dist/storage/plan-columns.mjs +238 -0
- package/dist/storage/prune-keep.mjs +134 -41
- package/dist/storage/prune-walk.mjs +202 -62
- package/dist/storage/prune.mjs +194 -91
- package/dist/storage/push-allotment.mjs +91 -12
- package/dist/storage/push-uploads.mjs +4 -4
- package/dist/storage/pushed-commits.mjs +4 -2
- package/dist/storage/quarantine.d.mts +1 -1
- package/dist/storage/range-cache.mjs +125 -8
- package/dist/storage/ready.d.mts +1 -1
- package/dist/storage/ready.mjs +8 -6
- package/dist/storage/receive-bounds.mjs +23 -8
- package/dist/storage/repack-backlog.mjs +6 -3
- package/dist/storage/repack.d.mts +1 -1
- package/dist/storage/rows.d.mts +1 -1
- package/dist/storage/rows.mjs +1 -1
- package/dist/storage/runs.mjs +195 -43
- package/dist/storage/send-list.d.mts +1 -0
- package/dist/storage/send-list.mjs +54 -10
- package/dist/storage/single-flight.mjs +13 -7
- package/dist/storage/stream-whole.mjs +127 -26
- package/dist/storage/unpack.mjs +371 -79
- package/dist/storage/visible.mjs +2 -2
- package/dist/storage/walk.mjs +192 -38
- package/dist/storage/wants.mjs +5 -5
- package/dist/store/bodies.mjs +38 -0
- package/dist/store/call-count.d.mts +8 -12
- package/dist/store/call-count.mjs +34 -46
- package/dist/store/catalogue.d.mts +2 -2
- package/dist/store/catalogue.mjs +145 -35
- package/dist/store/crossing.mjs +1 -3
- package/dist/store/cursor-seal.d.mts +1 -2
- package/dist/store/cursor-seal.mjs +16 -6
- package/dist/store/door.mjs +183 -0
- package/dist/store/errors.d.mts +3 -4
- package/dist/store/errors.mjs +15 -33
- package/dist/store/git-store.mjs +25 -7
- package/dist/store/job-try.mjs +9 -32
- package/dist/store/list-job.mjs +44 -8
- package/dist/store/records.d.mts +3 -0
- package/dist/store/records.mjs +3 -0
- package/dist/store/repo-record.d.mts +1 -2
- package/dist/store/repo-record.mjs +32 -20
- package/dist/store/reservations.mjs +1 -1
- package/dist/store/scopes.mjs +11 -0
- package/dist/store/settle.mjs +4 -4
- package/dist/sync/github.mjs +3 -3
- package/dist/sync/import.mjs +31 -18
- package/dist/sync/lfs-batch.mjs +4 -5
- package/dist/sync/lfs-copy.mjs +17 -6
- package/dist/sync/mirror.mjs +34 -31
- package/dist/sync/said.mjs +16 -37
- package/dist/sync/step.mjs +33 -25
- package/dist/sync/tries.mjs +9 -9
- package/dist/topics/advance.mjs +10 -11
- package/dist/topics/base.d.mts +15 -0
- package/dist/topics/base.mjs +8 -0
- package/dist/topics/host.mjs +1 -1
- package/dist/topics/layer.d.mts +4 -9
- package/dist/topics/layer.mjs +2 -3
- package/dist/topics/members.mjs +4 -4
- package/dist/topics/public.d.mts +2 -1
- package/dist/topics/topic.mjs +2 -2
- package/package.json +5 -4
- package/dist/contracts/promises.d.mts +0 -39
- package/dist/core/call-names.d.mts +0 -3
- package/dist/core/clock.mjs +0 -18
- package/dist/lfs/calls.mjs +0 -26
- package/dist/rest/api.d.mts +0 -23
- package/dist/rest/blobs.d.mts +0 -833
- package/dist/rest/commits.d.mts +0 -3543
- package/dist/rest/errors.d.mts +0 -2124
- package/dist/rest/events.d.mts +0 -426
- package/dist/rest/files.d.mts +0 -1342
- package/dist/rest/forks.d.mts +0 -2160
- package/dist/rest/handlers.d.mts +0 -8
- package/dist/rest/merges.d.mts +0 -477
- package/dist/rest/queue.d.mts +0 -5917
- package/dist/rest/refs.d.mts +0 -2988
- package/dist/rest/repos.d.mts +0 -2567
- package/dist/rest/tags.d.mts +0 -1316
- package/dist/rest/tokens.d.mts +0 -2614
- package/dist/rest/topics.d.mts +0 -2224
- package/dist/rest/trees.d.mts +0 -1709
- package/dist/rest/work.d.mts +0 -1695
- package/dist/server/lifecycle.d.mts +0 -2
- package/dist/store/promises.d.mts +0 -11
- package/dist/store/promises.mjs +0 -327
package/dist/core/purge.mjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import { gitError, isGitError } from "../contracts/result.mjs";
|
|
1
2
|
import { repackJobName } from "../storage/repack-job.mjs";
|
|
2
3
|
import { objectCollections } from "../storage/layout.mjs";
|
|
3
4
|
import { tooLargeRead } from "../storage/object-rows.mjs";
|
|
4
5
|
import { forkedFrom, reconcile, releaseHold } from "../store/catalogue.mjs";
|
|
5
|
-
import { storeCall } from "../store/errors.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { storeCall, storeCommit } from "../store/errors.mjs";
|
|
7
|
+
import { currentRepo, gitJob } from "../store/job-try.mjs";
|
|
7
8
|
import { outboxCollections } from "../store/outbox.mjs";
|
|
8
9
|
import { keyKept } from "../store/records.mjs";
|
|
9
10
|
import { readRecord } from "../store/repo-record.mjs";
|
|
10
11
|
import { collections, newChangeId, repoScope } from "../store/scopes.mjs";
|
|
11
|
-
import { isDeliverJob,
|
|
12
|
+
import { droppedDelivery, isDeliverJob, notFailed, sentThrough } from "./events/deliver.mjs";
|
|
13
|
+
import { retiredAmong } from "./events/retired.mjs";
|
|
12
14
|
import { indexJobName } from "./index-job.mjs";
|
|
13
15
|
import * as Effect from "effect/Effect";
|
|
14
16
|
import * as Schema from "effect/Schema";
|
|
@@ -39,10 +41,31 @@ const purgeBackstop = 6e5;
|
|
|
39
41
|
*/
|
|
40
42
|
const purgeRunningRelook = 6e4;
|
|
41
43
|
/**
|
|
42
|
-
*
|
|
44
|
+
* How long a purge waits without progress on a stalled or unowned blocker (an orphaned drained
|
|
45
|
+
* row with no drain job, a failed drain job, an unretired dropped delivery, a missing fork record,
|
|
46
|
+
* or a deleted fork whose `git.purge` has failed or is absent) before failing permanently (#2685).
|
|
47
|
+
*/
|
|
48
|
+
const purgeStallLimit = 72e5;
|
|
49
|
+
/**
|
|
50
|
+
* How long a purge waits without progress while an active drain job (`git.repack`, `git.index`, an
|
|
51
|
+
* active delivery, or a running retired delivery) is waiting or running, while a registration
|
|
52
|
+
* purge part answers `waits`, while a deleted fork's own `git.purge` still stands non-failed, or
|
|
53
|
+
* while a fork-hold walk hits its check limit with holds unchecked, before failing permanently:
|
|
54
|
+
* past `defaultDeliverRetry`'s 3-day window and `@ref0/github`'s 24 h 5 m multipart release upload
|
|
55
|
+
* window so legitimate work finishes without changing exported `PurgeStep` (#2685).
|
|
56
|
+
*/
|
|
57
|
+
const purgeDrainLimit = 3456e5;
|
|
58
|
+
/** How many blocking drain jobs a stuck error names at most. */
|
|
59
|
+
const stuckNamesMost = 8;
|
|
60
|
+
/** Built-in retry bounds for transient purge failures (store errors, failed drops). */
|
|
61
|
+
const purgeRetryLimit = 20;
|
|
62
|
+
const purgeRetryDelay = 1e3;
|
|
63
|
+
const purgeRetryMaxDelay = 3e5;
|
|
64
|
+
/**
|
|
65
|
+
* The lease a purge claims a dropped delivery's waiting job under, only to settle it done in the
|
|
43
66
|
* same try: no handler runs under it.
|
|
44
67
|
*/
|
|
45
|
-
const
|
|
68
|
+
const droppedLease = "1 minute";
|
|
46
69
|
/**
|
|
47
70
|
* A step's page where its rows passed one read's `limits.answerBytes`, as object rows can: rows
|
|
48
71
|
* of `limits.valueBytes` each fill half an answer.
|
|
@@ -54,9 +77,10 @@ const purgeLargePage = /* @__PURE__ */ Math.floor(limits.answerBytes / limits.va
|
|
|
54
77
|
* deletes its index's files, and each delivery's, `git.deliver.<name>`, sends `repo.deleted`. A
|
|
55
78
|
* failed one holds the purge until a host retries or discards it. A delivery's waiting job that
|
|
56
79
|
* has sent `repo.deleted` holds it no longer, since it waits only to trim events the purge
|
|
57
|
-
* deletes itself. A
|
|
58
|
-
*
|
|
59
|
-
*
|
|
80
|
+
* deletes itself. A retired delivery's, one the host names in `events.retired`, holds it only
|
|
81
|
+
* while a try of it runs, on an instance that still runs it in a deploy: then the purge claims it,
|
|
82
|
+
* and ends it if its row is there under the claim, as `endDropped` says. A delivery the server
|
|
83
|
+
* doesn't run and the host hasn't retired holds it as any delivery's does. A new job that deletes a repo's bytes joins this list, or its check below.
|
|
60
84
|
* Every other job ends on the record the purge deletes last: git.list's projection the purge runs
|
|
61
85
|
* itself before it.
|
|
62
86
|
*/
|
|
@@ -103,6 +127,11 @@ const purgeCollections = [
|
|
|
103
127
|
collections.upkeep,
|
|
104
128
|
collections.stats,
|
|
105
129
|
objectCollections.objects,
|
|
130
|
+
objectCollections.stagedObjects,
|
|
131
|
+
objectCollections.stagedSizes,
|
|
132
|
+
objectCollections.objectChunks,
|
|
133
|
+
objectCollections.batches,
|
|
134
|
+
objectCollections.batchQuarantine,
|
|
106
135
|
objectCollections.cruft,
|
|
107
136
|
objectCollections.prune,
|
|
108
137
|
objectCollections.index,
|
|
@@ -117,57 +146,177 @@ const purgeCollections = [
|
|
|
117
146
|
const purgeJobName = "git.purge";
|
|
118
147
|
/** The repo's one `git.purge` row. */
|
|
119
148
|
const purgeJobKey = "purge";
|
|
120
|
-
const
|
|
149
|
+
const WaitKind = /* @__PURE__ */ Schema.Literals(["drain", "stall"]);
|
|
150
|
+
/**
|
|
151
|
+
* No-progress tracking carried across `more` steps: `since` and `wait` bound scheduled post-guard
|
|
152
|
+
* waits (`purgeDrainLimit` for active drain jobs, `purgeStallLimit` for stalled/unowned blockers),
|
|
153
|
+
* and `spins` bounds consecutive immediate-retry misses (`purgeSpinTries`). Every field is optional
|
|
154
|
+
* so `{}` rows decode unchanged, and genuine progress clears all three back to `{}` (#2685).
|
|
155
|
+
*/
|
|
156
|
+
const PurgeData = /* @__PURE__ */ Schema.Struct({
|
|
157
|
+
since: Schema.optionalKey(Schema.Number),
|
|
158
|
+
wait: Schema.optionalKey(WaitKind),
|
|
159
|
+
spins: Schema.optionalKey(Schema.Int)
|
|
160
|
+
});
|
|
121
161
|
const again = { kind: "more" };
|
|
162
|
+
const hasStuckState = (data) => data.since !== void 0 || data.wait !== void 0 || data.spins !== void 0;
|
|
163
|
+
/** Genuine progress made: clears prior stall/spin tracking when any was set. */
|
|
164
|
+
const progressed = (data) => hasStuckState(data) ? {
|
|
165
|
+
kind: "more",
|
|
166
|
+
data: {}
|
|
167
|
+
} : again;
|
|
168
|
+
/** Permanent `git.purge` refusal naming the blocker and the host-level `jobs.retry` recovery path. */
|
|
169
|
+
const purgeStuck = (scope, blocker, detail) => gitError("FAILED_PRECONDITION", `${purgeJobName} of ${scope} is stuck on ${detail}: clear the blocker, then call jobs.retry('${scope}', { name: '${purgeJobName}', key: '${purgeJobKey}' })`, { context: {
|
|
170
|
+
reason: "purge-stuck",
|
|
171
|
+
blocker
|
|
172
|
+
} });
|
|
173
|
+
/** Whether `failure` is a permanent `purge-stuck` refusal, which `purgeRetry` never retries. */
|
|
174
|
+
const isPurgeStuck = (failure) => isGitError(failure.error) && failure.error.code === "FAILED_PRECONDITION" && failure.error.context?.["reason"] === "purge-stuck";
|
|
175
|
+
/** A random share of a wait, at least 0 and under 1, from `crypto.getRandomValues`. */
|
|
176
|
+
const randomShare = () => (crypto.getRandomValues(/* @__PURE__ */ new Uint32Array(1))[0] ?? 0) / 2 ** 32;
|
|
177
|
+
/**
|
|
178
|
+
* `git.purge`'s retry policy: a stuck refusal fails immediately with no further tries, while
|
|
179
|
+
* transient store or drop errors keep the built-in 20-try exponential backoff (1 s to 5 min).
|
|
180
|
+
*/
|
|
181
|
+
const purgeRetry = (failure) => {
|
|
182
|
+
if (isPurgeStuck(failure)) return false;
|
|
183
|
+
if (failure.attempt >= purgeRetryLimit) return false;
|
|
184
|
+
const wait = Math.min(purgeRetryMaxDelay, purgeRetryDelay * 2 ** (failure.attempt - 1));
|
|
185
|
+
return Math.round(wait / 2 + wait / 2 * randomShare());
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* One scheduled post-guard wait of `kind` (`'stall'` or `'drain'`), due at `nextAt`: records
|
|
189
|
+
* `since` on the first wait of that kind, clamps the next look to `since + limit` so a far due
|
|
190
|
+
* time cannot overshoot the cap, and fails permanently once `at - since` reaches its limit.
|
|
191
|
+
*/
|
|
192
|
+
const waitOrFail = (scope, data, at, nextAt, kind, blocker, detail) => {
|
|
193
|
+
const limit = kind === "drain" ? purgeDrainLimit : purgeStallLimit;
|
|
194
|
+
const since = data.wait === kind && data.since !== void 0 ? data.since : at;
|
|
195
|
+
if (at - since >= limit) return Effect.fail(purgeStuck(scope, blocker, detail));
|
|
196
|
+
return Effect.succeed({
|
|
197
|
+
kind: "more",
|
|
198
|
+
at: Math.min(nextAt, since + limit),
|
|
199
|
+
data: {
|
|
200
|
+
since,
|
|
201
|
+
wait: kind
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Classifies a non-live fork hold for `waitOrFail`:
|
|
207
|
+
* - an exhausted walk (more holds than `forkHoldChecks` unchecked) waits under `purgeDrainLimit`;
|
|
208
|
+
* - a dead walk checks at most one `git.purge` listing per deleted fork hold, short-circuiting on
|
|
209
|
+
* the first standing non-failed `git.purge` (`purgeDrainLimit`) so a source waits for a healthy
|
|
210
|
+
* deleted fork's long drain (such as a 24 h 5 m multipart upload);
|
|
211
|
+
* - deleted forks whose `git.purge` has failed or is absent, and gone fork records, wait under
|
|
212
|
+
* `purgeStallLimit`.
|
|
213
|
+
*/
|
|
214
|
+
const forkHoldWait = /* @__PURE__ */ Effect.fnUntraced(function* (store, hold) {
|
|
215
|
+
if (hold.kind === "exhausted") return {
|
|
216
|
+
kind: "drain",
|
|
217
|
+
detail: `fork hold ${hold.hold} (more than ${hold.checked} fork holds unchecked)`
|
|
218
|
+
};
|
|
219
|
+
let firstDeletedHold;
|
|
220
|
+
let firstDeletedReason;
|
|
221
|
+
for (const entry of hold.deleted) {
|
|
222
|
+
const job = (yield* storeCall(store.jobs.list(repoScope(entry.fork), { name: purgeJobName }))).items.find((item) => item.key === purgeJobKey);
|
|
223
|
+
if (job !== void 0 && job.state !== "failed") return {
|
|
224
|
+
kind: "drain",
|
|
225
|
+
detail: `fork hold ${entry.hold} (fork purge ${job.state})`
|
|
226
|
+
};
|
|
227
|
+
if (firstDeletedHold === void 0) {
|
|
228
|
+
firstDeletedHold = entry.hold;
|
|
229
|
+
firstDeletedReason = job === void 0 ? "no purge job" : "purge failed";
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (hold.state === "deleted" && firstDeletedHold !== void 0 && firstDeletedReason !== void 0) return {
|
|
233
|
+
kind: "stall",
|
|
234
|
+
detail: `fork hold ${firstDeletedHold} (fork deleted, ${firstDeletedReason})`
|
|
235
|
+
};
|
|
236
|
+
return {
|
|
237
|
+
kind: "stall",
|
|
238
|
+
detail: `fork hold ${hold.hold} (fork ${hold.state})`
|
|
239
|
+
};
|
|
240
|
+
});
|
|
241
|
+
/**
|
|
242
|
+
* One immediate no-progress retry (CAS miss, scope version move, or dropped-delivery fence miss):
|
|
243
|
+
* counts consecutive spins since last progress and fails permanently at `purgeSpinTries`.
|
|
244
|
+
*/
|
|
245
|
+
const spinOrFail = (scope, data, blocker, detail) => {
|
|
246
|
+
const spins = (data.spins ?? 0) + 1;
|
|
247
|
+
if (spins >= 20) return Effect.fail(purgeStuck(scope, blocker, detail));
|
|
248
|
+
const next = { spins };
|
|
249
|
+
if (data.since !== void 0) next.since = data.since;
|
|
250
|
+
if (data.wait !== void 0) next.wait = data.wait;
|
|
251
|
+
return Effect.succeed({
|
|
252
|
+
kind: "more",
|
|
253
|
+
data: next
|
|
254
|
+
});
|
|
255
|
+
};
|
|
122
256
|
/**
|
|
123
257
|
* When a purge at `at` looks again for one drain job or delivery's: a waiting one's due, a running
|
|
124
258
|
* one's `purgeRunningRelook`, a failed one's `purgeBackstop`. A due time no later than the
|
|
125
|
-
* running re-look's is the queue's to claim at once.
|
|
259
|
+
* running re-look's is the queue's to claim at once. A dropped delivery's waiting job, which only
|
|
260
|
+
* an instance that still runs it claims, is looked at again no sooner than `purgeBackstop`, so a
|
|
261
|
+
* purge held on one that no instance claims steps, and logs, once a backstop.
|
|
126
262
|
*/
|
|
127
|
-
const relookFor = (item, at) => {
|
|
263
|
+
const relookFor = (item, at, dropped) => {
|
|
128
264
|
if (item.state === "failed") return at + purgeBackstop;
|
|
129
|
-
return item.state === "waiting" ? Math.max(item.due, at + purgeRunningRelook) : at + purgeRunningRelook;
|
|
265
|
+
return item.state === "waiting" ? Math.max(item.due, at + (dropped ? purgeBackstop : purgeRunningRelook)) : at + purgeRunningRelook;
|
|
130
266
|
};
|
|
131
267
|
/**
|
|
132
|
-
* When a stray delivery's job, one the server no longer runs, stops holding the purge:
|
|
133
|
-
* `purgeBackstop` past its due, or past its failure, by which an instance that still runs it would
|
|
134
|
-
* have claimed it.
|
|
135
|
-
*
|
|
136
|
-
* Which delivery is stray is this instance's own list, and the time is the row's, not the
|
|
137
|
-
* deploy's. In a rolling deploy that drops a delivery, a new instance purges at once a repo already
|
|
138
|
-
* deleted whose job of it is overdue or failed past `purgeBackstop`, within seconds of starting, and
|
|
139
|
-
* an old instance that still runs the delivery loses that repo's `repo.deleted`. So can one whose
|
|
140
|
-
* claim, or a host's retry, lands between a step's read and its deletes, which no store call fences.
|
|
141
|
-
*/
|
|
142
|
-
const strayEnd = (item) => (item.state === "failed" ? item.failedAt ?? item.due : item.due) + purgeBackstop;
|
|
143
|
-
/**
|
|
144
268
|
* When a purge at `at` looks again for the drain jobs and deliveries waiting, running or failed in
|
|
145
|
-
* `scope`, the soonest of theirs
|
|
146
|
-
* is `repo.deleted`'s `seq`, past which a waiting delivery holds nothing; with none,
|
|
147
|
-
* A
|
|
269
|
+
* `scope`, the soonest of theirs, `at`: none when none is left. A page of its jobs at a time.
|
|
270
|
+
* `deleted` is `repo.deleted`'s `seq`, past which a waiting delivery holds nothing; with none,
|
|
271
|
+
* each holds. A retired delivery's job holds only while a try of it runs, and a dropped one's the
|
|
272
|
+
* host hasn't retired holds as any delivery's does, with a warning that names it, once a step.
|
|
273
|
+
* `endDropped` reads the rows again once it holds their jobs' claims, so this read only lets go. `dropped` is whether it listed a job of a delivery
|
|
274
|
+
* the server doesn't run, which `endDropped` must end before the step deletes anything.
|
|
148
275
|
*/
|
|
149
276
|
const draining = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, at, deleted, deliveries) {
|
|
150
277
|
let after;
|
|
151
278
|
let soonest;
|
|
279
|
+
let anyDropped = false;
|
|
280
|
+
let anyActive = false;
|
|
281
|
+
const blockers = [];
|
|
152
282
|
for (;;) {
|
|
153
283
|
const page = after === void 0 ? {} : { page: { after } };
|
|
154
|
-
const listing = yield* storeCall(
|
|
284
|
+
const listing = yield* storeCall(store.jobs.list(scope, page));
|
|
285
|
+
const names = listing.items.flatMap((item) => droppedDelivery(item, deliveries) ?? []);
|
|
286
|
+
const retired = yield* retiredAmong(store, new Set(names));
|
|
287
|
+
anyDropped ||= names.length > 0;
|
|
155
288
|
for (const item of listing.items) {
|
|
156
289
|
const delivery = isDeliverJob(item);
|
|
157
290
|
if (!drainJobs.has(item.name) && !delivery) continue;
|
|
158
291
|
if (delivery && item.state === "waiting" && deleted !== void 0 && (yield* sentThrough(store, scope, item, deleted))) continue;
|
|
159
|
-
const
|
|
160
|
-
if (
|
|
161
|
-
const
|
|
292
|
+
const dropped = droppedDelivery(item, deliveries);
|
|
293
|
+
if (dropped !== void 0 && item.state !== "running" && retired.has(dropped)) continue;
|
|
294
|
+
const unretired = dropped !== void 0 && !retired.has(dropped);
|
|
295
|
+
if (unretired) yield* Effect.logWarning(`git.purge of ${scope} waits on ${item.name}, a delivery this server doesn't run: add '${dropped}' to events.retired`);
|
|
296
|
+
if (item.state !== "failed" && !unretired) anyActive = true;
|
|
297
|
+
if (blockers.length < stuckNamesMost) {
|
|
298
|
+
const note = unretired ? `${item.state}, unretired delivery '${dropped}'` : item.state;
|
|
299
|
+
blockers.push(`${item.name}/${item.key} (${note})`);
|
|
300
|
+
}
|
|
301
|
+
const relook = relookFor(item, at, dropped !== void 0);
|
|
162
302
|
soonest = soonest === void 0 ? relook : Math.min(soonest, relook);
|
|
163
303
|
}
|
|
164
|
-
if (listing.next === void 0)
|
|
304
|
+
if (listing.next === void 0) {
|
|
305
|
+
const kind = anyActive ? "drain" : "stall";
|
|
306
|
+
const detail = `${blockers.length === 1 ? "drain job" : "drain jobs"} ${blockers.join(", ")}`;
|
|
307
|
+
return {
|
|
308
|
+
at: soonest,
|
|
309
|
+
dropped: anyDropped,
|
|
310
|
+
kind,
|
|
311
|
+
detail
|
|
312
|
+
};
|
|
313
|
+
}
|
|
165
314
|
after = listing.next;
|
|
166
315
|
}
|
|
167
316
|
});
|
|
168
317
|
/** One collection's next page of keys, at one version: a smaller page where its rows are large. */
|
|
169
318
|
const pageOf = (store, scope, collection) => {
|
|
170
|
-
const read = (limit) => Effect.map(storeCall(
|
|
319
|
+
const read = (limit) => Effect.map(storeCall(store.read(scope, [{
|
|
171
320
|
collection,
|
|
172
321
|
limit
|
|
173
322
|
}])), (snapshot) => ({
|
|
@@ -188,13 +337,13 @@ const firstLeft = (store, scope) => {
|
|
|
188
337
|
collection,
|
|
189
338
|
limit: 1
|
|
190
339
|
}));
|
|
191
|
-
const together = Effect.map(storeCall(
|
|
340
|
+
const together = Effect.map(storeCall(store.read(scope, reads)), (snapshot) => ({
|
|
192
341
|
version: snapshot.version,
|
|
193
342
|
left: purgeCollections.find((_, index) => (snapshot.results[index]?.length ?? 0) > 0)
|
|
194
343
|
}));
|
|
195
344
|
const apart = Effect.fnUntraced(function* () {
|
|
196
345
|
for (const collection of purgeCollections) {
|
|
197
|
-
const snapshot = yield* storeCall(
|
|
346
|
+
const snapshot = yield* storeCall(store.read(scope, [{
|
|
198
347
|
collection,
|
|
199
348
|
limit: 1
|
|
200
349
|
}]));
|
|
@@ -204,7 +353,7 @@ const firstLeft = (store, scope) => {
|
|
|
204
353
|
};
|
|
205
354
|
}
|
|
206
355
|
return {
|
|
207
|
-
version: (yield* storeCall(
|
|
356
|
+
version: (yield* storeCall(store.read(scope, []))).version,
|
|
208
357
|
left: void 0
|
|
209
358
|
};
|
|
210
359
|
});
|
|
@@ -215,11 +364,11 @@ const discardFailed = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope)
|
|
|
215
364
|
let after;
|
|
216
365
|
for (;;) {
|
|
217
366
|
const page = after === void 0 ? {} : { page: { after } };
|
|
218
|
-
const listing = yield* storeCall(
|
|
367
|
+
const listing = yield* storeCall(store.jobs.list(scope, {
|
|
219
368
|
state: "failed",
|
|
220
369
|
...page
|
|
221
370
|
}));
|
|
222
|
-
yield* Effect.forEach(listing.items, (item) => storeCall(
|
|
371
|
+
yield* Effect.forEach(listing.items, (item) => storeCall(store.jobs.discard(scope, {
|
|
223
372
|
name: item.name,
|
|
224
373
|
key: item.key
|
|
225
374
|
})), { discard: true });
|
|
@@ -235,13 +384,13 @@ const discardFailed = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope)
|
|
|
235
384
|
const dropScopes = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, internalId) {
|
|
236
385
|
const named = yield* parts.scopes(internalId);
|
|
237
386
|
if (named.length > 64) return yield* Effect.die(/* @__PURE__ */ new TypeError(`The registrations name ${named.length} scopes of '${internalId}', past 64`));
|
|
238
|
-
for (const scope of [...named, repoScope(internalId)]) yield* storeCall(
|
|
387
|
+
for (const scope of [...named, repoScope(internalId)]) yield* storeCall(store.drop(scope));
|
|
239
388
|
});
|
|
240
389
|
/**
|
|
241
|
-
* A
|
|
390
|
+
* A dropped delivery's waiting job made due at `at`: a save moves a waiting job's due only earlier,
|
|
242
391
|
* so a claim takes it. Its handler never runs, since no queue of this server runs its delivery.
|
|
243
392
|
*/
|
|
244
|
-
const
|
|
393
|
+
const droppedDueAt = (item, at) => defineJob({
|
|
245
394
|
name: item.name,
|
|
246
395
|
schema: Schema.toStandardSchemaV1(Schema.Unknown),
|
|
247
396
|
handler: () => {
|
|
@@ -253,47 +402,92 @@ const strayDueAt = (item, at) => defineJob({
|
|
|
253
402
|
at
|
|
254
403
|
});
|
|
255
404
|
/**
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
405
|
+
* Ends the jobs left in `scope` of deliveries the server doesn't run, a page of them at a time, or
|
|
406
|
+
* answers `false` when the purge must look again first, having deleted nothing. `draining` let each
|
|
407
|
+
* go: retired, or a waiting one that sent `repo.deleted`, through `deleted`. A step runs it before
|
|
408
|
+
* any part or page, so a try of one never reads the repo's rows after a delete took them: an
|
|
409
|
+
* `events` page gone under a try that still owes `repo.deleted` is that event lost.
|
|
410
|
+
*
|
|
411
|
+
* It claims the waiting ones first, each made due at `at`, since no queue of this server claims
|
|
412
|
+
* one, then reads their retirement rows in one read: so what it ends was retired while it held the
|
|
413
|
+
* claim, and a restore that landed before that read finds its job released and every row kept. A
|
|
414
|
+
* waiting job settles done only when its row is there, or it sent `repo.deleted`; a failed one is
|
|
415
|
+
* discarded only when its row is there, and the store refuses that once a `work.retry` took it.
|
|
416
|
+
* Anything else answers `false`: a row gone, a job another instance claimed or ran between the list
|
|
417
|
+
* and the claim, a claim that lapsed under `droppedLease` before its settle, a settle refused, or
|
|
418
|
+
* a discard refused. Each claim it doesn't settle done it releases, so its delivery claims it. A
|
|
419
|
+
* restore that lands after the read is the retire's: the ends it decided stand, though their
|
|
420
|
+
* settles may land after it, as `events.retired` says.
|
|
261
421
|
*/
|
|
262
|
-
const
|
|
422
|
+
const endDropped = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, at, deleted, deliveries) {
|
|
263
423
|
let after;
|
|
264
424
|
for (;;) {
|
|
265
425
|
const page = after === void 0 ? {} : { page: { after } };
|
|
266
|
-
const listing = yield* storeCall(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
426
|
+
const listing = yield* storeCall(store.jobs.list(scope, page));
|
|
427
|
+
const dropped = listing.items.filter((item) => droppedDelivery(item, deliveries) !== void 0);
|
|
428
|
+
if (dropped.some((item) => item.state === "running")) return false;
|
|
429
|
+
const waiting = dropped.filter((item) => item.state === "waiting");
|
|
430
|
+
const later = waiting.flatMap((item) => item.due > at ? [droppedDueAt(item, at)] : []);
|
|
431
|
+
if (later.length > 0) yield* storeCall(store.add(scope, { jobs: later }));
|
|
432
|
+
const names = waiting.map((item) => item.name);
|
|
433
|
+
const request = {
|
|
434
|
+
lease: droppedLease,
|
|
435
|
+
names,
|
|
436
|
+
limit: names.length
|
|
437
|
+
};
|
|
438
|
+
const { claims } = waiting.length === 0 ? { claims: [] } : yield* storeCall(store.jobs.claim(scope, request));
|
|
439
|
+
const retired = yield* retiredAmong(store, droppedNames(dropped, deliveries));
|
|
440
|
+
if ((yield* Effect.forEach(claims, (claim) => endClaimed(store, scope, claim, retired, deleted, deliveries, at))).includes(false) || claims.length < waiting.length) return false;
|
|
441
|
+
for (const item of dropped.filter((each) => each.state === "failed")) {
|
|
442
|
+
if (!retired.has(droppedDelivery(item, deliveries) ?? "")) return false;
|
|
443
|
+
const job = {
|
|
444
|
+
name: item.name,
|
|
445
|
+
key: item.key
|
|
279
446
|
};
|
|
280
|
-
|
|
281
|
-
yield* Effect.forEach(claims, (claim) => storeCall(() => store.settle(claim, { kind: "done" })), { discard: true });
|
|
447
|
+
if (!(yield* storeCall(store.jobs.discard(scope, job)).pipe(Effect.as(true), Effect.catchIf(notFailed, () => Effect.succeed(false))))) return false;
|
|
282
448
|
}
|
|
283
|
-
if (listing.next === void 0) return;
|
|
449
|
+
if (listing.next === void 0) return true;
|
|
284
450
|
after = listing.next;
|
|
285
451
|
}
|
|
286
452
|
});
|
|
453
|
+
/** The deliveries `items` name that the server doesn't run. */
|
|
454
|
+
const droppedNames = (items, deliveries) => new Set(items.flatMap((item) => droppedDelivery(item, deliveries) ?? []));
|
|
455
|
+
/**
|
|
456
|
+
* Settles `claim`, a dropped delivery's job, done when its delivery is in `retired`, the read made
|
|
457
|
+
* while the claim held, or it sent `repo.deleted`, and answers whether it did: else, or when the
|
|
458
|
+
* settle hands back a claim of it again, it releases the claim.
|
|
459
|
+
*/
|
|
460
|
+
const endClaimed = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, claim, retired, deleted, deliveries, at) {
|
|
461
|
+
const delivery = droppedDelivery(claim.job, deliveries);
|
|
462
|
+
const sent = deleted !== void 0 && (yield* sentThrough(store, scope, claim.job, deleted));
|
|
463
|
+
if (!(delivery !== void 0 && (retired.has(delivery) || sent))) {
|
|
464
|
+
yield* storeCall(store.jobs.settle(claim, {
|
|
465
|
+
kind: "released",
|
|
466
|
+
at
|
|
467
|
+
}));
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
const { ok, next } = yield* storeCall(store.jobs.settle(claim, { kind: "done" }));
|
|
471
|
+
if (next !== void 0) {
|
|
472
|
+
yield* storeCall(store.jobs.settle(next, {
|
|
473
|
+
kind: "released",
|
|
474
|
+
at
|
|
475
|
+
}));
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
return ok;
|
|
479
|
+
});
|
|
287
480
|
/**
|
|
288
481
|
* One step in the repo's scope: none for a repo that isn't deleted. It waits until its delete's
|
|
289
482
|
* `fetchLimits` has passed, nor while a receipt it holds still answers, `keyKept` past the delete;
|
|
290
483
|
* then while a drain job or a drained row stands, or a fork holds the
|
|
291
|
-
* repo, each wait till its own time to look again; else
|
|
484
|
+
* repo, each wait till its own time to look again; else the dropped deliveries' jobs ended, then
|
|
485
|
+
* each part's step, then a page of
|
|
292
486
|
* `purgeCollections`, then the fork's hold on its source, then the record, then the drops. A repo
|
|
293
487
|
* with no record is one whose record this purge deleted, since only a delete queues it: its
|
|
294
488
|
* drops run again, each done already or done now.
|
|
295
489
|
*/
|
|
296
|
-
const purgeStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, internalId) {
|
|
490
|
+
const purgeStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, internalId, data) {
|
|
297
491
|
const scope = repoScope(internalId);
|
|
298
492
|
const drainedReads = drainedCollections.map((collection) => ({
|
|
299
493
|
collection,
|
|
@@ -325,51 +519,61 @@ const purgeStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, int
|
|
|
325
519
|
};
|
|
326
520
|
const deleted = record.nextSeq === void 0 ? void 0 : record.nextSeq - 1;
|
|
327
521
|
const drain = yield* draining(store, scope, at, deleted, parts.deliveries);
|
|
328
|
-
if (drain !== void 0) return
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
if (
|
|
333
|
-
|
|
522
|
+
if (drain.at !== void 0) return yield* waitOrFail(scope, data, at, drain.at, drain.kind, "drain", drain.detail);
|
|
523
|
+
const drainedLeft = drainedCollections.filter((_, index) => (drained[index]?.length ?? 0) > 0);
|
|
524
|
+
if (drainedLeft.length > 0) return yield* waitOrFail(scope, data, at, at + purgeBackstop, "stall", "drained-rows", `drained rows with no drain job (${drainedLeft.join(", ")})`);
|
|
525
|
+
const hold = yield* forkedFrom(store, internalId);
|
|
526
|
+
if (hold?.kind === "live") return hasStuckState(data) ? {
|
|
527
|
+
...backstop,
|
|
528
|
+
data: {}
|
|
529
|
+
} : backstop;
|
|
530
|
+
if (hold !== void 0) {
|
|
531
|
+
const waiting = yield* forkHoldWait(store, hold);
|
|
532
|
+
return yield* waitOrFail(scope, data, at, at + purgeBackstop, waiting.kind, "fork-hold", waiting.detail);
|
|
533
|
+
}
|
|
534
|
+
if (drain.dropped && !(yield* endDropped(store, scope, at, deleted, parts.deliveries))) return yield* spinOrFail(scope, data, "end-dropped", "ending dropped delivery jobs");
|
|
334
535
|
for (const part of parts.parts) {
|
|
335
536
|
const step = yield* part(store, internalId);
|
|
336
|
-
if (step === "
|
|
337
|
-
if (step === "did") return
|
|
537
|
+
if (step === "done") continue;
|
|
538
|
+
if (step === "did") return progressed(data);
|
|
539
|
+
const detail = step === "waits" ? "a purge part waiting" : `purge part '${step.waits}' waiting`;
|
|
540
|
+
return yield* waitOrFail(scope, data, at, at + purgeBackstop, "drain", "part", detail);
|
|
338
541
|
}
|
|
339
542
|
const { left, version } = yield* firstLeft(store, scope);
|
|
340
543
|
if (left !== void 0) {
|
|
341
544
|
const page = yield* pageOf(store, scope, left);
|
|
342
|
-
yield*
|
|
545
|
+
const committed = yield* storeCommit(store.commit(scope, {
|
|
343
546
|
id: newChangeId(),
|
|
344
547
|
expect: page.version,
|
|
345
548
|
delete: page.keys
|
|
346
549
|
}));
|
|
347
|
-
return
|
|
550
|
+
if (!committed.ok || page.keys.length === 0) return yield* spinOrFail(scope, data, "page-commit", `deleting collection '${left}' (${committed.ok ? "empty page" : "commit contended"})`);
|
|
551
|
+
return progressed(data);
|
|
348
552
|
}
|
|
349
|
-
yield* reconcile(store, internalId);
|
|
350
|
-
if (!(yield* releaseHold(store, internalId, record))) return
|
|
553
|
+
if (record.staged !== true) yield* reconcile(store, internalId);
|
|
554
|
+
if (!(yield* releaseHold(store, internalId, record))) return yield* spinOrFail(scope, data, "release-hold", "releasing fork hold (catalogue contended)");
|
|
351
555
|
yield* discardFailed(store, scope);
|
|
352
|
-
yield* endStrays(store, scope, at, parts.deliveries);
|
|
353
556
|
const own = yield* pageOf(store, scope, collections.repo);
|
|
354
|
-
if (own.version !== version) return
|
|
355
|
-
if (!(yield*
|
|
557
|
+
if (own.version !== version || version !== snapshot.version) return yield* spinOrFail(scope, data, "record-version", "deleting repo record (scope moved)");
|
|
558
|
+
if (!(yield* storeCommit(store.commit(scope, {
|
|
356
559
|
id: newChangeId(),
|
|
357
560
|
expect: version,
|
|
358
561
|
delete: own.keys
|
|
359
|
-
}))).ok) return
|
|
562
|
+
}))).ok) return yield* spinOrFail(scope, data, "record-commit", "deleting repo record (commit contended)");
|
|
360
563
|
return yield* dropScopes(parts, store, internalId);
|
|
361
564
|
});
|
|
362
565
|
const PurgeJob = /* @__PURE__ */ Job.make(purgeJobName, {
|
|
363
566
|
payload: PurgeData,
|
|
364
567
|
concurrency: 1,
|
|
568
|
+
retry: purgeRetry,
|
|
365
569
|
rebuild: () => ({})
|
|
366
570
|
});
|
|
367
571
|
/** `git.purge`, over one server's parts: each try one page of the repo's rows. */
|
|
368
|
-
const purgeJob = (parts) => gitJob(PurgeJob, () =>
|
|
572
|
+
const purgeJob = (parts) => gitJob(PurgeJob, (data) => Effect.flatMap(currentRepo, (repo) => purgeStep(parts, parts.store, repo, data)));
|
|
369
573
|
/** The repo's `git.purge` row, due at `at`. */
|
|
370
574
|
const purgeJobRow = (job, at) => job.job({
|
|
371
575
|
key: purgeJobKey,
|
|
372
576
|
data: {},
|
|
373
577
|
at
|
|
374
578
|
});
|
|
375
|
-
export { purgeBackstop, purgeCollections, purgeJob, purgeJobKey, purgeJobName, purgeJobRow, purgePage, purgeRunningRelook };
|
|
579
|
+
export { purgeBackstop, purgeCollections, purgeDrainLimit, purgeJob, purgeJobKey, purgeJobName, purgeJobRow, purgePage, purgeRunningRelook, purgeStallLimit };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { awaitingUpkeep } from "../storage/batches.mjs";
|
|
1
2
|
import { gitError } from "../contracts/result.mjs";
|
|
2
3
|
import { packRow } from "../store/git-store.mjs";
|
|
3
4
|
import { refBytesMost, refRowBytes, storesPeel } from "../store/ref-rows.mjs";
|
|
@@ -98,6 +99,7 @@ const problemOf = (read, command, update) => {
|
|
|
98
99
|
const requestProblem = (read, command, index) => {
|
|
99
100
|
if (read.revoked !== void 0) return read.revoked;
|
|
100
101
|
if (command.received?.quarantine !== void 0 && read.quarantine !== "open") return gitError("UNAVAILABLE", "The push's pack outlived its quarantine, so it may be gone", { hint: "Push again" });
|
|
102
|
+
if (read.batches !== void 0 && read.batches + 1 > 16) return awaitingUpkeep(read.batches, 16);
|
|
101
103
|
const most = pushRefLimitOf(index);
|
|
102
104
|
const where = index === void 0 ? "" : " on a server that keeps a ref index";
|
|
103
105
|
if (command.updates.length > most) return gitError("RESOURCE_EXHAUSTED", `A push moves at most ${most} refs${where}`, {
|
|
@@ -2,7 +2,7 @@ import "../contracts/ids.mjs";
|
|
|
2
2
|
import "../contracts/objects.mjs";
|
|
3
3
|
import "../contracts/push-uploads.mjs";
|
|
4
4
|
import "../contracts/result.mjs";
|
|
5
|
-
import "../
|
|
5
|
+
import "../contracts/call-allowance.mjs";
|
|
6
6
|
import "./ancestry.mjs";
|
|
7
7
|
import "effect/Effect";
|
|
8
8
|
/** A server's sizes for a pushed file, `pushes.files` resolved: a warning only when there's one. */
|