Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The Standard Library as Architecture

Garage’s distributed algorithms are visible in ordinary ownership and collection choices, not only in networking code.

Arc<T>: stable shared services

Garage owns Arc<System>, Arc<BlockManager>, and typed Arc<Table<...>> values. Request handlers, RPC endpoints, and workers clone handles, not the database or cluster state. Arc answers “who may keep this service alive?”; interior synchronization answers “who may mutate it now?”

Enums: lifecycle states are data

An object version is explicitly Uploading or Complete; block RPCs and table RPCs are enums; workers report Busy, Throttled, Idle, or Done. Matches force code to account for each protocol and lifecycle state.

Drop: cancellation is an execution path

InterruptedCleanup begins armed around a large upload. Normal completion cancels it. Early return, task cancellation, or panic drops it while armed and schedules cleanup. This is RAII applied to distributed metadata obligations.

BTreeMap and BTreeSet: deterministic reconciliation

Range reads merge entries from several replicas by ordered encoded key. BTreeMap both deduplicates and restores the requested enumeration order; BTreeSet records which keys need read repair. The collection invariant is part of the consistency algorithm.

HashMap: batch network work by destination

insert_many groups encoded entries by replica node. Shared Arc<ByteBuf> values avoid re-encoding or copying the same update into every bookkeeping structure.

Ownership as resource accounting

The block sender acquires an owned semaphore permit proportional to buffered kilobytes and embeds it in RequestStrategy. The permit’s lifetime now equals the network obligation’s lifetime, including error and cancellation.

The recurring lesson is that Rust’s standard ownership tools become most useful when a type owns a real operational obligation: a service lifetime, an incomplete upload, a deterministic merge, or scarce buffer memory.