Documentation ¶
Overview ¶
Package gossip implements a protocol for sharing information between Cockroach nodes using an ad-hoc, peer-to-peer network. The self-assembled network aims to minimize time for new information to reach each node, and minimize network traffic required.
Gossiped information is identified by key. Gossip information is captured by info objects. Info objects may be stored individually (e.g. the number of nodes in the system), or may be organized into groups (e.g. multiple values of the same type from different originators).
Groups organize multiple instance of info for the same key prefix. Groups come in two types: MinGroup groups keep only the minimum values seen; MaxGroup groups keep only the maximum values seen. An example is load or disk capacity values for nodes. In a cluster with thousands of nodes, groups force the gossip network to limit itself to only a portion of total data volume (e.g. the 100 least loaded nodes or the 100 disks with most unused capacity).
Single-valued info values can have any type. Values to be used with groups must either be of type int64, float64, string or implement the util.Ordered interface.
A map of info objects and a map of Group objects are kept by a Gossip instance. Single-valued info objects can be added via Gossip.AddInfo(). Groups must be registered via Gossip.RegisterGroup(). Info objects are added to groups if their key matches. Info can be queried for single-valued keys via Gossip.GetInfo. Sorted values for groups are queried via Gossip.GetGroupInfos().
Index ¶
- Constants
- func MakeNodeIDGossipKey(nodeID proto.NodeID) string
- type Callback
- type Gossip
- func (g *Gossip) AddInfo(key string, val interface{}, ttl time.Duration) error
- func (g *Gossip) GetGroupInfos(prefix string) ([]interface{}, error)
- func (g *Gossip) GetInfo(key string) (interface{}, error)
- func (g *Gossip) GetInfosAsJSON() ([]byte, error)
- func (s Gossip) Gossip(args *proto.GossipRequest, reply *proto.GossipResponse) error
- func (g *Gossip) Incoming() []net.Addr
- func (g *Gossip) MaxHops() uint32
- func (g *Gossip) Outgoing() []net.Addr
- func (g *Gossip) RegisterCallback(pattern string, method Callback)
- func (g *Gossip) RegisterGroup(prefix string, limit int, typeOf GroupType) error
- func (g *Gossip) SetBootstrap(bootstraps []net.Addr)
- func (g *Gossip) SetInterval(interval time.Duration)
- func (g *Gossip) Start(rpcServer *rpc.Server)
- func (g *Gossip) Stop() <-chan error
- type GroupType
Constants ¶
const ( // MaxPeers is the maximum number of connected gossip peers. MaxPeers = 10 // TestInterval is the default gossip interval used for running tests. TestInterval = 10 * time.Millisecond // TestBootstrap is the default gossip bootstrap used for running tests. TestBootstrap = "" )
const ( // KeyClusterID is the unique UUID for this Cockroach cluster. // The value is a string UUID for the cluster. KeyClusterID = "cluster-id" // KeyConfigAccounting is the accounting configuration map. KeyConfigAccounting = "accounting" // KeyConfigPermission is the permission configuration map. KeyConfigPermission = "permissions" // KeyConfigZone is the zone configuration map. KeyConfigZone = "zones" // KeyMaxAvailCapacityPrefix is the key prefix for gossiping available // store capacity. The suffix is composed of: <node ID>-<store ID>. // The value is a storage.StoreDescriptor struct. KeyMaxAvailCapacityPrefix = "max-avail-capacity-" // KeyNodeCount is the count of gossip nodes in the network. The // value is an int64 containing the count of nodes in the cluster. // TODO(spencer): should remove this and instead just count the // number of node ids being gossiped. KeyNodeCount = "node-count" // KeyNodeIDPrefix is the key prefix for gossiping node id // addresses. The actual key is suffixed with the hexadecimal // representation of the node id and the value is the host:port // string address of the node. E.g. node-1bfa: fwd56.sjcb1:24001 KeyNodeIDPrefix = "node-" // KeySentinel is a key for gossip which must not expire or else the // node considers itself partitioned and will retry with bootstrap hosts. KeySentinel = KeyClusterID // KeyFirstRangeDescriptor is the descriptor for the "first" // range. The "first" range contains the meta1 key range, the first // level of the bi-level key addressing scheme. The value is a slice // of storage.Replica structs. KeyFirstRangeDescriptor = "first-range" )
Constants for gossip keys.
Variables ¶
This section is empty.
Functions ¶
func MakeNodeIDGossipKey ¶
MakeNodeIDGossipKey returns the gossip key for node ID info.
Types ¶
type Callback ¶
Callback is a callback method to be invoked on gossip update of info denoted by key. The contentsChanged bool indicates whether the info contents were updated. False indicates the info timestamp was refreshed, but its contents remained unchanged.
type Gossip ¶
type Gossip struct { Name string // Optional node name Connected chan struct{} // Closed upon initial connection RPCContext *rpc.Context // The context required for RPC // contains filtered or unexported fields }
Gossip is an instance of a gossip node. It embeds a gossip server. During bootstrapping, the bootstrap list contains candidates for entry to the gossip network.
func (*Gossip) AddInfo ¶
AddInfo adds or updates an info object. Returns an error if info couldn't be added.
func (*Gossip) GetGroupInfos ¶
GetGroupInfos returns a slice of info values from specified group, or an error if group is not registered.
func (*Gossip) GetInfo ¶
GetInfo returns an info value by key or an error if specified key does not exist or has expired.
func (*Gossip) GetInfosAsJSON ¶
GetInfosAsJSON returns the contents of the infostore, marshalled to JSON.
func (Gossip) Gossip ¶
func (s Gossip) Gossip(args *proto.GossipRequest, reply *proto.GossipResponse) error
Gossip receives gossiped information from a peer node. The received delta is combined with the infostore, and this node's own gossip is returned to requesting client.
func (*Gossip) MaxHops ¶
MaxHops returns the maximum number of hops to reach the furthest gossiped information currently in the network.
func (*Gossip) Outgoing ¶
Outgoing returns a slice of outgoing gossip client connection addresses. Note that these outgoing client connections may not actually be legitimately connected. They may be in the process of trying, or may already have failed, but haven't yet been processed by the gossip instance.
func (*Gossip) RegisterCallback ¶
RegisterCallback registers a callback for a key pattern to be invoked whenever new info for a gossip key matching pattern is received. The callback method is invoked with the info key which matched pattern.
func (*Gossip) RegisterGroup ¶
RegisterGroup registers a new group with info store. Returns an error if the group was already registered.
func (*Gossip) SetBootstrap ¶
SetBootstrap initializes the set of gossip node addresses used to bootstrap the gossip network.
func (*Gossip) SetInterval ¶
SetInterval sets the interval at which fresh info is gossiped to incoming gossip clients.
func (*Gossip) Start ¶
Start launches the gossip instance, which commences joining the gossip network using the supplied rpc server and the gossip bootstrap addresses specified via command-line flag: -gossip.
This method starts bootstrap loop, gossip server, and client management in separate goroutines and returns.