cockroach: github.com/abhinavdahiya/cockroach/gossip Index | Files | Directories

package gossip

import "github.com/abhinavdahiya/cockroach/gossip"

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:
	BootstrapInfo
	Request
	Response
	InfoStatus
	Info

Index

Package Files

client.go doc.go gossip.go gossip.pb.go info.go infostore.go keys.go node_set.go server.go

Constants

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

    // DefaultGossipStoresInterval is the default interval for gossiping storage-
    // related info.
    DefaultGossipStoresInterval = 1 * time.Minute
)
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 range 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.

Variables

var (
    ErrInvalidLengthGossip = fmt.Errorf("proto: negative length found during unmarshaling")
    ErrIntOverflowGossip   = fmt.Errorf("proto: integer overflow")
)

func MakeKey Uses

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 Uses

func MakeNodeIDKey(nodeID roachpb.NodeID) string

MakeNodeIDKey returns the gossip key for node ID info.

func MakePrefixPattern Uses

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 Uses

func MakeStoreKey(storeID roachpb.StoreID) string

MakeStoreKey returns the gossip key for the given store.

func RegisterGossipServer Uses

func RegisterGossipServer(s *grpc.Server, srv GossipServer)

type BootstrapInfo Uses

type BootstrapInfo struct {
    // A map from node ID to address.
    Addresses []cockroach_util.UnresolvedAddr `protobuf:"bytes,1,rep,name=addresses" json:"addresses"`
    // Timestamp at which the bootstrap info was written.
    Timestamp cockroach_util_hlc.Timestamp `protobuf:"bytes,2,opt,name=timestamp" json:"timestamp"`
}

BootstrapInfo contains information necessary to bootstrapping the gossip network from a cold start.

func (*BootstrapInfo) Descriptor Uses

func (*BootstrapInfo) Descriptor() ([]byte, []int)

func (*BootstrapInfo) Marshal Uses

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

func (*BootstrapInfo) MarshalTo Uses

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

func (*BootstrapInfo) ProtoMessage Uses

func (*BootstrapInfo) ProtoMessage()

func (*BootstrapInfo) Reset Uses

func (m *BootstrapInfo) Reset()

func (*BootstrapInfo) Size Uses

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

func (*BootstrapInfo) String Uses

func (m *BootstrapInfo) String() string

func (*BootstrapInfo) Unmarshal Uses

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

type Callback Uses

type Callback func(string, roachpb.Value)

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

type Gossip Uses

type Gossip struct {
    Connected chan struct{} // Closed upon initial connection
    // 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 Uses

func New(rpcContext *rpc.Context, resolvers []resolver.Resolver, stopper *stop.Stopper) *Gossip

New creates an instance of a gossip node.

func (*Gossip) AddInfo Uses

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 Uses

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

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

func (*Gossip) EnableSimulationCycler Uses

func (g *Gossip) EnableSimulationCycler(enable bool)

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 Uses

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 Uses

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

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

func (*Gossip) GetInfoStatus Uses

func (g *Gossip) GetInfoStatus() InfoStatus

GetInfoStatus returns the a copy of the contents of the infostore.

func (*Gossip) GetNodeDescriptor Uses

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

GetNodeDescriptor looks up the descriptor of the node by ID.

func (*Gossip) GetNodeID Uses

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

GetNodeID returns the instance's saved node ID.

func (*Gossip) GetNodeIDAddress Uses

func (g *Gossip) GetNodeIDAddress(nodeID roachpb.NodeID) (*util.UnresolvedAddr, error)

GetNodeIDAddress looks up the address of the node by ID.

func (*Gossip) GetResolvers Uses

func (g *Gossip) GetResolvers() []resolver.Resolver

GetResolvers returns a copy of the resolvers slice.

func (*Gossip) GetSystemConfig Uses

func (g *Gossip) GetSystemConfig() (config.SystemConfig, bool)

GetSystemConfig returns the local unmarshalled version of the system config. The second return value indicates whether the system config has been set yet.

func (Gossip) Gossip Uses

func (s Gossip) Gossip(stream Gossip_GossipServer) 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 Uses

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

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

func (Gossip) InfosReceived Uses

func (s Gossip) InfosReceived() int

InfosReceived returns the total count of infos received from clients.

func (Gossip) InfosSent Uses

func (s Gossip) InfosSent() int

InfosSent returns the total count of infos sent to clients.

func (*Gossip) LogStatus Uses

func (g *Gossip) LogStatus()

LogStatus logs the current status of gossip such as the incoming and outgoing connections.

func (*Gossip) MaxHops Uses

func (g *Gossip) MaxHops() uint32

MaxHops returns the maximum number of hops to reach any other node in the system, according to the infos which have reached this node via gossip network.

func (*Gossip) Outgoing Uses

func (g *Gossip) Outgoing() []roachpb.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 Uses

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

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) RegisterSystemConfigChannel Uses

func (g *Gossip) RegisterSystemConfigChannel() <-chan struct{}

RegisterSystemConfigChannel registers a channel to signify updates for the system config. It is notified after registration, and whenever a new system config is successfully unmarshalled.

func (*Gossip) ResetNodeID Uses

func (g *Gossip) ResetNodeID(nodeID roachpb.NodeID)

ResetNodeID resets the infostore's node ID. NOTE: use only from unittests.

func (*Gossip) SetBootstrapInterval Uses

func (g *Gossip) SetBootstrapInterval(interval time.Duration)

SetBootstrapInterval sets a minimum interval between successive attempts to connect to new hosts in order to join the gossip network.

func (*Gossip) SetCullInterval Uses

func (g *Gossip) SetCullInterval(interval time.Duration)

SetCullInterval sets the interval between periodic shutdown of outgoing gossip client connections in an effort to improve the fitness of the network.

func (*Gossip) SetNodeDescriptor Uses

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) SetNodeID Uses

func (g *Gossip) SetNodeID(nodeID roachpb.NodeID)

SetNodeID sets the infostore's node ID.

func (*Gossip) SetResolvers Uses

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) SetStorage Uses

func (g *Gossip) SetStorage(storage Storage) error

SetStorage provides an instance of the Storage interface for reading and writing gossip bootstrap data from persistent storage. This should be invoked as early in the lifecycle of a gossip instance as possible, but can be called at any time.

func (*Gossip) SimulationCycle Uses

func (g *Gossip) SimulationCycle()

SimulationCycle cycles this gossip node's server by allowing all connected clients to proceed one step.

func (*Gossip) Start Uses

func (g *Gossip) Start(grpcServer *grpc.Server, addr net.Addr)

Start launches the gossip instance, which commences joining the gossip network using the supplied rpc server and previously known peer addresses in addition to any bootstrap addresses specified via --join.

The supplied address is used to identify the gossip instance in the gossip network; it will be used by other instances to connect to this instance.

This method starts bootstrap loop, gossip server, and client management in separate goroutines and returns.

type GossipClient Uses

type GossipClient interface {
    Gossip(ctx context.Context, opts ...grpc.CallOption) (Gossip_GossipClient, error)
}

func NewGossipClient Uses

func NewGossipClient(cc *grpc.ClientConn) GossipClient

type GossipServer Uses

type GossipServer interface {
    Gossip(Gossip_GossipServer) error
}

type Gossip_GossipClient Uses

type Gossip_GossipClient interface {
    Send(*Request) error
    Recv() (*Response, error)
    grpc.ClientStream
}

type Gossip_GossipServer Uses

type Gossip_GossipServer interface {
    Send(*Response) error
    Recv() (*Request, error)
    grpc.ServerStream
}

type Info Uses

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,json=origStamp,proto3" json:"orig_stamp,omitempty"`
    // Wall time when info is to be discarded (Unix-nanos).
    TTLStamp int64 `protobuf:"varint,3,opt,name=ttl_stamp,json=ttlStamp,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,json=nodeId,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,json=peerId,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) Descriptor Uses

func (*Info) Descriptor() ([]byte, []int)

func (*Info) Marshal Uses

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

func (*Info) MarshalTo Uses

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

func (*Info) ProtoMessage Uses

func (*Info) ProtoMessage()

func (*Info) Reset Uses

func (m *Info) Reset()

func (*Info) Size Uses

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

func (*Info) String Uses

func (m *Info) String() string

func (*Info) Unmarshal Uses

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

type InfoStatus Uses

type InfoStatus struct {
    Infos map[string]Info `protobuf:"bytes,1,rep,name=infos" json:"infos" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value"`
}

InfoStatus contains information about the current status of the infoStore.

func (*InfoStatus) Descriptor Uses

func (*InfoStatus) Descriptor() ([]byte, []int)

func (*InfoStatus) Marshal Uses

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

func (*InfoStatus) MarshalTo Uses

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

func (*InfoStatus) ProtoMessage Uses

func (*InfoStatus) ProtoMessage()

func (*InfoStatus) Reset Uses

func (m *InfoStatus) Reset()

func (*InfoStatus) Size Uses

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

func (*InfoStatus) String Uses

func (m *InfoStatus) String() string

func (*InfoStatus) Unmarshal Uses

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

type Request Uses

type Request struct {
    // Requesting node's ID.
    NodeID github_com_cockroachdb_cockroach_roachpb.NodeID `protobuf:"varint,1,opt,name=node_id,json=nodeId,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"`
    // Map of high water timestamps from infos originating at other
    // nodes, as seen by the requester.
    HighWaterStamps map[github_com_cockroachdb_cockroach_roachpb.NodeID]int64 `protobuf:"bytes,3,rep,name=high_water_stamps,json=highWaterStamps,castkey=github.com/cockroachdb/cockroach/roachpb.NodeID" json:"high_water_stamps" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"`
    // Delta of Infos originating at sender.
    Delta map[string]*Info `protobuf:"bytes,4,rep,name=delta" json:"delta,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value"`
}

Request is the request struct passed with the Gossip RPC.

func (*Request) Descriptor Uses

func (*Request) Descriptor() ([]byte, []int)

func (*Request) GetUser Uses

func (*Request) GetUser() string

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

func (*Request) Marshal Uses

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

func (*Request) MarshalTo Uses

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

func (*Request) ProtoMessage Uses

func (*Request) ProtoMessage()

func (*Request) Reset Uses

func (m *Request) Reset()

func (*Request) Size Uses

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

func (*Request) String Uses

func (m *Request) String() string

func (*Request) Unmarshal Uses

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

type Response Uses

type Response struct {
    // Responding Node's ID.
    NodeID github_com_cockroachdb_cockroach_roachpb.NodeID `protobuf:"varint,1,opt,name=node_id,json=nodeId,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.
    AlternateAddr *cockroach_util.UnresolvedAddr `protobuf:"bytes,3,opt,name=alternate_addr,json=alternateAddr" json:"alternate_addr,omitempty"`
    // Node ID of the alternate address, if alternate_addr is not nil.
    AlternateNodeID github_com_cockroachdb_cockroach_roachpb.NodeID `protobuf:"varint,4,opt,name=alternate_node_id,json=alternateNodeId,proto3,casttype=github.com/cockroachdb/cockroach/roachpb.NodeID" json:"alternate_node_id,omitempty"`
    // Delta of Infos which are fresh according to the map of Node info messages
    // passed with the request.
    Delta map[string]*Info `protobuf:"bytes,5,rep,name=delta" json:"delta,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value"`
    // Map of high water timestamps from infos originating at other
    // nodes, as seen by the responder.
    HighWaterStamps map[github_com_cockroachdb_cockroach_roachpb.NodeID]int64 `protobuf:"bytes,6,rep,name=high_water_stamps,json=highWaterStamps,castkey=github.com/cockroachdb/cockroach/roachpb.NodeID" json:"high_water_stamps" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"`
}

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

func (*Response) Descriptor Uses

func (*Response) Descriptor() ([]byte, []int)

func (*Response) Marshal Uses

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

func (*Response) MarshalTo Uses

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

func (*Response) ProtoMessage Uses

func (*Response) ProtoMessage()

func (*Response) Reset Uses

func (m *Response) Reset()

func (*Response) Size Uses

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

func (*Response) String Uses

func (m *Response) String() string

func (*Response) Unmarshal Uses

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

type Storage Uses

type Storage interface {
    // ReadBootstrapInfo fetches the bootstrap data from the persistent
    // store into the provided bootstrap protobuf. Returns nil or an
    // error on failure.
    ReadBootstrapInfo(*BootstrapInfo) error
    // WriteBootstrapInfo stores the provided bootstrap data to the
    // persistent store. Returns nil or an error on failure.
    WriteBootstrapInfo(*BootstrapInfo) error
}

Storage is an interface which allows the gossip instance to read and write bootstrapping data to persistent storage between instantiations.

Directories

PathSynopsis
resolver
simulation

Package gossip imports 28 packages (graph). Updated 2017-03-13. Refresh now. Tools for package owners. This is a dead-end fork (no commits since the fork).