Documentation
¶
Overview ¶
Package cdb contains an implementation of ../store.Store that uses CockroachDB.
Index ¶
- Constants
- Variables
- func SetQuarantineMetrics(d machine.Description)
- type Store
- func (s *Store) Delete(ctx context.Context, machineID string) error
- func (s *Store) Get(ctx context.Context, machineID string) (machine.Description, error)
- func (s *Store) GetFreeMachines(ctx context.Context, pool string) ([]machine.Description, error)
- func (s *Store) List(ctx context.Context) ([]machine.Description, error)
- func (s *Store) ListPowerCycle(ctx context.Context) ([]string, error)
- func (s *Store) Update(ctx context.Context, machineID string, updateCallback store.UpdateCallback) error
- type Tables
Constants ¶
const ( GetAndLockRow statement = iota Update Get ListPowerCycle List Delete GetFreeMachines )
All the different statements we need. Each statement will appear in Statements.
const (
// DatabaseName is the name of the database.
DatabaseName = "machineserver"
)
const Schema = `` /* 1401-byte string literal not displayed */
Variables ¶
var ( MaintenanceTag = map[string]string{"state": "Maintenance"} QuarantineTag = map[string]string{"state": "Quarantined"} RecoveringTag = map[string]string{"state": "Recovering"} )
var Description = []string{
"maintenance_mode",
"is_quarantined",
"recovering",
"attached_device",
"annotation",
"note",
"version",
"powercycle",
"powercycle_state",
"last_updated",
"battery",
"temperatures",
"running_swarmingTask",
"launched_swarming",
"recovery_start",
"device_uptime",
"ssh_user_ip",
"supplied_dimensions",
"dimensions",
"task_request",
"task_started",
}
var Statements = map[statement]string{ GetAndLockRow: fmt.Sprintf(` SELECT %s FROM Description WHERE dimensions @> CONCAT('{"id": ["', $1, '"]}')::JSONB FOR UPDATE`, descriptionAllNonComputedColumns), Update: fmt.Sprintf(` UPSERT INTO Description (%s) VALUES %s `, descriptionAllNonComputedColumns, sqlutil.ValuesPlaceholders(len(Description), 1), ), Get: fmt.Sprintf(` SELECT %s FROM Description WHERE dimensions @> CONCAT('{"id": ["', $1, '"]}')::JSONB `, descriptionAllNonComputedColumns), ListPowerCycle: ` SELECT machine_id FROM Description@by_powercycle WHERE powercycle = TRUE `, List: fmt.Sprintf(` SELECT %s FROM Description `, descriptionAllNonComputedColumns), Delete: ` DELETE FROM Description WHERE dimensions @> CONCAT('{"id": ["', $1, '"]}')::JSONB `, GetFreeMachines: fmt.Sprintf(` SELECT %s FROM Description@by_running_task WHERE running_task = FALSE AND dimensions @> CONCAT('{"task_type": ["sktask"], "pool":["', $1, '"]}')::JSONB `, descriptionAllNonComputedColumns), }
Statements are all the SQL statements used in Store.
In the below statements you might see something like:
CONCAT('{"id": ["', $1, '"]}')::JSONB
This allows building up a JSONB expression while still allowing the use of placeholders, like '$1'. The following will not work, since the $1 is inside a string and thus not substituted.
'{"id": ["$1"]}'
var TaskResult = []string{
"result",
"id",
"machine_id",
"finished",
"status",
}
Functions ¶
func SetQuarantineMetrics ¶
func SetQuarantineMetrics(d machine.Description)
Reflects MaintenanceMode, Quarantined, and Recovering into metrics.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements ../store.Store.
func (*Store) GetFreeMachines ¶
GetFreeMachines implements ../store.Store.
func (*Store) ListPowerCycle ¶
ListPowerCycle implements ../store.Store.
type Tables ¶
type Tables struct { Description []machine.Description TaskResult []machine.TaskResult }
Tables represents all SQL tables used by machineserver.
Directories
¶
Path | Synopsis |
---|---|
Package expectedschema contains the schema the database is expected to have.
|
Package expectedschema contains the schema the database is expected to have. |
Application exportschema exports the expected schema as a serialized schema.Description.
|
Application exportschema exports the expected schema as a serialized schema.Description. |
Command line tool to set up the CockroachDB database for machineserver.
|
Command line tool to set up the CockroachDB database for machineserver. |
This executable generates a go file that contains the SQL schema for machineserver defined as a string.
|
This executable generates a go file that contains the SQL schema for machineserver defined as a string. |