spool

package
v0.0.0-...-08e143e Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActiveNode

type ActiveNode struct {
	// corresponding node model
	Model *model.Node

	// node status
	Status *Status

	// send check ping to the node and receive the node's information
	// It SHOULD be buffered channel for non-blocking at the socket pool
	Ping chan bool

	// save shards on the node
	Save chan []*model.ShardToSave

	// load shards from the node
	Load chan *LoadChan

	// delete shards on the node
	Delete chan []*model.ShardToDelete

	// flush the deleted shard list to the node
	Flush chan bool
	// contains filtered or unexported fields
}

func NewActiveNode

func NewActiveNode(conn *websocket.Conn, nodeModel *model.Node) *ActiveNode

func (*ActiveNode) Run

func (node *ActiveNode) Run()

* Run the websocket operations using non-blocking channels.

type DataMsg

type DataMsg struct {
	Type     string      `json:"type"`
	Contents interface{} `json:"contents"`
}

type LoadChan

type LoadChan struct {
	Shards []*model.ShardToLoad
	WG     *sync.WaitGroup
}

type SocketPool

type SocketPool struct {
	// mutex for all nodes' status
	NodesStatusLock sync.Mutex

	// registered nodes
	Nodes map[*ActiveNode]bool

	// register requests from the node
	Register chan *ActiveNode

	// unregister requests from the node
	Unregister chan *ActiveNode
	// contains filtered or unexported fields
}

func Pool

func Pool() *SocketPool

* Return the singleton socket pool instance.

func (*SocketPool) CheckAllNodes

func (pool *SocketPool) CheckAllNodes()

* Send ping concurrently to nodes whose current status is old and wait for all pong response.

This function change nodes' status. So you SHOULD use this function with the `NodesStatusLock` which is mutex for all nodes' status.

func (*SocketPool) FindActiveNode

func (pool *SocketPool) FindActiveNode(machineID string) *ActiveNode

* Find active node in the pool by machine id.

func (*SocketPool) SelectNodes

func (pool *SocketPool) SelectNodes() (*ring.Ring, *ring.Ring)

* Select the nodes to save the files and sort them by node selection algorithm. Return type is ring, which is circular list, because select the nodes until all shards are scheduled.

The first return value is the safe nodes that have latest(reliable) status. The second return value is the unsafe nodes that have old(unreliable) status.

This function read nodes' status at specific time. So you SHOULD use this function with the `NodesStatusLock` which is mutex for all nodes' status.

func (*SocketPool) TotalCapacity

func (pool *SocketPool) TotalCapacity() uint64

type Status

type Status struct {
	// TODO: measure rtt when ping and pong
	// round trip time (ms)
	RTT uint `json:"rtt"`

	// network bandwidth (Mbps)
	Bandwidth uint `json:"bandwidth"`

	// available capacity of the node (Byte)
	Capacity uint64 `json:"capacity"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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