state

package
v0.0.0-...-ae3a0a2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NeedsUpgrade

func NeedsUpgrade(bdb *bbolt.DB) (upgradeTo09, upgradeTo13 bool, err error)

NeedsUpgrade returns true if the BoltDB needs upgrading or false if it is already up to date.

func UpgradeAllocs

func UpgradeAllocs(logger hclog.Logger, tx *boltdd.Tx) error

UpgradeAllocs upgrades the boltdb schema. Example 0.8 schema:

allocations
  15d83e8a-74a2-b4da-3f17-ed5c12895ea8
    echo
      simple-all (342 bytes)
    alloc (2827 bytes)
    alloc-dir (166 bytes)
    immutable (15 bytes)
    mutable (1294 bytes)

func UpgradeDynamicPluginRegistry

func UpgradeDynamicPluginRegistry(logger hclog.Logger, tx *boltdd.Tx) error

Types

type BoltStateDB

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

BoltStateDB persists and restores Nomad client state in a boltdb. All methods are safe for concurrent access.

func (*BoltStateDB) Close

func (s *BoltStateDB) Close() error

Close releases all database resources and unlocks the database file on disk. All transactions must be closed before closing the database.

func (*BoltStateDB) DB

func (s *BoltStateDB) DB() *boltdd.DB

DB allows access to the underlying BoltDB for testing purposes.

func (*BoltStateDB) DeleteAllocationBucket

func (s *BoltStateDB) DeleteAllocationBucket(allocID string, opts ...WriteOption) error

DeleteAllocationBucket is used to delete an allocation bucket if it exists.

func (*BoltStateDB) DeleteCheckResults

func (s *BoltStateDB) DeleteCheckResults(allocID string, checkIDs []structs.CheckID) error

func (*BoltStateDB) DeleteTaskBucket

func (s *BoltStateDB) DeleteTaskBucket(allocID, taskName string) error

DeleteTaskBucket is used to delete a task bucket if it exists.

func (*BoltStateDB) GetAllAllocations

func (s *BoltStateDB) GetAllAllocations() ([]*structs.Allocation, map[string]error, error)

GetAllAllocations gets all allocations persisted by this client and returns a map of alloc ids to errors for any allocations that could not be restored.

If a fatal error was encountered it will be returned and the other two values will be nil.

func (*BoltStateDB) GetCheckResults

func (s *BoltStateDB) GetCheckResults() (checks.ClientResults, error)

GetCheckResults gets the check results associated with allocID from the state store.

func (*BoltStateDB) GetDeploymentStatus

func (s *BoltStateDB) GetDeploymentStatus(allocID string) (*structs.AllocDeploymentStatus, error)

GetDeploymentStatus retrieves an allocation's DeploymentStatus or returns an error.

func (*BoltStateDB) GetDevicePluginState

func (s *BoltStateDB) GetDevicePluginState() (*dmstate.PluginState, error)

GetDevicePluginState stores the device manager's plugin state or returns an error.

func (*BoltStateDB) GetDriverPluginState

func (s *BoltStateDB) GetDriverPluginState() (*driverstate.PluginState, error)

GetDriverPluginState stores the driver manager's plugin state or returns an error.

func (*BoltStateDB) GetDynamicPluginRegistryState

func (s *BoltStateDB) GetDynamicPluginRegistryState() (*dynamicplugins.RegistryState, error)

GetDynamicPluginRegistryState stores the dynamic plugin registry's registry state or returns an error.

func (*BoltStateDB) GetNetworkStatus

func (s *BoltStateDB) GetNetworkStatus(allocID string) (*structs.AllocNetworkStatus, error)

GetNetworkStatus retrieves an allocation's NetworkStatus or returns an error.

func (*BoltStateDB) GetTaskRunnerState

func (s *BoltStateDB) GetTaskRunnerState(allocID, taskName string) (*trstate.LocalState, *structs.TaskState, error)

GetTaskRunnerState returns the LocalState and TaskState for a TaskRunner. LocalState or TaskState will be nil if they do not exist.

If an error is encountered both LocalState and TaskState will be nil.

func (*BoltStateDB) Name

func (s *BoltStateDB) Name() string

func (*BoltStateDB) PurgeCheckResults

func (s *BoltStateDB) PurgeCheckResults(allocID string) error

func (*BoltStateDB) PutAllocation

func (s *BoltStateDB) PutAllocation(alloc *structs.Allocation, opts ...WriteOption) error

PutAllocation stores an allocation or returns an error.

func (*BoltStateDB) PutCheckResult

func (s *BoltStateDB) PutCheckResult(allocID string, qr *structs.CheckQueryResult) error

PutCheckResult puts qr into the state store.

func (*BoltStateDB) PutDeploymentStatus

func (s *BoltStateDB) PutDeploymentStatus(allocID string, ds *structs.AllocDeploymentStatus) error

PutDeploymentStatus stores an allocation's DeploymentStatus or returns an error.

func (*BoltStateDB) PutDevicePluginState

func (s *BoltStateDB) PutDevicePluginState(ps *dmstate.PluginState) error

PutDevicePluginState stores the device manager's plugin state or returns an error.

func (*BoltStateDB) PutDriverPluginState

func (s *BoltStateDB) PutDriverPluginState(ps *driverstate.PluginState) error

PutDriverPluginState stores the driver manager's plugin state or returns an error.

func (*BoltStateDB) PutDynamicPluginRegistryState

func (s *BoltStateDB) PutDynamicPluginRegistryState(ps *dynamicplugins.RegistryState) error

PutDynamicPluginRegistryState stores the dynamic plugin registry's state or returns an error.

func (*BoltStateDB) PutNetworkStatus

func (s *BoltStateDB) PutNetworkStatus(allocID string, ds *structs.AllocNetworkStatus, opts ...WriteOption) error

PutNetworkStatus stores an allocation's DeploymentStatus or returns an error.

func (*BoltStateDB) PutTaskRunnerLocalState

func (s *BoltStateDB) PutTaskRunnerLocalState(allocID, taskName string, val *trstate.LocalState) error

PutTaskRunnerLocalState stores TaskRunner's LocalState or returns an error.

func (*BoltStateDB) PutTaskState

func (s *BoltStateDB) PutTaskState(allocID, taskName string, state *structs.TaskState) error

PutTaskState stores a task's state or returns an error.

func (*BoltStateDB) Upgrade

func (s *BoltStateDB) Upgrade() error

Upgrade bolt state db from 0.8 schema to 0.9 schema. Noop if already using 0.9 schema. Creates a backup before upgrading.

type ErrDB

type ErrDB struct {
	// Allocs is a preset slice of allocations used in GetAllAllocations
	Allocs []*structs.Allocation
}

ErrDB implements a StateDB that returns errors on restore methods, used for testing

func (*ErrDB) Close

func (m *ErrDB) Close() error

func (*ErrDB) DeleteAllocationBucket

func (m *ErrDB) DeleteAllocationBucket(allocID string, opts ...WriteOption) error

func (*ErrDB) DeleteCheckResults

func (m *ErrDB) DeleteCheckResults(allocID string, checkIDs []structs.CheckID) error

func (*ErrDB) DeleteTaskBucket

func (m *ErrDB) DeleteTaskBucket(allocID, taskName string) error

func (*ErrDB) GetAllAllocations

func (m *ErrDB) GetAllAllocations() ([]*structs.Allocation, map[string]error, error)

func (*ErrDB) GetCheckResults

func (m *ErrDB) GetCheckResults() (checks.ClientResults, error)

func (*ErrDB) GetDeploymentStatus

func (m *ErrDB) GetDeploymentStatus(allocID string) (*structs.AllocDeploymentStatus, error)

func (*ErrDB) GetDevicePluginState

func (m *ErrDB) GetDevicePluginState() (*dmstate.PluginState, error)

func (*ErrDB) GetDriverPluginState

func (m *ErrDB) GetDriverPluginState() (*driverstate.PluginState, error)

func (*ErrDB) GetDynamicPluginRegistryState

func (m *ErrDB) GetDynamicPluginRegistryState() (*dynamicplugins.RegistryState, error)

func (*ErrDB) GetNetworkStatus

func (m *ErrDB) GetNetworkStatus(allocID string) (*structs.AllocNetworkStatus, error)

func (*ErrDB) GetTaskRunnerState

func (m *ErrDB) GetTaskRunnerState(allocID string, taskName string) (*state.LocalState, *structs.TaskState, error)

func (*ErrDB) Name

func (m *ErrDB) Name() string

func (*ErrDB) PurgeCheckResults

func (m *ErrDB) PurgeCheckResults(allocID string) error

func (*ErrDB) PutAllocation

func (m *ErrDB) PutAllocation(alloc *structs.Allocation, opts ...WriteOption) error

func (*ErrDB) PutCheckResult

func (m *ErrDB) PutCheckResult(allocID string, qr *structs.CheckQueryResult) error

func (*ErrDB) PutDeploymentStatus

func (m *ErrDB) PutDeploymentStatus(allocID string, ds *structs.AllocDeploymentStatus) error

func (*ErrDB) PutDevicePluginState

func (m *ErrDB) PutDevicePluginState(ps *dmstate.PluginState) error

func (*ErrDB) PutDriverPluginState

func (m *ErrDB) PutDriverPluginState(ps *driverstate.PluginState) error

func (*ErrDB) PutDynamicPluginRegistryState

func (m *ErrDB) PutDynamicPluginRegistryState(state *dynamicplugins.RegistryState) error

func (*ErrDB) PutNetworkStatus

func (m *ErrDB) PutNetworkStatus(allocID string, ns *structs.AllocNetworkStatus, opts ...WriteOption) error

func (*ErrDB) PutTaskRunnerLocalState

func (m *ErrDB) PutTaskRunnerLocalState(allocID string, taskName string, val *state.LocalState) error

func (*ErrDB) PutTaskState

func (m *ErrDB) PutTaskState(allocID string, taskName string, state *structs.TaskState) error

func (*ErrDB) Upgrade

func (m *ErrDB) Upgrade() error

type MemDB

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

MemDB implements a StateDB that stores data in memory and should only be used for testing. All methods are safe for concurrent use.

func NewMemDB

func NewMemDB(logger hclog.Logger) *MemDB

func (*MemDB) Close

func (m *MemDB) Close() error

func (*MemDB) DeleteAllocationBucket

func (m *MemDB) DeleteAllocationBucket(allocID string, _ ...WriteOption) error

func (*MemDB) DeleteCheckResults

func (m *MemDB) DeleteCheckResults(allocID string, checkIDs []structs.CheckID) error

func (*MemDB) DeleteTaskBucket

func (m *MemDB) DeleteTaskBucket(allocID, taskName string) error

func (*MemDB) GetAllAllocations

func (m *MemDB) GetAllAllocations() ([]*structs.Allocation, map[string]error, error)

func (*MemDB) GetCheckResults

func (m *MemDB) GetCheckResults() (checks.ClientResults, error)

func (*MemDB) GetDeploymentStatus

func (m *MemDB) GetDeploymentStatus(allocID string) (*structs.AllocDeploymentStatus, error)

func (*MemDB) GetDevicePluginState

func (m *MemDB) GetDevicePluginState() (*dmstate.PluginState, error)

GetDevicePluginState stores the device manager's plugin state or returns an error.

func (*MemDB) GetDriverPluginState

func (m *MemDB) GetDriverPluginState() (*driverstate.PluginState, error)

func (*MemDB) GetDynamicPluginRegistryState

func (m *MemDB) GetDynamicPluginRegistryState() (*dynamicplugins.RegistryState, error)

func (*MemDB) GetNetworkStatus

func (m *MemDB) GetNetworkStatus(allocID string) (*structs.AllocNetworkStatus, error)

func (*MemDB) GetTaskRunnerState

func (m *MemDB) GetTaskRunnerState(allocID string, taskName string) (*state.LocalState, *structs.TaskState, error)

func (*MemDB) Name

func (m *MemDB) Name() string

func (*MemDB) PurgeCheckResults

func (m *MemDB) PurgeCheckResults(allocID string) error

func (*MemDB) PutAllocation

func (m *MemDB) PutAllocation(alloc *structs.Allocation, _ ...WriteOption) error

func (*MemDB) PutCheckResult

func (m *MemDB) PutCheckResult(allocID string, qr *structs.CheckQueryResult) error

func (*MemDB) PutDeploymentStatus

func (m *MemDB) PutDeploymentStatus(allocID string, ds *structs.AllocDeploymentStatus) error

func (*MemDB) PutDevicePluginState

func (m *MemDB) PutDevicePluginState(ps *dmstate.PluginState) error

func (*MemDB) PutDriverPluginState

func (m *MemDB) PutDriverPluginState(ps *driverstate.PluginState) error

func (*MemDB) PutDynamicPluginRegistryState

func (m *MemDB) PutDynamicPluginRegistryState(ps *dynamicplugins.RegistryState) error

func (*MemDB) PutNetworkStatus

func (m *MemDB) PutNetworkStatus(allocID string, ns *structs.AllocNetworkStatus, _ ...WriteOption) error

func (*MemDB) PutTaskRunnerLocalState

func (m *MemDB) PutTaskRunnerLocalState(allocID string, taskName string, val *state.LocalState) error

func (*MemDB) PutTaskState

func (m *MemDB) PutTaskState(allocID string, taskName string, state *structs.TaskState) error

func (*MemDB) Upgrade

func (m *MemDB) Upgrade() error

type NewStateDBFunc

type NewStateDBFunc func(logger hclog.Logger, stateDir string) (StateDB, error)

NewStateDBFunc creates a StateDB given a state directory.

func GetStateDBFactory

func GetStateDBFactory(devMode bool) NewStateDBFunc

GetStateDBFactory returns a func for creating a StateDB

type NoopDB

type NoopDB struct{}

NoopDB implements a StateDB that does not persist any data.

func (NoopDB) Close

func (n NoopDB) Close() error

func (NoopDB) DeleteAllocationBucket

func (n NoopDB) DeleteAllocationBucket(allocID string, opts ...WriteOption) error

func (NoopDB) DeleteCheckResults

func (n NoopDB) DeleteCheckResults(allocID string, checkIDs []structs.CheckID) error

func (NoopDB) DeleteTaskBucket

func (n NoopDB) DeleteTaskBucket(allocID, taskName string) error

func (NoopDB) GetAllAllocations

func (n NoopDB) GetAllAllocations() ([]*structs.Allocation, map[string]error, error)

func (NoopDB) GetCheckResults

func (n NoopDB) GetCheckResults() (checks.ClientResults, error)

func (NoopDB) GetDeploymentStatus

func (n NoopDB) GetDeploymentStatus(allocID string) (*structs.AllocDeploymentStatus, error)

func (NoopDB) GetDevicePluginState

func (n NoopDB) GetDevicePluginState() (*dmstate.PluginState, error)

func (NoopDB) GetDriverPluginState

func (n NoopDB) GetDriverPluginState() (*driverstate.PluginState, error)

func (NoopDB) GetDynamicPluginRegistryState

func (n NoopDB) GetDynamicPluginRegistryState() (*dynamicplugins.RegistryState, error)

func (NoopDB) GetNetworkStatus

func (n NoopDB) GetNetworkStatus(allocID string) (*structs.AllocNetworkStatus, error)

func (NoopDB) GetTaskRunnerState

func (n NoopDB) GetTaskRunnerState(allocID string, taskName string) (*state.LocalState, *structs.TaskState, error)

func (NoopDB) Name

func (n NoopDB) Name() string

func (NoopDB) PurgeCheckResults

func (n NoopDB) PurgeCheckResults(allocID string) error

func (NoopDB) PutAllocation

func (n NoopDB) PutAllocation(alloc *structs.Allocation, opts ...WriteOption) error

func (NoopDB) PutCheckResult

func (n NoopDB) PutCheckResult(allocID string, qr *structs.CheckQueryResult) error

func (NoopDB) PutDeploymentStatus

func (n NoopDB) PutDeploymentStatus(allocID string, ds *structs.AllocDeploymentStatus) error

func (NoopDB) PutDevicePluginState

func (n NoopDB) PutDevicePluginState(ps *dmstate.PluginState) error

func (NoopDB) PutDriverPluginState

func (n NoopDB) PutDriverPluginState(ps *driverstate.PluginState) error

func (NoopDB) PutDynamicPluginRegistryState

func (n NoopDB) PutDynamicPluginRegistryState(ps *dynamicplugins.RegistryState) error

func (NoopDB) PutNetworkStatus

func (n NoopDB) PutNetworkStatus(allocID string, ds *structs.AllocNetworkStatus, opts ...WriteOption) error

func (NoopDB) PutTaskRunnerLocalState

func (n NoopDB) PutTaskRunnerLocalState(allocID string, taskName string, val *state.LocalState) error

func (NoopDB) PutTaskState

func (n NoopDB) PutTaskState(allocID string, taskName string, state *structs.TaskState) error

func (NoopDB) Upgrade

func (n NoopDB) Upgrade() error

type RegistryState12

type RegistryState12 struct {
	Plugins map[string]map[string]*dynamicplugins.PluginInfo
}

RegistryState12 is the dynamic plugin registry state persisted before 1.3.0.

type StateDB

type StateDB interface {
	// Name of implementation.
	Name() string

	// Upgrade ensures the layout of the database is at the latest version
	// or returns an error. Corrupt data will be dropped when possible.
	// Errors should be considered critical and unrecoverable.
	Upgrade() error

	// GetAllAllocations returns all valid allocations and a map of
	// allocation IDs to retrieval errors.
	//
	// If a single error is returned then both allocations and the map will be nil.
	GetAllAllocations() ([]*structs.Allocation, map[string]error, error)

	// PutAllocation stores an allocation or returns an error if it could
	// not be stored.
	PutAllocation(*structs.Allocation, ...WriteOption) error

	// GetDeploymentStatus gets the allocation's deployment status. It may be nil.
	GetDeploymentStatus(allocID string) (*structs.AllocDeploymentStatus, error)

	// PutDeploymentStatus sets the allocation's deployment status. It may be nil.
	PutDeploymentStatus(allocID string, ds *structs.AllocDeploymentStatus) error

	// GetNetworkStatus gets the allocation's network status. It may be nil.
	GetNetworkStatus(allocID string) (*structs.AllocNetworkStatus, error)

	// PutNetworkStatus puts the allocation's network status. It may be nil.
	PutNetworkStatus(allocID string, ns *structs.AllocNetworkStatus, opts ...WriteOption) error

	// GetTaskRunnerState returns the LocalState and TaskState for a
	// TaskRunner. Either state may be nil if it is not found, but if an
	// error is encountered only the error will be non-nil.
	GetTaskRunnerState(allocID, taskName string) (*state.LocalState, *structs.TaskState, error)

	// PutTaskRunnerLocalState stores the LocalState for a TaskRunner or
	// returns an error.
	PutTaskRunnerLocalState(allocID, taskName string, val *state.LocalState) error

	// PutTaskState stores the TaskState for a TaskRunner or returns an
	// error.
	PutTaskState(allocID, taskName string, state *structs.TaskState) error

	// DeleteTaskBucket deletes a task's state bucket if it exists. No
	// error is returned if it does not exist.
	DeleteTaskBucket(allocID, taskName string) error

	// DeleteAllocationBucket deletes an allocation's state bucket if it
	// exists. No error is returned if it does not exist.
	DeleteAllocationBucket(allocID string, opts ...WriteOption) error

	// GetDevicePluginState is used to retrieve the device manager's plugin
	// state.
	GetDevicePluginState() (*dmstate.PluginState, error)

	// PutDevicePluginState is used to store the device manager's plugin
	// state.
	PutDevicePluginState(state *dmstate.PluginState) error

	// GetDriverPluginState is used to retrieve the driver manager's plugin
	// state.
	GetDriverPluginState() (*driverstate.PluginState, error)

	// PutDriverPluginState is used to store the driver manager's plugin
	// state.
	PutDriverPluginState(state *driverstate.PluginState) error

	// GetDynamicPluginRegistryState is used to retrieve a dynamic plugin manager's state.
	GetDynamicPluginRegistryState() (*dynamicplugins.RegistryState, error)

	// PutDynamicPluginRegistryState is used to store the dynamic plugin manager's state.
	PutDynamicPluginRegistryState(state *dynamicplugins.RegistryState) error

	// PutCheckResult sets the query result for the check implied in qr.
	PutCheckResult(allocID string, qr *structs.CheckQueryResult) error

	// DeleteCheckResults removes the given set of check results.
	DeleteCheckResults(allocID string, checkIDs []structs.CheckID) error

	// PurgeCheckResults removes all check results of the given allocation.
	PurgeCheckResults(allocID string) error

	// GetCheckResults is used to restore the set of check results on this Client.
	GetCheckResults() (checks.ClientResults, error)

	// Close the database. Unsafe for further use after calling regardless
	// of return value.
	Close() error
}

StateDB implementations store and load Nomad client state.

func NewBoltStateDB

func NewBoltStateDB(logger hclog.Logger, stateDir string) (StateDB, error)

NewBoltStateDB creates or opens an existing boltdb state file or returns an error.

type TaskRunnerHandle08

type TaskRunnerHandle08 struct {
	// Docker specific handle info
	ContainerID string `json:"ContainerID"`
	Image       string `json:"Image"`

	// LXC specific handle info
	ContainerName string `json:"ContainerName"`
	LxcPath       string `json:"LxcPath"`

	// Executor reattach config
	PluginConfig struct {
		Pid      int    `json:"Pid"`
		AddrNet  string `json:"AddrNet"`
		AddrName string `json:"AddrName"`
	} `json:"PluginConfig"`
}

func UnmarshalPre09HandleID

func UnmarshalPre09HandleID(raw []byte) (*TaskRunnerHandle08, error)

UnmarshalPre09HandleID decodes the pre09 json encoded handle ID

func (*TaskRunnerHandle08) ReattachConfig

func (t *TaskRunnerHandle08) ReattachConfig() *pstructs.ReattachConfig

type WriteOption

type WriteOption func(*WriteOptions)

WriteOption is a function that modifies WriteOptions struct above.

func WithBatchMode

func WithBatchMode() WriteOption

WithBatchMode enables Batch mode for write requests (Put* and Delete* operations above).

type WriteOptions

type WriteOptions struct {
	// In Batch mode, concurrent writes (Put* and Delete* operations above) are
	// coalesced into a single transaction, increasing write performance. To benefit
	// from this mode, writes must happen concurrently in goroutines, as every write
	// request still waits for the shared transaction to commit before returning.
	// See https://github.com/boltdb/bolt#batch-read-write-transactions for details.
	// This mode is only supported for BoltDB state backend and is ignored in other backends.
	BatchMode bool
}

WriteOptions adjusts the way the data is persisted by the StateDB above. Default is zero/false values for all fields. To provide different values, use With* functions below, like this: statedb.PutAllocation(alloc, WithBatchMode())

Jump to

Keyboard shortcuts

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