Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

iTrellis/node

Repository files navigation

node

Achieve this repo, move it into github.com/iTellis/common

a nodes ring for a key to get node

Build

  • GoDoc

Get Node Methods

Direct

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

Consistent hashing

WIKI

Random

to get the node by random

Usage

// Node params for a 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

	number uint32
}

// Manager node manager functions defines.
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
}

New a node manager

	directNode, _ := node.New(node.NodeTypeDirect, "direct")
	randomNode, _ := node.New(node.NodeTypeRandom, "random")
	consistentNode, _ := node.New(node.NodeTypeConsistent, "consistent")
	roundrobinNode, _ := node.New(node.NodeTypeRoundRobin, "roundrobin")

Or

	directNode, _ := node.NewDirect("direct")
	randomNode, _ := node.NewRandom("random")
	consistentNode, _ := node.NewConsistent("consistent")
	roundrobinNode, _ := node.NewRoundRobin("roundrobin")