Documentation ¶
Index ¶
- type Config
- type Event
- type Int
- type Metrics
- type Node
- func (n *Node) Get(key string) ([]byte, error)
- func (n *Node) Join(address string) error
- func (n *Node) Local(key string) bool
- func (n *Node) Metrics() interface{}
- func (n *Node) NotifyJoin(node *memberlist.Node)
- func (n *Node) NotifyLeave(node *memberlist.Node)
- func (n *Node) NotifyUpdate(node *memberlist.Node)
- func (n *Node) Peer(key string) (transport.Peer, string)
- func (n *Node) Put(key string, value []byte) error
- func (n *Node) Shutdown() error
- func (n *Node) Watch(key string) *Watcher
- type Watcher
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 Metrics ¶
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 ¶
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 ¶
Retrieves the value for a given key. If the key is not local, it forwards the request to the appropriate peer.
func (*Node) Local ¶
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 ¶
Retrieves the peer responsible for a given key and returns both the peer and its address.