Documentation
¶
Index ¶
- Constants
- Variables
- func GetInfoByPath(pathname string) (stype uint32, groupid uint32, sid uint64)
- func GetPath(groupid uint32, stype uint32, sid uint64) string
- func GetPathLoad(groupid uint32, stype uint32, sid uint64) string
- func GetPathServerInfo(pathname string) (stype uint32, groupid uint32, sid uint64)
- func GetPathStatus(groupid uint32, stype uint32, sid uint64) string
- func GetWatchByType(sType global.ServerTypeEnum) string
- func GetWatchPath(sGroup uint32, sType uint32) string
- type DiscoveryMgr
- func (mgr *DiscoveryMgr) ClearServerInfoAll()
- func (mgr *DiscoveryMgr) GetServerById(groupid uint32, stype global.ServerTypeEnum, serverId uint64) (IServerInfo, error)
- func (mgr *DiscoveryMgr) GetServerByType(sGroup uint32, sType global.ServerTypeEnum) (result IServerInfo, err error)
- func (mgr *DiscoveryMgr) GetServerList(sType global.ServerTypeEnum, sGroup uint32) ([]IServerInfo, error)
- func (mgr *DiscoveryMgr) Start() (err error)
- func (mgr *DiscoveryMgr) UpLoad()
- func (mgr *DiscoveryMgr) UpStatus(status int32)
- func (mgr *DiscoveryMgr) Watch(stype, groupid uint32, smap IServerMap)
- func (mgr *DiscoveryMgr) WatchByStype(stype global.ServerTypeEnum, smap IServerMap)
- type IExt
- type IServerInfo
- type IServerMap
- type ServerInfo
- func (this *ServerInfo) GetGroupID() uint32
- func (this *ServerInfo) GetListenAdd(v string) string
- func (this *ServerInfo) GetLoad() int64
- func (this *ServerInfo) GetOthGroupID() uint32
- func (this *ServerInfo) GetServerID() uint64
- func (this *ServerInfo) GetSrvType() uint32
- func (this *ServerInfo) GetStatus() protomsg.ServerStatus
- func (this *ServerInfo) GetToken() string
- func (this *ServerInfo) SetLoad(v int64)
- func (this *ServerInfo) SetStatus(v int32)
- type ServerMapByMinID
- type ServerMapByRand
- func (this *ServerMapByRand) Delete(path string)
- func (this *ServerMapByRand) DeleteAll()
- func (this *ServerMapByRand) GetBalancing(stype, groupid uint32) (result IServerInfo, err error)
- func (this *ServerMapByRand) GetListByTypeAGroup(sType, sGroup uint32) (result []IServerInfo, err error)
- func (this *ServerMapByRand) GetServerByID(stype, groupid uint32, serverId uint64) (result IServerInfo, err error)
- func (this *ServerMapByRand) LoadWatchAll(key string)
- func (this *ServerMapByRand) Put(sinfo IServerInfo)
- func (this *ServerMapByRand) SetExt(ext IExt)
- func (this *ServerMapByRand) UpLoad(path string, val int64) IServerInfo
- func (this *ServerMapByRand) UpStatus(path string, val int32)
- func (this *ServerMapByRand) WatchCallDelay(evt *clientv3.Event)
Constants ¶
View Source
const ( PATH_INFO = "info" //服务器信息 PATH_LOAD = "load" //服务器负载 PATH_STATUS = "status" //服务器状态 )
View Source
const GroupGlobalID uint32 = 0
通服的groupid, 所有分组的服务器都可以连
Variables ¶
View Source
var ErrServerBusy = errors.New("Get server failed, busy")
ErrServerBusy 服务器忙
Functions ¶
func GetInfoByPath ¶
按需要拆数据
func GetPathServerInfo ¶
折路径
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) 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 // 获取服务器负载器 GetDirMgr() *DiscoveryMgr }
外部对象需要实现的逻辑
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() int64 // 设置服务器繁忙数值 SetLoad(v int64) // 服务器状态 GetStatus() protomsg.ServerStatus // 设置服务器状态 SetStatus(v int32) }
服务器信息
type IServerMap ¶
type IServerMap interface { //加入服务器信息 Put(sinfo IServerInfo) //删除 服务器信息 根据path中的信息删除服务器信息 Delete(path string) //更新Load值 UpLoad(path string, val int64) IServerInfo //根据负载逻辑,获取服务器 GetBalancing(sType, sGroup uint32) (result IServerInfo, err error) //获取组的指定类型服务器列表 GetListByTypeAGroup(sType, sGroup uint32) ([]IServerInfo, error) //获取指定服务器 GetServerByID(sType, sGroup uint32, serverId uint64) (result IServerInfo, err error) //删除所有服务器信息 DeleteAll() // 监听函数 WatchCallDelay(evt *clientv3.Event) // 加载全量 LoadWatchAll(key string) //设置管理器 SetExt(ext IExt) }
type ServerInfo ¶
type ServerInfo struct { Number uint64 //线编号 ServerID uint64 //服务器ID SrvType global.ServerTypeEnum //服务器类型 GroupID uint32 //服务器组ID OthGroupID uint32 //对应公共组ID ListenMap map[string]string //地址信息 Token string //链接过去用来验证的Token Load int64 //服务器繁忙数值 0到100,100表示很忙 Status int32 // protomsg.ServerStatus }
注册在etcd中的服务器信息,上层可以组合它实现IServerInfo,实现自定义注册数据
func (*ServerInfo) GetStatus ¶
func (this *ServerInfo) GetStatus() protomsg.ServerStatus
func (*ServerInfo) SetStatus ¶
func (this *ServerInfo) SetStatus(v int32)
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 // contains filtered or unexported fields }
随机负载
func NewServerMapByRand ¶
func NewServerMapByRand() (result *ServerMapByRand)
func (*ServerMapByRand) Delete ¶
func (this *ServerMapByRand) Delete(path string)
删除 服务器信息 根据path中的信息删除服务器信息
func (*ServerMapByRand) GetBalancing ¶
func (this *ServerMapByRand) GetBalancing(stype, groupid 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) LoadWatchAll ¶
func (this *ServerMapByRand) LoadWatchAll(key string)
func (*ServerMapByRand) UpLoad ¶
func (this *ServerMapByRand) UpLoad(path string, val int64) IServerInfo
更新Load值
func (*ServerMapByRand) UpStatus ¶
func (this *ServerMapByRand) UpStatus(path string, val int32)
更新服务器状态
func (*ServerMapByRand) WatchCallDelay ¶
func (this *ServerMapByRand) WatchCallDelay(evt *clientv3.Event)
监听函数
Click to show internal directories.
Click to hide internal directories.