models

package
v0.0.0-...-18a74ac Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2014 License: MIT Imports: 14 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(zkConn zkhelper.Conn, productName string, gcType int, keep int) error

func CreateActionRootPath

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

func CreateProxyInfo

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

func ExtraSeqList

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

func ForceRemoveLock

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

func GetActionObject

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

func GetActionSeqList

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

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 InitSlotSet

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

danger operation !

func NewAction

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

func SetSlots

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

func WaitForReceiver

func WaitForReceiver(zkConn zkhelper.Conn, productName string, actionZkPath string, proxies []ProxyInfo) 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(zkConn zkhelper.Conn, productName string, seq int64) (*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"
)

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

func GetProxyInfo

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

func ProxyList

func ProxyList(zkConn 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)

type Server

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

func GetServer

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

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"`
	ProductName string   `json:"product_name"`
	Servers     []Server `json:"servers"`
}

redis server group

func GetGroup

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

func NewServerGroup

func NewServerGroup(productName string, id int) *ServerGroup

func ServerGroups

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

func (*ServerGroup) AddServer

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

func (*ServerGroup) Create

func (self *ServerGroup) Create(zkConn zkhelper.Conn) error

func (*ServerGroup) Exists

func (self *ServerGroup) Exists(zkConn zkhelper.Conn) (bool, error)

func (*ServerGroup) GetServers

func (self *ServerGroup) GetServers(zkConn zkhelper.Conn) ([]Server, error)

func (*ServerGroup) Master

func (self *ServerGroup) Master(zkConn zkhelper.Conn) (*Server, error)

func (*ServerGroup) Promote

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

func (*ServerGroup) Remove

func (self *ServerGroup) Remove(zkConn zkhelper.Conn) error

func (*ServerGroup) RemoveServer

func (self *ServerGroup) RemoveServer(zkConn zkhelper.Conn, s Server) 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"`
}

func GetMigratingSlots

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

func GetSlot

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

func NewSlot

func NewSlot(productName string, id int) *Slot

func NoGroupSlots

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

func Slots

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

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

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