gossip

package module
v0.0.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: Apache-2.0 Imports: 3 Imported by: 12

README

gossip

Travis branch Code Coverage

Go implementation of the Gossip protocol.

Overview

This package provides an implementation of an eventually consistent in-memory data store. The data store values are exchanged using a push-pull gossip protocol.

// Create a gossiper
g := NewGossiper("<ip>:<port>", "<unique node id>", "<peer-list>")
// Add peer nodes with whom you want to gossip
g.AddNode("<peer_ip>:<peer_port>")
...
// update self values
g.UpdateSelf("<some_key>", "<any_value>")
// start gossip
g.Start()

These values are exchanged using the gossip protocol between the configured peers.

// Get the current view of the world
storeKeys = g.GetStoreKeys()
for _, key := range storeKeys.List {
	nodeInfoMap := g.GetStoreKeyValue(key)
	for id,  nodeInfo := nodeInfoList.List {
		// if nodeInfo.Status != types.NODE_STATUS_INVALID
        // then nodeInfo has valid data.
	}
}

// Stop gossiping
g.Stop()

Contributing

Testing

To test, run make test. This will run the unit tests

Vendoring

For vendoring, use make vendor and make vendor-update. This project uses Go Modules.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GossipStore

type GossipStore interface {
	// types.NodeId of this Store
	NodeId() types.NodeId

	// Update updates the value for this node.
	// Side-effects include updating the last update ts
	// for this node.
	UpdateSelf(types.StoreKey, interface{})

	// GetSelfStatus returns the node's status
	GetSelfStatus() types.NodeStatus

	// GetStoreValue returns the StoreValue associated with
	// the given key
	GetStoreKeyValue(key types.StoreKey) types.NodeValueMap

	// GetStoreKeys returns all the keys present in the store
	GetStoreKeys() []types.StoreKey

	// Update updates the current state of the gossip data
	// with the newly available data
	Update(newData types.NodeInfoMap)

	// UpdateSelfStatus
	UpdateSelfStatus(types.NodeStatus)

	// UpdateNodeStatus
	UpdateNodeStatus(types.NodeId, types.NodeStatus) error

	// MetaInfo returns meta information for the
	// current available data
	MetaInfo() types.NodeMetaInfo

	// GetLocalState returns our nodeInfoMap
	GetLocalState() types.NodeInfoMap

	// GetLocalNodeInfo returns
	GetLocalNodeInfo(types.NodeId) (types.NodeInfo, error)

	// Add a new node in the database
	AddNode(types.NodeId, types.NodeStatus, bool, string)

	// Remove a node from the database
	RemoveNode(types.NodeId) error
}

type Gossiper

type Gossiper interface {
	// Gossiper has a gossip store
	GossipStore

	// Start begins the gossip protocol using memberlist
	// To join an existing cluster provide atleast one ip of the known node.
	Start(startConfiguration types.GossipStartConfiguration) error

	// GossipInterval gets the gossip interval
	GossipInterval() time.Duration

	// Stop stops the gossiping. Leave timeout indicates the minimum time
	// required to successfully broadcast the leave message to all other nodes.
	Stop(leaveTimeout time.Duration) error

	// GetNodes returns a list of the connection addresses
	GetNodes() []string

	// UpdateCluster updates gossip with latest peer nodes info
	UpdateCluster(map[types.NodeId]types.NodeUpdate)

	// ExternalNodeLeave is used to indicate gossip that one of the nodes might be down.
	// It checks quorum and appropriately marks either self down or the other node down.
	// It returns the nodeId that was marked down
	ExternalNodeLeave(nodeId types.NodeId) types.NodeId

	// UpdateClusterDomainsActiveMap updates the cluster domain active map
	// All the nodes in an inactive domain will shoot themselves down
	// and will not participate in quorum decisions
	UpdateClusterDomainsActiveMap(types.ClusterDomainsActiveMap) error

	// UpdateSelfClusterDomain updates this node's cluster domain
	UpdateSelfClusterDomain(selfFailureDomain string)

	// Ping pings the given node's ip:port
	// Note: This API is only supported with Gossip Version v2 and higher
	Ping(nodeId types.NodeId, ipPort string) (time.Duration, error)
}

func New

func New(
	ip string,
	selfNodeId types.NodeId,
	genNumber uint64,
	gossipIntervals types.GossipIntervals,
	gossipVersion string,
	clusterId string,
	selfFailureDomain string,
) Gossiper

New returns an initialized Gossip node which identifies itself with the given ip

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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