cloud/bmaas: clean up bmdb package
Everything living in sessions.go made this a bit unreadable.
We also drive-by add some extra metadata fields to Connection. This will
come in handy in an upcoming change.
Change-Id: Ibabec9e3bd0b29b727638b9450a53ba28c33e678
Reviewed-on: https://review.monogon.dev/c/monogon/+/1130
Reviewed-by: Leopold Schabel <leo@monogon.tech>
Tested-by: Jenkins CI
diff --git a/cloud/bmaas/bmdb/bmdb.go b/cloud/bmaas/bmdb/bmdb.go
index d56e083..5699381 100644
--- a/cloud/bmaas/bmdb/bmdb.go
+++ b/cloud/bmaas/bmdb/bmdb.go
@@ -6,3 +6,41 @@
// library might turn into a shim which instead connects to a coordinator
// service over gRPC.
package bmdb
+
+import "source.monogon.dev/cloud/lib/component"
+
+// BMDB is the Bare Metal Database, a common schema to store information about
+// bare metal machines in CockroachDB. This struct is supposed to be
+// embedded/contained by different components that interact with the BMDB, and
+// provides a common interface to BMDB operations to these components.
+//
+// The BMDB provides two mechanisms facilitating a 'reactive work system' being
+// implemented on the bare metal machine data:
+//
+// - Sessions, which are maintained by heartbeats by components and signal the
+// liveness of said components to other components operating on the BMDB. These
+// effectively extend CockroachDB's transactions to be visible as row data. Any
+// session that is not actively being updated by a component can be expired by a
+// component responsible for lease garbage collection.
+// - Work locking, which bases on Sessions and allows long-standing
+// multi-transaction work to be performed on given machines, preventing
+// conflicting work from being performed by other components. As both Work
+// locking and Sessions are plain row data, other components can use SQL queries
+// to exclude machines to act on by constraining SELECT queries to not return
+// machines with some active work being performed on them.
+type BMDB struct {
+ Config
+}
+
+// Config is the configuration of the BMDB connector.
+type Config struct {
+ Database component.CockroachConfig
+
+ // ComponentName is a human-readable name of the component connecting to the
+ // BMDB, and is stored in any Sessions managed by this component's connector.
+ ComponentName string
+ // RuntimeInfo is a human-readable 'runtime information' (eg. software version,
+ // host machine/job information, IP address, etc.) stored alongside the
+ // ComponentName in active Sessions.
+ RuntimeInfo string
+}