rpc

package
v0.0.0-...-d9a8df2 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2016 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package rpc is a generated protocol buffer package.

It is generated from these files:

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

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 {
	// Embed the base context.
	base.Context

	Stopper      *stop.Stopper
	RemoteClocks *RemoteClockMonitor

	HeartbeatInterval time.Duration
	HeartbeatTimeout  time.Duration
	// contains filtered or unexported fields
}

Context contains the fields required by the rpc framework.

func NewContext

func NewContext(baseCtx *base.Context, clock *hlc.Clock, stopper *stop.Stopper) *Context

NewContext creates an rpc Context with the supplied values.

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(addr string) roachpb.InternalServer

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

func (*Context) SetLocalInternalServer

func (ctx *Context) SetLocalInternalServer(internalServer roachpb.InternalServer, addr string)

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 ManualHeartbeatService

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

A ManualHeartbeatService allows manual control of when heartbeats occur, to facilitate testing.

func (*ManualHeartbeatService) Ping

Ping waits until the heartbeat service is ready to respond to a Heartbeat.

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"`
}

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 RemoteClockMonitor

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

RemoteClockMonitor keeps track of the most recent measurements of remote offsets from this node to connected nodes.

func (*RemoteClockMonitor) MonitorRemoteOffsets

func (r *RemoteClockMonitor) MonitorRemoteOffsets(stopper *stop.Stopper) error

MonitorRemoteOffsets periodically checks that the offset of this server's clock from the true cluster time is within MaxOffset. If the offset exceeds MaxOffset, then this method will trigger a fatal error, causing the node to suicide.

func (*RemoteClockMonitor) Registry

func (r *RemoteClockMonitor) Registry() *metric.Registry

Registry returns a registry with the metrics tracked by this server, which can be used to access its stats or be added to another registry.

func (*RemoteClockMonitor) UpdateOffset

func (r *RemoteClockMonitor) UpdateOffset(addr string, offset RemoteOffset)

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

It only updates the offset for addr if one the following three cases holds: 1. There is no prior offset for that address. 2. The old offset for addr was measured before r.mu.lastMonitoredAt. We never use values during monitoring that are older than r.mu.lastMonitoredAt. 3. The new offset's error is smaller than the old offset's error.

The third case allows the monitor to use the most precise clock reading of the remote addr during the next findOffsetInterval() invocation. We may measure the remote clock several times before we next calculate the cluster offset. When we do the measurement, we want to use the reading with the smallest error. Because r.monitorInterval > heartbeatInterval, this gives us several chances to accurately read the remote clock. Note that we don't want r.monitorInterval to be too large, else we might end up relying on old information.

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