store

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SyncStatusSynced indicates that a container record is synchronised with the Docker daemon. The record may
	// become outdated even when the status is "synced" if the machine crashes or a network partition occurs.
	// The cluster membership state of the machine should also be checked to determine if the record can be trusted.
	SyncStatusSynced = "synced"
	// SyncStatusOutdated indicates that a container record may be outdated, for example, due to being unable
	// to retrieve the container's state from the Docker daemon or when the machine is being stopped or restarted.
	SyncStatusOutdated = "outdated"
)

Variables

View Source
var (
	//go:embed schema.sql
	Schema string

	ErrKeyNotFound     = errors.New("key not found")
	ErrMachineNotFound = errors.New("machine not found")
)

Functions

This section is empty.

Types

type ContainerRecord

type ContainerRecord struct {
	Container  api.ServiceContainer
	MachineID  string
	SyncStatus string
	UpdatedAt  time.Time
}

type DeleteOptions

type DeleteOptions struct {
	IDs []string
}

type ListOptions

type ListOptions struct {
	// MachineIDs filters containers by the machine IDs they are running on.
	MachineIDs      []string
	ServiceIDOrName ServiceIDOrNameOptions
}

type ServiceIDOrNameOptions

type ServiceIDOrNameOptions struct {
	ID   string
	Name string
}

ServiceIDOrNameOptions filters containers by the service ID or name they are part of. If both ID and Name are provided, they are combined with an OR operator.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a cluster store backed by a distributed Corrosion database.

func New

func New(corro *corrosion.APIClient) *Store

func (*Store) CreateMachine

func (s *Store) CreateMachine(ctx context.Context, m *pb.MachineInfo) error

func (*Store) CreateOrUpdateContainer

func (s *Store) CreateOrUpdateContainer(ctx context.Context, ctr api.ServiceContainer, machineID string) error

CreateOrUpdateContainer creates a new container record or updates an existing one in the store database. The container is associated with the given machine ID that indicates which machine the container is running on.

func (*Store) DBVersion added in v0.16.0

func (s *Store) DBVersion(ctx context.Context) (int64, error)

DBVersion returns the current cr-sqlite database version (Lamport timestamp).

func (*Store) Delete

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

func (*Store) DeleteContainers

func (s *Store) DeleteContainers(ctx context.Context, opts DeleteOptions) error

DeleteContainers deletes container records from the store database that match the given options.

func (*Store) DeleteMachine added in v0.10.0

func (s *Store) DeleteMachine(ctx context.Context, id string) error

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string, value any) error

func (*Store) GetMachine added in v0.10.0

func (s *Store) GetMachine(ctx context.Context, machineID string) (*pb.MachineInfo, error)

func (*Store) ListContainers

func (s *Store) ListContainers(ctx context.Context, opts ListOptions) ([]ContainerRecord, error)

ListContainers returns a list of container records from the store database that match the given options.

func (*Store) ListMachines

func (s *Store) ListMachines(ctx context.Context) ([]*pb.MachineInfo, error)

func (*Store) Put

func (s *Store) Put(ctx context.Context, key string, value any) error

func (*Store) SubscribeContainers

func (s *Store) SubscribeContainers(ctx context.Context) ([]ContainerRecord, <-chan struct{}, error)

SubscribeContainers returns a list of containers and a channel that signals changes to the list. The channel doesn't receive any values, it just signals when a container(s) has been added, updated, or deleted in the database.

func (*Store) SubscribeMachines

func (s *Store) SubscribeMachines(ctx context.Context) ([]*pb.MachineInfo, <-chan struct{}, error)

SubscribeMachines returns a list of machines and a channel that signals changes to the list. The channel doesn't receive any values, it just signals when a machine has been added, updated, or deleted in the database.

func (*Store) UpdateMachine added in v0.10.0

func (s *Store) UpdateMachine(ctx context.Context, m *pb.MachineInfo) error

Jump to

Keyboard shortcuts

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