batch

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNotFoundService          = errors.New("not found service")
	ErrorSameRegIsInstanceRequest = errors.New("there is the same instance request")
	ErrorRegIsInstanceTimeout     = errors.New("polaris-sever regis instance busy")
)

Functions

func SendClientReply

func SendClientReply(futures interface{}, code apimodel.Code, result error)

SendReply 批量答复futures

Types

type ClientCtrl

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

InstanceCtrl 批量操作实例的类

func NewBatchDeregisterClientCtrl

func NewBatchDeregisterClientCtrl(storage store.Store, config *CtrlConfig) (*ClientCtrl, error)

NewBatchDeregisterClientCtrl 注册客户端批量操作对象

func NewBatchRegisterClientCtrl

func NewBatchRegisterClientCtrl(storage store.Store, config *CtrlConfig) (*ClientCtrl, error)

NewBatchRegisterClientCtrl 注册客户端批量操作对象

func (*ClientCtrl) Start

func (ctrl *ClientCtrl) Start(ctx context.Context)

Start 开始启动批量操作实例的相关协程

type ClientFuture

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

InstanceFuture 创建实例的异步结构体

func (*ClientFuture) Client

func (future *ClientFuture) Client() *model.Client

Client 获取 client 信息

func (*ClientFuture) Code

func (future *ClientFuture) Code() apimodel.Code

Code 获取code

func (*ClientFuture) Reply

func (future *ClientFuture) Reply(code apimodel.Code, result error)

Reply future的应答

func (*ClientFuture) SetClient

func (future *ClientFuture) SetClient(client *model.Client)

SetClient 设置 client 信息

func (*ClientFuture) Wait

func (future *ClientFuture) Wait() error

Wait 外部调用者,需要调用Wait等待执行结果

type Config

type Config struct {
	Register         *CtrlConfig `mapstructure:"register"`
	Deregister       *CtrlConfig `mapstructure:"deregister"`
	Heartbeat        *CtrlConfig `mapstructure:"heartbeat"`
	ClientRegister   *CtrlConfig `mapstructure:"clientRegister"`
	ClientDeregister *CtrlConfig `mapstructure:"clientDeregister"`
}

Config 批量配置,控制最大的条目,批量等待时间等

func ParseBatchConfig

func ParseBatchConfig(opt map[string]interface{}) (*Config, error)

ParseBatchConfig 解析配置文件为config

type Controller

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

Controller 批量控制器

func NewBatchCtrlWithConfig

func NewBatchCtrlWithConfig(storage store.Store, cacheMgn *cache.CacheManager, config *Config) (*Controller, error)

NewBatchCtrlWithConfig 根据配置文件创建一个批量控制器

func (*Controller) AsyncCreateInstance

func (bc *Controller) AsyncCreateInstance(svcId string, instance *apiservice.Instance, needWait bool) *InstanceFuture

AsyncCreateInstance 异步创建实例,返回一个future,根据future获取创建结果

func (*Controller) AsyncDeleteInstance

func (bc *Controller) AsyncDeleteInstance(instance *apiservice.Instance, needWait bool) *InstanceFuture

AsyncDeleteInstance 异步合并反注册

func (*Controller) AsyncDeregisterClient

func (bc *Controller) AsyncDeregisterClient(client *apiservice.Client) *ClientFuture

AsyncDeregisterClient 异步合并反注册

func (*Controller) AsyncHeartbeat

func (bc *Controller) AsyncHeartbeat(instance *apiservice.Instance, healthy bool,
	lastBeatTime int64) *InstanceFuture

AsyncHeartbeat 异步心跳

func (*Controller) AsyncRegisterClient

func (bc *Controller) AsyncRegisterClient(client *apiservice.Client) *ClientFuture

AsyncRegisterClient 异步合并反注册

func (*Controller) ClientDeregisterOpen

func (bc *Controller) ClientDeregisterOpen() bool

ClientDeregisterOpen 删除客户端是否开启

func (*Controller) ClientRegisterOpen

func (bc *Controller) ClientRegisterOpen() bool

ClientRegisterOpen 添加客户端是否开启

func (*Controller) CreateInstanceOpen

func (bc *Controller) CreateInstanceOpen() bool

CreateInstanceOpen 创建是否开启

func (*Controller) DeleteInstanceOpen

func (bc *Controller) DeleteInstanceOpen() bool

DeleteInstanceOpen 删除实例是否开启

func (*Controller) HeartbeatOpen

func (bc *Controller) HeartbeatOpen() bool

HeartbeatOpen 心跳是否开启

func (*Controller) Start

func (bc *Controller) Start(ctx context.Context)

Start 开启批量控制器 启动多个协程,接受外部create/delete请求

type CtrlConfig

type CtrlConfig struct {
	// 是否开启Batch工作模式
	Open bool `mapstructure:"open"`
	// 注册请求队列的长度
	QueueSize int `mapstructure:"queueSize"`
	// 最长多久一次批量操作
	WaitTime string `mapstructure:"waitTime"`
	// 每次操作最大的批量数
	MaxBatchCount int `mapstructure:"maxBatchCount"`
	// 写store的并发协程数
	Concurrency int `mapstructure:"concurrency"`
	// 任务最大存活周期
	TaskLife string `mapstructure:"taskLife"`
}

CtrlConfig batch控制配置项

type InstanceCtrl

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

InstanceCtrl 批量操作实例的类

func NewBatchDeregisterCtrl

func NewBatchDeregisterCtrl(storage store.Store, cacheMgn *cache.CacheManager, config *CtrlConfig) (
	*InstanceCtrl, error)

NewBatchDeregisterCtrl 实例反注册的操作对象

func NewBatchHeartbeatCtrl

func NewBatchHeartbeatCtrl(storage store.Store, cacheMgn *cache.CacheManager, config *CtrlConfig) (
	*InstanceCtrl, error)

NewBatchHeartbeatCtrl 实例心跳的操作对象

func NewBatchRegisterCtrl

func NewBatchRegisterCtrl(storage store.Store, cacheMgn *cache.CacheManager,
	config *CtrlConfig) (*InstanceCtrl, error)

NewBatchRegisterCtrl 注册实例批量操作对象

func (*InstanceCtrl) Start

func (ctrl *InstanceCtrl) Start(ctx context.Context)

Start 开始启动批量操作实例的相关协程

type InstanceFuture

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

InstanceFuture 创建实例的异步结构体

func (*InstanceFuture) CanDrop

func (future *InstanceFuture) CanDrop() bool

CanDrop 该 future 是否可以丢弃

func (*InstanceFuture) Code

func (future *InstanceFuture) Code() apimodel.Code

Code 获取code

func (*InstanceFuture) Instance

func (future *InstanceFuture) Instance() *model.Instance

Instance 获取ins

func (*InstanceFuture) Reply

func (future *InstanceFuture) Reply(cur time.Time, code apimodel.Code, result error)

Reply future的应答

func (*InstanceFuture) SetInstance

func (future *InstanceFuture) SetInstance(instance *model.Instance)

SetInstance 设置ins

func (*InstanceFuture) Wait

func (future *InstanceFuture) Wait() error

Wait 外部调用者,需要调用Wait等待执行结果

Jump to

Keyboard shortcuts

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