models

package
v0.0.0-...-70285c8 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2016 License: MIT Imports: 15 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"
)
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 ActionGC

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

func CreateActionRootPath

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

func CreateProxyFenceNode

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

func CreateProxyInfo

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

func ExtraSeqList

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

func ForceRemoveDeadFence

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

func ForceRemoveLock

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

func GetActionObject

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

func GetActionResponsePath

func GetActionResponsePath(productName string) string

func GetActionSeqList

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

func GetFenceProxyMap

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

func GetProxyFencePath

func GetProxyFencePath(productName string) string

func GetProxyPath

func GetProxyPath(productName string) string

func GetSlotBasePath

func GetSlotBasePath(productName string) string

func GetSlotPath

func GetSlotPath(productName string, slotId int) string

func GetWatchActionPath

func GetWatchActionPath(productName string) string

func GroupExists

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

func InitSlotSet

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

danger operation !

func NewAction

func NewAction(coordConn zkhelper.Conn, productName string, actionType ActionType, target interface{}, desc string, needConfirm bool) error

func NewActionWithTimeout

func NewActionWithTimeout(coordConn zkhelper.Conn, productName string, actionType ActionType, target interface{}, desc string, needConfirm bool, timeoutInMs int) error

func SetProxyStatus

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

func SetSlotRange

func SetSlotRange(coordConn zkhelper.Conn, productName string, fromSlot, toSlot, groupId int, status SlotStatus) error

func SetSlots

func SetSlots(coordConn zkhelper.Conn, productName string, slots []*Slot, groupId int, status SlotStatus) error

func WaitForReceiverWithTimeout

func WaitForReceiverWithTimeout(coordConn zkhelper.Conn, productName string, actionCoordPath string, proxies []ProxyInfo, timeoutInMs int) error

Types

type Action

type Action struct {
	Type      ActionType  `json:"type"`
	Desc      string      `json:"desc"`
	Target    interface{} `json:"target"`
	Ts        string      `json:"ts"` // timestamp
	Receivers []string    `json:"receivers"`
}

func GetActionWithSeq

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

func (*Action) String

func (a *Action) String() string

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"

	ActionTimeoutMs     = 30 * 1000
	CheckTimeIntervalMs = 500
	MaxKeepActionsNum   = 500
)

type ProxyInfo

type ProxyInfo struct {
	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"`
}

func GetProxyInfo

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

func ProxyList

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

func (*ProxyInfo) DebugVars

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

func (*ProxyInfo) Ops

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

func (*ProxyInfo) String

func (p *ProxyInfo) String() string

type Server

type Server struct {
	Type    string `json:"type"`
	GroupId int    `json:"group_id"`
	Addr    string `json:"addr"`
}

redis server instance

func GetServer

func GetServer(coordConn zkhelper.Conn, coordPath string) (*Server, error)

func NewServer

func NewServer(serverType string, addr string) *Server

func (*Server) String

func (s *Server) String() string

type ServerGroup

type ServerGroup struct {
	Id          int       `json:"id"`
	ProductName string    `json:"product_name"`
	Servers     []*Server `json:"servers"`
}

redis server group

func GetGroup

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

func NewServerGroup

func NewServerGroup(productName string, id int) *ServerGroup

func ServerGroups

func ServerGroups(coordConn zkhelper.Conn, productName string) ([]*ServerGroup, error)

func (*ServerGroup) AddServer

func (sg *ServerGroup) AddServer(coordConn zkhelper.Conn, s *Server, auth string) error

func (*ServerGroup) Create

func (sg *ServerGroup) Create(coordConn zkhelper.Conn) error

func (*ServerGroup) Exists

func (sg *ServerGroup) Exists(coordConn zkhelper.Conn) (bool, error)

func (*ServerGroup) GetServers

func (sg *ServerGroup) GetServers(coordConn zkhelper.Conn) ([]*Server, error)

func (*ServerGroup) Master

func (sg *ServerGroup) Master(coordConn zkhelper.Conn) (*Server, error)

func (*ServerGroup) Promote

func (sg *ServerGroup) Promote(conn zkhelper.Conn, addr string, auth string) error

func (*ServerGroup) Remove

func (sg *ServerGroup) Remove(coordConn zkhelper.Conn) error

func (*ServerGroup) RemoveServer

func (sg *ServerGroup) RemoveServer(coordConn zkhelper.Conn, addr string) error

func (*ServerGroup) String

func (sg *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"`
}

func GetMigratingSlots

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

func GetSlot

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

func NewSlot

func NewSlot(productName string, id int) *Slot

func NoGroupSlots

func NoGroupSlots(coordConn zkhelper.Conn, productName string) ([]*Slot, error)

func Slots

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

func (*Slot) SetMigrateStatus

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

func (*Slot) String

func (s *Slot) String() string

func (*Slot) Update

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

type SlotMigrateStatus

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

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

Jump to

Keyboard shortcuts

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