gossip

package
v0.0.0-...-4b82dee Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2015 License: Apache-2.0 Imports: 23 Imported by: 0

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.

Single-valued info values can have any type.

A map of info objects is kept by a Gossip instance. Single-valued info objects can be added via Gossip.AddInfo(). Info can be queried for single-valued keys via Gossip.GetInfo.

Package gossip is a generated protocol buffer package.

It is generated from these files:
	cockroach/gossip/gossip.proto

It has these top-level messages:
	Request
	Response
	Info

Index

Constants

View Source
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
)
View Source
const (
	// KeyClusterID is the unique UUID for this Cockroach cluster.
	// The value is a string UUID for the cluster.  The cluster ID is
	// gossiped by all nodes that contain a replica of the first range,
	// and it serves as a check for basic gossip connectivity. The
	// Gossip.Connected channel is closed when we see this key.
	KeyClusterID = "cluster-id"

	// KeyConfigZone is the zone configuration map.
	KeyConfigZone = "zones"

	// KeyStorePrefix is the key prefix for gossiping stores in the network.
	// The suffix is a store ID and the value is proto.StoreDescriptor.
	KeyStorePrefix = "store"

	// KeyNodeIDPrefix is the key prefix for gossiping node id
	// addresses. The actual key is suffixed with the decimal
	// representation of the node id and the value is the host:port
	// string address of the node. E.g. node:1 => 127.0.0.1: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.  The sentinel is gossiped by the node that holds
	// the leader lease for the first range.
	KeySentinel = "sentinel"

	// 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"

	// KeySystemDB is the gossip key for the system DB span.
	KeySystemDB = "system-db"
)

Constants for gossip keys.

Variables

View Source
var (
	ErrInvalidLengthGossip = fmt.Errorf("proto: negative length found during unmarshaling")
)
View Source
var (
	// TestBootstrap is the default gossip bootstrap used for running tests.
	TestBootstrap = []resolver.Resolver{}
)

Functions

func MakeKey

func MakeKey(components ...string) string

MakeKey creates a canonical key under which to gossip a piece of information. The first argument will typically be one of the key constants defined in this package.

func MakeNodeIDKey

func MakeNodeIDKey(nodeID proto.NodeID) string

MakeNodeIDKey returns the gossip key for node ID info.

func MakePrefixPattern

func MakePrefixPattern(prefix string) string

MakePrefixPattern returns a regular expression pattern that matches precisely the Gossip keys created by invocations of MakeKey with multiple arguments for which the first argument is equal to the given prefix.

func MakeStoreKey

func MakeStoreKey(storeID proto.StoreID) string

MakeStoreKey returns the gossip key for the given store.

Types

type Callback

type Callback func(key string, content []byte)

Callback is a callback method to be invoked on gossip update of info denoted by key.

type Gossip

type Gossip struct {
	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 New

func New(rpcContext *rpc.Context, gossipInterval time.Duration, resolvers []resolver.Resolver) *Gossip

New creates an instance of a gossip node.

func (*Gossip) AddInfo

func (g *Gossip) AddInfo(key string, val []byte, ttl time.Duration) error

AddInfo adds or updates an info object. Returns an error if info couldn't be added.

func (*Gossip) AddInfoProto

func (g *Gossip) AddInfoProto(key string, proto gogoproto.Message, ttl time.Duration) error

AddInfoProto adds or updates an info object. Returns an error if info couldn't be added.

func (*Gossip) GetInfo

func (g *Gossip) GetInfo(key string) ([]byte, error)

GetInfo returns an info value by key or an error if specified key does not exist or has expired.

func (*Gossip) GetInfoProto

func (g *Gossip) GetInfoProto(key string, proto gogoproto.Message) error

GetInfoProto returns an info value by key or an error if specified key does not exist or has expired.

func (*Gossip) GetInfosAsJSON

func (g *Gossip) GetInfosAsJSON() ([]byte, error)

GetInfosAsJSON returns the contents of the infostore, marshalled to JSON.

func (*Gossip) GetNodeDescriptor

func (g *Gossip) GetNodeDescriptor(nodeID proto.NodeID) (*proto.NodeDescriptor, error)

GetNodeDescriptor looks up the descriptor of the node by ID.

func (*Gossip) GetNodeID

func (g *Gossip) GetNodeID() proto.NodeID

GetNodeID returns the instance's saved NodeID.

func (*Gossip) GetNodeIDAddress

func (g *Gossip) GetNodeIDAddress(nodeID proto.NodeID) (net.Addr, error)

GetNodeIDAddress looks up the address of the node by ID.

func (*Gossip) GetZoneConfig

func (g *Gossip) GetZoneConfig() (*config.PrefixConfigMap, error)

GetZoneConfig returns the zone config map.

func (Gossip) Gossip

func (s Gossip) Gossip(argsI gogoproto.Message) (gogoproto.Message, 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) Incoming

func (g *Gossip) Incoming() []proto.NodeID

Incoming returns a slice of incoming gossip client connection node IDs.

func (*Gossip) MaxHops

func (g *Gossip) MaxHops() uint32

MaxHops returns the maximum number of hops to reach the furthest gossiped information currently in the network.

func (*Gossip) Outgoing

func (g *Gossip) Outgoing() []proto.NodeID

Outgoing returns a slice of outgoing gossip client connection node IDs. 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

func (g *Gossip) RegisterCallback(pattern string, method Callback)

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) SetNodeDescriptor

func (g *Gossip) SetNodeDescriptor(desc *proto.NodeDescriptor) error

SetNodeDescriptor adds the node descriptor to the gossip network and sets the infostore's node ID.

func (*Gossip) SetResolvers

func (g *Gossip) SetResolvers(resolvers []resolver.Resolver)

SetResolvers initializes the set of gossip resolvers used to find nodes to bootstrap the gossip network.

func (*Gossip) Start

func (g *Gossip) Start(rpcServer *rpc.Server, stopper *stop.Stopper)

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.

type Info

type Info struct {
	Value cockroach_proto1.Value `protobuf:"bytes,1,opt,name=value" json:"value"`
	// Wall time when info is to be discarded (Unix-nanos)
	TTLStamp int64 `protobuf:"varint,2,opt,name=ttl_stamp,proto3" json:"ttl_stamp,omitempty"`
	// Number of hops from originator
	Hops uint32 `protobuf:"varint,3,opt,name=hops,proto3" json:"hops,omitempty"`
	// Originating node's ID
	NodeID github_com_cockroachdb_cockroach_proto.NodeID `protobuf:"varint,4,opt,name=node_id,proto3,casttype=github.com/cockroachdb/cockroach/proto.NodeID" json:"node_id,omitempty"`
}

Info is the basic unit of information traded over the gossip network.

func (*Info) GetValue

func (m *Info) GetValue() cockroach_proto1.Value

func (*Info) Marshal

func (m *Info) Marshal() (data []byte, err error)

func (*Info) MarshalTo

func (m *Info) MarshalTo(data []byte) (int, error)

func (*Info) ProtoMessage

func (*Info) ProtoMessage()

func (*Info) Reset

func (m *Info) Reset()

func (*Info) Size

func (m *Info) Size() (n int)

func (*Info) String

func (m *Info) String() string

func (*Info) Unmarshal

func (m *Info) Unmarshal(data []byte) error

type Request

type Request struct {
	// Requesting node's ID.
	NodeID github_com_cockroachdb_cockroach_proto.NodeID `protobuf:"varint,1,opt,name=node_id,proto3,casttype=github.com/cockroachdb/cockroach/proto.NodeID" json:"node_id,omitempty"`
	// Address of the requesting client.
	Addr cockroach_util.UnresolvedAddr `protobuf:"bytes,2,opt,name=addr" json:"addr"`
	// Local address of client on requesting node (this is a kludge to
	// allow gossip to know when client connections are dropped).
	LAddr cockroach_util.UnresolvedAddr `protobuf:"bytes,3,opt,name=l_addr" json:"l_addr"`
	// Maximum sequence number of gossip from this peer.
	MaxSeq int64 `protobuf:"varint,4,opt,name=max_seq,proto3" json:"max_seq,omitempty"`
	// Delta of new Infos since last gossip.
	Delta map[string]*Info `` /* 137-byte string literal not displayed */
}

Request is the request struct passed with the Gossip RPC.

func (*Request) GetAddr

func (m *Request) GetAddr() cockroach_util.UnresolvedAddr

func (*Request) GetDelta

func (m *Request) GetDelta() map[string]*Info

func (*Request) GetLAddr

func (m *Request) GetLAddr() cockroach_util.UnresolvedAddr

func (*Request) GetUser

func (m *Request) GetUser() string

GetUser implements userRequest. Gossip messages are always sent by the node user.

func (*Request) Marshal

func (m *Request) Marshal() (data []byte, err error)

func (*Request) MarshalTo

func (m *Request) MarshalTo(data []byte) (int, error)

func (*Request) ProtoMessage

func (*Request) ProtoMessage()

func (*Request) Reset

func (m *Request) Reset()

func (*Request) Size

func (m *Request) Size() (n int)

func (*Request) String

func (m *Request) String() string

func (*Request) Unmarshal

func (m *Request) Unmarshal(data []byte) error

type Response

type Response struct {
	// Responding Node's ID.
	NodeID github_com_cockroachdb_cockroach_proto.NodeID `protobuf:"varint,1,opt,name=node_id,proto3,casttype=github.com/cockroachdb/cockroach/proto.NodeID" json:"node_id,omitempty"`
	// Address of the responding client.
	Addr cockroach_util.UnresolvedAddr `protobuf:"bytes,2,opt,name=addr" json:"addr"`
	// Non-nil means client should retry with this address.
	Alternate *cockroach_util.UnresolvedAddr `protobuf:"bytes,3,opt,name=alternate" json:"alternate,omitempty"`
	// Maximum sequence number of gossip from this peer.
	MaxSeq int64 `protobuf:"varint,4,opt,name=max_seq,proto3" json:"max_seq,omitempty"`
	// Requested delta of server's infostore.
	Delta map[string]*Info `` /* 137-byte string literal not displayed */
}

Response is returned from the Gossip.Gossip RPC. Delta will be nil in the event that Alternate is set.

func (*Response) GetAddr

func (m *Response) GetAddr() cockroach_util.UnresolvedAddr

func (*Response) GetAlternate

func (m *Response) GetAlternate() *cockroach_util.UnresolvedAddr

func (*Response) GetDelta

func (m *Response) GetDelta() map[string]*Info

func (*Response) Marshal

func (m *Response) Marshal() (data []byte, err error)

func (*Response) MarshalTo

func (m *Response) MarshalTo(data []byte) (int, error)

func (*Response) ProtoMessage

func (*Response) ProtoMessage()

func (*Response) Reset

func (m *Response) Reset()

func (*Response) Size

func (m *Response) Size() (n int)

func (*Response) String

func (m *Response) String() string

func (*Response) Unmarshal

func (m *Response) Unmarshal(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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