lb

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SkipNone = 0
	SkipUUID = (1 << iota)
	SkipSnapUUID
	SkipCapacity
)
View Source
const (
	// these two are supposedly mutually exclusive...
	ACLAllowAny  = "ALLOW_ANY"
	ACLAllowNone = "ALLOW_NONE"
)
View Source
const (
	DefaultClientPoolDialTimeout = 10 * time.Second
	DefaultClientPoolLingerTime  = 10 * time.Minute
	DefaultClientPoolReapCycle   = time.Minute
)

ClientPool options defaults

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Close()
	// ID() returns a unique opaque string ID of this client.
	ID() string
	// Targets() returns a sorted list of unique target endpoints this instance handles.
	Targets() string

	RemoteOk(ctx context.Context) error
	GetCluster(ctx context.Context) (*Cluster, error)
	GetClusterInfo(ctx context.Context) (*ClusterInfo, error)
	ListNodes(ctx context.Context) ([]*Node, error)

	CreateVolume(ctx context.Context, name string, capacity uint64,
		replicaCount uint32, compress bool, acl []string, projectName string,
		snapshotID guuid.UUID, qosPolicyName string, blocking bool,
	) (*Volume, error)
	DeleteVolume(ctx context.Context, uuid guuid.UUID, projectName string, blocking bool) error
	GetVolume(ctx context.Context, uuid guuid.UUID, projectName string) (*Volume, error)
	GetVolumeByName(ctx context.Context, name string, projectName string) (*Volume, error)
	UpdateVolume(ctx context.Context, uuid guuid.UUID, projectName string,
		hook VolumeUpdateHook,
	) (*Volume, error)

	CreateSnapshot(ctx context.Context, name string, projectName string, srcVolUUID guuid.UUID,
		descr string, blocking bool,
	) (*Snapshot, error)
	DeleteSnapshot(ctx context.Context, uuid guuid.UUID, projectName string, blocking bool) error
	GetSnapshot(ctx context.Context, uuid guuid.UUID, projectName string) (*Snapshot, error)
	GetSnapshotByName(ctx context.Context, name string, projectName string) (*Snapshot, error)
}

type ClientPool

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

ClientPool maintains a pool of long-lived LB clients that can be reused across individual RPC invocations to avoid connection/authentication overheads. only one live client per target is kept.

func NewClientPool

func NewClientPool(dialer DialFunc) *ClientPool

NewClientPool creates and sets up a LB client pool with default config. see NewClientPoolWithOptions() for a more flexible version.

func NewClientPoolWithOptions

func NewClientPoolWithOptions(dialer DialFunc, opts ClientPoolOptions) *ClientPool

NewClientPoolWithOptions creates and sets up a LB client pool using the timeouts specified in `opts`. uninitialised values in `opts` are set to defaults.

func (*ClientPool) Close

func (cp *ClientPool) Close()

Close wraps up the LB client pool operation. it is a blocking call that will invoke Close() each of the individual clients and wait for those calls to return.

func (*ClientPool) GetClient

func (cp *ClientPool) GetClient(
	ctx context.Context, targets endpoint.Slice, mgmtScheme string,
) (Client, error)

GetClient returns a ready-to-use LB client that can be used to control `target` LB. if none exist at the time of invocation, one will be created and connected to `target` transparently. GetClient() might block for the duration of dialling - within the constraints of the global pool dial timeout and `ctx` passed in (timeout, cancellation). this `ctx` has effect only on dialling, subsequent individual requests to the client itself take their own contexts.

clients obtained from the pool using GetClient() must be returned to the pool using PutClient() once the caller is done using them.

func (*ClientPool) PutClient

func (cp *ClientPool) PutClient(c Client)

PutClient returns a client that necessarily must have been previously obtained from the receiver pool back to the pool.

type ClientPoolOptions

type ClientPoolOptions struct {
	// callers are expected to occasionally retry if dialling fails,
	// normally at the behest of higher-level business logic.
	// default: `lb.DefaultClientPoolDialTimeout`
	DialTimeout time.Duration

	// LB client is not immediately closed when the last active user
	// returns it to the pool, but are left in live state for
	// approximately `LingerTime` for future reuse. after that they
	// are harvested at some point by the reaper.
	// default: `DefaultClientPoolLingerTime`
	LingerTime time.Duration

	// approximately once every `ReapCycle` LB clients that are
	// past their `LingerTime` will be harvested.
	// default: `DefaultClientPoolReapCycle`
	ReapCycle time.Duration
}

ClientPoolOptions defines ClientPool operational behaviour

type Cluster

type Cluster struct {
	UUID               guuid.UUID
	SubsysNQN          string
	CurrMaxReplicas    uint32
	MaxReplicas        uint32
	DiscoveryEndpoints []string
	ApiEndpoints       []string
	Capacity           uint64
}

type ClusterInfo

type ClusterInfo struct {
	UUID               guuid.UUID
	SubsysNQN          string
	CurrMaxReplicas    uint32
	MaxReplicas        uint32
	DiscoveryEndpoints []string
	ApiEndpoints       []string
	NvmeEndpoints      []string
}

type DialFunc

type DialFunc func(context.Context, endpoint.Slice, string) (Client, error)

type Node

type Node struct {
	Name     string
	UUID     guuid.UUID
	DataEP   endpoint.EP
	HostName string
	State    NodeState
}

type NodeState

type NodeState int32
const (
	NodeStateUnknown NodeState = 0
	NodeActive       NodeState = 1
	NodeActivating   NodeState = 2
	NodeInactive     NodeState = 3
	NodeUnattached   NodeState = 4
	NodeAttaching    NodeState = 6
	NodeDetaching    NodeState = 7
)

match present LB API values. here's to API stability!

func (NodeState) String

func (s NodeState) String() string

type NodesByName

type NodesByName []*Node

for sort.Interface:

func (NodesByName) Len

func (n NodesByName) Len() int

func (NodesByName) Less

func (n NodesByName) Less(i, j int) bool

func (NodesByName) Swap

func (n NodesByName) Swap(i, j int)

type Snapshot

type Snapshot struct {
	// "core" snapshot properties.
	Name               string
	UUID               guuid.UUID
	Capacity           uint64
	State              SnapshotState
	SrcVolUUID         guuid.UUID
	SrcVolName         string
	SrcVolReplicaCount uint32
	SrcVolCompression  bool
	CreationTime       time.Time

	ETag        string
	ProjectName string
}

type SnapshotState

type SnapshotState int32
const (
	SnapshotStateUnknown SnapshotState = 0
	SnapshotCreating     SnapshotState = 1
	SnapshotAvailable    SnapshotState = 2
	SnapshotDeleting     SnapshotState = 3
	SnapshotDeleted      SnapshotState = 4
	SnapshotFailed       SnapshotState = 7
)

func (SnapshotState) String

func (s SnapshotState) String() string

type Volume

type Volume struct {
	// "core" volume properties. q.v. IsSameAs().
	Name               string
	UUID               guuid.UUID
	ReplicaCount       uint32
	Capacity           uint64
	LogicalUsedStorage uint64
	Compression        bool
	SnapshotUUID       guuid.UUID
	QosPolicyName      string

	ACL []string

	State      VolumeState
	Protection VolumeProtection

	ETag        string
	ProjectName string
}

func (*Volume) ExplainDiffsFrom

func (v *Volume) ExplainDiffsFrom(other *Volume, lDescr, rDescr string, skipFields uint32) []string

ExplainDiffsFrom returns a list of human-readable sentences describing the differences between a pair of volumes. the volumes are referred to in the output as lDescr and rDescr, a pair of adjectives will work well for those. only "core" volume properties are examined.

func (*Volume) IsAccessible

func (v *Volume) IsAccessible() bool

func (*Volume) IsSameAs

func (v *Volume) IsSameAs(other *Volume) bool

IsSameAs compares only "core" volume properties, rather than transient state, such as the current State, Protection and ACL.

func (*Volume) IsUsable

func (v *Volume) IsUsable() bool

func (*Volume) IsWritable

func (v *Volume) IsWritable() bool

type VolumeProtection

type VolumeProtection int32
const (
	VolumeProtectionUnknown VolumeProtection = 0
	VolumeProtected         VolumeProtection = 1
	VolumeDegraded          VolumeProtection = 2
	VolumeReadOnly          VolumeProtection = 3
	VolumeNotAvailable      VolumeProtection = 4
)

match present LB API values. here's to API stability!

func (VolumeProtection) String

func (s VolumeProtection) String() string

type VolumeState

type VolumeState int32
const (
	VolumeStateUnknown VolumeState = 0
	VolumeCreating     VolumeState = 1
	VolumeAvailable    VolumeState = 2
	VolumeDeleting     VolumeState = 3

	// TODO: remove deprecated states once the LightOS API drops them:
	VolumeDeletedDEPRECATED VolumeState = 4

	VolumeFailed   VolumeState = 7
	VolumeUpdating VolumeState = 8

	VolumeRollback  VolumeState = 9
	VolumeMigrating VolumeState = 10
)

match present LB API values. here's to API stability!

func (VolumeState) String

func (s VolumeState) String() string

type VolumeUpdate

type VolumeUpdate struct {
	// full desired target ACL. nil slice to not update ACL, empty slice
	// to clear ACL.
	ACL []string

	Capacity uint64
}

VolumeUpdate struct expresses the desired state of the specified (i.e. non-nil/default) volume properties.

type VolumeUpdateHook

type VolumeUpdateHook func(vol *Volume) (update *VolumeUpdate, err error)

VolumeUpdateHook is passed to Client.UpdateVolume(). it will be invoked by UpdateVolume() with the freshly updated state of the volume as `vol` param. if updates to the volume are required, VolumeUpdateHook should return `update` with the desired state of the specified fields, otherwise - nil `update` should be returned, causing the update operation to be skipped. if the UpdateVolume() operation should be aborted, VolumeUpdateHook should return non-nil `err`, this error will be propagated back verbatim to the UpdateVolume() caller. care should, therefore, be taken when choosing the error type and value to return, if the ability to differentiate between the local/remote client/server errors and VolumeUpdateHook errors is a consideration.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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