rpc

package
v0.0.0-...-c2bae5a Latest Latest
Warning

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

Go to latest
Published: May 12, 2015 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package rpc provides RPC server and clients specific to Cockroach.

Index

Constants

View Source
const (
	// OrderStable uses endpoints in the order provided.
	OrderStable = iota
	// OrderRandom randomly orders available endpoints.
	OrderRandom
)

Variables

This section is empty.

Functions

func Send

func Send(opts Options, method string, addrs []net.Addr, getArgs func(addr net.Addr) interface{},
	getReply func() interface{}, context *Context) ([]interface{}, error)

Send sends one or more method RPCs to clients specified by the slice of endpoint addrs. Arguments for methods are obtained using the supplied getArgs function. The number of required replies is given by opts.N. Reply structs are obtained through the getReply() function. On success, Send returns a slice of replies of length opts.N. Otherwise, Send returns an error if and as soon as the number of failed RPCs exceeds the available endpoints less the number of required replies.

Types

type Client

type Client struct {
	Ready  chan struct{} // Closed when client is connected
	Closed chan struct{} // Closed when connection has closed

	*rpc.Client // Embedded RPC client
	// contains filtered or unexported fields
}

Client is a Cockroach-specific RPC client with an embedded go rpc.Client struct.

func NewClient

func NewClient(addr net.Addr, opts *util.RetryOptions, context *Context) *Client

NewClient returns a client RPC stub for the specified address (usually a TCP host:port, but for testing may be a unix domain socket). The process-wide client RPC cache is consulted first; if the requested client is not present, it's created and the cache is updated. Specify opts to fine tune client connection behavior or nil to use defaults (i.e. indefinite retries with exponential backoff).

The Client.Ready channel is closed after the client has connected and completed one successful heartbeat. The Closed channel is closed if the client fails to connect or if the client's Close() method is invoked.

func (*Client) Addr

func (c *Client) Addr() net.Addr

Addr returns remote address of the client.

func (*Client) Close

func (c *Client) Close()

Close removes the client from the clients map and closes the Closed channel.

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns whether the client is connected.

func (*Client) IsHealthy

func (c *Client) IsHealthy() bool

IsHealthy returns whether the client is healthy.

func (*Client) LocalAddr

func (c *Client) LocalAddr() net.Addr

LocalAddr returns the local address of the client.

func (*Client) RemoteOffset

func (c *Client) RemoteOffset() proto.RemoteOffset

RemoteOffset returns the most recently measured offset of the client clock from the remote server clock.

type ClusterOffsetInterval

type ClusterOffsetInterval struct {
	Lowerbound int64 // The lowerbound on the offset in nanoseconds.
	Upperbound int64 // The upperbound on the offset in nanoseconds.
}

ClusterOffsetInterval is the best interval we can construct to estimate this node's offset from the cluster.

type Context

type Context struct {
	RemoteClocks *RemoteClockMonitor
	DisableCache bool // Disable client cache when calling NewClient()
	// contains filtered or unexported fields
}

Context contains the fields required by the rpc framework.

func NewContext

func NewContext(clock *hlc.Clock, config *tls.Config, stopper *util.Stopper) *Context

NewContext creates an rpc Context with the supplied values.

func (*Context) Copy

func (c *Context) Copy() *Context

Copy creates a copy of the rpc Context config values, but with a new remote clock monitor.

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(args *proto.PingRequest, reply *proto.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 MajorityIntervalNotFoundError

type MajorityIntervalNotFoundError struct{}

MajorityIntervalNotFoundError indicates that we could not find a majority overlap in our estimate of remote clocks.

func (MajorityIntervalNotFoundError) Error

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 Options

type Options struct {
	// N is the number of successful responses required.
	N int
	// Ordering indicates how the available endpoints are ordered when
	// deciding which to send to (if there are more than one).
	Ordering OrderingPolicy
	// SendNextTimeout is the duration after which RPCs are sent to
	// other replicas in a set.
	SendNextTimeout time.Duration
	// Timeout is the maximum duration of an RPC before failure.
	// 0 for no timeout.
	Timeout time.Duration
}

An Options structure describes the algorithm for sending RPCs to one or more replicas, depending on error conditions and how many successful responses are required.

type OrderingPolicy

type OrderingPolicy int

OrderingPolicy is an enum for ordering strategies when there are multiple endpoints available.

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

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

func (r *RemoteClockMonitor) UpdateOffset(addr string, offset proto.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.lastMonitoredAt. We never use values during monitoring that are older than r.lastMonitoredAt. 3. The new offset's error is smaller than the old offset's error. Note: InfiniteOffsets implicitly have the largest 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 monitorInterval > heartbeatInterval, this gives us several chances to accurately read the remote clock. Note that we don't want monitorInterval to be too large, else we might end up relying on old information.

type SendError

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

A SendError indicates that too many RPCs to the replica set failed to achieve requested number of successful responses. canRetry is set depending on the types of errors encountered.

func (SendError) CanRetry

func (s SendError) CanRetry() bool

CanRetry implements the Retryable interface.

func (SendError) Error

func (s SendError) Error() string

Error implements the error interface.

type Server

type Server struct {
	*rpc.Server // Embedded RPC server instance
	// contains filtered or unexported fields
}

Server is a Cockroach-specific RPC server with an embedded go RPC server struct. By default it handles a simple heartbeat protocol to measure link health. It also supports close callbacks.

TODO(spencer): heartbeat protocol should also measure link latency.

func NewServer

func NewServer(addr net.Addr, context *Context) *Server

NewServer creates a new instance of Server.

func (*Server) AddCloseCallback

func (s *Server) AddCloseCallback(cb func(conn net.Conn))

AddCloseCallback adds a callback to the closeCallbacks slice to be invoked when a connection is closed.

func (*Server) Addr

func (s *Server) Addr() net.Addr

Addr returns the server's network address.

func (*Server) Close

func (s *Server) Close()

Close closes the listener.

func (*Server) Listen

func (s *Server) Listen() error

Listen listens on the configured address but does not start accepting connections until Serve is called.

func (*Server) Serve

func (s *Server) Serve(handler http.Handler)

Serve accepts and services connections on the already started listener.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements an http.Handler that answers RPC requests.

func (*Server) Start

func (s *Server) Start() error

Start runs the RPC server. After this method returns, the socket will have been bound. Use Server.Addr() to ascertain server address.

Directories

Path Synopsis
message.pb
Package message is a generated protocol buffer package.
Package message is a generated protocol buffer package.
wire.pb
Package wire is a generated protocol buffer package.
Package wire is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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