models

package
v0.0.0-...-c415e3a Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: Apache-2.0 Imports: 21 Imported by: 3

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 BaseDir = "/icefire"
View Source
const (
	INVALID_ID = -1
)

Variables

View Source
var (
	ErrSlotAlreadyExists = errors.New("slots already exists")
	ErrUnknownSlotStatus = errors.New("unknown slot status, slot status should be (online, offline, migrate, pre_migrate)")
)
View Source
var ErrGroupMasterNotFound = errors.New("group master not found")
View Source
var ErrReceiverTimeout = errors.New("receiver timeout")

Functions

func ActionGC

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

todo need to delete completed action

func ActionPath

func ActionPath(product string, seq string) string

func CliDir

func CliDir(product string) string

func CliPath

func CliPath(product string, name string) string

func CreateActionRootPath

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

func ExtraSeqList

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

func ForceRemoveLock

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

func GetWatchActionDir

func GetWatchActionDir(product string) string

func GroupDir

func GroupDir(product string) string

func GroupPath

func GroupPath(product string, gid int) string

func LockPath

func LockPath(product string) string

func NewClient

func NewClient(coordinator string, addrlist string, auth string, timeout time.Duration) (client.Client, error)

func ProductDir

func ProductDir(product string) string

func ProxyDir

func ProxyDir(product string) string

func ProxyPath

func ProxyPath(product string, id string) string

func ServerDir

func ServerDir(product string) string

func ServerPath

func ServerPath(product string, addr string) string

func SlotDir

func SlotDir(product string) string

func SlotPath

func SlotPath(product string, sid int) string

func ValidateProduct

func ValidateProduct(name string) 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 (*Action) Encode

func (a *Action) Encode() []byte

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 Lock

type Lock struct {
	Hostname string `json:"hostname"`
	Pid      int    `json:"pid"`
}

func NewLock

func NewLock() *Lock

func (*Lock) Encode

func (t *Lock) Encode() []byte

func (*Lock) Name

func (t *Lock) Name() string

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 (ProxyInfo) DebugVars

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

func (*ProxyInfo) Encode

func (p *ProxyInfo) Encode() []byte

func (ProxyInfo) Ops

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

type Server

type Server struct {
	ID      int        `json:"id"`
	GroupId int        `json:"group_id"`
	Addr    string     `json:"addr"`
	Type    ServerType `json:"type"` // todo remove
}

func GetServer

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

func NewServer

func NewServer(serverType ServerType, addr string) *Server

func (*Server) Encode

func (s *Server) Encode() []byte

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

func NewServerGroup

func NewServerGroup(productName string, id int) *ServerGroup

func (*ServerGroup) Encode

func (g *ServerGroup) Encode() []byte

func (*ServerGroup) ServerExists

func (self *ServerGroup) ServerExists(addr string) (bool, error)

func (ServerGroup) String

func (self ServerGroup) String() string

type ServerInfo

type ServerInfo struct {
	Addr string     `json:"addr"`
	Type ServerType `json:"type"`
}

type ServerType

type ServerType string
const (
	ServerTypeLeader    ServerType = "leader"
	ServerTypeFollower  ServerType = "follower"
	ServerTypeCandidate ServerType = "candidate"
	ServerTypeOffline   ServerType = "offline"
)

type Slot

type Slot struct {
	ProductName string    `json:"product_name"`
	Id          int       `json:"id"`
	GroupId     int       `json:"group_id"`
	State       SlotState `json:"state"`
}

func NewSlot

func NewSlot(productName string, id int) *Slot

func (*Slot) Encode

func (s *Slot) Encode() []byte

func (*Slot) String

func (s *Slot) String() string

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

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore(client client.Client, product string) *Store

func (*Store) Acquire

func (s *Store) Acquire(topom *Topom) error

func (*Store) ActionPath

func (s *Store) ActionPath(seq string) string

func (*Store) CheckAsOnlyMaster

func (s *Store) CheckAsOnlyMaster(sg *ServerGroup) (*Server, error)

func (*Store) CliDir

func (s *Store) CliDir() string

func (*Store) CliPath

func (s *Store) CliPath(name string) string

func (*Store) Client

func (s *Store) Client() client.Client

func (*Store) Close

func (s *Store) Close() error

func (*Store) CreateActoinInOrderer

func (s *Store) CreateActoinInOrderer(a *Action) (p string, err error)

func (*Store) DeleteAction

func (s *Store) DeleteAction(id int) error

func (*Store) DeleteGroup

func (s *Store) DeleteGroup(gid int) error

func (*Store) DeletePath

func (s *Store) DeletePath(path string) error

func (*Store) DeleteProxy

func (s *Store) DeleteProxy(id string) error

func (*Store) DeleteServer

func (s *Store) DeleteServer(addr string) error

func (*Store) DeleteSlot

func (s *Store) DeleteSlot(sid int) error

func (*Store) Exists

func (s *Store) Exists(path string) (bool, error)

func (*Store) GetActionObject

func (s *Store) GetActionObject(seq string, act interface{}) error

func (*Store) GetActionSeqList

func (s *Store) GetActionSeqList() ([]string, error)

func (*Store) GetActionWithSeq

func (s *Store) GetActionWithSeq(seq string) (*Action, error)

func (*Store) GetMigratingSlots

func (s *Store) GetMigratingSlots() ([]Slot, error)

func (*Store) GetServer

func (s *Store) GetServer(addr string, must bool) (*Server, error)

func (*Store) GetServerByPath

func (s *Store) GetServerByPath(path string, must bool) (*Server, error)

func (*Store) GetServers

func (s *Store) GetServers(sg *ServerGroup) ([]Server, error)

todo only need sg id

func (*Store) GetSlot

func (s *Store) GetSlot(sid int, must bool) (*Slot, error)

func (*Store) GroupDir

func (s *Store) GroupDir() string

func (*Store) GroupExists

func (s *Store) GroupExists(gid int) (bool, error)

func (*Store) GroupPath

func (s *Store) GroupPath(gid int) string

func (*Store) InitSlotSet

func (s *Store) InitSlotSet(productName string, totalSlotNum int) error

func (*Store) ListGroup

func (s *Store) ListGroup() (map[int]*ServerGroup, error)

func (*Store) LoadGroup

func (s *Store) LoadGroup(gid int, must bool) (*ServerGroup, error)

func (*Store) LoadProxy

func (s *Store) LoadProxy(id string) (*ProxyInfo, error)

func (*Store) LoadTopom

func (s *Store) LoadTopom(must bool) (*Topom, error)

func (*Store) Lock

func (s *Store) Lock() error

func (*Store) LockPath

func (s *Store) LockPath() string

func (*Store) Master

func (s *Store) Master(sg *ServerGroup) (*Server, error)

func (*Store) NewAction

func (s *Store) NewAction(actionType ActionType, target interface{}, desc string, needConfirm bool) (err error)

func (*Store) ProxyDir

func (s *Store) ProxyDir() string

func (*Store) ProxyPath

func (s *Store) ProxyPath(id string) string

func (*Store) RegisterActiveCli

func (s *Store) RegisterActiveCli(l *Lock) error

func (*Store) Release

func (s *Store) Release() error

func (*Store) ServerDir

func (s *Store) ServerDir() string

func (*Store) ServerPath

func (s *Store) ServerPath(addr string) string

func (*Store) SetMigrateStatus

func (s *Store) SetMigrateStatus(slot *Slot, fromGroup, toGroup int) error

func (*Store) SetSlotRange

func (s *Store) SetSlotRange(productName string, fromSlot, toSlot, groupId int, status SlotStatus) error

func (*Store) SlotDir

func (s *Store) SlotDir() string

func (*Store) SlotPath

func (s *Store) SlotPath(sid int) string

func (*Store) Slots

func (s *Store) Slots() ([]Slot, error)

func (*Store) UnLock

func (s *Store) UnLock() error

func (*Store) UnregisterActiveCli

func (s *Store) UnregisterActiveCli(name string) error

func (*Store) UpdateGroup

func (s *Store) UpdateGroup(g *ServerGroup) error

func (*Store) UpdateProxy

func (s *Store) UpdateProxy(proxyInfo *ProxyInfo) error

func (*Store) UpdateServer

func (s *Store) UpdateServer(server *Server) error

func (*Store) UpdateSlot

func (s *Store) UpdateSlot(m *Slot) error

func (*Store) UpdateSlotWithoutAction

func (s *Store) UpdateSlotWithoutAction(m *Slot) error

func (*Store) WatchActions

func (s *Store) WatchActions() (<-chan client.Event, []string, error)

type Topom

type Topom struct {
	Token     string `json:"token"`
	StartTime string `json:"start_time"`
	AdminAddr string `json:"admin_addr"`

	ProductName string `json:"product_name"`

	Pid int    `json:"pid"`
	Pwd string `json:"pwd"`
	Sys string `json:"sys"`
}

func LoadTopom

func LoadTopom(client client.Client, product string, must bool) (*Topom, error)

func (*Topom) Encode

func (t *Topom) Encode() []byte

Directories

Path Synopsis
* * @Author: zhangchao * @Description: * @Date: 2021/9/14 4:27 下午
* * @Author: zhangchao * @Description: * @Date: 2021/9/14 4:27 下午
fs
zk

Jump to

Keyboard shortcuts

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