models

package
v0.0.0-...-90f6a64 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2016 License: GPL-3.0, MIT Imports: 16 Imported by: 0

Documentation

Index

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"
)

proxy状态

View Source
const (
	SERVER_TYPE_MASTER  string = "master"
	SERVER_TYPE_SLAVE   string = "slave"
	SERVER_TYPE_OFFLINE string = "offline"
)

redis-server的状态类型

View Source
const (
	DEFAULT_SLOT_NUM = 1024
)

slot的上限

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 ActionGC

func ActionGC(zkConn zkhelper.Conn, productName string, gcType int, keep int) error

删除zk上的 aciton 和 ActionResponse 下的部分节点

func CreateActionRootPath

func CreateActionRootPath(zkConn zkhelper.Conn, path string) error

func CreateProxyFenceNode

func CreateProxyFenceNode(zkConn zkhelper.Conn, productName string, pi *ProxyInfo) (string, error)

在fence节点下创建proxy信息

func CreateProxyInfo

func CreateProxyInfo(zkConn zkhelper.Conn, productName string, pi *ProxyInfo) (string, error)

在zk上创建proxy信息

func ExtraSeqList

func ExtraSeqList(nodes []string) ([]int, error)

将字符串序号数组转换成int数组,并且排序

func ForceRemoveDeadFence

func ForceRemoveDeadFence(zkConn zkhelper.Conn, productName string) error

删除fence节点下处于异常状态的节点信息

func ForceRemoveLock

func ForceRemoveLock(zkConn zkhelper.Conn, productName string) error

强制删除Lock节点

func GetActionObject

func GetActionObject(zkConn zkhelper.Conn, productName string, seq int64, act interface{}, provider string) error

根据序号获取解析后的 action 对象

func GetActionResponsePath

func GetActionResponsePath(productName string) string

zk事件回复路径

func GetActionSeqList

func GetActionSeqList(zkConn zkhelper.Conn, productName string) ([]int, error)

func GetFenceProxyMap

func GetFenceProxyMap(zkConn zkhelper.Conn, productName string) (map[string]bool, error)

获取fence节点下的所有proxy的信息,value为true

func GetProxyFencePath

func GetProxyFencePath(productName string) string

func GetProxyPath

func GetProxyPath(productName string) string

proxy信息在zk中存放的路径

func GetSlotBasePath

func GetSlotBasePath(productName string) string

func GetSlotPath

func GetSlotPath(productName string, slotId int) string

func GetWatchActionPath

func GetWatchActionPath(productName string) string

zk事件路径

func GroupExists

func GroupExists(zkConn zkhelper.Conn, productName string, groupId int) (bool, error)

确认指定的group_id在zk上是否存在

func InitSlotSet

func InitSlotSet(zkConn zkhelper.Conn, productName string, totalSlotNum int) error

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 NewActionWithTimeout(zkConn zkhelper.Conn, productName string, actionType ActionType, target interface{}, desc string, needConfirm bool, timeoutInMs int) error

func SetProxyStatus

func SetProxyStatus(zkConn zkhelper.Conn, productName string, proxyName string, status string) error

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
}

func GetActionWithSeq

func GetActionWithSeq(zkConn zkhelper.Conn, productName string, seq int64, provider string) (*Action, error)

根据序号获取通知信息

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

func GetProxyInfo(zkConn zkhelper.Conn, productName string, proxyName string) (*ProxyInfo, error)

从zk的proxy的节点上获取该proxy的详细信息

func ProxyList

func ProxyList(zkConn zkhelper.Conn, productName string, filter func(*ProxyInfo) bool) ([]ProxyInfo, error)

从zk中获取所有的proxy的信息,可以通过filter指定过滤函数

func (*ProxyInfo) DebugVars

func (p *ProxyInfo) DebugVars() (map[string]interface{}, error)

func (*ProxyInfo) Ops

func (p *ProxyInfo) Ops() (int64, error)

通过调用proxy的用于debug的http服务地址,来获取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

func GetServer

func GetServer(zkConn zkhelper.Conn, zkPath string) (*Server, error)

给定路径,返回redis-server信息

func NewServer

func NewServer(serverType string, addr string) *Server

func (*Server) String

func (self *Server) String() string

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 GetGroup

func GetGroup(zkConn zkhelper.Conn, productName string, groupId int) (*ServerGroup, error)

获取指定group_id的group信息,包括所有的内部的redis-server信息

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) AddServer

func (self *ServerGroup) AddServer(zkConn zkhelper.Conn, s *Server, passwd string) error

向此group中添加一台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

func GetMigratingSlots(conn zkhelper.Conn, productName string) ([]*Slot, error)

获取状态处于 SLOT_STATUS_MIGRATE 和 SLOT_STATUS_PRE_MIGRATE 的节点信息

func GetSlot

func GetSlot(zkConn zkhelper.Conn, productName string, id int) (*Slot, error)

获取指定id的slot的信息

func NewSlot

func NewSlot(productName string, id int) *Slot

func Slots

func Slots(zkConn zkhelper.Conn, productName string) ([]*Slot, error)

返回zk中存储的所有的slots的信息学

func (*Slot) SetMigrateStatus

func (s *Slot) SetMigrateStatus(zkConn zkhelper.Conn, fromGroup, toGroup int) error

func (*Slot) String

func (s *Slot) String() string

func (*Slot) Update

func (s *Slot) Update(zkConn zkhelper.Conn) error

更新slot的状态信息

type SlotMigrateStatus

type SlotMigrateStatus struct {
	From int `json:"from"`
	To   int `json:"to"`
}

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"
)

Jump to

Keyboard shortcuts

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