"How much did the protein run use" is a question about a piece of work, not about c003-15. A tenant asks for clusters over months; individually each one is an address, some hardware and a lease, and nothing joined them up. A project groups them, and is optional throughout. Somebody who wants one cluster for an afternoon should not have to invent a project to get it, and requiring one would mean every tenant carrying a "default" that means nothing. The form does not even ask when there are none: a field whose only option is "none" is a question with one answer. The cost side needed no new columns. The cluster record already said when it was created and destroyed, and cluster_vm said how many cores and how much memory it held; what was missing was anything that read them. cluster_usage is that, and it is a view rather than a table because a derived number stored is a number that can disagree with what it was derived from. It works retroactively - every cluster this estate has ever built now has a line. Core-hours are reserved, not executed, and the view says so. That is the honest unit for an on-demand cluster: the hardware was yours and nobody else could have it, whether or not a job ran. What was actually executed is a Slurm accounting question and there is no slurmdbd. The project is attached inside the allocating transaction, for the same reason the placement and the applications are, and it is checked there to be the tenant's own and still open - a cluster filed against somebody else's project leaks what they are working on. Closing keeps history and stops it being offered. There is no delete: the reference from cluster is RESTRICT, because a project removed from under its clusters leaves their cost attributed to nothing, and afterwards is when the question gets asked. A release now writes manifest.json beside home.tgz: the nodes, the wall time, the core-hours. The database knows all of it and outlives the cluster, but the tarball can be moved off this host and the description travels with it. Not fatal if it fails - the data is already safe by then, and holding hardware because a note could not be written is the wrong trade. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Control plane database
001-schema.sql is the whole of it. Apply it with psql -f; every statement
is IF NOT EXISTS, so re-applying is safe.
The DSN is not in this repository. It lives on the database host in
/etc/hpcod/db.env (mode 0640, root:hpcod) as HPCOD_DB_DSN, which is also
where the service reads it from.
Running the store tests
internal/store is tested against a real PostgreSQL, because what it relies
on - a partial unique index, a generated column, an advisory lock - is
database behaviour that a fake would not reproduce. The tests skip unless
HPCOD_TEST_DSN is set.
Each test builds the schema in a scratch schema of its own and drops it
afterwards, and refuses to run if current_schema() is not that scratch
schema. So the DSN may point at the production database: the tests cannot
see or touch the clusters recorded there.
PostgreSQL listens on loopback only, so the tests run where it does. Ship a cross-compiled binary rather than installing a Go toolchain on that host:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go test -c -o store.test ./internal/store/
ssh $DBHOST mkdir -p /tmp/hpcodstore/internal/store /tmp/hpcodstore/db
scp store.test $DBHOST:/tmp/hpcodstore/internal/store/
scp db/001-schema.sql $DBHOST:/tmp/hpcodstore/db/
ssh $DBHOST "cd /tmp/hpcodstore/internal/store && \
sudo sh -c 'set -a; . /etc/hpcod/db.env; set +a; \
HPCOD_TEST_DSN=\"\$HPCOD_DB_DSN\" ./store.test -test.v'"
ssh $DBHOST rm -rf /tmp/hpcodstore
The password never leaves the host: the DSN is read from the env file there.