node

package
v0.0.0-...-70736be Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashFromAddr

func HashFromAddr(id, host string, port uint32) string

func Init

func Init(conf *Config)

Init initializes and starts servers and services including CommandServer, CoordinatorServer, etc.

Types

type CommandServer

type CommandServer struct {
	nodegrpc.UnimplementedCommandApiServer
	// contains filtered or unexported fields
}

func (*CommandServer) Del

func (*CommandServer) Get

func (*CommandServer) Set

func (*CommandServer) Start

func (s *CommandServer) Start()

type Config

type Config struct {
	Node   NodeConfig
	Gossip GossipConfig

	// Dev or Production mode
	DevMode bool
}

func (*Config) GetCoordinatorAddr

func (c *Config) GetCoordinatorAddr() string

func (*Config) GetGossipAddr

func (c *Config) GetGossipAddr() string

func (*Config) GetNodeAddr

func (c *Config) GetNodeAddr() string

func (*Config) Validate

func (c *Config) Validate() (error, *Config)

Validate check the conf object and returns a modified/validated version of the config object TODO: Improve the validation for every available config

type Coordinator

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

Coordinator acts as a proxy to the clients to store or receive key/values from the cluster. The coordinator handles replication and consistency. In a write-scenario, coordinator locates the right nodes for a KEY in the ring, then sends N concurrent write-requests to corresponding nodes and waits to receive W successful responses (Quorum Consensus with N replica).

func NewCoordinator

func NewCoordinator(conf *Config, nodeSrv *nodeService, storageSrv *storageService, ring *ring.Ring[*Node]) *Coordinator

type CoordinatorServer

type CoordinatorServer struct {
	nodegrpc.UnimplementedCoordinatorApiServer
	// contains filtered or unexported fields
}

CoordinatorServer handles the communication between client and cluster. It receives GET/PUT/... requests from clients and coordinates the request to the cluster. TODO: implement REST server/controller

func (*CoordinatorServer) Del

func (*CoordinatorServer) Get

func (*CoordinatorServer) Set

func (*CoordinatorServer) Start

func (cs *CoordinatorServer) Start()

type GossipConfig

type GossipConfig struct {
	Port     int
	Interval time.Duration
	Peers    []string
}

type Node

type Node struct {
	Id      string
	Name    string
	Host    string
	Port    uint32
	RamSize uint32

	Conn   *grpc.ClientConn
	Client nodegrpc.CommandApiClient
}

Node Implements ring.Comparable in order to be saved on the ring

func (*Node) Addr

func (n *Node) Addr() string

func (*Node) Hash

func (n *Node) Hash() string

Hash generates a unique string from the node data.

func (*Node) MarshalLogObject

func (n *Node) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject helps the `zap` to create a structural log of cacheNode object

type NodeConfig

type NodeConfig struct {
	// A unique name in the cluster/memberlist
	Name string
	// The public hostname or IP of the node. Default is os.Hostname()
	Host string

	// Internal/Command Port
	Port int
	// Coordinator/Public Port used by clients
	CoordinatorPort int

	RamSize int `mapstructure:ram_size`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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