Documentation ¶
Overview ¶
Package rpc provides RPC server and clients specific to Cockroach.
Index ¶
- Constants
- func Send(opts Options, method string, addrs []net.Addr, ...) ([]interface{}, error)
- type Client
- type ClusterOffsetInterval
- type Context
- type HeartbeatService
- type MajorityIntervalNotFoundError
- type ManualHeartbeatService
- type Options
- type OrderingPolicy
- type RemoteClockMonitor
- type SendError
- type Server
Constants ¶
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 ¶
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) Close ¶
func (c *Client) Close()
Close removes the client from the clients map and closes the Closed channel.
func (*Client) IsConnected ¶
IsConnected returns whether the client is connected.
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.
func (ClusterOffsetInterval) String ¶
func (i ClusterOffsetInterval) String() string
type Context ¶
type Context struct { // Embed the base context. base.Context Stopper *util.Stopper 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 ¶
NewContext creates an rpc Context with the supplied values.
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 ¶
func (MajorityIntervalNotFoundError) Error() string
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 ¶
func (mhs *ManualHeartbeatService) Ping(args *proto.PingRequest, reply *proto.PingResponse) error
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.
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.
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 (*Server) AddCloseCallback ¶
AddCloseCallback adds a callback to the closeCallbacks slice to be invoked when a connection is closed.
func (*Server) Listen ¶
Listen listens on the configured address but does not start accepting connections until Serve is called.