|
STAR
Cal STAR — firmware, DAQ server, and engine design
|
Directories | |
| stardesign | |
The server-side core shared by the STAR design tools — EngineDesign, pid-designer and recovery-calculator.
Each app used to carry its own copy of userdata.py, storage.py, directory.py and a ~600-line documents router. Several were byte-identical. That was survivable while the code only decided whose folder your own data lived in — a bug meant one app misbehaved. Design sharing changed the stakes: the check that decides whether you may edit someone else's design lives in here now, and three copies of a permission check is three chances to fix a bug in only two places.
| Module | What it owns |
|---|---|
| userdata | The on-disk layout: <root>/<user>/<app>/…, identity from X-Auth-Email, and the path sanitising that keeps ?owner= from escaping the root. |
| storage | Version history — microversions and immutable releases — on the local volume or in a versioned S3 bucket. |
| directory | The team roster the share picker offers: the auth service's login records unioned with whoever already has data on the volume. |
| documents | The design CRUD, sharing and checkout router, as a factory. This is where _resolve_doc lives — the single place cross-user access is granted — and the checkout compare-and-set. |
| admins | Whether the caller is an admin — a fixed list of emails, plus STAR_ADMINS. |
Each app binds the shared code to its own vocabulary and keeps its existing module paths, so nothing else in the app changes:
The apps differ in only four things: the <app> path segment, the route prefix, the payload shape ({"config": …} vs {"nodes": …, "edges": …}), and the noun in user-facing strings. Everything else is here.
Path-installed, not published — it is versioned with the repo:
Its consumers' images build from the repo root so this directory is inside the build context; see each Dockerfile.api and the .dockerignore.
Concurrent editing is not resolved, it is prevented: at most one person holds a design's write token, and only the holder may save.
The compare-and-set runs inside _index_lock — the same flock that already serialises index writes — so two simultaneous takes cannot both win.
flock is per-machine. All three design tools run on the one apps machine sharing the userdata volume, so this holds today. Running a design tool on a second machine against the same volume would break the guarantee silently.
The obvious race test — N processes taking at once, assert one wins — passes with the locking deleted. The critical section is sub-millisecond, so contenders mostly serialise on their own; neither a barrier nor 48 contenders fixed it. test_take_cannot_proceed_while_the_index_lock_is_held is the real guard: it holds the same flock and asserts a take blocks. That fails every run, in every app, the moment the lock goes.
DesignStore switches, all off by default, so an app that does not set them behaves exactly as before.
Admins are the fixed list in admins.py, compared against X-Auth-Email. STAR_ADMINS adds emails on top — STAR_ADMINS=local in dev, where every request is the local user.