flux

package module
v0.0.0-...-d441946 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: BSD-3-Clause Imports: 12 Imported by: 0

README

Flux

Flux is a distributed key-value store with realtime notification capabilities.

It use github.com/hashicorp/memberlist for cluster discovery and a simple hash ring implementation for key distribution.

It also allows setting up watchers to monitor for key changes. For that it use the HTML content streaming.

API Reference

Reading a key

curl http://127.0.0.1:8000/key1?watch=true

Watching key changes

curl http://127.0.0.1:8000/key1?watch=true

Writing a key

curl -X POST http://127.0.0.1:8000/key1 -H "Content-Type: text/plain" -d 'value1' 

License

This project is licensed under the BSD License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Addr    string
	Store   storage.Store
	OnJoin  func(id string)
	OnLeave func(id string)
	PeerFn  func(string) transport.Peer
	HashFn  consistent.HashFn
}

func DefaultConfig

func DefaultConfig() Config

Provides a convenient way to create a configuration with default values.

type Event

type Event struct {
	Type  string
	Value interface{}
}

type Int

type Int int64

func (*Int) Decrement

func (c *Int) Decrement()

func (*Int) Increment

func (c *Int) Increment()

func (*Int) Set

func (c *Int) Set(v int64)

type Metrics

type Metrics struct {
	Keys      Int
	Deletions Int
	Inserts   Int
	Reads     Int
}

Metrics holds the counters for various operations in the node such as key inserts, deletions, reads, and total number of keys.

type Node

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

Represents a node in the distributed system. It manges key distribution using a consistent hash ring Interacts with other nodes using the memberlist package.

func New

func New(config Config) (*Node, error)

Initializes a new Node with the provided configuration. It sets up the consistent hash ring, initializes peer connections, configures the memberlist for managing cluster membership, and starts a goroutine for periodically rebalancing local stored keys.

func (*Node) Get

func (n *Node) Get(key string) ([]byte, error)

Retrieves the value for a given key. If the key is not local, it forwards the request to the appropriate peer.

func (*Node) Join

func (n *Node) Join(address string) error

Add an address to the cluster.

func (*Node) Local

func (n *Node) Local(key string) bool

Checks if a given key belongs to the local node based on the consistent hash ring.

func (*Node) Metrics

func (n *Node) Metrics() interface{}

Return statistics and membership information.

func (*Node) NotifyJoin

func (n *Node) NotifyJoin(node *memberlist.Node)

Handle node membership changes in the cluster.

func (*Node) NotifyLeave

func (n *Node) NotifyLeave(node *memberlist.Node)

func (*Node) NotifyUpdate

func (n *Node) NotifyUpdate(node *memberlist.Node)

func (*Node) Peer

func (n *Node) Peer(key string) (transport.Peer, string)

Retrieves the peer responsible for a given key and returns both the peer and its address.

func (*Node) Put

func (n *Node) Put(key string, value []byte) error

Stores a key-value pair. It the key is not local, it forwards the request to the appropriate peer.

func (*Node) Shutdown

func (n *Node) Shutdown() error

Close the node's attached storage.

func (*Node) Watch

func (n *Node) Watch(key string) *Watcher

Sets up a watcher for a given key.

type Watcher

type Watcher struct {
	Channel chan *Event
	Remove  func()
}

Watcher implements a simple event notification bus system

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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