local

package
v0.0.0-...-2cfabc9 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package local provides a master-slave implementation to run on a local machine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Master

type Master struct {
	Slave
	ReplicationFactor int
	ClusterSet        cluster.Set
	Primary           bool
}

Master is a local master runtime.

func NewMaster

func NewMaster(local, rmt string, scale int) *Master

NewMaster initializes a new local master runtime.

func (*Master) Assist

func (master *Master) Assist(p lib.Master) error

Assist puts the peer node in the replica set and notifies the other cluster masters.

func (*Master) Cluster

func (master *Master) Cluster() ([]lib.Node, error)

Cluster returns a instance of the cluster set.

func (*Master) ClusterGroup

func (master *Master) ClusterGroup(hash int) []int

ClusterGroup returns the ids of the nodes addressed by the hash.

func (*Master) Join

func (master *Master) Join(p lib.Node) error

Join puts the peer node in the cluster set, requests it to mirror one of its group peers and notifies the other masters in the replica set.

func (*Master) Listen

func (master *Master) Listen() error

Listen waits for new connections.

func (*Master) Read

func (master *Master) Read(key string) (string, lib.Revision, error)

func (*Master) Rebuild

func (master *Master) Rebuild() error

Rebuild refetches the replica and cluster set.

func (*Master) Replicas

func (master *Master) Replicas() ([]lib.Master, error)

Replicas returns an instance of the replica set.

func (*Master) Role

func (master *Master) Role() (lib.Role, error)

Role returns the master nodes role. If it returns primary, it had no peer on startup. if it returns secondary, it joined an existing cluster on startup.

func (*Master) Store

func (master *Master) Store(key, value string, rev lib.Revision) error

Store puts a key-value pair in the cluster. It looks up the matching cluster group for the key and tells every node in the group to store the key-value pair locally.

type Node

type Node interface {
	Listen() error
}

Node is a local node that can listen for incoming connections.

type Slave

type Slave struct {
	PublicAddress string
	ReplicaSet    replicas.Set
	Latest        lib.Revision
	KeepAlive     bool
	Entries       hashtable.Map
	NodeStatus    lib.Status
}

Slave is a local slave runtime.

func NewSlave

func NewSlave(local, rmt string) *Slave

NewSlave initiates a new slave node.

func (*Slave) Address

func (slave *Slave) Address() string

Address returns the nodes public address.

func (*Slave) Keys

func (slave *Slave) Keys() ([]string, error)

Keys tells the replica to retrieve all keys in the cluster.

func (*Slave) Listen

func (slave *Slave) Listen() error

Listen for and handle incoming connections.

func (*Slave) LocalKeys

func (slave *Slave) LocalKeys() ([]string, error)

LocalKeys returns all locally stored keys.

func (*Slave) LocalRead

func (slave *Slave) LocalRead(key string) (string, lib.Revision, error)

LocalRead looks up a key-value pair.

func (*Slave) LocalStore

func (slave *Slave) LocalStore(key, value string, rev lib.Revision) error

LocalStore stores the key-value pair locally.

func (*Slave) Mirror

func (slave *Slave) Mirror(peers []lib.Node) error

Mirror fetches the local key set from the peers and stores them locally.

func (*Slave) Read

func (slave *Slave) Read(key string) (string, lib.Revision, error)

Read tells a replica to look up a key-value pair.

func (*Slave) Rebuild

func (slave *Slave) Rebuild() error

Rebuild refetches the replica set.

func (*Slave) Revision

func (slave *Slave) Revision(rev lib.Revision) (lib.Revision, error)

Revision returns the latest stored revision.

func (*Slave) Role

func (slave *Slave) Role() (lib.Role, error)

Role returns the nodes role.

func (*Slave) Shutdown

func (slave *Slave) Shutdown() error

Shutdown stops the node service.

func (*Slave) Status

func (slave *Slave) Status() lib.Status

Status returns the nodes status.

func (*Slave) Store

func (slave *Slave) Store(key, value string, rev lib.Revision) error

Store tells a replica to store a key-value pair.

Directories

Path Synopsis
Package cluster provides functionality for managing node cluster sets.
Package cluster provides functionality for managing node cluster sets.
Package hashtable provides functionality for storing and retrieving key-value pairs associated with a specific revision.
Package hashtable provides functionality for storing and retrieving key-value pairs associated with a specific revision.
Package replicas provides functionality to manage master node sets.
Package replicas provides functionality to manage master node sets.

Jump to

Keyboard shortcuts

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