node

package module
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2020 License: GPL-3.0 Imports: 12 Imported by: 0

README

node

a nodes ring for a key to get node

Build

  • Build Status
  • GoDoc

Get Node Methods

Direct

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

Consistent hashing
Random

Usage

type Node struct {
	// for recognize node with input id
	ID string
	// node's probability weight
	Weight uint32
	// node's value
	Value interface{}
}

type NodeManager interface {
	// adds a node to the node ring.
	Add(node *Node)
	// get the node responsible for the data key.
	NodeFor(keys ...string) (*Node, bool)
	// removes all nodes from the node ring.
	Remove()
	// removes a node from the node ring.
	RemoveByID(id string)
	// print all nodes
	PrintNodes()
	// is the node ring empty
	IsEmpty() bool
}
New a node manager
	directNode := node.New(node.NodeTypeDirect, "direct")
	randomNode := node.New(node.NodeTypeRandom, "random")
	consistentNode := node.New(node.NodeTypeConsistent, "consistent")

Or

	directNode := node.NewDirect("direct")
	randomNode := node.NewRandom("random")
	consistentNode := node.NewConsistent("consistent")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 {
	// adds a node to the node ring.
	Add(node *Node)
	// get the node responsible for the data key.
	NodeFor(keys ...string) (*Node, bool)
	// removes all nodes from the node ring.
	Remove()
	// removes a node from the node ring.
	RemoveByID(id string)
	// print all nodes
	PrintNodes()
	// is the node ring empty
	IsEmpty() bool
}

Manager node manager functions defines.

func New

func New(nt Type, name string) Manager

New get node manager by node type

func NewConsistent

func NewConsistent(name string) Manager

NewConsistent get consistent node manager

func NewDirect

func NewDirect(name string) Manager

NewDirect get direct node manager

func NewRadmon

func NewRadmon(name string) Manager

NewRadmon get random node manager

type Node

type Node struct {
	// for recognize node with input id
	ID string
	// node's probability weight
	Weight uint32
	// node's value
	Value string
	// kvs for meta data
	Metadata config.Options
	// contains filtered or unexported fields
}

Node params for a node

type Type

type Type uint8

Type define node type

const (
	NodeTypeDirect Type = iota
	NodeTypeRandom
	NodeTypeConsistent
)

NodeType

Jump to

Keyboard shortcuts

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