pool

package
v1.6.2-rc Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrContextDone               = errors.New("context done")
	ErrNoResourceAvailableInPool = errors.New("no resource available in pool, applying")
	ErrNoResourceAvailable       = errors.New("no resource available, check quota")
	ErrResourceInvalid           = errors.New("resource state invalid")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Name of pool
	Name string

	// Type of resource in pool
	Type string

	// TargetMin minimum number of all resources(contains the used) in pool
	TargetMin int

	// Target cache target of resource in pool
	Target int

	// MaxCap max capacity of pool
	MaxCap int

	// MaxCapProbe if enable the capacity detection function
	MaxCapProbe bool

	// MonitorInterval period of pool monitor
	MonitorInterval time.Duration

	// GCProtectPeriod protect period of resource while gc action
	GCProtectPeriod time.Duration

	// Factory to create resource in pool
	Factory ObjectFactory

	// PreStart run before the pool starts working
	PreStart ResourcePoolHook
}

Config of pool.

type ObjectFactory

type ObjectFactory interface {
	// Name of ObjectFactory
	Name() string

	// Create a certain amount of resources
	Create(count int) ([]types.NetResource, error)

	// Release destroy resource
	Release(resource types.NetResource) error

	// ReleaseInValid destroy invalid resource
	ReleaseInValid(resource types.NetResource) (types.NetResource, error)

	// Valid check if the resource is valid
	Valid(resource types.NetResource) error

	// List all resource created by ObjectFactory
	List() (map[types.ResStatus]map[string]types.NetResource, error)

	// GC sync objects in ObjectFactory with remote provider
	GC() error

	// GetResourceLimit get the maximum number of resources that can be created by ObjectFactory
	GetResourceLimit() int
}

type ResourcePool

type ResourcePool interface {
	// Name of ResourcePool
	Name() string

	// Allocate a specified or available types.NetResource from pool
	// If no resources are available in ResourcePool, create one
	Allocate(ctx context.Context, prefer, owner string) (types.NetResource, error)

	// Release a specified resource by ID
	Release(resID string) error

	// Status get Status of ResourcePool
	Status() Status

	// GetSnapshot get snapshot of ResourcePool
	GetSnapshot() (ResourcePoolSnapshot, error)

	// GC sync resource in ResourcePool with resource in ObjectFactory
	GC(getAllocatedResMap func() (map[string]types.NetResourceAllocated, error)) error // resourceId -- vpcResource

	// GetResourceLimit get the maximum number of resources that can be created by ObjectFactory
	GetResourceLimit() int

	// ReCfgCache reconfigure pooling parameters
	ReCfgCache(target, targetMin int)
}

func NewResourcePool

func NewResourcePool(config Config) (ResourcePool, error)

NewResourcePool create a ResourcePool according to Config.

type ResourcePoolHook

type ResourcePoolHook func(pool ResourcePoolOp) error

type ResourcePoolOp

type ResourcePoolOp interface {
	// AddInuse add a used resource to pool
	AddInuse(res types.NetResource, owner string)

	// AddInvalid add an invalid resource to pool
	AddInvalid(res types.NetResource)

	// AddAvailable add a available resource to pool
	AddAvailable(res types.NetResource)
}

type ResourcePoolSnapshot

type ResourcePoolSnapshot interface {
	// PoolSnapshot snapshot of pool
	PoolSnapshot() map[string]types.NetResourceStatus

	// MetaSnapshot snapshot of ObjectFactory
	MetaSnapshot() map[string]types.NetResourceStatus
}

type ResourcePoolSnapshotCache

type ResourcePoolSnapshotCache struct {
	Pool map[string]types.NetResourceStatus
	Meta map[string]types.NetResourceStatus
}

func (*ResourcePoolSnapshotCache) MetaSnapshot

func (*ResourcePoolSnapshotCache) PoolSnapshot

type Status

type Status struct {
	TargetMin       int
	Target          int
	MaxCap          int
	MaxCapProbe     bool
	MonitorInterval time.Duration
	Total           int
	Available       int
	Short           int
	Over            int
}

Status basic information of pool.

Jump to

Keyboard shortcuts

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