Documentation
¶
Index ¶
- Constants
- Variables
- func ActionGC(zkConn zkhelper.Conn, productName string, gcType int, keep int) error
- func CreateActionRootPath(zkConn zkhelper.Conn, path string) error
- func CreateProxyFenceNode(zkConn zkhelper.Conn, productName string, pi *ProxyInfo) (string, error)
- func CreateProxyInfo(zkConn zkhelper.Conn, productName string, pi *ProxyInfo) (string, error)
- func ExtraSeqList(nodes []string) ([]int, error)
- func ForceRemoveDeadFence(zkConn zkhelper.Conn, productName string) error
- func ForceRemoveLock(zkConn zkhelper.Conn, productName string) error
- func GetActionObject(zkConn zkhelper.Conn, productName string, seq int64, act interface{}, ...) error
- func GetActionResponsePath(productName string) string
- func GetActionSeqList(zkConn zkhelper.Conn, productName string) ([]int, error)
- func GetFenceProxyMap(zkConn zkhelper.Conn, productName string) (map[string]bool, error)
- func GetProxyFencePath(productName string) string
- func GetProxyPath(productName string) string
- func GetSlotBasePath(productName string) string
- func GetSlotPath(productName string, slotId int) string
- func GetWatchActionPath(productName string) string
- func GroupExists(zkConn zkhelper.Conn, productName string, groupId int) (bool, error)
- func InitSlotSet(zkConn zkhelper.Conn, productName string, totalSlotNum int) error
- func NewAction(zkConn zkhelper.Conn, productName string, actionType ActionType, ...) error
- func NewActionWithTimeout(zkConn zkhelper.Conn, productName string, actionType ActionType, ...) error
- func SetProxyStatus(zkConn zkhelper.Conn, productName string, proxyName string, status string) error
- func SetSlotRange(zkConn zkhelper.Conn, productName string, fromSlot, toSlot, groupId int, ...) error
- func WaitForReceiverWithTimeout(zkConn zkhelper.Conn, productName string, actionZkPath string, ...) error
- type Action
- type ActionType
- type ProxyInfo
- type Server
- type ServerGroup
- func (self *ServerGroup) AddServer(zkConn zkhelper.Conn, s *Server, passwd string) error
- func (self *ServerGroup) Create(zkConn zkhelper.Conn) error
- func (self *ServerGroup) Exists(zkConn zkhelper.Conn) (bool, error)
- func (self *ServerGroup) GetServers(zkConn zkhelper.Conn) ([]*Server, error)
- func (self *ServerGroup) Master(zkConn zkhelper.Conn) (*Server, error)
- func (self *ServerGroup) Promote(conn zkhelper.Conn, addr, passwd string) error
- func (self *ServerGroup) Remove(zkConn zkhelper.Conn) error
- func (self *ServerGroup) RemoveServer(zkConn zkhelper.Conn, addr string) error
- func (self *ServerGroup) String() string
- type Slot
- type SlotMigrateStatus
- type SlotMultiSetParam
- type SlotState
- type SlotStatus
Constants ¶
const ( GC_TYPE_N = iota + 1 GC_TYPE_SEC )
const ( PROXY_STATE_ONLINE = "online" PROXY_STATE_OFFLINE = "offline" PROXY_STATE_MARK_OFFLINE = "mark_offline" )
proxy状态
const ( SERVER_TYPE_MASTER string = "master" SERVER_TYPE_SLAVE string = "slave" SERVER_TYPE_OFFLINE string = "offline" )
redis-server的状态类型
const (
DEFAULT_SLOT_NUM = 1024
)
slot的上限
const (
INVALID_ID = -1
)
默认无效的值
Variables ¶
var ErrNodeExists = errors.New("node already exists")
var ErrReceiverTimeout = errors.New("receiver timeout")
var ErrSlotAlreadyExists = errors.New("slots already exists")
var ErrUnknownProxyStatus = errors.New("unknown status, should be (online offline)")
var ErrUnknownSlotStatus = errors.New("unknown slot status, slot status should be (online, offline, migrate, pre_migrate)")
Functions ¶
func CreateProxyFenceNode ¶
在fence节点下创建proxy信息
func CreateProxyInfo ¶
在zk上创建proxy信息
func ForceRemoveDeadFence ¶
删除fence节点下处于异常状态的节点信息
func ForceRemoveLock ¶
强制删除Lock节点
func GetActionObject ¶
func GetActionObject(zkConn zkhelper.Conn, productName string, seq int64, act interface{}, provider string) error
根据序号获取解析后的 action 对象
func GetActionSeqList ¶
func GetFenceProxyMap ¶
获取fence节点下的所有proxy的信息,value为true
func GetProxyFencePath ¶
func GetSlotBasePath ¶
func GetSlotPath ¶
func GroupExists ¶
确认指定的group_id在zk上是否存在
func InitSlotSet ¶
danger operation ! 初始化所有slot的信息
func NewAction ¶
func NewAction(zkConn zkhelper.Conn, productName string, actionType ActionType, target interface{}, desc string, needConfirm bool) error
创建一个通知事件,会在 actions 里创建顺序节点 之后如果needConfirm为true,在 ActionResponse 里等待需要回复的proxies节点的回复,超过30s未回复的节点置为offline
func NewActionWithTimeout ¶
func SetProxyStatus ¶
func SetSlotRange ¶
func SetSlotRange(zkConn zkhelper.Conn, productName string, fromSlot, toSlot, groupId int, status SlotStatus) error
用于初始化时分配slots到指定group
func WaitForReceiverWithTimeout ¶
func WaitForReceiverWithTimeout(zkConn zkhelper.Conn, productName string, actionZkPath string, proxies []ProxyInfo, timeoutInMs int) error
proxy从actions里收到通知后会在 ActionResponse 里同样id的节点下创建以proxy_id命名的节点 每隔500ms查询一次该节点下的子节点,确认所有proxy都回复后退出,或者超时后退出,没有回复的proxy被置为offline
Types ¶
type Action ¶
type Action struct {
Type ActionType `json:"type"` // 类型
Desc string `json:"desc"` // 描述
Target interface{} `json:"target"` // 更新后的目标信息,例如 Slot、Proxy等
Ts string `json:"ts"` // timestamp
Receivers []string `json:"receivers"` // proxyInfo结构json后的字符串,或者直接是 proxy_id
}
type ActionType ¶
type ActionType string
const ( ACTION_TYPE_SERVER_GROUP_CHANGED ActionType = "group_changed" ACTION_TYPE_SERVER_GROUP_REMOVE ActionType = "group_remove" ACTION_TYPE_SLOT_CHANGED ActionType = "slot_changed" ACTION_TYPE_MULTI_SLOT_CHANGED ActionType = "multi_slot_changed" ACTION_TYPE_SLOT_MIGRATE ActionType = "slot_migrate" ACTION_TYPE_SLOT_PREMIGRATE ActionType = "slot_premigrate" )
操作消息类型 例如执行某个操作后需要通知其他proxy的时候使用
type ProxyInfo ¶
type ProxyInfo struct {
Id string `json:"id"` // proxy名字,用户在配置文件中配置
Addr string `json:"addr"` // proxy服务地址,用于提供代理服务
LastEvent string `json:"last_event"`
LastEventTs int64 `json:"last_event_ts"`
State string `json:"state"` // 当前状态
Description string `json:"description"` // 描述
DebugVarAddr string `json:"debug_var_addr"` // debug地址
Pid int `json:"pid"` // 进程pid
StartAt string `json:"start_at"` // 启动时间
}
func GetProxyInfo ¶
从zk的proxy的节点上获取该proxy的详细信息
type Server ¶
type Server struct {
Type string `json:"type"` // 类型, master,slave,offline
GroupId int `json:"group_id"` // 所属group_id
Addr string `json:"addr"` // 地址
}
redis server instance
type ServerGroup ¶
type ServerGroup struct {
Id int `json:"id"` // group_id
ProductName string `json:"product_name"` // 集群名称
Servers []*Server `json:"servers"` // 包含的所有redis-server信息
}
redis server group
func NewServerGroup ¶
func NewServerGroup(productName string, id int) *ServerGroup
func ServerGroups ¶
func ServerGroups(zkConn zkhelper.Conn, productName string) ([]*ServerGroup, error)
获取集群中所有groups的信息,包括内部所有redis-server的信息
func (*ServerGroup) Create ¶
func (self *ServerGroup) Create(zkConn zkhelper.Conn) error
在zk上新建group节点
func (*ServerGroup) Exists ¶
func (self *ServerGroup) Exists(zkConn zkhelper.Conn) (bool, error)
从zk上根据group_id获取自身的信息,获取不到的表示不存在
func (*ServerGroup) GetServers ¶
func (self *ServerGroup) GetServers(zkConn zkhelper.Conn) ([]*Server, error)
获取这个group中所有的redis-server的信息
func (*ServerGroup) Master ¶
func (self *ServerGroup) Master(zkConn zkhelper.Conn) (*Server, error)
返回此group中的类型为master的redis-server
func (*ServerGroup) Promote ¶
func (self *ServerGroup) Promote(conn zkhelper.Conn, addr, passwd string) error
提升指定地址的redis-server为这个group中的master 这里有个问题就是原来的master会被下线,并且其余的slave-server仍然slave of 旧的master,需要手动操作
func (*ServerGroup) Remove ¶
func (self *ServerGroup) Remove(zkConn zkhelper.Conn) error
删除group信息(要确定没有slot存储在这个group中)
func (*ServerGroup) RemoveServer ¶
func (self *ServerGroup) RemoveServer(zkConn zkhelper.Conn, addr string) error
从此group中删除指定地址的 redis-server
func (*ServerGroup) String ¶
func (self *ServerGroup) String() string
type Slot ¶
type Slot struct {
ProductName string `json:"product_name"`
Id int `json:"id"`
GroupId int `json:"group_id"`
State SlotState `json:"state"`
}
zk中 /zk/codis/productName/slots 下所存储的每一个slot信息,json格式
func GetMigratingSlots ¶
获取状态处于 SLOT_STATUS_MIGRATE 和 SLOT_STATUS_PRE_MIGRATE 的节点信息
func (*Slot) SetMigrateStatus ¶
type SlotMigrateStatus ¶
slot迁移信息
type SlotMultiSetParam ¶
type SlotMultiSetParam struct {
From int `json:"from"`
To int `json:"to"`
Status SlotStatus `json:"status"`
GroupId int `json:"group_id"`
}
批量迁移slot的通知
type SlotState ¶
type SlotState struct {
Status SlotStatus `json:"status"`
MigrateStatus SlotMigrateStatus `json:"migrate_status"`
LastOpTs string `json:"last_op_ts"` // operation timestamp
}
slot状态信息
type SlotStatus ¶
type SlotStatus string
const ( SLOT_STATUS_ONLINE SlotStatus = "online" SLOT_STATUS_OFFLINE SlotStatus = "offline" SLOT_STATUS_MIGRATE SlotStatus = "migrate" SLOT_STATUS_PRE_MIGRATE SlotStatus = "pre_migrate" )