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
- Variables
- func MakeKey(components ...string) string
- func MakeNodeIDKey(nodeID roachpb.NodeID) string
- func MakePrefixPattern(prefix string) string
- func MakeStoreKey(storeID roachpb.StoreID) string
- type Callback
- type Gossip
- func (g *Gossip) AddInfo(key string, val []byte, ttl time.Duration) error
- func (g *Gossip) AddInfoProto(key string, msg proto.Message, ttl time.Duration) error
- func (g *Gossip) EnableSimulationCycler(enable bool)
- func (g *Gossip) GetInfo(key string) ([]byte, error)
- func (g *Gossip) GetInfoProto(key string, msg proto.Message) error
- func (g *Gossip) GetInfosAsJSON() ([]byte, error)
- func (g *Gossip) GetNodeDescriptor(nodeID roachpb.NodeID) (*roachpb.NodeDescriptor, error)
- func (g *Gossip) GetNodeID() roachpb.NodeID
- func (g *Gossip) GetNodeIDAddress(nodeID roachpb.NodeID) (net.Addr, error)
- func (g *Gossip) GetSystemConfig() *config.SystemConfig
- func (s Gossip) Gossip(argsI proto.Message) (proto.Message, error)
- func (g *Gossip) Incoming() []roachpb.NodeID
- func (g *Gossip) Outgoing() []roachpb.NodeID
- func (g *Gossip) RegisterCallback(pattern string, method Callback) func()
- func (g *Gossip) RegisterSystemConfigCallback(method systemConfigCallback)
- func (g *Gossip) SetNodeDescriptor(desc *roachpb.NodeDescriptor) error
- func (g *Gossip) SetNodeID(nodeID roachpb.NodeID)
- func (g *Gossip) SetResolvers(resolvers []resolver.Resolver)
- func (g *Gossip) SimulationCycle()
- func (g *Gossip) Start(rpcServer *rpc.Server, stopper *stop.Stopper)
- type Info
- type Request
- func (*Request) GetUser() string
- func (m *Request) Marshal() (data []byte, err error)
- func (m *Request) MarshalTo(data []byte) (int, error)
- func (*Request) ProtoMessage()
- func (m *Request) Reset()
- func (m *Request) Size() (n int)
- func (m *Request) String() string
- func (m *Request) Unmarshal(data []byte) error
- type Response
Constants ¶
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" // KeyStorePrefix is the key prefix for gossiping stores in the network. // The suffix is a store ID and the value is roachpb.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" // KeySystemConfig is the gossip key for the system DB span. // The value if a config.SystemConfig which holds all key/value // pairs in the system DB span. KeySystemConfig = "system-db" )
Constants for gossip keys.
const ( // MaxHops is the maximum number of hops which any gossip info // should require to transit between any two nodes in a gossip // network. MaxHops = 5 )
Variables ¶
var ( ErrInvalidLengthGossip = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowGossip = fmt.Errorf("proto: integer overflow") )
var ( // TestBootstrap is the default gossip bootstrap used for running tests. TestBootstrap = []resolver.Resolver{} )
Functions ¶
func MakeKey ¶
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 ¶
MakeNodeIDKey returns the gossip key for node ID info.
func MakePrefixPattern ¶
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 ¶
MakeStoreKey returns the gossip key for the given store.
Types ¶
type Callback ¶
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 (*Gossip) AddInfo ¶
AddInfo adds or updates an info object. Returns an error if info couldn't be added.
func (*Gossip) AddInfoProto ¶
AddInfoProto adds or updates an info object. Returns an error if info couldn't be added.
func (*Gossip) EnableSimulationCycler ¶
EnableSimulationCycler is for TESTING PURPOSES ONLY. It sets a condition variable which is signaled at each cycle of the simulation via SimulationCycle(). The gossip server makes each connecting client wait for the cycler to signal before responding.
func (*Gossip) GetInfo ¶
GetInfo returns an info value by key or an error if specified key does not exist or has expired.
func (*Gossip) GetInfoProto ¶
GetInfoProto 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) GetNodeDescriptor ¶
GetNodeDescriptor looks up the descriptor of the node by ID.
func (*Gossip) GetNodeIDAddress ¶
GetNodeIDAddress looks up the address of the node by ID.
func (*Gossip) GetSystemConfig ¶
func (g *Gossip) GetSystemConfig() *config.SystemConfig
GetSystemConfig returns the local unmarshalled version of the system config. It may be nil if it was never gossiped.
func (Gossip) Gossip ¶
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) Outgoing ¶
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 ¶
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. Returns a function to unregister the callback.
func (*Gossip) RegisterSystemConfigCallback ¶
func (g *Gossip) RegisterSystemConfigCallback(method systemConfigCallback)
RegisterSystemConfigCallback registers a callback for the unmarshalled system config. It is called after registration, and whenever a new system config is successfully unmarshalled.
func (*Gossip) SetNodeDescriptor ¶
func (g *Gossip) SetNodeDescriptor(desc *roachpb.NodeDescriptor) error
SetNodeDescriptor adds the node descriptor to the gossip network and sets the infostore's node ID.
func (*Gossip) SetResolvers ¶
SetResolvers initializes the set of gossip resolvers used to find nodes to bootstrap the gossip network.
func (*Gossip) SimulationCycle ¶
func (g *Gossip) SimulationCycle()
SimulationCycle cycles this gossip node's server by allowing all connected clients to proceed one step.
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.
type Info ¶
type Info struct { Value cockroach_roachpb1.Value `protobuf:"bytes,1,opt,name=value" json:"value"` // Wall time of info when generated by originating node (Unix-nanos). OrigStamp int64 `protobuf:"varint,2,opt,name=orig_stamp,proto3" json:"orig_stamp,omitempty"` // Wall time when info is to be discarded (Unix-nanos). TTLStamp int64 `protobuf:"varint,3,opt,name=ttl_stamp,proto3" json:"ttl_stamp,omitempty"` // Number of hops from originator. Hops uint32 `protobuf:"varint,4,opt,name=hops,proto3" json:"hops,omitempty"` // Originating node's ID. NodeID github_com_cockroachdb_cockroach_roachpb.NodeID `protobuf:"varint,5,opt,name=node_id,proto3,casttype=github.com/cockroachdb/cockroach/roachpb.NodeID" json:"node_id,omitempty"` // Peer node ID which passed this info. PeerID github_com_cockroachdb_cockroach_roachpb.NodeID `protobuf:"varint,6,opt,name=peer_id,proto3,casttype=github.com/cockroachdb/cockroach/roachpb.NodeID" json:"peer_id,omitempty"` }
Info is the basic unit of information traded over the gossip network.
func (*Info) ProtoMessage ¶
func (*Info) ProtoMessage()
type Request ¶
type Request struct { // Requesting node's ID. NodeID github_com_cockroachdb_cockroach_roachpb.NodeID `protobuf:"varint,1,opt,name=node_id,proto3,casttype=github.com/cockroachdb/cockroach/roachpb.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"` // Map of all high water timestamps, by node, seen by the requester. HighWaterStamps map[int32]int64 `` /* 170-byte string literal not displayed */ // Delta of Infos originating at sender. Delta map[string]*Info `` /* 137-byte string literal not displayed */ }
Request is the request struct passed with the Gossip RPC.
func (*Request) GetUser ¶
GetUser implements security.RequestWithUser. Gossip messages are always sent by the node user.
func (*Request) ProtoMessage ¶
func (*Request) ProtoMessage()
type Response ¶
type Response struct { // Responding Node's ID. NodeID github_com_cockroachdb_cockroach_roachpb.NodeID `protobuf:"varint,1,opt,name=node_id,proto3,casttype=github.com/cockroachdb/cockroach/roachpb.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"` // Delta of Infos originating at nodes newer than specified high water timestamps. Delta map[string]*Info `` /* 137-byte string literal not displayed */ // Map of all high water timestamps, by node, seen by the responder. HighWaterStamps map[int32]int64 `` /* 170-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) ProtoMessage ¶
func (*Response) ProtoMessage()