serverMgr

package
v0.0.0-...-0012533 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrServerBusy = errors.New("Get server failed, busy")

ErrServerBusy 服务器忙

Functions

func GetPath

func GetPath(groupid uint32, stype uint32, sid uint64) string

获取注册路径

func GetPathLoad

func GetPathLoad(groupid uint32, stype uint32, sid uint64) string

获取写Load的路径

func GetPathServerInfo

func GetPathServerInfo(pathname string) (groupid uint32, stype uint32, sid uint64)

折路径

func GetWatchByType

func GetWatchByType(sType global.ServerTypeEnum) string

根据类型监听服务器

func GetWatchPath

func GetWatchPath(sGroup uint32, sType uint32) string

指定分组和类型的监听

Types

type DiscoveryMgr

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

使用ETCD进行服务发现

func NewDiscoveryMgr

func NewDiscoveryMgr(thgo *threads.ThreadGo, ext IExt) *DiscoveryMgr

func (*DiscoveryMgr) ClearServerInfoAll

func (mgr *DiscoveryMgr) ClearServerInfoAll()

清空服务器信息,因为可能是脏数据

func (*DiscoveryMgr) GetServerById

func (mgr *DiscoveryMgr) GetServerById(groupid uint32, stype global.ServerTypeEnum, serverId uint64) (IServerInfo, error)

GetServerById 根据服务器类型和ID取服务器

func (*DiscoveryMgr) GetServerByType

func (mgr *DiscoveryMgr) GetServerByType(sGroup uint32, sType global.ServerTypeEnum) (result IServerInfo, err error)

根据负载逻辑,获取服务器

func (*DiscoveryMgr) GetServerList

func (mgr *DiscoveryMgr) GetServerList(sType global.ServerTypeEnum, sGroup uint32) ([]IServerInfo, error)

根据负载逻辑,获取服务器

func (*DiscoveryMgr) GetServerListByType

func (mgr *DiscoveryMgr) GetServerListByType(sType global.ServerTypeEnum) ([]IServerInfo, error)

获取指定服务器类型的所有group服务器列表

func (*DiscoveryMgr) Start

func (mgr *DiscoveryMgr) Start() (err error)

开始注册

func (*DiscoveryMgr) UpLoad

func (mgr *DiscoveryMgr) UpLoad()

主动上报Load

func (*DiscoveryMgr) Watch

func (mgr *DiscoveryMgr) Watch(stype, groupid uint32, smap IServerMap)

监听指定服务器类型下的指定分组

func (*DiscoveryMgr) WatchByStype

func (mgr *DiscoveryMgr) WatchByStype(stype global.ServerTypeEnum, smap IServerMap)

监听所有group下的指定服务器类型

type IExt

type IExt interface {
	//根据类型生成一个新的IServerInfo对象,用与从etcd读出来后进行填充
	NewInfo(stype global.ServerTypeEnum) IServerInfo
	// 获取自己服务器需要注册的信息
	GetSelfInfo() IServerInfo
	//获取到新的服务器信息的时候回调,一般用来判断是否需要连接这个服务器
	WatchInfoCallBack(sinfo IServerInfo)
	//获取ETCD的实例
	GetEtcd() *etcd.EtcdAccess
}

外部对象需要实现的逻辑

type IServerInfo

type IServerInfo interface {
	//服务器组ID
	GetGroupID() uint32
	//服务器ID
	GetServerID() uint64
	//服务器类型
	GetSrvType() uint32
	//服务器公共组ID
	GetOthGroupID() uint32
	//Token
	GetToken() string
	//获取指定类型的连接地址
	GetListenAdd(v string) string
	// 服务器繁忙数值 0到100,100表示很忙
	GetLoad() int32
	// 设置服务器繁忙数值
	SetLoad(v int32)
	//服务一个副本出来
	Copy() IServerInfo
}

服务器信息

type IServerMap

type IServerMap interface {
	//加入服务器信息
	Put(sinfo IServerInfo)
	//删除一个服务器信息
	Delete(path string)
	//更新Load值
	UpLoad(path string, val int32) IServerInfo
	//根据负载逻辑,获取服务器
	GetBalancing(sType, sGroup uint32) (result IServerInfo, err error)
	//获取指定类型服务器列表
	GetListByType(sType uint32) ([]IServerInfo, error)
	//获取组的指定类型服务器列表
	GetListByTypeAGroup(sType, sGroup uint32) ([]IServerInfo, error)
	//获取指定服务器
	GetServerByID(sType, sGroup uint32, serverId uint64) (result IServerInfo, err error)
	//删除所有服务器信息
	DeleteAll()
}

type ServerInfo

type ServerInfo struct {
	ServerID   uint64                       //服务器ID
	SrvType    global.ServerTypeEnum        //服务器类型
	GroupID    uint32                       //服务器组ID
	OthGroupID uint32                       //对应公共组ID
	ListenMap  map[string]*global.ListenCfg //地址信息
	Token      string                       //链接过去用来验证的Token
	Load       int32                        //服务器繁忙数值 0到100,100表示很忙
}

注册在etcd中的服务器信息,上层可以组合它实现IServerInfo,实现自定义注册数据

func (*ServerInfo) Copy

func (this *ServerInfo) Copy() IServerInfo

服务一个副本出来

func (*ServerInfo) GetGroupID

func (this *ServerInfo) GetGroupID() uint32

服务器组ID

func (*ServerInfo) GetListenAdd

func (this *ServerInfo) GetListenAdd(v string) string

获取指定类型的连接地址

func (*ServerInfo) GetLoad

func (this *ServerInfo) GetLoad() int32

服务器繁忙数值 0到100,100表示很忙

func (*ServerInfo) GetOthGroupID

func (this *ServerInfo) GetOthGroupID() uint32

服务器公共组ID

func (*ServerInfo) GetServerID

func (this *ServerInfo) GetServerID() uint64

服务器ID

func (*ServerInfo) GetSrvType

func (this *ServerInfo) GetSrvType() uint32

服务器类型

func (*ServerInfo) GetToken

func (this *ServerInfo) GetToken() string

Token

func (*ServerInfo) SetLoad

func (this *ServerInfo) SetLoad(v int32)

设置服务器繁忙数值

type ServerMapByGway

type ServerMapByGway struct {
	Lock *sync.RWMutex
	//服务器信息
	Srvli map[uint64]map[uint64]IServerInfo
	Allli []IServerInfo
}

Login上的Gateway的负载器

func NewServerMapByGway

func NewServerMapByGway() (result *ServerMapByGway)

func (*ServerMapByGway) Delete

func (this *ServerMapByGway) Delete(path string)

删除一个服务器信息

func (*ServerMapByGway) DeleteAll

func (this *ServerMapByGway) DeleteAll()

删除所有服务器信息

func (*ServerMapByGway) GetBalancing

func (this *ServerMapByGway) GetBalancing(stype, groupid uint32) (result IServerInfo, err error)

根据负载逻辑,获取服务器

func (*ServerMapByGway) GetListByType

func (this *ServerMapByGway) GetListByType(styp uint32) (result []IServerInfo, err error)

获取指定类型服务器列表

func (*ServerMapByGway) GetListByTypeAGroup

func (this *ServerMapByGway) GetListByTypeAGroup(sType, sGroup uint32) (result []IServerInfo, err error)

获取组的指定类型服务器列表

func (*ServerMapByGway) GetServerByID

func (this *ServerMapByGway) GetServerByID(stype, groupid uint32, serverId uint64) (result IServerInfo, err error)

获取指定服务器

func (*ServerMapByGway) Put

func (this *ServerMapByGway) Put(sinfo IServerInfo)

加入服务器信息

func (*ServerMapByGway) UpLoad

func (this *ServerMapByGway) UpLoad(path string, val int32) IServerInfo

更新Load值

type ServerMapByMinID

type ServerMapByMinID struct {
	ServerMapByRand
}

优先分配小服务ID

func NewServerMapByMinID

func NewServerMapByMinID() (result *ServerMapByMinID)

func (*ServerMapByMinID) GetBalancing

func (this *ServerMapByMinID) GetBalancing(stype, groupid uint32) (result IServerInfo, err error)

根据负载逻辑,获取服务器

type ServerMapByRand

type ServerMapByRand struct {
	Lock *sync.RWMutex
	//服务器信息
	Srvli map[uint64]map[uint64]IServerInfo
}

随机负载

func NewServerMapByRand

func NewServerMapByRand() (result *ServerMapByRand)

func (*ServerMapByRand) Delete

func (this *ServerMapByRand) Delete(path string)

删除一个服务器信息

func (*ServerMapByRand) DeleteAll

func (this *ServerMapByRand) DeleteAll()

删除所有服务器信息

func (*ServerMapByRand) GetBalancing

func (this *ServerMapByRand) GetBalancing(stype, groupid uint32) (result IServerInfo, err error)

根据负载逻辑,获取服务器

func (*ServerMapByRand) GetListByType

func (this *ServerMapByRand) GetListByType(styp uint32) (result []IServerInfo, err error)

获取指定类型服务器列表

func (*ServerMapByRand) GetListByTypeAGroup

func (this *ServerMapByRand) GetListByTypeAGroup(sType, sGroup uint32) (result []IServerInfo, err error)

获取组的指定类型服务器列表

func (*ServerMapByRand) GetServerByID

func (this *ServerMapByRand) GetServerByID(stype, groupid uint32, serverId uint64) (result IServerInfo, err error)

获取指定服务器

func (*ServerMapByRand) Put

func (this *ServerMapByRand) Put(sinfo IServerInfo)

加入服务器信息

func (*ServerMapByRand) UpLoad

func (this *ServerMapByRand) UpLoad(path string, val int32) IServerInfo

更新Load值

Jump to

Keyboard shortcuts

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