rpc

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2018 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Overview

Package rpc is a generated protocol buffer package.

It is generated from these files:

cockroach/pkg/rpc/heartbeat.proto

It has these top-level messages:

RemoteOffset
PingRequest
PingResponse

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthHeartbeat = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowHeartbeat   = fmt.Errorf("proto: integer overflow")
)
View Source
var ErrNotConnected = errors.New("not connected")

ErrNotConnected is returned by ConnHealth when there is no connection to the host (e.g. GRPCDial was never called for that address).

View Source
var ErrNotHeartbeated = errors.New("not yet heartbeated")

ErrNotHeartbeated is returned by ConnHealth when we have not yet performed the first heartbeat.

View Source
var SourceAddr = func() net.Addr {
	const envKey = "COCKROACH_SOURCE_IP_ADDRESS"
	if sourceAddr, ok := envutil.EnvString(envKey, 0); ok {
		sourceIP := net.ParseIP(sourceAddr)
		if sourceIP == nil {
			panic(fmt.Sprintf("unable to parse %s '%s' as IP address", envKey, sourceAddr))
		}
		return &net.TCPAddr{
			IP: sourceIP,
		}
	}
	return nil
}()

SourceAddr provides a way to specify a source/local address for outgoing connections. It should only ever be set by testing code, and is not thread safe (so it must be initialized before the server starts).

Functions

func NewServer

func NewServer(ctx *Context) *grpc.Server

NewServer is a thin wrapper around grpc.NewServer that registers a heartbeat service.

func RegisterHeartbeatServer

func RegisterHeartbeatServer(s *grpc.Server, srv HeartbeatServer)

Types

type Context

type Context struct {
	*base.Config

	AmbientCtx log.AmbientContext
	LocalClock *hlc.Clock

	Stopper      *stop.Stopper
	RemoteClocks *RemoteClockMonitor

	HeartbeatCB func()

	// For unittesting.
	BreakerFactory func() *circuit.Breaker
	// contains filtered or unexported fields
}

Context contains the fields required by the rpc framework.

func NewContext

func NewContext(
	ambient log.AmbientContext, baseCtx *base.Config, hlcClock *hlc.Clock, stopper *stop.Stopper,
) *Context

NewContext creates an rpc Context with the supplied values.

func (*Context) ConnHealth

func (ctx *Context) ConnHealth(target string) error

ConnHealth returns whether the most recent heartbeat succeeded or not. This should not be used as a definite status of a node's health and just used to prioritize healthy nodes over unhealthy ones.

func (*Context) GRPCDial

func (ctx *Context) GRPCDial(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

GRPCDial calls grpc.Dial with the options appropriate for the context.

func (*Context) GetLocalInternalServerForAddr

func (ctx *Context) GetLocalInternalServerForAddr(target string) roachpb.InternalServer

GetLocalInternalServerForAddr returns the context's internal batch server for target, if it exists.

func (*Context) NewBreaker

func (ctx *Context) NewBreaker() *circuit.Breaker

NewBreaker creates a new circuit breaker properly configured for RPC connections.

func (*Context) SetLocalInternalServer

func (ctx *Context) SetLocalInternalServer(internalServer roachpb.InternalServer)

SetLocalInternalServer sets the context's local internal batch server.

type HeartbeatClient

type HeartbeatClient interface {
	Ping(ctx context.Context, in *PingRequest, opts ...grpc.CallOption) (*PingResponse, error)
}

func NewHeartbeatClient

func NewHeartbeatClient(cc *grpc.ClientConn) HeartbeatClient

type HeartbeatServer

type HeartbeatServer interface {
	Ping(context.Context, *PingRequest) (*PingResponse, error)
}

type HeartbeatService

type HeartbeatService struct {
	// contains filtered or unexported fields
}

A HeartbeatService exposes a method to echo its request params. It doubles as a way to measure the offset of the server from other nodes. It uses the clock to return the server time every heartbeat. It also keeps track of remote clocks sent to it by storing them in the remoteClockMonitor.

func (*HeartbeatService) Ping

func (hs *HeartbeatService) Ping(ctx context.Context, args *PingRequest) (*PingResponse, error)

Ping echos the contents of the request to the response, and returns the server's current clock value, allowing the requester to measure its clock. The requester should also estimate its offset from this server along with the requester's address.

type PingRequest

type PingRequest struct {
	// Echo this string with PingResponse.
	Ping string `protobuf:"bytes,1,opt,name=ping" json:"ping"`
	// The last offset the client measured with the server.
	Offset RemoteOffset `protobuf:"bytes,2,opt,name=offset" json:"offset"`
	// The address of the client.
	Addr string `protobuf:"bytes,3,opt,name=addr" json:"addr"`
	// The configured maximum clock offset (in nanoseconds) on the server.
	MaxOffsetNanos int64 `protobuf:"varint,4,opt,name=max_offset_nanos,json=maxOffsetNanos" json:"max_offset_nanos"`
}

A PingRequest specifies the string to echo in response. Fields are exported so that they will be serialized in the rpc call.

func (*PingRequest) Descriptor

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

func (*PingRequest) GetUser

func (*PingRequest) GetUser() string

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

func (*PingRequest) Marshal

func (m *PingRequest) Marshal() (dAtA []byte, err error)

func (*PingRequest) MarshalTo

func (m *PingRequest) MarshalTo(dAtA []byte) (int, error)

func (*PingRequest) ProtoMessage

func (*PingRequest) ProtoMessage()

func (*PingRequest) Reset

func (m *PingRequest) Reset()

func (*PingRequest) Size

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

func (*PingRequest) String

func (m *PingRequest) String() string

func (*PingRequest) Unmarshal

func (m *PingRequest) Unmarshal(dAtA []byte) error

type PingResponse

type PingResponse struct {
	// An echo of value sent with PingRequest.
	Pong       string `protobuf:"bytes,1,opt,name=pong" json:"pong"`
	ServerTime int64  `protobuf:"varint,2,opt,name=server_time,json=serverTime" json:"server_time"`
}

A PingResponse contains the echoed ping request string.

func (*PingResponse) Descriptor

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

func (*PingResponse) Marshal

func (m *PingResponse) Marshal() (dAtA []byte, err error)

func (*PingResponse) MarshalTo

func (m *PingResponse) MarshalTo(dAtA []byte) (int, error)

func (*PingResponse) ProtoMessage

func (*PingResponse) ProtoMessage()

func (*PingResponse) Reset

func (m *PingResponse) Reset()

func (*PingResponse) Size

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

func (*PingResponse) String

func (m *PingResponse) String() string

func (*PingResponse) Unmarshal

func (m *PingResponse) Unmarshal(dAtA []byte) error

type RemoteClockMetrics

type RemoteClockMetrics struct {
	ClockOffsetMeanNanos   *metric.Gauge
	ClockOffsetStdDevNanos *metric.Gauge
	LatencyHistogramNanos  *metric.Histogram
}

RemoteClockMetrics is the collection of metrics for the clock monitor.

type RemoteClockMonitor

type RemoteClockMonitor struct {
	// contains filtered or unexported fields
}

RemoteClockMonitor keeps track of the most recent measurements of remote offsets and round-trip latency from this node to connected nodes.

func (*RemoteClockMonitor) AllLatencies added in v1.1.0

func (r *RemoteClockMonitor) AllLatencies() map[string]time.Duration

AllLatencies returns a map of all currently valid latency measurements.

func (*RemoteClockMonitor) Latency

func (r *RemoteClockMonitor) Latency(addr string) (time.Duration, bool)

Latency returns the exponentially weighted moving average latency to the given node address. Returns true if the measurement is valid, or false if we don't have enough samples to compute a reliable average.

func (*RemoteClockMonitor) Metrics

func (r *RemoteClockMonitor) Metrics() *RemoteClockMetrics

Metrics returns the metrics struct. Useful to examine individual metrics, or to add to the registry.

func (*RemoteClockMonitor) UpdateOffset

func (r *RemoteClockMonitor) UpdateOffset(
	ctx context.Context, addr string, offset RemoteOffset, roundTripLatency time.Duration,
)

UpdateOffset is a thread-safe way to update the remote clock and latency measurements.

It only updates the offset for addr if one of the following cases holds: 1. There is no prior offset for that address. 2. The old offset for addr was measured long enough ago to be considered stale. 3. The new offset's error is smaller than the old offset's error.

Pass a roundTripLatency of 0 or less to avoid recording the latency.

func (*RemoteClockMonitor) VerifyClockOffset

func (r *RemoteClockMonitor) VerifyClockOffset(ctx context.Context) error

VerifyClockOffset calculates the number of nodes to which the known offset is healthy (as defined by RemoteOffset.isHealthy). It returns nil iff more than half the known offsets are healthy, and an error otherwise. A non-nil return indicates that this node's clock is unreliable, and that the node should terminate.

type RemoteOffset

type RemoteOffset struct {
	// The estimated offset from the remote server, in nanoseconds.
	Offset int64 `protobuf:"varint,1,opt,name=offset" json:"offset"`
	// The maximum error of the measured offset, in nanoseconds.
	Uncertainty int64 `protobuf:"varint,2,opt,name=uncertainty" json:"uncertainty"`
	// Measurement time, in nanoseconds from unix epoch.
	MeasuredAt int64 `protobuf:"varint,3,opt,name=measured_at,json=measuredAt" json:"measured_at"`
}

RemoteOffset keeps track of this client's estimate of its offset from a remote server. Uncertainty is the maximum error in the reading of this offset, so that the real offset should be in the interval [Offset - Uncertainty, Offset + Uncertainty]. If the last heartbeat timed out, Offset = 0.

Offset and Uncertainty are measured using the remote clock reading technique described in http://se.inf.tu-dresden.de/pubs/papers/SRDS1994.pdf, page 6.

func (*RemoteOffset) Descriptor

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

func (*RemoteOffset) Marshal

func (m *RemoteOffset) Marshal() (dAtA []byte, err error)

func (*RemoteOffset) MarshalTo

func (m *RemoteOffset) MarshalTo(dAtA []byte) (int, error)

func (*RemoteOffset) ProtoMessage

func (*RemoteOffset) ProtoMessage()

func (*RemoteOffset) Reset

func (m *RemoteOffset) Reset()

func (*RemoteOffset) Size

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

func (RemoteOffset) String

func (r RemoteOffset) String() string

String formats the RemoteOffset for human readability.

func (*RemoteOffset) Unmarshal

func (m *RemoteOffset) Unmarshal(dAtA []byte) error

Jump to

Keyboard shortcuts

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