cdb

package
v0.0.0-...-72e1b05 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package cdb contains an implementation of ../store.Store that uses CockroachDB.

Index

Constants

View Source
const (
	GetAndLockRow statement = iota
	Update
	Get
	ListPowerCycle
	List
	Delete
	GetFreeMachines
)

All the different statements we need. Each statement will appear in Statements.

View Source
const (
	// DatabaseName is the name of the database.
	DatabaseName = "machineserver"
)
View Source
const Schema = `` /* 1401-byte string literal not displayed */

Variables

View Source
var (
	MaintenanceTag = map[string]string{"state": "Maintenance"}
	QuarantineTag  = map[string]string{"state": "Quarantined"}
	RecoveringTag  = map[string]string{"state": "Recovering"}
)
View Source
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",
}
View Source
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"]}'
View Source
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 New

func New(ctx context.Context, db pool.Pool, pools *pools.Pools) (*Store, error)

New returns a new *Store that uses the give Pool.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, machineID string) error

Delete implements ../store.Store.

func (*Store) Get

func (s *Store) Get(ctx context.Context, machineID string) (machine.Description, error)

Get implements ../store.Store.

func (*Store) GetFreeMachines

func (s *Store) GetFreeMachines(ctx context.Context, pool string) ([]machine.Description, error)

GetFreeMachines implements ../store.Store.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]machine.Description, error)

List implements ../store.Store.

func (*Store) ListPowerCycle

func (s *Store) ListPowerCycle(ctx context.Context) ([]string, error)

ListPowerCycle implements ../store.Store.

func (*Store) Update

func (s *Store) Update(ctx context.Context, machineID string, updateCallback store.UpdateCallback) error

Update 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL