ebully

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 19 Imported by: 0

README

ebully

Documentation

Index

Constants

View Source
const (
	TemporaryCharacter = iota
	Master
	Follower
)
View Source
const (
	NodeUp = iota
	NodeDown
	MasterChange
)
View Source
const (
	MaxInt64 = 1<<64 - 1
)

Variables

This section is empty.

Functions

func EncodeMessage

func EncodeMessage(msgType uint16, nodeId uint64,
	character CharacterType) [12]byte

Types

type CharacterType

type CharacterType int

func DecodeMessage

func DecodeMessage(msg []byte) (msgType uint16,
	nodeId uint64, character CharacterType)

type Config

type Config struct {
	ID             uint64
	MasterAddr     string
	SelfAddr       string
	RetryCount     int
	RpcTimeOut     time.Duration
	HeartBeatTime  time.Duration
	Logger         *zap.Logger
	Listener       net.Listener
	ServiceAddress string

	EnableTcpProxy   bool
	NodeUpCallback   func(*nodepb.NodeInfo)
	NodeDownCallback func(*nodepb.NodeInfo)
}

type EBully

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

func NewEBully

func NewEBully(cfg Config) *EBully

func (*EBully) Character

func (e *EBully) Character() NodeCharacterType

func (*EBully) ID

func (e *EBully) ID() uint64

func (*EBully) Leave

func (e *EBully) Leave() error

func (*EBully) Meet

func (e *EBully) Meet(masterAddr string) (err error)

func (*EBully) PeerIds

func (e *EBully) PeerIds() []uint64

func (*EBully) PeerList

func (e *EBully) PeerList() []*nodepb.NodeInfo

func (*EBully) Shutdown

func (e *EBully) Shutdown() error

func (*EBully) Start

func (e *EBully) Start()

func (*EBully) Weight

func (e *EBully) Weight() int

type Node

type Node struct {
	nodepb.UnsafeNodeServer
	// contains filtered or unexported fields
}

func (*Node) GetCharacter

func (n *Node) GetCharacter() int64

获取角色

func (*Node) HearbeatRpc

func (n *Node) HearbeatRpc(ctx context.Context, req *nodepb.NodeInfo) (resp *nodepb.HearbeatResp, err error)

Hearbeat 接收心跳

func (*Node) Leave

func (n *Node) Leave() error

func (*Node) LeaveRpc

func (n *Node) LeaveRpc(ctx context.Context, req *nodepb.LeaveReq) (resp *nodepb.LeaveResp, err error)

ShutdownRpc node down RPC

func (*Node) MeetRpc

func (n *Node) MeetRpc(ctx context.Context, req *nodepb.NodeInfo) (resp *nodepb.MeetResp, err error)

Meet加入集群,返回ack=true时,表明当前节点应该为主节点,收到响应信息的节点为从节点 ack=false时,表明当前节点为从节点,收到响应信息的节点参考Redirect字段去寻找主节点

func (*Node) NodeMessageRpc

func (n *Node) NodeMessageRpc(ctx context.Context, req *nodepb.MessageReq) (resp *nodepb.MessageResp, err error)

NodeMessage接受消息

func (*Node) PeerIdListRpc

func (n *Node) PeerIdListRpc(ctx context.Context, req *nodepb.EmptyMessage) (resp *nodepb.NodeIdListResp, err error)

Peers获取集群节点

func (*Node) PeerIds

func (n *Node) PeerIds() []uint64

func (*Node) PeerInfos

func (n *Node) PeerInfos() []*nodepb.NodeInfo

func (*Node) PeerInfosRpc

func (n *Node) PeerInfosRpc(ctx context.Context, req *nodepb.EmptyMessage) (resp *nodepb.NodeInfoResp, err error)

Peers获取集群节点

func (*Node) SetCharacter

func (n *Node) SetCharacter(c int64)

获取角色

func (*Node) SetMasterMeta

func (n *Node) SetMasterMeta(nodeinfo *nodepb.NodeInfo) *Node

func (*Node) Start

func (n *Node) Start()

func (*Node) Stop

func (n *Node) Stop() error

type NodeCharacterType

type NodeCharacterType int

func (NodeCharacterType) String

func (nct NodeCharacterType) String() string

type NodeMeta

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

func NewNodeMeta

func NewNodeMeta(nodeInfo *node.NodeInfo) *NodeMeta

func (*NodeMeta) Address

func (meta *NodeMeta) Address() string

Address return the address string

func (*NodeMeta) InstanceID

func (meta *NodeMeta) InstanceID() uint64

UinqueId return the id of node ,it implement the interface named loadbalance.Instance.

func (*NodeMeta) InstanceWeight

func (meta *NodeMeta) InstanceWeight() int

Weight return the its memory capacity as the weight , it implement the interface named loadbalance.Instance.

func (*NodeMeta) Leave

func (meta *NodeMeta) Leave(nodeInfo *node.LeaveReq) (*node.LeaveResp, error)

SendHearbeat to the address of node in the node meta

func (*NodeMeta) Meet

func (meta *NodeMeta) Meet(msg *node.NodeInfo) (*node.MeetResp, error)

Meet to the address of node in the node meta

func (*NodeMeta) NodeInfoList

func (meta *NodeMeta) NodeInfoList() (*node.NodeInfoResp, error)

func (*NodeMeta) SendHearbeat

func (meta *NodeMeta) SendHearbeat(nodeInfo *node.NodeInfo) (*node.HearbeatResp, error)

SendHearbeat to the address of node in the node meta

func (*NodeMeta) ServiceAddress

func (meta *NodeMeta) ServiceAddress() string

Address return the address string

func (*NodeMeta) UpdateId

func (meta *NodeMeta) UpdateId(id uint64) *NodeMeta

func (*NodeMeta) UpdateInfo

func (meta *NodeMeta) UpdateInfo(nodeInfo *node.NodeInfo) *NodeMeta

type NodeMetaList

type NodeMetaList []*NodeMeta

func (NodeMetaList) Len

func (metaList NodeMetaList) Len() int

func (NodeMetaList) Less

func (metaList NodeMetaList) Less(i, j int) bool

func (NodeMetaList) Swap

func (metaList NodeMetaList) Swap(i, j int)

type SafeNodeMetaList

type SafeNodeMetaList struct {
	NodeMetaList
	// contains filtered or unexported fields
}

func (*SafeNodeMetaList) Append

func (so *SafeNodeMetaList) Append(node *NodeMeta)

func (*SafeNodeMetaList) BinarySearch

func (so *SafeNodeMetaList) BinarySearch(target uint64) int

func (*SafeNodeMetaList) Broadcast

func (so *SafeNodeMetaList) Broadcast(msg *node.MessageReq)

func (*SafeNodeMetaList) DeleteIndex

func (so *SafeNodeMetaList) DeleteIndex(i int)

func (*SafeNodeMetaList) SafeDo

func (so *SafeNodeMetaList) SafeDo(f func(so *SafeNodeMetaList))

func (*SafeNodeMetaList) Sort

func (so *SafeNodeMetaList) Sort()

Directories

Path Synopsis
pb

Jump to

Keyboard shortcuts

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