@ref0/git 0.11.0 → 0.14.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 +8 -7
- package/dist/auth/auth.d.mts +2 -2
- package/dist/auth/auth.mjs +3 -6
- package/dist/auth/authorize.mjs +1 -17
- package/dist/auth/helpers.mjs +3 -11
- package/dist/auth/host-services.mjs +11 -0
- package/dist/auth/policy.d.mts +27 -7
- package/dist/auth/policy.mjs +8 -4
- package/dist/auth/tokens-layer.d.mts +1 -2
- package/dist/auth/tokens-layer.mjs +2 -3
- package/dist/auth/tokens-public.d.mts +3 -3
- package/dist/auth/tokens.d.mts +1 -8
- package/dist/auth/tokens.mjs +1 -8
- package/dist/auth.d.mts +1 -4
- package/dist/auth.mjs +1 -3
- package/dist/client/git-http.mjs +18 -4
- package/dist/client/push-upload.mjs +33 -7
- package/dist/client/remote.mjs +94 -28
- package/dist/client/slice-push.d.mts +1 -1
- package/dist/contracts/access.d.mts +8 -8
- package/dist/contracts/actors.d.mts +2 -34
- package/dist/contracts/blobs.d.mts +2 -2
- package/dist/contracts/client.d.mts +8 -3
- package/dist/contracts/commits.d.mts +10 -2
- package/dist/contracts/commits.mjs +9 -1
- package/dist/contracts/files.d.mts +2 -2
- package/dist/contracts/forks.d.mts +14 -3
- package/dist/contracts/git.d.mts +41 -12
- package/dist/contracts/git.mjs +3 -2
- package/dist/contracts/lfs.d.mts +0 -7
- package/dist/contracts/objects.d.mts +80 -10
- package/dist/contracts/operations.d.mts +3 -0
- package/dist/contracts/operations.mjs +12 -2
- package/dist/contracts/push-uploads.d.mts +44 -5
- package/dist/contracts/push-uploads.mjs +7 -3
- package/dist/contracts/refs.d.mts +28 -6
- package/dist/contracts/remote.mjs +1 -3
- package/dist/contracts/repo-records.d.mts +1 -0
- package/dist/contracts/repos.d.mts +90 -2
- package/dist/contracts/repos.mjs +29 -2
- package/dist/contracts/result.d.mts +30 -23
- package/dist/contracts/result.mjs +24 -9
- package/dist/contracts/rules.d.mts +22 -22
- package/dist/contracts/server.d.mts +28 -77
- package/dist/contracts/signin.d.mts +1 -1
- package/dist/contracts/sync.d.mts +90 -19
- package/dist/contracts/sync.mjs +34 -10
- package/dist/contracts/tokens.d.mts +1 -6
- package/dist/contracts/tokens.mjs +1 -2
- package/dist/contracts/topics.d.mts +0 -5
- package/dist/contracts/work.d.mts +66 -2
- package/dist/contracts/work.mjs +8 -1
- package/dist/core/access.d.mts +1 -0
- package/dist/core/access.mjs +34 -13
- package/dist/core/ancestry.d.mts +9 -0
- package/dist/core/ancestry.mjs +6 -6
- package/dist/core/asked.mjs +68 -0
- package/dist/core/call-names.mjs +1 -0
- package/dist/core/call-services.mjs +2 -1
- package/dist/core/events/deliver.d.mts +1 -0
- package/dist/core/events/deliver.mjs +15 -3
- package/dist/core/forks.mjs +42 -16
- package/dist/core/imports.mjs +156 -13
- package/dist/core/index-job.mjs +9 -6
- package/dist/core/job-view.mjs +8 -9
- package/dist/core/mirror-rows.mjs +19 -4
- package/dist/core/objects/commits.mjs +16 -6
- package/dist/core/objects/reading.mjs +17 -9
- package/dist/core/parts.d.mts +8 -2
- package/dist/core/parts.mjs +1 -4
- package/dist/core/purge.mjs +76 -6
- package/dist/core/push-decide.mjs +1 -1
- package/dist/core/push-files.d.mts +12 -0
- package/dist/core/push-files.mjs +225 -0
- package/dist/core/push-repo.d.mts +8 -0
- package/dist/core/push-repo.mjs +56 -0
- package/dist/core/push.d.mts +17 -0
- package/dist/core/push.mjs +107 -32
- package/dist/core/receipts.mjs +26 -10
- package/dist/core/ref-view.mjs +59 -5
- package/dist/core/refs.mjs +18 -10
- package/dist/core/registered-rows.mjs +7 -5
- package/dist/core/repack.mjs +16 -11
- package/dist/core/repo-info.mjs +16 -9
- package/dist/core/repos.mjs +30 -14
- 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/core/seam.mjs +2 -2
- package/dist/core/view.d.mts +6 -0
- package/dist/core/view.mjs +45 -12
- package/dist/core/work.mjs +47 -22
- package/dist/effect.d.mts +3 -1
- package/dist/effect.mjs +3 -1
- package/dist/engine/reads.mjs +13 -6
- package/dist/engine/walk.mjs +4 -4
- package/dist/event-streams/event-streams.d.mts +1 -1
- package/dist/event-streams/event-streams.mjs +1 -1
- package/dist/event-streams/stream.d.mts +1 -1
- package/dist/event-streams/stream.mjs +1 -1
- package/dist/extend.d.mts +4 -3
- package/dist/extend.mjs +3 -2
- package/dist/http/answers.mjs +4 -2
- package/dist/http/core-parts.mjs +64 -15
- package/dist/http/handler.mjs +2 -2
- package/dist/http/node.mjs +5 -4
- package/dist/http/parts.d.mts +1 -0
- package/dist/http/push-upload-job.mjs +503 -0
- package/dist/http/push-uploads.d.mts +1 -0
- package/dist/http/push-uploads.mjs +120 -59
- package/dist/http/upload-pack.mjs +7 -6
- package/dist/index.d.mts +23 -24
- package/dist/index.mjs +4 -7
- package/dist/lfs/base.d.mts +7 -3
- package/dist/lfs/base.mjs +2 -1
- package/dist/lfs/copy.d.mts +46 -0
- package/dist/lfs/copy.mjs +26 -0
- package/dist/lfs/layer.mjs +4 -2
- package/dist/lfs/locks.mjs +14 -9
- package/dist/lfs/objects.d.mts +6 -0
- package/dist/lfs/objects.mjs +95 -61
- package/dist/lfs/rows.d.mts +13 -0
- package/dist/lfs/service.d.mts +1 -7
- package/dist/lfs/service.mjs +1 -9
- package/dist/lfs/upload-most.mjs +5 -5
- package/dist/node.d.mts +2 -2
- package/dist/protocol/bytes/sha256-hasher.d.mts +15 -0
- package/dist/protocol/bytes/sha256.d.mts +32 -0
- package/dist/protocol/bytes/sha256.mjs +105 -49
- package/dist/protocol/wire/advertisement.mjs +9 -4
- package/dist/protocol/wire/lines.d.mts +4 -2
- package/dist/protocol/wire/lines.mjs +11 -5
- package/dist/protocol/wire/push-uploads.mjs +13 -1
- package/dist/protocol/wire/v2.mjs +2 -2
- package/dist/protocol.d.mts +3 -1
- package/dist/protocol.mjs +3 -1
- package/dist/queue/advance.mjs +1 -1
- package/dist/queue/calls.mjs +21 -1
- package/dist/queue/host.d.mts +1 -7
- package/dist/queue/host.mjs +1 -7
- package/dist/queue/layer.mjs +1 -1
- package/dist/queue/trim.mjs +1 -1
- package/dist/rest/blobs.d.mts +16 -8
- package/dist/rest/blobs.mjs +1 -1
- package/dist/rest/caller.d.mts +49 -9
- package/dist/rest/caller.mjs +1 -1
- package/dist/rest/client.d.mts +10 -3
- package/dist/rest/client.mjs +4 -0
- package/dist/rest/commits.d.mts +272 -239
- package/dist/rest/errors.d.mts +24 -4
- package/dist/rest/events.d.mts +9 -6
- package/dist/rest/events.mjs +1 -2
- package/dist/rest/files.d.mts +112 -100
- package/dist/rest/forks.d.mts +146 -122
- package/dist/rest/handler.mjs +4 -57
- package/dist/rest/handlers.d.mts +1 -1
- package/dist/rest/handlers.mjs +18 -4
- package/dist/rest/layer.mjs +10 -2
- package/dist/rest/me.d.mts +8 -4
- package/dist/rest/merges.d.mts +8 -4
- package/dist/rest/paths.mjs +1 -0
- package/dist/rest/queue.d.mts +292 -236
- package/dist/rest/refs.d.mts +98 -69
- package/dist/rest/repos.d.mts +133 -105
- package/dist/rest/tags.d.mts +100 -88
- package/dist/rest/tokens.d.mts +192 -168
- package/dist/rest/topics.d.mts +154 -134
- package/dist/rest/trees.d.mts +32 -16
- package/dist/rest/work.d.mts +467 -20
- package/dist/rest/work.mjs +8 -0
- package/dist/server/edge-node.d.mts +9 -13
- package/dist/server/edge-node.mjs +9 -12
- package/dist/server/git-layer.d.mts +1 -6
- package/dist/server/git-layer.mjs +2 -2
- package/dist/server/git-namespace.d.mts +4 -4
- package/dist/server/joined.d.mts +15 -22
- package/dist/server/joined.mjs +5 -29
- package/dist/server/lifecycle.mjs +107 -23
- package/dist/server/registry.mjs +9 -1
- package/dist/server/server.mjs +139 -216
- package/dist/storage/budget.mjs +2 -2
- package/dist/storage/clean-up.mjs +13 -10
- package/dist/storage/fetch.mjs +13 -8
- package/dist/storage/file-limits.mjs +24 -0
- package/dist/storage/index-build.d.mts +1 -0
- package/dist/storage/index-build.mjs +106 -62
- package/dist/storage/index-fetch.mjs +16 -3
- package/dist/storage/index-reach.mjs +33 -5
- package/dist/storage/index-remap.mjs +8 -1
- package/dist/storage/index-shallow.mjs +5 -3
- package/dist/storage/largest-files.mjs +48 -0
- package/dist/storage/lfs-pointers.mjs +10 -1
- package/dist/storage/loose.mjs +3 -1
- package/dist/storage/memory-budget.mjs +154 -8
- package/dist/storage/merge-cut.mjs +5 -4
- package/dist/storage/pack-reads.mjs +246 -34
- package/dist/storage/pack-receive.mjs +83 -25
- package/dist/storage/packs.mjs +37 -21
- package/dist/storage/prune-keep.mjs +203 -34
- package/dist/storage/prune-seen.mjs +11 -6
- package/dist/storage/prune-walk.mjs +219 -81
- package/dist/storage/prune.mjs +629 -196
- package/dist/storage/push-uploads.mjs +36 -12
- package/dist/storage/quarantine.mjs +9 -7
- package/dist/storage/ready.mjs +47 -19
- package/dist/storage/receive-bounds.mjs +29 -8
- package/dist/storage/receive-state.mjs +8 -0
- package/dist/storage/receive-steps.mjs +71 -18
- package/dist/storage/repack.d.mts +1 -1
- package/dist/storage/repack.mjs +1 -8
- package/dist/storage/rows.mjs +12 -1
- package/dist/storage/shallow.d.mts +1 -0
- package/dist/storage/shallow.mjs +26 -4
- package/dist/storage/stream-whole.mjs +5 -2
- package/dist/storage/visible.mjs +29 -1
- package/dist/storage/walk.mjs +2 -1
- package/dist/store/catalogue.mjs +1 -0
- package/dist/store/cursor-seal-namespace.d.mts +2 -0
- package/dist/store/cursor-seal-public.d.mts +5 -0
- package/dist/store/cursor-seal-public.mjs +5 -0
- package/dist/store/cursor-seal.d.mts +16 -2
- package/dist/store/cursor-seal.mjs +26 -14
- package/dist/store/errors.mjs +9 -1
- package/dist/store/records.d.mts +2 -0
- package/dist/store/records.mjs +9 -6
- package/dist/store/repo-record.d.mts +27 -0
- package/dist/store/repo-record.mjs +141 -4
- package/dist/store/scopes.mjs +10 -2
- package/dist/sync/bound.d.mts +2 -0
- package/dist/sync/bound.mjs +11 -2
- package/dist/sync/github.d.mts +6 -1
- package/dist/sync/github.mjs +63 -42
- package/dist/sync/http.mjs +36 -1
- package/dist/sync/import.mjs +4 -2
- package/dist/sync/layer.mjs +6 -2
- package/dist/sync/lfs-batch.mjs +119 -0
- package/dist/sync/lfs-copy.mjs +251 -0
- package/dist/sync/mirror.mjs +227 -147
- package/dist/sync/said.mjs +204 -0
- package/dist/sync/smart-http.mjs +4 -2
- package/dist/sync/step.mjs +33 -13
- package/dist/sync/tries.mjs +71 -24
- package/dist/sync.d.mts +2 -2
- package/dist/topics/advance.mjs +10 -3
- package/dist/topics/host.mjs +1 -19
- package/dist/topics/layer.mjs +1 -1
- package/package.json +3 -8
- package/dist/auth/bridge.mjs +0 -30
- package/dist/auth/helpers.d.mts +0 -17
- package/dist/core/purge.d.mts +0 -8
- package/dist/core/registered-rows.d.mts +0 -4
- package/dist/core/repack.d.mts +0 -11
- package/dist/http/handler.d.mts +0 -2
- package/dist/rest/handler.d.mts +0 -21
- package/dist/rest.d.mts +0 -2
- package/dist/rest.mjs +0 -1
- package/dist/server/registry.d.mts +0 -16
- package/dist/server/server.d.mts +0 -36
- package/dist/storage/repack-job.d.mts +0 -3
- package/dist/topics/host.d.mts +0 -7
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";
|
|
@@ -12,16 +13,17 @@ import { hiddenUnder } from "../protocol/wire/lines.mjs";
|
|
|
12
13
|
import { receiveRefs, sendPush } from "../client/remote.mjs";
|
|
13
14
|
import { objectsFace, oneShotReads } from "../storage/calls.mjs";
|
|
14
15
|
import { decodeRow, storeCall } from "../store/errors.mjs";
|
|
15
|
-
import { MirrorRow } from "../core/mirror-rows.mjs";
|
|
16
|
+
import { MirrorRow, destinationText, mirrorJobKey } from "../core/mirror-rows.mjs";
|
|
17
|
+
import { notFailed } from "../core/events/deliver.mjs";
|
|
16
18
|
import { collections, newChangeId, repoScope } from "../store/scopes.mjs";
|
|
17
19
|
import { asSync, mirrorLimits } from "./bound.mjs";
|
|
18
20
|
import { readImport } from "../core/imports.mjs";
|
|
19
|
-
import { fromRemote, httpOf, openedFor, remoteOf, syncObjects, tried, unknownProvider } from "./tries.mjs";
|
|
20
|
-
import { CoreParts, ObjectsParts, overStore } from "../core/parts.mjs";
|
|
21
|
+
import { fromRemote, httpOf, keptFieldsOf, openedFor, remoteOf, syncObjects, thrownOf, tried, unknownProvider } from "./tries.mjs";
|
|
22
|
+
import { CoreParts, ObjectsParts, QueueParts, overStore } from "../core/parts.mjs";
|
|
21
23
|
import * as Clock$1 from "effect/Clock";
|
|
22
24
|
import * as Effect from "effect/Effect";
|
|
23
25
|
import * as Result from "effect/Result";
|
|
24
|
-
import { CurrentJob, jsonBytes } from "@ref0/infra";
|
|
26
|
+
import { CurrentJob, isInfraError, jsonBytes } from "@ref0/infra";
|
|
25
27
|
// src/sync/mirror.ts
|
|
26
28
|
/** How long a mirror waits before it reads its repo's import again, while the import runs. */
|
|
27
29
|
const importWait = 1e4;
|
|
@@ -50,7 +52,12 @@ const longestReceipt = {
|
|
|
50
52
|
oid: "0".repeat(64),
|
|
51
53
|
at: Number.MAX_SAFE_INTEGER
|
|
52
54
|
};
|
|
53
|
-
const sameSource = (a, b) => a
|
|
55
|
+
const sameSource = (a, b) => destinationText(a) === destinationText(b);
|
|
56
|
+
/**
|
|
57
|
+
* A mirror's saver as one text, one a caller as `callerKey` has it: a decoded row holds only
|
|
58
|
+
* `SavedCaller`'s fields, in its order.
|
|
59
|
+
*/
|
|
60
|
+
const saverOf = (row) => JSON.stringify(row.by);
|
|
54
61
|
const stateOf = (repo, ref, row) => {
|
|
55
62
|
const state = {
|
|
56
63
|
repo,
|
|
@@ -58,16 +65,18 @@ const stateOf = (repo, ref, row) => {
|
|
|
58
65
|
state: row.state
|
|
59
66
|
};
|
|
60
67
|
if (row.paused !== void 0) state.paused = row.paused;
|
|
68
|
+
if (row.deletes === true) state.deletes = true;
|
|
61
69
|
if (row.lastPushed !== void 0) state.lastPushed = row.lastPushed;
|
|
62
70
|
return state;
|
|
63
71
|
};
|
|
64
72
|
/**
|
|
65
|
-
* `mirror`: the mirror's row, active, and its job due now, in one commit,
|
|
66
|
-
* update the repo, sees the ref, and the
|
|
73
|
+
* `mirror`: the mirror's row, active, and its destination's job due now, in one commit, then that
|
|
74
|
+
* job retried if it had failed, once the caller may update the repo, sees the ref, and the
|
|
75
|
+
* destination names a provider `Sync.layer` was given. Sent
|
|
67
76
|
* again, it writes the same row, so a paused mirror resumes and an active one pushes again. A row
|
|
68
77
|
* past `mirrorLimits.rowBytes` is refused, and so is a new mirror on a repo that holds
|
|
69
78
|
* `mirrorLimits.mirrors`; a mirror the repo holds is saved again whatever the count, keeping its
|
|
70
|
-
* `lastPushed` while its destination is the same.
|
|
79
|
+
* `lastPushed` while its destination is the same, and `deletes` only when it's sent again.
|
|
71
80
|
*/
|
|
72
81
|
const mirrorWith = /* @__PURE__ */ Effect.fnUntraced(function* (bound, input) {
|
|
73
82
|
const { destination } = input;
|
|
@@ -98,6 +107,7 @@ const mirrorWith = /* @__PURE__ */ Effect.fnUntraced(function* (bound, input) {
|
|
|
98
107
|
state: "active",
|
|
99
108
|
by: yield* savedCallerOf(actor.id, caller)
|
|
100
109
|
};
|
|
110
|
+
if (input.deletes === true) saved.deletes = true;
|
|
101
111
|
const largest = {
|
|
102
112
|
...saved,
|
|
103
113
|
state: "paused",
|
|
@@ -106,9 +116,10 @@ const mirrorWith = /* @__PURE__ */ Effect.fnUntraced(function* (bound, input) {
|
|
|
106
116
|
};
|
|
107
117
|
const bytes = jsonBytes(mirrorRow(ref, largest));
|
|
108
118
|
if (bytes > mirrorLimits.rowBytes) return yield* fail("INVALID_ARGUMENT", `The mirror of '${ref}' takes ${bytes} bytes: a mirror takes at most ${mirrorLimits.rowBytes}`, { hint: "Name a shorter destination or ref" });
|
|
119
|
+
const key = mirrorJobKey(saved.destination);
|
|
109
120
|
const job = bound.mirrorJob.encodedJob({
|
|
110
|
-
key
|
|
111
|
-
data: {
|
|
121
|
+
key,
|
|
122
|
+
data: { destination: saved.destination }
|
|
112
123
|
});
|
|
113
124
|
const { store } = yield* CoreParts;
|
|
114
125
|
const scope = repoScope(internalId);
|
|
@@ -123,192 +134,232 @@ const mirrorWith = /* @__PURE__ */ Effect.fnUntraced(function* (bound, input) {
|
|
|
123
134
|
});
|
|
124
135
|
const row = { ...saved };
|
|
125
136
|
if (held?.lastPushed !== void 0 && sameSource(held.destination, saved.destination)) row.lastPushed = held.lastPushed;
|
|
126
|
-
if ((yield* storeCall(() => store.commit(scope, {
|
|
137
|
+
if (!(yield* storeCall(() => store.commit(scope, {
|
|
127
138
|
id: newChangeId(),
|
|
128
139
|
expect: read.version,
|
|
129
140
|
put: [mirrorRow(ref, row)],
|
|
130
141
|
jobs: [job]
|
|
131
|
-
}))).ok)
|
|
142
|
+
}))).ok) continue;
|
|
143
|
+
const { jobs } = yield* QueueParts;
|
|
144
|
+
if ((yield* storeCall(() => jobs.retry(scope, job)).pipe(Effect.catchIf(notFailed, () => Effect.void), Effect.catchIf((error) => isInfraError(error.cause) && error.cause.reason === "compacted", () => Effect.succeed(false)))) === false) {
|
|
145
|
+
yield* storeCall(() => jobs.discard(scope, job)).pipe(Effect.catchIf(notFailed, () => Effect.void));
|
|
146
|
+
yield* storeCall(() => store.add(scope, { jobs: [job] }));
|
|
147
|
+
}
|
|
148
|
+
return stateOf(input.repo, ref, row);
|
|
132
149
|
}
|
|
133
150
|
return yield* contended();
|
|
134
151
|
});
|
|
135
|
-
/** The mirror's row and the read's version. */
|
|
136
|
-
const mirrorOf = /* @__PURE__ */ Effect.fnUntraced(function* (attempt) {
|
|
137
|
-
const { internalId, ref } = attempt;
|
|
138
|
-
const { store } = yield* CoreParts;
|
|
139
|
-
const snapshot = yield* storeCall(() => store.read(repoScope(internalId), [mirrorKey(ref)]));
|
|
140
|
-
const [[own] = []] = snapshot.results;
|
|
141
|
-
return {
|
|
142
|
-
mirror: own === void 0 ? void 0 : yield* decodeRow(MirrorRow, own, `Mirror '${ref}'`),
|
|
143
|
-
version: snapshot.version
|
|
144
|
-
};
|
|
145
|
-
});
|
|
146
|
-
/** The mirror's row, whether the repo's import still runs, and the row read's version. */
|
|
147
|
-
const readMirror = /* @__PURE__ */ Effect.fnUntraced(function* (attempt) {
|
|
148
|
-
const { mirror, version } = yield* mirrorOf(attempt);
|
|
149
|
-
const imported = yield* readImport((yield* CoreParts).store, attempt.internalId);
|
|
150
|
-
return {
|
|
151
|
-
mirror,
|
|
152
|
-
importing: imported.row?.state === "running" && !imported.cancelled,
|
|
153
|
-
version
|
|
154
|
-
};
|
|
155
|
-
});
|
|
156
|
-
const again = { kind: "more" };
|
|
157
152
|
/**
|
|
158
|
-
* The
|
|
159
|
-
*
|
|
153
|
+
* The mirrors whose rows name `destination`, among every mirror row in `store`, which
|
|
154
|
+
* `mirrorLimits.mirrors` keeps within one read, and the read's version.
|
|
160
155
|
*/
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
156
|
+
const destinationRows = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, destination) {
|
|
157
|
+
const snapshot = yield* storeCall(() => store.read(repoScope(internalId), [mirrorsRead]));
|
|
158
|
+
const [rows = []] = snapshot.results;
|
|
159
|
+
const mirrored = [];
|
|
160
|
+
for (const row of rows) {
|
|
161
|
+
const decoded = yield* decodeRow(MirrorRow, row, `Mirror '${row.id}'`);
|
|
162
|
+
if (sameSource(decoded.destination, destination)) mirrored.push({
|
|
163
|
+
ref: row.id,
|
|
164
|
+
row: decoded
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
mirrored,
|
|
169
|
+
version: snapshot.version
|
|
167
170
|
};
|
|
168
|
-
return (yield* storeCall(() => store.commit(repoScope(attempt.internalId), {
|
|
169
|
-
id: newChangeId(),
|
|
170
|
-
expect: version,
|
|
171
|
-
put: [mirrorRow(attempt.ref, row)]
|
|
172
|
-
}))).ok ? void 0 : again;
|
|
173
171
|
});
|
|
174
172
|
/**
|
|
175
|
-
* The
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
173
|
+
* The try's pauses and receipts, in one commit. The pauses commit only at `version`, the read the
|
|
174
|
+
* try began with: a push that moved a ref since, or a resume, moved the rows, so a stale try
|
|
175
|
+
* records no pause and its next read decides. A receipt, `oid` at the try's time, goes on the
|
|
176
|
+
* mirror's row as it is, read again after a commit another write beat: a pause, a resume or a save
|
|
177
|
+
* since keeps it while the row names the same destination, and a row removed or sent elsewhere
|
|
178
|
+
* takes none, nor does one that `writeTries` other writes beat: the push stands either way.
|
|
179
179
|
*/
|
|
180
|
-
const
|
|
181
|
-
const { store } =
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
};
|
|
186
|
-
let row = mirror;
|
|
187
|
-
let expect = version;
|
|
180
|
+
const settle = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, read, settled) {
|
|
181
|
+
const { store } = attempt.context;
|
|
182
|
+
const at = yield* Clock$1.currentTimeMillis;
|
|
183
|
+
let { mirrored, version } = read;
|
|
184
|
+
let { pauses } = settled;
|
|
188
185
|
for (let tries = 0; tries < 5; tries += 1) {
|
|
189
|
-
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
186
|
+
const put = [];
|
|
187
|
+
for (const { ref, row } of mirrored) {
|
|
188
|
+
const why = pauses.get(ref);
|
|
189
|
+
const oid = settled.receipts.get(ref);
|
|
190
|
+
if (why === void 0 && oid === void 0) continue;
|
|
191
|
+
const next = why === void 0 ? { ...row } : {
|
|
192
|
+
...row,
|
|
193
|
+
state: "paused",
|
|
194
|
+
paused: why
|
|
195
|
+
};
|
|
196
|
+
if (oid !== void 0) next.lastPushed = {
|
|
197
|
+
oid,
|
|
198
|
+
at
|
|
199
|
+
};
|
|
200
|
+
put.push(mirrorRow(ref, next));
|
|
201
|
+
}
|
|
202
|
+
if (put.length === 0) break;
|
|
194
203
|
if ((yield* storeCall(() => store.commit(repoScope(attempt.internalId), {
|
|
195
204
|
id: newChangeId(),
|
|
196
|
-
expect,
|
|
197
|
-
put
|
|
198
|
-
}))).ok)
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
205
|
+
expect: version,
|
|
206
|
+
put
|
|
207
|
+
}))).ok) break;
|
|
208
|
+
settled.more ||= pauses.size > 0;
|
|
209
|
+
pauses = /* @__PURE__ */ new Map();
|
|
210
|
+
({mirrored, version} = yield* destinationRows(store, attempt.internalId, attempt.destination));
|
|
202
211
|
}
|
|
212
|
+
return settled.more ? { kind: "more" } : void 0;
|
|
203
213
|
});
|
|
204
|
-
/**
|
|
205
|
-
const
|
|
214
|
+
/** The edits whose upstream tip their ref goes on from: the walks the push decide's kinds take. */
|
|
215
|
+
const goingOn = /* @__PURE__ */ Effect.fnUntraced(function* (listed, edits) {
|
|
216
|
+
const going = /* @__PURE__ */ new Set();
|
|
217
|
+
if (edits.length === 0) return going;
|
|
206
218
|
const kinds = yield* kindsOf({
|
|
207
219
|
objects: oneShotReads(objectsFace(syncObjects(yield* ObjectsParts))),
|
|
208
220
|
listed,
|
|
209
221
|
pushed: () => Effect.succeed(void 0),
|
|
210
|
-
edits
|
|
222
|
+
edits
|
|
211
223
|
});
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
224
|
+
for (const update of kinds.updates) {
|
|
225
|
+
if (kinds.refused.has(update.ref)) continue;
|
|
226
|
+
if (update.kind !== "force" || (yield* kinds.exact(update)) === "fast-forward") going.add(update.ref);
|
|
227
|
+
}
|
|
228
|
+
return going;
|
|
216
229
|
});
|
|
217
|
-
const upstreamOf = /* @__PURE__ */ Effect.fnUntraced(function* (http) {
|
|
230
|
+
const upstreamOf = /* @__PURE__ */ Effect.fnUntraced(function* (http, heard) {
|
|
218
231
|
const read = yield* Effect.result(receiveRefs(http));
|
|
219
232
|
if (Result.isSuccess(read)) return {
|
|
220
233
|
kind: "read",
|
|
221
234
|
refs: read.success
|
|
222
235
|
};
|
|
223
236
|
const { failure } = read;
|
|
224
|
-
if (!refusedCodes.has(failure.code)) return yield* Effect.fail(fromRemote("advertise")(failure));
|
|
237
|
+
if (!refusedCodes.has(failure.code)) return yield* Effect.fail(fromRemote("advertise", heard)(failure));
|
|
225
238
|
return { kind: "refused" };
|
|
226
239
|
});
|
|
227
240
|
/**
|
|
228
|
-
*
|
|
229
|
-
* `viewAgainOf` asks it, in the try's own context
|
|
230
|
-
* failed fails the try.
|
|
241
|
+
* The mirrors whose savers still see their refs, each saver asked again once, now, for a fetch,
|
|
242
|
+
* as `viewAgainOf` asks it, in the try's own context; the rest pause `unseen`. `undefined` for a
|
|
243
|
+
* repo deleted since. A host that failed fails the try.
|
|
231
244
|
*/
|
|
232
|
-
const
|
|
233
|
-
const { internalId,
|
|
245
|
+
const seenOf = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, active, settled) {
|
|
246
|
+
const { internalId, context } = attempt;
|
|
234
247
|
const record = yield* hostRecordOf((yield* CoreParts).store, internalId);
|
|
235
|
-
if (record === void 0) return
|
|
248
|
+
if (record === void 0) return void 0;
|
|
236
249
|
const repo = repoAccess({
|
|
237
250
|
name: record.name,
|
|
238
251
|
record,
|
|
239
252
|
internalId
|
|
240
253
|
});
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
254
|
+
const views = /* @__PURE__ */ new Map();
|
|
255
|
+
const seen = [];
|
|
256
|
+
for (const mirror of active) {
|
|
257
|
+
const saver = saverOf(mirror.row);
|
|
258
|
+
const viewed = views.get(saver) ?? (yield* viewAgainOf(mirror.row.by, repo, "fetch", context.signal));
|
|
259
|
+
views.set(saver, viewed);
|
|
260
|
+
if (viewed.kind !== "refused" && viewed.view.sees(mirror.ref)) seen.push(mirror);
|
|
261
|
+
else settled.pauses.set(mirror.ref, "unseen");
|
|
262
|
+
}
|
|
263
|
+
return seen;
|
|
244
264
|
});
|
|
245
265
|
/**
|
|
246
|
-
* One mirror try
|
|
247
|
-
*
|
|
248
|
-
* advertised.
|
|
249
|
-
* - a
|
|
250
|
-
* - a saver
|
|
251
|
-
* -
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
* -
|
|
255
|
-
*
|
|
266
|
+
* One mirror try, for every mirror of the job's destination: their rows, each saver asked again,
|
|
267
|
+
* then each ref's tip, the upstream's advertisement read once, and one push of every ref that
|
|
268
|
+
* differs, each from the upstream's tip, so the upstream only ever moves from the ID it advertised.
|
|
269
|
+
* - a destination with no active mirror ends; one whose repo's import runs waits for it;
|
|
270
|
+
* - a mirror whose saver no longer sees its ref pauses `unseen`, before the tip is read;
|
|
271
|
+
* - a ref with no tip is left out, and the upstream keeps its copy (Q393), unless its mirror
|
|
272
|
+
* `deletes`: then the upstream's ref goes in the same push, from the ID the mirror's receipt
|
|
273
|
+
* says it left there, and one pushed there since pauses it `diverged`, alone;
|
|
274
|
+
* - an upstream already at a ref's tip leaves it out, keeping its receipt when the row has none;
|
|
275
|
+
* - an upstream tip a ref doesn't go on from pauses that ref's mirror `diverged`, alone;
|
|
276
|
+
* - a credential, or a POST, the upstream refuses pauses every mirror the push held `refused`;
|
|
277
|
+
* - each update the upstream takes keeps its receipt, `lastPushed`, on its mirror's row, `null`
|
|
278
|
+
* for a delete;
|
|
279
|
+
* - a refused update whose upstream ref has moved since is stale, and the job reads again; one
|
|
280
|
+
* whose upstream ref hasn't pauses its mirror `refused`.
|
|
281
|
+
* Each try sends only what still differs, so one that dies mid-push and runs again pushes no ref
|
|
282
|
+
* twice.
|
|
256
283
|
*/
|
|
257
284
|
const mirrorStep = /* @__PURE__ */ Effect.fnUntraced(function* (attempt) {
|
|
258
|
-
const
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
if (
|
|
285
|
+
const { store } = attempt.context;
|
|
286
|
+
const read = yield* destinationRows(store, attempt.internalId, attempt.destination);
|
|
287
|
+
const active = read.mirrored.filter(({ row }) => row.state === "active");
|
|
288
|
+
if (active.length === 0) return void 0;
|
|
289
|
+
const imported = yield* readImport(store, attempt.internalId);
|
|
290
|
+
if (imported.row?.state === "running" && !imported.cancelled) return {
|
|
262
291
|
kind: "more",
|
|
263
292
|
at: (yield* Clock$1.currentTimeMillis) + importWait
|
|
264
293
|
};
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
294
|
+
const settled = {
|
|
295
|
+
pauses: /* @__PURE__ */ new Map(),
|
|
296
|
+
receipts: /* @__PURE__ */ new Map(),
|
|
297
|
+
more: false
|
|
298
|
+
};
|
|
299
|
+
const seen = yield* seenOf(attempt, active, settled);
|
|
300
|
+
if (seen === void 0) return void 0;
|
|
301
|
+
if (seen.length > 0) yield* asSync(pushStep(attempt, seen, settled));
|
|
302
|
+
return yield* settle(attempt, read, settled);
|
|
269
303
|
});
|
|
270
|
-
/** The try past its
|
|
271
|
-
const pushStep = /* @__PURE__ */ Effect.fnUntraced(function* (attempt,
|
|
272
|
-
const { bound,
|
|
304
|
+
/** The try past its savers' checks: the tips, the upstream's, and the one push between them. */
|
|
305
|
+
const pushStep = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, seen, settled) {
|
|
306
|
+
const { bound, context } = attempt;
|
|
273
307
|
const stored = yield* ObjectsParts;
|
|
274
308
|
const opened = yield* openedFor(bound.caller, attempt.internalId);
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (mirror.lastPushed?.oid === tip) return void 0;
|
|
284
|
-
return yield* pushedTo(attempt, version, mirror, tip);
|
|
309
|
+
if (opened === void 0) return;
|
|
310
|
+
const tipped = [];
|
|
311
|
+
for (const mirror of seen) {
|
|
312
|
+
const tip = opened.refs.get(mirror.ref) ?? null;
|
|
313
|
+
if (tip !== null || mirror.row.deletes === true) tipped.push({
|
|
314
|
+
...mirror,
|
|
315
|
+
tip
|
|
316
|
+
});
|
|
285
317
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
318
|
+
if (tipped.length === 0) return;
|
|
319
|
+
const remote = yield* remoteOf(bound, attempt.destination, context.signal, "write");
|
|
320
|
+
const { http, heard } = yield* httpOf(remote, keptFieldsOf(bound, attempt.destination));
|
|
321
|
+
const upstream = yield* upstreamOf(http, heard);
|
|
322
|
+
if (upstream.kind === "refused") {
|
|
323
|
+
for (const { ref } of tipped) settled.pauses.set(ref, "refused");
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const differ = [];
|
|
327
|
+
for (const { ref, row, tip } of tipped) {
|
|
328
|
+
const from = upstream.refs.refs.get(ref) ?? null;
|
|
329
|
+
if (from === tip) {
|
|
330
|
+
if (row.lastPushed?.oid !== tip) settled.receipts.set(ref, tip);
|
|
331
|
+
} else if (tip === null && row.lastPushed?.oid !== from) settled.pauses.set(ref, "diverged");
|
|
332
|
+
else differ.push({
|
|
333
|
+
ref,
|
|
334
|
+
from,
|
|
335
|
+
to: tip
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
const going = yield* goingOn(opened.listed, differ.filter(({ from, to }) => from !== null && to !== null));
|
|
339
|
+
const edits = [];
|
|
340
|
+
for (const edit of differ) if (edit.to === null || edit.from === null || going.has(edit.ref)) edits.push(edit);
|
|
341
|
+
else settled.pauses.set(edit.ref, "diverged");
|
|
342
|
+
if (edits.length === 0) return;
|
|
292
343
|
const source = {
|
|
293
344
|
objects: objectsFace(syncObjects(stored)),
|
|
294
345
|
listed: opened.listed,
|
|
295
346
|
limits: stored.fetchLimits
|
|
296
347
|
};
|
|
297
|
-
const pushed = yield* Effect.result(sendPush(http, source, upstream.refs,
|
|
348
|
+
const pushed = yield* Effect.result(sendPush(http, source, upstream.refs, edits, {}));
|
|
298
349
|
if (Result.isFailure(pushed)) {
|
|
299
350
|
const { failure } = pushed;
|
|
300
|
-
if (!refusedCodes.has(failure.code)) return yield* Effect.fail(fromRemote("take a push")(failure));
|
|
301
|
-
|
|
351
|
+
if (!refusedCodes.has(failure.code)) return yield* Effect.fail(fromRemote("take a push", heard)(failure));
|
|
352
|
+
for (const { ref } of edits) settled.pauses.set(ref, "refused");
|
|
353
|
+
return;
|
|
302
354
|
}
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
const
|
|
309
|
-
const reread
|
|
310
|
-
|
|
311
|
-
return yield* paused(attempt, version, mirror, "refused");
|
|
355
|
+
const applied = new Set(pushed.success.updates.flatMap((update) => update.kind === "applied" ? [update.ref] : []));
|
|
356
|
+
const rejected = [];
|
|
357
|
+
for (const edit of edits) if (!applied.has(edit.ref)) rejected.push(edit);
|
|
358
|
+
else settled.receipts.set(edit.ref, edit.to);
|
|
359
|
+
if (rejected.length === 0) return;
|
|
360
|
+
const reread = yield* upstreamOf(http, heard);
|
|
361
|
+
for (const { ref } of rejected) if (reread.kind === "read" && reread.refs.refs.get(ref) !== upstream.refs.refs.get(ref)) settled.more = true;
|
|
362
|
+
else settled.pauses.set(ref, "refused");
|
|
312
363
|
});
|
|
313
364
|
/** `sync.mirror`'s handler over `bound`: one try, its failure thrown as `SyncTryError`. */
|
|
314
365
|
const mirrorTry = /* @__PURE__ */ Effect.fnUntraced(function* (bound, data) {
|
|
@@ -316,12 +367,38 @@ const mirrorTry = /* @__PURE__ */ Effect.fnUntraced(function* (bound, data) {
|
|
|
316
367
|
const attempt = {
|
|
317
368
|
bound,
|
|
318
369
|
internalId: yield* currentRepo,
|
|
319
|
-
|
|
370
|
+
destination: data.destination,
|
|
320
371
|
context
|
|
321
372
|
};
|
|
322
373
|
return yield* tried(Effect.provideContext(overStore(context.store)(mirrorStep(attempt)), bound.needs));
|
|
323
374
|
});
|
|
324
375
|
/**
|
|
376
|
+
* Once a destination's job has failed for good, every active mirror its rows name paused
|
|
377
|
+
* `refused`, so `mirrors` says why it stopped and saving one again resumes it: read again after a
|
|
378
|
+
* commit another write beat, until the queue's bound on `onFailure` aborts the signal.
|
|
379
|
+
*/
|
|
380
|
+
const mirrorFailed = /* @__PURE__ */ Effect.fnUntraced(function* (bound, data) {
|
|
381
|
+
const context = yield* CurrentJob.CurrentJob;
|
|
382
|
+
const internalId = yield* currentRepo;
|
|
383
|
+
const marked = Effect.gen(function* () {
|
|
384
|
+
for (;;) {
|
|
385
|
+
const read = yield* destinationRows(context.store, internalId, data.destination);
|
|
386
|
+
const put = read.mirrored.flatMap(({ ref, row }) => row.state === "active" ? [mirrorRow(ref, {
|
|
387
|
+
...row,
|
|
388
|
+
state: "paused",
|
|
389
|
+
paused: "refused"
|
|
390
|
+
})] : []);
|
|
391
|
+
if (put.length === 0) return;
|
|
392
|
+
if ((yield* storeCall(() => context.store.commit(repoScope(internalId), {
|
|
393
|
+
id: newChangeId(),
|
|
394
|
+
expect: read.version,
|
|
395
|
+
put
|
|
396
|
+
}))).ok) return;
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
yield* Effect.provideContext(marked, bound.needs).pipe(Effect.mapError(thrownOf));
|
|
400
|
+
});
|
|
401
|
+
/**
|
|
325
402
|
* `mirrors`: each of the repo's mirror rows, by ref, once the caller may read the repo: only those
|
|
326
403
|
* whose ref the caller sees, so a private ref's mirror answers as no mirror.
|
|
327
404
|
*/
|
|
@@ -359,19 +436,22 @@ const removeMirrorWith = /* @__PURE__ */ Effect.fnUntraced(function* (_bound, in
|
|
|
359
436
|
kind: "repo.update",
|
|
360
437
|
repo: input.repo
|
|
361
438
|
};
|
|
362
|
-
const
|
|
439
|
+
const opened = yield* openRepo(caller, operation, [], input.internalId, "first-read");
|
|
440
|
+
const { internalId, name, record } = opened;
|
|
363
441
|
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
442
|
const { store } = yield* CoreParts;
|
|
370
443
|
const scope = repoScope(internalId);
|
|
444
|
+
let refView;
|
|
371
445
|
for (let tries = 0; tries < 5; tries += 1) {
|
|
372
|
-
const
|
|
446
|
+
const asked = tries === 0 ? opened : void 0;
|
|
447
|
+
const read = yield* readAsked(store, internalId, [mirrorKey(ref)], [], asked);
|
|
448
|
+
if (refView === void 0) refView = yield* refViewIn(caller, repoAccess({
|
|
449
|
+
name,
|
|
450
|
+
record,
|
|
451
|
+
internalId
|
|
452
|
+
}));
|
|
373
453
|
const [[own] = []] = read.results;
|
|
374
|
-
if (own === void 0) return yield* none;
|
|
454
|
+
if (own === void 0 || !refView.sees(ref)) return yield* none;
|
|
375
455
|
if ((yield* storeCall(() => store.commit(scope, {
|
|
376
456
|
id: newChangeId(),
|
|
377
457
|
expect: read.version,
|
|
@@ -380,4 +460,4 @@ const removeMirrorWith = /* @__PURE__ */ Effect.fnUntraced(function* (_bound, in
|
|
|
380
460
|
}
|
|
381
461
|
return yield* contended();
|
|
382
462
|
});
|
|
383
|
-
export { mirrorTry, mirrorWith, mirrorsWith, removeMirrorWith };
|
|
463
|
+
export { mirrorFailed, mirrorTry, mirrorWith, mirrorsWith, removeMirrorWith };
|