node

package
v0.0.0-...-6fba4f8 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Online means the node can receive request.
	Online = "online"

	// Pausing means the node is pausing.
	Pausing = "pausing"

	// Paused means the node is already paused.
	Paused = "paused"

	// Closing means the node is closing, and the state will be Offline when closed.
	Closing = "closing"

	// Offline means the node is offline, and will not provide service.
	Offline = "offline"
)

Variables

View Source
var (
	// DefaultRootPath is the root path of the keys stored in etcd, the `v1` is the tidb-binlog's version.
	DefaultRootPath = "/tidb-binlog/v1"

	// PumpNode is the name of pump.
	PumpNode = "pump"

	// DrainerNode is the name of drainer.
	DrainerNode = "drainer"

	// NodePrefix is the map (node => it's prefix in storage)
	NodePrefix = map[string]string{
		PumpNode:    "pumps",
		DrainerNode: "drainers",
	}
)

Functions

func AnalyzeNodeID

func AnalyzeNodeID(key string) string

AnalyzeNodeID returns nodeID by analyze key path.

Types

type EtcdRegistry

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

EtcdRegistry wraps the reactions with etcd

func NewEtcdRegistry

func NewEtcdRegistry(cli *etcd.Client, reqTimeout time.Duration) *EtcdRegistry

NewEtcdRegistry returns an EtcdRegistry client

func (*EtcdRegistry) Close

func (r *EtcdRegistry) Close() error

Close closes the etcd client

func (*EtcdRegistry) Node

func (r *EtcdRegistry) Node(pctx context.Context, prefix, nodeID string) (*Status, error)

Node returns the nodeStatus that matchs nodeID in the etcd

func (*EtcdRegistry) Nodes

func (r *EtcdRegistry) Nodes(pctx context.Context, prefix string) ([]*Status, error)

Nodes retruns all the nodeStatuses in the etcd

func (*EtcdRegistry) UpdateNode

func (r *EtcdRegistry) UpdateNode(pctx context.Context, prefix string, status *Status) error

UpdateNode update the node information.

type Label

type Label struct {
	Labels map[string]string `json:"labels"`
}

Label is key/value pairs that are attached to objects

type Node

type Node interface {
	// ID returns the uuid representing of this pump node
	ID() string
	// a short ID as 8 bytes length
	ShortID() string
	// RefreshStatus refresh node's status.
	RefreshStatus(ctx context.Context, status *Status) error
	// Heartbeat refreshes the state of this pump node in etcd periodically
	// if the pump is dead, the key 'root/nodes/<nodeID>/alive' will dissolve after a TTL time passed
	Heartbeat(ctx context.Context) <-chan error
	// Notify queries all living drainer from etcd, and notifies them
	Notify(ctx context.Context) error
	// NodeStatus returns this node's status
	NodeStatus() *Status
	// NodesStatus returns all pump nodes
	NodesStatus(ctx context.Context) ([]*Status, error)
	// Quit quits the node.
	Quit() error
}

Node defines pump node

type Status

type Status struct {
	// the id of node.
	NodeID string `json:"nodeId"`

	// the host of pump or node.
	Addr string `json:"host"`

	// the state of pump.
	State string `json:"state"`

	// the node is alive or not.
	IsAlive bool `json:"isAlive"`

	// the score of node, it is report by node, calculated by node's qps, disk usage and binlog's data size.
	// if Score is less than 0, means this node is useless. Now only used for pump.
	Score int64 `json:"score"`

	// the label of this node. Now only used for pump.
	// pump client will only send to a pump which label is matched.
	Label *Label `json:"label"`

	// for pump: max commit ts in pump
	// for drainer: drainer has consume all binlog less than or equal MaxCommitTS
	MaxCommitTS int64 `json:"maxCommitTS"`

	// UpdateTS is the last update ts of node's status.
	UpdateTS int64 `json:"updateTS"`
}

Status describes the status information of a tidb-binlog node in etcd.

func CloneStatus

func CloneStatus(status *Status) *Status

CloneStatus returns a new status with same value.

func NewStatus

func NewStatus(nodeID, addr, state string, score int64, maxCommitTS int64, updateTS int64) *Status

NewStatus returns a new status.

func NodesStatusFromEtcdNode

func NodesStatusFromEtcdNode(root *etcd.Node) ([]*Status, error)

NodesStatusFromEtcdNode returns nodes' status under root node.

func (*Status) String

func (s *Status) String() string

Jump to

Keyboard shortcuts

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