IF Commons GitHub

logical/lock

Written to: 2 requirements: 2 proved, 0 partly, 0 failing, 0 with no test recorded. 0003-anyfs-serve-logical FR-006, 0003-anyfs-serve-logical FR-007

The table of locks, in memory: exclusive write locks of a depth of 0 or infinity, with a token, an owner and a time at which each ends. Nothing is shared between servers, and a lock that ends is gone the next time anyone asks, so no timer runs. A caller holds a lock by submitting its token; a request that changes a resource a lock covers, without the token, is refused with 423.

import { newLockTable } from "./lock.ts";
const table = newLockTable(() => 0, { maxSeconds: 3600, maxLocks: 10 });
const made = table.create({ path: "/a" as never, depth: "0", owner: "<D:href>me</D:href>", seconds: 60 });
made.kind; // "ok"

Source: commons/anyfs-serve/src/logical/lock.ts

1 of 6 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

LockDepthtypeno test imports it
type LockDepth = "0" | "infinity";

How far a lock reaches: the resource, or it and everything below.

Locktypeno test imports it
type Lock = { readonly token: string; readonly path: PosixPath; readonly depth: LockDepth; readonly owner: string; readonly expires: number; readonly seconds: number };

One lock.

LockRequesttypeno test imports it
type LockRequest = { readonly path: PosixPath; readonly depth: LockDepth; readonly owner: string; readonly seconds: number };

What a lock is asked for.

LockProblemtypeno test imports it
type LockProblem = { readonly kind: "locked"; readonly by: Lock } | { readonly kind: "full" } | { readonly kind: "unknown-token" };

Why a lock is not made or changed.

LockTabletypeno test imports it
type LockTable = { /** Locks the resource, unless a lock covers it or a lock below it would be covered. */ create(re… (1101 characters)
type LockTable = {
  /** Locks the resource, unless a lock covers it or a lock below it would be covered. */
  create(request: LockRequest): Result<Lock, LockProblem>;
  /** Moves the end of a lock to now plus the seconds (at most the limit). */
  refresh(token: string, seconds: number): Result<Lock, LockProblem>;
  /** Releases a lock held at a resource. */
  release(token: string, path: PosixPath): Result<void, LockProblem>;
  /** The locks that cover a resource: at it, or above it with a depth of infinity. */
  covering(path: PosixPath): readonly Lock[];
  /** The locks at or below a resource. */
  below(path: PosixPath): readonly Lock[];
  /** The first lock a change of the resource would break, given the tokens the caller submitted; with `subtree`, the locks below it count too. */
  blocking(path: PosixPath, submitted: ReadonlySet<string>, subtree: boolean): Lock | undefined;
  /** What a token is a lock of, if it is still one. */
  find(token: string): Lock | undefined;
  /** Forgets the locks at or below a resource (it was deleted or moved). */
  drop(path: PosixPath): void;
};

The table.

newLockTablefunction
function newLockTable(now: () => number, limits: { readonly maxSeconds: number; readonly maxLocks: number; }): LockTable

An empty table with a clock; the clock is read each time, so a test sets the time.

Imported by 14 tests of the run (14 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.