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 SetSlots(zkConn zkhelper.Conn, productName string, slots []*Slot, 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
- func GetMigratingSlots(conn zkhelper.Conn, productName string) ([]*Slot, error)
- func GetSlot(zkConn zkhelper.Conn, productName string, id int) (*Slot, error)
- func NewSlot(productName string, id int) *Slot
- func NoGroupSlots(zkConn zkhelper.Conn, productName string) ([]*Slot, error)
- func Slots(zkConn zkhelper.Conn, productName string) ([]*Slot, error)
- type SlotMigrateStatus
- type SlotMultiSetParam
- type SlotState
- type SlotStatus
Constants ¶
View Source
const ( GC_TYPE_N = iota + 1 GC_TYPE_SEC )
View Source
const ( PROXY_STATE_ONLINE = "online" PROXY_STATE_OFFLINE = "offline" PROXY_STATE_MARK_OFFLINE = "mark_offline" )
View Source
const ( SERVER_TYPE_MASTER string = "master" SERVER_TYPE_SLAVE string = "slave" SERVER_TYPE_OFFLINE string = "offline" )
View Source
const (
DEFAULT_SLOT_NUM = 1024
)
View Source
const (
INVALID_ID = -1
)
Variables ¶
View Source
var ErrNodeExists = errors.New("node already exists")
View Source
var ErrReceiverTimeout = errors.New("receiver timeout")
View Source
var ErrSlotAlreadyExists = errors.New("slots already exists")
View Source
var ErrUnknownProxyStatus = errors.New("unknown status, should be (online offline)")
View Source
var ErrUnknownSlotStatus = errors.New("unknown slot status, slot status should be (online, offline, migrate, pre_migrate)")
Functions ¶
func CreateProxyFenceNode ¶
func CreateProxyInfo ¶
func ExtraSeqList ¶
func ForceRemoveDeadFence ¶
只保留 online proxy 的 fence 节点。
func GetActionObject ¶
func GetActionResponsePath ¶
func GetActionSeqList ¶
只能应用据children节点纯数字结构的(?)
func GetFenceProxyMap ¶
这个 true/false 什么用?
func GetProxyFencePath ¶
func GetProxyPath ¶
func GetSlotBasePath ¶
func GetSlotPath ¶
func GetWatchActionPath ¶
func GroupExists ¶
func InitSlotSet ¶
danger operation ! slots数是固定的, 所以这里直接覆盖写(?) 好像时外层调用方检查slot是否存在并提供了force参数.
func NewActionWithTimeout ¶
func SetProxyStatus ¶
func SetSlotRange ¶
func SetSlotRange(zkConn zkhelper.Conn, productName string, fromSlot, toSlot, groupId int, status SlotStatus) error
同上, 只是指定slots的方式不同
Types ¶
type Action ¶
type Action struct {
// 操作类型
Type ActionType `json:"type"`
Desc string `json:"desc"`
// 这个字段是?
Target interface{} `json:"target"`
Ts string `json:"ts"` // timestamp
// 保存的是一个json串, 可以解析为models.ProxyInfo结构体
// 见 proxy.go needResponse() 函数
Receivers []string `json:"receivers"`
}
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" )
type ProxyInfo ¶
type ProxyInfo struct {
// proxy name
Id string `json:"id"`
Addr string `json:"addr"`
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"`
Pid int `json:"pid"`
StartAt string `json:"start_at"`
}
本proxy的信息 json demo:
{
"id":"proxy_1",
"addr":"workstation-centos-7.kmiku7.com:19000",
"last_event":"",
"last_event_ts":0,
"state":"online",
"description":"",
"debug_var_addr":"workstation-centos-7.kmiku7.com:11000",
"pid":17618,
"start_at":"2015-08-01 22:10:54.608791733 +0800 CST"
}
func GetProxyInfo ¶
type Server ¶
type Server struct {
Type string `json:"type"`
GroupId int `json:"group_id"`
Addr string `json:"addr"`
}
redis server instance 信息作为json保存在节点内
type ServerGroup ¶
type ServerGroup struct {
Id int `json:"id"`
ProductName string `json:"product_name"`
Servers []*Server `json:"servers"`
}
redis server group 节点内没有保存任何信息, 信息都在路径名字内
func NewServerGroup ¶
func NewServerGroup(productName string, id int) *ServerGroup
func ServerGroups ¶
func ServerGroups(zkConn zkhelper.Conn, productName string) ([]*ServerGroup, error)
先拿到groups列表, 然后循环处理每个group, 每个group先读group信息, 在读取对应的server信息.
func (*ServerGroup) GetServers ¶
func (self *ServerGroup) GetServers(zkConn zkhelper.Conn) ([]*Server, error)
func (*ServerGroup) Promote ¶
func (self *ServerGroup) Promote(conn zkhelper.Conn, addr, passwd string) error
func (*ServerGroup) RemoveServer ¶
func (self *ServerGroup) RemoveServer(zkConn zkhelper.Conn, addr string) error
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"`
}
demo json:
{"product_name":"test","id":0,"group_id":1,"state":{"status":"online","migrate_status":{"from":-1,"to":-1},"last_op_ts":"0"}}
func GetMigratingSlots ¶
func (*Slot) SetMigrateStatus ¶
type SlotMigrateStatus ¶
type SlotMultiSetParam ¶
type SlotMultiSetParam struct {
From int `json:"from"`
To int `json:"to"`
Status SlotStatus `json:"status"`
GroupId int `json:"group_id"`
}
type SlotState ¶
type SlotState struct {
Status SlotStatus `json:"status"`
// 这个字段只有Status处于migrage/pre_migrate才有效(?)
MigrateStatus SlotMigrateStatus `json:"migrate_status"`
LastOpTs string `json:"last_op_ts"` // operation timestamp
}
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" )
Click to show internal directories.
Click to hide internal directories.