node

package
v0.0.0-...-608e6a2 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: GPL-3.0 Imports: 14 Imported by: 0

README

node

a nodes ring for a key to get node

Get Node Methods

Direct

direct to get last added node, node's wight is unavailable

Consistent hashing

WIKI

Random

to get the node by random

RoundRobin

to get the node by RoundRobin

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NodeType_name = map[int32]string{
		0: "NODE_TYPE_DIRECT",
		1: "NODE_TYPE_RANDOM",
		2: "NODE_TYPE_CONSISTENT",
		3: "NODE_TYPE_ROUNDROBIN",
	}
	NodeType_value = map[string]int32{
		"NODE_TYPE_DIRECT":     0,
		"NODE_TYPE_RANDOM":     1,
		"NODE_TYPE_CONSISTENT": 2,
		"NODE_TYPE_ROUNDROBIN": 3,
	}
)

Enum value maps for NodeType.

View Source
var (
	Protocol_name = map[int32]string{
		0: "PROTOCOL_LOCAL",
		1: "PROTOCOL_GRPC",
		2: "PROTOCOL_HTTP",
		3: "PROTOCOL_QUIC",
	}
	Protocol_value = map[string]int32{
		"PROTOCOL_LOCAL": 0,
		"PROTOCOL_GRPC":  1,
		"PROTOCOL_HTTP":  2,
		"PROTOCOL_QUIC":  3,
	}
)

Enum value maps for Protocol.

View Source
var File_trellis_tech_trellis_v1_proto_node_proto protoreflect.FileDescriptor

Functions

func NewNodes

func NewNodes(cfg config.Config) (ms map[string]Manager, err error)

NewNodes 增加Nodes节点

func NewNodesFromConfig

func NewNodesFromConfig(filepath string) (map[string]Manager, error)

NewNodesFromConfig 同步配置文件

Types

type Manager

type Manager interface {
	// Add adds a node to the node ring.
	Add(node *Node)
	// NodeFor get the node responsible for the data key.
	NodeFor(keys ...string) (*Node, bool)
	// Remove removes all nodes from the node ring.
	Remove()
	// RemoveByValue removes a node from the node ring.
	RemoveByValue(id string)
	// PrintNodes print all nodes
	PrintNodes()
	// IsEmpty is the node ring empty
	IsEmpty() bool
}

Manager node manager functions defines.

func New

func New(nt NodeType, name string) (Manager, error)

New node manager with node type, it has no nodes

func NewConsistent

func NewConsistent(name string) (Manager, error)

NewConsistent get consistent node manager

func NewDirect

func NewDirect(name string) (Manager, error)

NewDirect get direct node manager

func NewRandom

func NewRandom(name string) (Manager, error)

NewRandom get random node manager

func NewRoundRobin

func NewRoundRobin(name string) (Manager, error)

NewRoundRobin get round robin node manager

func NewWithNodes

func NewWithNodes(nt NodeType, name string, nodes []*Node) (Manager, error)

NewWithNodes new node manager by node type with nodes

type Node

type Node struct {

	// @gotags: json:"weight" yaml:"weight"
	Weight uint32 `protobuf:"varint,1,opt,name=weight,proto3" json:"weight" yaml:"weight"`
	// @gotags: json:"value" yaml:"value"
	Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value" yaml:"value"`
	// @gotags: json:"ttl" yaml:"ttl"
	TTL uint64 `protobuf:"varint,3,opt,name=TTL,proto3" json:"ttl" yaml:"ttl"`
	// @gotags: json:"heartbeat" yaml:"heartbeat"
	Heartbeat uint64 `protobuf:"varint,4,opt,name=heartbeat,proto3" json:"heartbeat" yaml:"heartbeat"`
	// @gotags: json:"protocol" yaml:"protocol"
	Protocol Protocol `protobuf:"varint,5,opt,name=protocol,proto3,enum=node.Protocol" json:"protocol" yaml:"protocol"`
	// @gotags: protobuf:"-" json:"-" yaml:"-"
	Number uint32 `protobuf:"-" json:"-" yaml:"-"`
	// @gotags: json:"metadata" yaml:"metadata"
	Metadata map[string]string `` /* 163-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*Node) Copy

func (x *Node) Copy() *Node

Copy node

func (*Node) Descriptor deprecated

func (*Node) Descriptor() ([]byte, []int)

Deprecated: Use Node.ProtoReflect.Descriptor instead.

func (*Node) Get

func (x *Node) Get(key string) (string, bool)

Get value from metadata

func (*Node) GetHeartbeat

func (x *Node) GetHeartbeat() uint64

func (*Node) GetMetadata

func (x *Node) GetMetadata() map[string]string

func (*Node) GetNumber

func (x *Node) GetNumber() uint32

func (*Node) GetProtocol

func (x *Node) GetProtocol() Protocol

func (*Node) GetTTL

func (x *Node) GetTTL() uint64

func (*Node) GetValue

func (x *Node) GetValue() string

func (*Node) GetWeight

func (x *Node) GetWeight() uint32

func (*Node) ProtoMessage

func (*Node) ProtoMessage()

func (*Node) ProtoReflect

func (x *Node) ProtoReflect() protoreflect.Message

func (*Node) Reset

func (x *Node) Reset()

func (*Node) Set

func (x *Node) Set(key, value string)

Set kv pair from metadata

func (*Node) String

func (x *Node) String() string

type NodeType

type NodeType int32
const (
	NodeType_NODE_TYPE_DIRECT     NodeType = 0
	NodeType_NODE_TYPE_RANDOM     NodeType = 1
	NodeType_NODE_TYPE_CONSISTENT NodeType = 2
	NodeType_NODE_TYPE_ROUNDROBIN NodeType = 3
)

func (NodeType) Descriptor

func (NodeType) Descriptor() protoreflect.EnumDescriptor

func (NodeType) Enum

func (x NodeType) Enum() *NodeType

func (NodeType) EnumDescriptor deprecated

func (NodeType) EnumDescriptor() ([]byte, []int)

Deprecated: Use NodeType.Descriptor instead.

func (NodeType) Number

func (x NodeType) Number() protoreflect.EnumNumber

func (NodeType) String

func (x NodeType) String() string

func (NodeType) Type

type Protocol

type Protocol int32
const (
	// 本地服务,直接访问
	Protocol_PROTOCOL_LOCAL Protocol = 0
	// RPC协议的服务
	Protocol_PROTOCOL_GRPC Protocol = 1
	// HTTP协议的服务
	Protocol_PROTOCOL_HTTP Protocol = 2
	// HTTP 3.0协议的服务
	Protocol_PROTOCOL_QUIC Protocol = 3
)

func (Protocol) Descriptor

func (Protocol) Descriptor() protoreflect.EnumDescriptor

func (Protocol) Enum

func (x Protocol) Enum() *Protocol

func (Protocol) EnumDescriptor deprecated

func (Protocol) EnumDescriptor() ([]byte, []int)

Deprecated: Use Protocol.Descriptor instead.

func (Protocol) Number

func (x Protocol) Number() protoreflect.EnumNumber

func (Protocol) String

func (x Protocol) String() string

func (Protocol) Type

Jump to

Keyboard shortcuts

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