blob: 5699381fb3ab334fabcace97a1f5d77c87ce79cd [file] [log] [blame]
Serge Bazanski35e8d792022-10-11 11:32:30 +02001// Package bmdb implements a connector to the Bare Metal Database, which is the
2// main data store backing information about bare metal machines.
3//
4// All components of the BMaaS project connect directly to the underlying
5// CockroachDB database storing this data via this library. In the future, this
6// library might turn into a shim which instead connects to a coordinator
7// service over gRPC.
8package bmdb
Serge Bazanskide4e8412023-02-15 23:28:04 +01009
10import "source.monogon.dev/cloud/lib/component"
11
12// BMDB is the Bare Metal Database, a common schema to store information about
13// bare metal machines in CockroachDB. This struct is supposed to be
14// embedded/contained by different components that interact with the BMDB, and
15// provides a common interface to BMDB operations to these components.
16//
17// The BMDB provides two mechanisms facilitating a 'reactive work system' being
18// implemented on the bare metal machine data:
19//
20// - Sessions, which are maintained by heartbeats by components and signal the
21// liveness of said components to other components operating on the BMDB. These
22// effectively extend CockroachDB's transactions to be visible as row data. Any
23// session that is not actively being updated by a component can be expired by a
24// component responsible for lease garbage collection.
25// - Work locking, which bases on Sessions and allows long-standing
26// multi-transaction work to be performed on given machines, preventing
27// conflicting work from being performed by other components. As both Work
28// locking and Sessions are plain row data, other components can use SQL queries
29// to exclude machines to act on by constraining SELECT queries to not return
30// machines with some active work being performed on them.
31type BMDB struct {
32 Config
33}
34
35// Config is the configuration of the BMDB connector.
36type Config struct {
37 Database component.CockroachConfig
38
39 // ComponentName is a human-readable name of the component connecting to the
40 // BMDB, and is stored in any Sessions managed by this component's connector.
41 ComponentName string
42 // RuntimeInfo is a human-readable 'runtime information' (eg. software version,
43 // host machine/job information, IP address, etc.) stored alongside the
44 // ComponentName in active Sessions.
45 RuntimeInfo string
46}