Documentation ¶
Index ¶
- Constants
- Variables
- func IdentityKey(path string) (string, error)
- type Backend
- type Client
- type EtcdBackend
- func (c *EtcdBackend) Delete(key string) error
- func (c *EtcdBackend) Get(key string) (string, error)
- func (c *EtcdBackend) List(key string, recursive bool) ([]string, error)
- func (c *EtcdBackend) ListKeys(key string, recursive bool) ([]string, error)
- func (c *EtcdBackend) Set(key, value string) error
- func (c *EtcdBackend) SetDir(key string, ttl uint64) error
- func (c *EtcdBackend) UpdateDir(key string, ttl uint64) error
- type HTTPError
- type KeyFunc
- type KeyTransport
- type KeyTransportError
- type Node
- type Provider
- type Registry
Constants ¶
const (
DefaultKeyPrefix = "/datad/"
)
Variables ¶
var ( // NodeMembershipTTL is the time-to-live of the etcd key that denotes a // node's membership in the cluster. NodeMembershipTTL = 10 * time.Second // BalanceInterval is the time interval for starting a balancing job on the // whole keyspace on each node. BalanceInterval = 5 * time.Minute )
var ErrKeyNotExist = errors.New("key does not exist")
var ErrNoAvailableNodesForRegistration = errors.New("no available nodes to register key with")
var ErrNoNodesForKey = errors.New("key has no nodes")
var (
Log = log.New(os.Stderr, "datad: ", log.Ltime|log.Lmicroseconds|log.Lshortfile)
)
var RegistrationTTL = 60 * time.Second
Functions ¶
func IdentityKey ¶
IdentityKey is a KeyFunc that treats each path as a key.
Types ¶
type Backend ¶
type Backend interface { Get(key string) (string, error) List(key string, recursive bool) ([]string, error) // ListKeys lists only keys (not directories). ListKeys(key string, recursive bool) ([]string, error) Set(key, value string) error SetDir(key string, ttl uint64) error UpdateDir(key string, ttl uint64) error Delete(key string) error }
type Client ¶
type Client struct { // KeyURLPrefix, if set, is prepended to all HTTP request URL paths using // the transport from TransportForKey. It is useful when your keys refer to // data hosted on a HTTP server at somewhere other than the root path. For // example, if the datad key "/foo" refers to "http://example.com/api/foo", // then KeyURLPrefix would be "/api/". KeyURLPrefix string Log *log.Logger // contains filtered or unexported fields }
A Client routes requests for data.
func (*Client) NodesForKey ¶
NodesForKey returns a list of nodes that, according to the registry, hold the data specified by key.
func (*Client) NodesInCluster ¶
NodesInCluster returns a list of all nodes in the cluster.
func (*Client) TransportForKey ¶
func (c *Client) TransportForKey(key string, underlying http.RoundTripper) (*KeyTransport, error)
TransportForKey returns a HTTP transport (http.RoundTripper) optimized for accessing the data specified by key.
If key is not registered to any nodes, ErrNoNodesForKey is returned.
type EtcdBackend ¶
type EtcdBackend struct {
// contains filtered or unexported fields
}
func (*EtcdBackend) Delete ¶
func (c *EtcdBackend) Delete(key string) error
func (*EtcdBackend) ListKeys ¶
func (c *EtcdBackend) ListKeys(key string, recursive bool) ([]string, error)
func (*EtcdBackend) Set ¶
func (c *EtcdBackend) Set(key, value string) error
type KeyFunc ¶
A KeyFunc maps path-space onto key-space.
In other words, it returns the key (a string) of the data stored at path. The key, in datad terms, is the unit of storage.
Depending on the type of data, keys and paths may be a 1-to-1 mapping, or paths may point to resources inside of a key. For example, you might key on repositories clone URLs and allow paths that refer to specific files or commits inside of a repository.
type KeyTransport ¶
type KeyTransport struct {
// contains filtered or unexported fields
}
func (*KeyTransport) CancelRequest ¶
func (t *KeyTransport) CancelRequest(req *http.Request)
CancelRequest is to allow a nonzero Timeout on the http.Client. TODO(sqs): check this.
func (*KeyTransport) RoundTrip ¶
RoundTrip implements http.RoundTripper. If at least one node responds successfully, no error is returned. If all nodes fail to respond successfully, a *KeyTransportError is returned with the errors from each node.
func (*KeyTransport) SyncWithRegistry ¶
func (t *KeyTransport) SyncWithRegistry() error
SyncWithRegistry updates the list of nodes that this transport attempts to make HTTP requests to. The new nodes are looked up in the registry.
type KeyTransportError ¶
type KeyTransportError struct { URL string NodeErrors map[string]error // OtherError is an error encountered while trying to register key with other nodes. OtherError error }
KeyTransportError denotes that the key transport's RoundTrip failed. It records the individual errors for each node it attempted to contact.
func (*KeyTransportError) Error ¶
func (e *KeyTransportError) Error() string
type Node ¶
type Node struct { Name string Provider Provider // Updaters is the maximum number of concurrent calls to Provider.Update // that may be executing at any given time on this node. Updaters int Log *log.Logger // contains filtered or unexported fields }
A Node ensures that the provider's keys are registered and coordinates distribution of data among the other nodes in the cluster.
func NewNode ¶
NewNode creates a new node to publish data from a provider to the cluster. The name ("host:port") is advertised to the cluster and therefore must be accessible by the other clients and nodes in the cluster. The name should be the host and port where the data on this machine is accessible.
Call Start on this node to begin publishing its keys to the cluster.
type Provider ¶
type Provider interface { // HasKey returns whether this provider has the underlying data for key. If // not, it returns the error ErrKeyNotExist. HasKey(key string) (bool, error) // Keys returns a list of keys under keyPrefix. Keys(keyPrefix string) ([]string, error) // Update performs a synchronous update of this key's data from the // underlying data source. If key does not exist in this provider, it will // be created. Update(key string) error }
A Provider makes data accessible to the datad cluster.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
A Registry contains a bidirectional mapping between data keys and nodes: (1) for a given data key, a list of cluster nodes that have the underlying data on disk; and (2) for a given node, a list of data keys that it should fetch/compute and store on disk.