rpc

package
v0.0.0-...-2b2087e Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2014 License: Apache-2.0 Imports: 9 Imported by: 0

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

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.

func (SendError) CanRetry

func (s SendError) CanRetry() bool

CanRetry implements the Retryable 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 and clock skew.

func NewServer

func NewServer(addr net.Addr) *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) 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.

Jump to

Keyboard shortcuts

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