Documentation ¶
Overview ¶
Package rpc provides RPC server and clients specific to Cockroach.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Send ¶
func Send(argsMap map[net.Addr]interface{}, method string, replyChanI interface{}, opts Options) error
Send sends one or more RPCs to clients specified by the keys of argsMap (with corresponding values of the map as arguments) according to availability and the number of required responses specified by opts.N. One or more replies are sent on the replyChan channel if successful; otherwise an error is returned on failure. Note that on error, some replies may have been sent on the channel. Send returns an error if the number of errors exceeds the possibility of attaining the required successful responses.
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) *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) 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.
type HeartbeatService ¶
type HeartbeatService struct{}
A HeartbeatService exposes a method to echo its request params.
func (*HeartbeatService) Ping ¶
func (hs *HeartbeatService) Ping(args *PingRequest, reply *PingResponse) error
Ping echos the contents of the request to the response.
type Options ¶
type Options struct { // N is the number of successful responses required. N int // 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 PingRequest ¶
type PingRequest struct {
Ping string // Echo this string with PingResponse.
}
A PingRequest specifies the string to echo in response.
type PingResponse ¶
type PingResponse struct {
Pong string // An echo of value sent with PingRequest.
}
A PingResponse contains the echoed ping request string.
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.
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 and clock skew.
func (*Server) AddCloseCallback ¶
AddCloseCallback adds a callback to the closeCallbacks slice to be invoked when a connection is closed.