cluster

package
v1.0.1-rc1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LocalPeer = "local"

	ReportMethod  = "Cluster.Report"
	RequestMethod = "Cluster.Invoke"
)

Variables

View Source
var (
	NoConfigErr        = errors.New("no configuration")
	NoPeersErr         = errors.New("no peers defined")
	PartitionedErr     = errors.New("cluster partitioned")
	PeerUnavailableErr = errors.New("peer unavailable")
)

Functions

func Init

func Init(cnf *config.ClusterConfig) (core.LocalPeer, error)

Init 初始化集群,返回本节点在集群中的名称 如果是单实例模式,节点名称为local 如果是集群模式,节点名称为配置文件中定义的本节点的名称 如果未传入配置文件,返回错误,节点名称为空字符串

func Shutdown

func Shutdown()

func Start

func Start(router core.Router)

Types

type Cluster

type Cluster struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

集群有两个角色一个是主节点角色,一个是从节点角色。在同一时间,集群的节点只承担一种角色

func (*Cluster) Invoke

func (c *Cluster) Invoke(msg *RequestPkt, resp *RespPkt) (err error)

Invoke called by a remote peer.

func (*Cluster) Ping

func (c *Cluster) Ping(ping *PingRequest, unused *bool) error

Ping 集群内部接口,供远端主节点调用rpc.Client.Call("Cluster.Ping"...

func (*Cluster) Report

func (c *Cluster) Report(msg *RequestPkt, resp *RespPkt) (err error)

Report 用于接收来自远端节点的内部广播,并调用本地Router.Register方法. 看作是内部节点对其他节点的广播,不对客户端开放 Called by remote peer

func (*Cluster) Vote

func (c *Cluster) Vote(req *VoteRequest, resp *VoteResponse) error

Vote 集群内部接口,用于接收远端节点发出的投票rpc.Client.Go("Cluster.Vote"...

type PeerValue

type PeerValue struct {
	PeerName string
	PeerAddr string
}

func (*PeerValue) String

func (p *PeerValue) String() string

type PingRequest

type PingRequest struct {
	// 主节点名称
	Leader string
	// 选举的轮次
	Term int
	// Ring hash signature that represents the cluster
	Signature string
	// 当前活动的集群名称集合
	PeerValues []*PeerValue
}

PingRequest 是主节点ping跟随节点时发送的数据

type PktType

type PktType uint8
const (
	RequestPktType PktType = iota + 1
	OnlinePktType
	OfflinePktType
)

type RequestPkt

type RequestPkt struct {
	// 发送这条请求的节点名称
	PeerName string
	AppName  string
	Paths    []core.MethodPath
	PktType  PktType
	// Ring hash signature of the node sending this request
	// Signature must match the signature of the receiver, otherwise the
	// Cluster is desynchronized.
	Signature string
	Pkt       proto.Message
}

maybe protobuf 这里需要定义交互需要的协议

type RespPkt

type RespPkt struct {
	Code      int
	PeerValue *PeerValue // response from which peer
	Pkt       proto.Message
}

maybe protobuf

type VoteRequest

type VoteRequest struct {
	// 发出本次投票的候选节点名称
	PeerValue *PeerValue
	// 当前选举的轮次
	Term int
}

ClusterVoteRequest is a request from a leader candidate to a node to vote for the candidate.

type VoteResponse

type VoteResponse struct {
	// 已对发出的投票请求投票
	Result bool
	// 节点投票后的轮次
	Term int
}

ClusterVoteResponse is a vote from a node.

Jump to

Keyboard shortcuts

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