Skip to content

Commit 4cc291e

Browse files
committed
feat: add clone, push, fetch and remote landing
Nodes share work with one remote: a server over HTTP, or another repository's path served by an in-process OriginService. `Remote` answers the same calls either way. A clone follows `policy` and one target: it fetches their chains, with the revisions they landed and the records of their changes, and only the tip's snapshot. Each acceptance must follow the one before it, and is verified against the authority of the policy governing it: an acceptance of `policy` by the one before it, any other by the policy it names, which must be on the verified chain of `policy`. Acceptances only stored, like a revision's base, govern nothing. Other snapshots are fetched when a command reads them, marked while they're fetched, so an interrupted fetch is never taken for a whole snapshot. Snapshots only leave a repository by walking them (`POST snapshots/fetch`, skipping what the caller's snapshots hold at the same path, optionally under some paths), so #6 can filter reads by path; records are fetched by id, with the description or payload they carry. A move of the working copy fetches what it needs before it publishes `moving`, so one that cannot reach the remote moves nothing. Fetched chains append several acceptances at once: recovering such an append a crash cut short logs that the target advanced to each of them. `push` compares each change's heads with the remote's inventory and refuses a stale change before uploading anything, and the server checks the heads again as it publishes the revisions (`PUT records?expect=`), so a push racing another is refused too. It sends snapshots, then revisions, then statements, each after what it needs, and says which statements stay because they need one the remote lacks. It only shares revisions based on acceptances the remote has. Transfers go in parts of at most 64 MiB, both ways. `fetch` brings new acceptances, then the records of the changes the remote's events since the last fetch say moved, so a fetch that brings nothing doesn't grow with the history; without a cursor, or once it expired, it compares every change it knows. `pull` fetches, then rebases the working copy onto its target's tip. `land`, `land --from` and `target new` go to the remote's queue for every target it has; `watch` long-polls its events.
1 parent 075c601 commit 4cc291e

35 files changed

Lines changed: 6100 additions & 553 deletions

File tree

‎AGENTS.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ review bots read and write at the same time, written in Rust.
2020
server. `OriginService` (`service.rs`) is the one API over a repository:
2121
the HTTP routes (`http.rs`) and the command line's commands that the API
2222
offers only translate into its calls, so neither duplicates the other.
23+
`sync.rs` shares records with a remote (`remote.rs`), which answers the
24+
same calls over the SDK or, for a local path, in-process.
2325
- `tools/xtask`: development tasks, run with `cargo xtask`, such as timing
2426
origin against git (`just bench-git`).
2527

@@ -30,15 +32,18 @@ to a hot path (hashing, storage, snapshots, transfer) should come with a
3032
benchmark, and its numbers in the pull request.
3133

3234
- `just bench`: the divan micro-benchmarks (encoding, store writes,
33-
snapshots, input digests and promotion, landing, reading events, and the
34-
server's request latency and long-poll wakeups).
35+
snapshots, input digests and promotion, landing, reading events, the
36+
server's request latency and long-poll wakeups, syncing a 20,000-file
37+
tree over HTTP, and a fetch that brings nothing from a long history).
3538
- `just bench-git`: times origin against git on a 20,000-file tree with
3639
hyperfine, and rewrites `docs/benchmarks.md`.
3740

3841
End-to-end tests run the `origin` binary with `ORIGIN_CONFIG_DIR` set to a
3942
temporary directory, which holds the user's `config.toml` and node key.
4043
The HTTP tests drive every SDK method against a real server. One fails
41-
while `docs/openapi.json` is stale: `just openapi` rewrites it.
44+
while `docs/openapi.json` is stale: `just openapi` rewrites it. The sync
45+
tests clone, push and land through `origin serve` and through local paths;
46+
`tests/common` holds the helpers every end-to-end test shares.
4247

4348
## Commits & Pull Requests
4449

‎README.md‎

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ origin workspace list | rm <path>
4444

4545
origin op log [-n <count>] # what this node did, operation by operation, in every workspace
4646
origin undo # move this workspace's working copy back one operation
47-
origin watch [--kind <kind>] [--subject <id>] [--since <cursor>] # events, as they happen
47+
origin watch [--kind <kind>] [--subject <id>] [--since <cursor>] [--local] # events, as they happen
48+
49+
origin clone <url> [<path>] [--target <target>] # follow a remote's target, starting a change on its tip
50+
origin remote [<url>] # show or set the remote: http://host:port/<repo>, or a path
51+
origin push [<change>...] # share changes and the ones below them; lands nothing
52+
origin fetch [--target <t>] [--change <id>] # new acceptances, and the records of known changes
53+
origin pull # fetch, then move the working copy onto its target's tip
4854
```
4955

5056
Landing rebases a change onto the target's tip, file by file, checks the
@@ -78,6 +84,25 @@ op log, one a line starting with a cursor: `statement.issued`,
7884
takes an event name or a statement kind (`core.conflict`, `ci.*`), and
7985
`--since` resumes after a cursor.
8086

87+
A repository can have one remote, a server or another repository's path,
88+
shared by its workspaces. A clone holds the chains of the targets it
89+
follows, `policy` and one other, verified against their authorities' keys,
90+
and the records of the changes it knows, which each `fetch` brings as they
91+
move: it asks the remote's events what moved since the last fetch, so a
92+
fetch that brings nothing is quick however long the history. It fetches
93+
snapshots only when a command reads them, starting with its target's tip.
94+
`push` shares revisions, their files and statements, and refuses a change
95+
the remote has a newer revision of, even one pushed while it sends:
96+
`fetch`, then `converge` it. A statement that needs one the remote lacks
97+
stays, and the push says so. A landing is decided on the evidence the
98+
remote holds when it's tried: send a statement together with the one it
99+
supersedes, as `push` does, or a landing waiting on the first may take it.
100+
`land`, `land --from` and `target
101+
new` go to the remote's queue for every target the remote has, after pushing
102+
what lands, and `watch` long-polls the remote's events (`--local` for this
103+
node's). Fetching never changes your files; `pull` then moves the working
104+
copy onto its target's new tip, like a landing elsewhere does.
105+
81106
Changes are named by a unique prefix of their id, or `@` for the working
82107
copy's. A revision is `@`, a change (for its head), or a unique prefix of
83108
the revision's id. Your name and node key live in `$ORIGIN_CONFIG_DIR`, or
@@ -116,11 +141,18 @@ key = "node.key" # its secret key, created if missing
116141
demo = "repos/demo"
117142
```
118143

119-
The HTTP API, under `/api/v1`, puts and fetches records in batches, lists
120-
statements, revisions, targets and their logs, lands changes and targets,
121-
and streams events by long-poll: `GET
144+
The HTTP API, under `/api/v1`, puts records in batches, if the changes
145+
they revise are where the client saw them, and fetches them by id, walks
146+
snapshots for the trees and blobs a client lacks (the only way files leave
147+
a server), in parts of at most 64 MiB each way, compares the records of
148+
changes, lists statements, revisions, targets and their logs, lands
149+
changes and targets, and streams
150+
events by long-poll: `GET
122151
/api/v1/repos/<repo>/events?cursor=<n>&wait=30s` answers as soon as there
123-
are events after the cursor, with a JSON batch and the next cursor.
152+
are events after the cursor, with a JSON batch, the next cursor, and the
153+
generation of the op log it's of: pass it back as `generation`, and a
154+
cursor of another log, such as from before the repository was restored,
155+
is refused as expired.
124156
[`docs/openapi.json`](docs/openapi.json) describes it, and
125157
[`origin-client`](crates/origin-client) is its Rust SDK. Nothing
126158
authenticates callers yet.

‎apps/origin-src/Cargo.toml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ anyhow.workspace = true
2020
axum.workspace = true
2121
clap.workspace = true
2222
getrandom.workspace = true
23+
origin-client.workspace = true
2324
origin-platform.workspace = true
2425
origin-shared.workspace = true
2526
serde.workspace = true
@@ -35,7 +36,6 @@ zstd.workspace = true
3536

3637
[dev-dependencies]
3738
divan.workspace = true
38-
origin-client.workspace = true
3939
# The benchmarks build their working trees with the fixtures.
4040
origin-src = { workspace = true, features = ["fixture"] }
4141
serde_json.workspace = true
@@ -65,6 +65,10 @@ harness = false
6565
name = "packs"
6666
harness = false
6767

68+
[[bench]]
69+
name = "sync"
70+
harness = false
71+
6872
[[bench]]
6973
name = "workspace"
7074
harness = false

0 commit comments

Comments
 (0)