Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion scripts/native-proof/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,12 @@ are sealed, so their comparisons use the census's exclusive extents.
`pendingBytes` and `availableBytes` are the admission reservations. A
`btrfs filesystem du` census reports total, exclusive and shared extents per
path. Git's `count-objects` is recorded as logical object size only; no
logical size or sum of `st_blocks` is reported as unique usage. The run checks:
logical size or sum of `st_blocks` is reported as unique usage. Every row also
carries `io`: the pool loop device's block reads and writes from
`/proc/diskstats`, and this process's own I/O with its reaped transport
workers from `/proc/self/io`, both since the previous row and after a `sync`.
Cold, warm and refresh rows add `peak`, the highest combined charge and
reservation sampled every 50 ms while the step ran. The run checks:

- **Reuse.** A repeat read inside the refresh window, and an unchanged
refresh after it, reuse the one source root and allocate at most 256 KiB.
Expand All @@ -419,6 +424,22 @@ logical size or sum of `st_blocks` is reported as unique usage. The run checks:
- **Sharing loss.** `git repack -a -d -f` in a worktree, or a linked
`git worktree add` inside one, allocates its objects or checkout as new
extents charged to that worktree alone.
- **Write-time EDQUOT.** A worktree writing past its allowance is refused by
`write()` with `EDQUOT`, charging neither its sibling nor its source. A
commit larger than one operation's allowance is refused inside the refresh
fetch, with Git's quota error. Past the refresh window the previous commit's
validation has also lapsed, so no stale copy may be served: the request
rejects as `capacity`, the previous root is neither served nor withdrawn,
and the staging root is released and reclaimed.
- **Cancellation.** A refresh whose only requester leaves once its staging
root is writable rejects as `cancelled`, publishes nothing, and its staging
root is released and reclaimed.
- **Crash and restart.** A second app instance on the same database
(`reference-efficiency-crash-child.ts`) is killed with `SIGKILL` while its
staging root is writable. The manager keeps that root writable and charged.
The next instance's startup `recover()` releases it, retains nothing and
keeps the previous source, and the space is observed reclaimed. The changed
refresh then runs on that restarted instance.

Repository features, as the transport handles them:

Expand Down
39 changes: 39 additions & 0 deletions scripts/native-proof/pool-io.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Block I/O counters for the reference pool proofs (#3513): the pool loop
* device's cumulative counters from /proc/diskstats (512-byte sectors), and
* this process's own from /proc/self/io, which include its reaped children.
* Callers sync before reading, so delayed Btrfs writeback is counted in the
* step that caused it. Null when a counter cannot be read.
*/
import { readFileSync, statSync } from "node:fs";

/** The fixture's pool loop device (reference-pool-fixture.py). */
export const POOL_DEVICE = "/dev/brain-pool-loop";
export interface PoolIo { device: { readOps: number; readBytes: number; writeOps: number; writeBytes: number }; process: { readBytes: number; writeBytes: number; rchar: number; wchar: number } }

export function poolIo(device = POOL_DEVICE): PoolIo | null {
try { return parsePoolIo(statSync(device).rdev, readFileSync("/proc/diskstats", "utf8"), readFileSync("/proc/self/io", "utf8")); }
catch { return null; }
}

/** Linux `dev_t` decoding, so a loop minor above 255 (the fixture's 2429) matches its diskstats row. */
export function deviceNumbers(rdev: number): { major: number; minor: number } {
return { major: (rdev >> 8) & 0xfff, minor: (rdev & 0xff) | ((rdev >> 12) & 0xfff00) };
}

export function parsePoolIo(rdev: number, diskstats: string, selfIo: string): PoolIo | null {
const { major, minor } = deviceNumbers(rdev);
const fields = diskstats.split("\n").map(line => line.trim().split(/\s+/)).find(row => Number(row[0]) === major && Number(row[1]) === minor);
if (!fields || fields.length < 10) return null;
const own = Object.fromEntries(selfIo.trim().split("\n").map(line => line.split(": ")).map(([key, value]) => [key, Number(value)]));
const process = { readBytes: own.read_bytes, writeBytes: own.write_bytes, rchar: own.rchar, wchar: own.wchar };
if (Object.values(process).some(value => !Number.isFinite(value))) return null;
return { device: { readOps: Number(fields[3]), readBytes: Number(fields[5]) * 512, writeOps: Number(fields[7]), writeBytes: Number(fields[9]) * 512 },
process: process as PoolIo["process"] };
}

export function poolIoDelta(now: PoolIo | null, then: PoolIo | null): PoolIo | null {
if (!now || !then) return null;
const minus = <K extends string>(a: Record<K, number>, b: Record<K, number>) => Object.fromEntries(Object.keys(a).map(key => [key, a[key as K] - b[key as K]])) as Record<K, number>;
return { device: minus(now.device, then.device), process: minus(now.process, then.process) };
}
22 changes: 22 additions & 0 deletions scripts/native-proof/reference-efficiency-crash-child.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* The crashed app instance of case 19 (#3513). It opens the case's database
* and the served pool, requests the pending changed refresh and is killed by
* the proof with SIGKILL once its staging root is writable, so no cleanup of
* its own runs. Arguments: database, manager socket, repository, principal and
* the case's fixed clock.
*/
import { createUiDb } from "../../packages/ui-server/src/db/client.js";
import { createReferenceSources } from "../../packages/ui-server/src/brain/reference-source.js";
import { createReferenceTransport } from "../../packages/ui-server/src/brain/reference-transport.js";
import { referenceWorktreeDependents } from "../../packages/ui-server/src/brain/reference-worktrees.js";
import { createNativeBrainManagerClient } from "../../packages/ui-sdk/src/server/native-brain-manager-client.js";

const [dbPath, socketPath, repository, principalId, clock] = process.argv.slice(2) as [string, string, string, string, string];
const db = createUiDb(dbPath);
const sources = createReferenceSources({ db, pool: createNativeBrainManagerClient({ socketPath, timeoutMs: 20_000 }),
transport: createReferenceTransport({ brainPath: "/brain-fixture/brain" }), brain: "ithaca", credentials: {}, now: () => Number(clock),
dependents: rootId => referenceWorktreeDependents(db, rootId) });
console.log("requesting");
const lease = await sources.request({ principalId, repository, revision: "main" });
// Reached only if the proof was too late to kill this instance; the proof then fails on its own assertion.
console.log(`acquired ${lease.rootId}`);
Loading
Loading