Documentation
¶
Index ¶
- Constants
- func PrepareEndpointList(srvs []string, port int) []string
- type ClusterStatus
- type ElectionResponse
- type EphemeralKey
- type EtcdConnector
- func (ec *EtcdConnector) ComputeServerRTT() error
- func (ec *EtcdConnector) ConstructPath(dir string, key string) string
- func (ec *EtcdConnector) NewEphemeralKey(path string) *EphemeralKey
- func (ec *EtcdConnector) NewHealthMonitor() *HealthMonitor
- func (ec *EtcdConnector) NewLeaderElector(key, val string, interval time.Duration) LeaderElector
- func (ec *EtcdConnector) NewObserver(key string) *Observer
- func (ec *EtcdConnector) NewServiceTracker(path string) ServiceTracker
- type HealthMonitor
- type LeaderElector
- type LeaderElectorStatus
- type Observer
- type ObserverResponse
- type ServiceData
- type ServiceTracker
Constants ¶
const ( // Timeout value set on every http request sent to the etcd service. TIMEOUT_PER_REQUEST = (2 * time.Second) // Default TTL value that will be used for keys (used mainly by // EphemeralKey and LeaderElector operations). TTL_VAL = (10 * time.Second) // Default ticker value that will be used to refresh the TTL. TTL_REFRESH_TIMEOUT = (TTL_VAL - (1 * time.Second)) )
const LE_SLEEP_INTERVAL = 5 * time.Second
Variables ¶
This section is empty.
Functions ¶
func PrepareEndpointList ¶
Description:
A helper routine to construct an array of strings from the given server list and port number into the following format 'http://<server>:<port>'.
Parameters:
@srvs - An array of strings representing the hostname or IP addresses of all the servers that make up the etcd service. @port - Port at which the servers will accept client connections.
Return value:
- An array of strings in 'http://<server>:<port>' format.
Types ¶
type ClusterStatus ¶
type ClusterStatus int32
A type to indicate the status of the cluster.
const ( ClusterStatusHealthy ClusterStatus = iota ClusterStatusUnhealthy ClusterStatusUnknown )
type ElectionResponse ¶
type ElectionResponse struct { Status LeaderElectorStatus Err error }
A structure that will be sent back to the caller to notify if the caller has acquired or lost leadership. On success, @err will be nil.
type EphemeralKey ¶
type EphemeralKey struct {
// contains filtered or unexported fields
}
A descriptor structure for the Ephemeral key.
func (*EphemeralKey) Create ¶
Description:
A routine that instantiates an ephemeral key by creating one at @keyPath specified. The routine also sets @val, passed by the user, as the value to the key and uses @interval as the time to renew the TTL of the key at regular intervals.
Parameters:
@val - User defined value that will be set for the ephemeral key. @interval - Interval at which the TTL will be renewed.
Return value:
- A channel on which errors that occur during TTL renewal will be notified.
- Error object describing the error, if any, that occurs during initial setup.
func (*EphemeralKey) Delete ¶
func (ek *EphemeralKey) Delete()
Description:
A routine that deletes the EphemeralKey instance. Once stopped an attempt will be made to manually delete the ephemeral key from etcd namespace. The deletion is attempted by the go-routine created in Create API.
Parameters:
None
Return value:
None
func (*EphemeralKey) Update ¶
func (ek *EphemeralKey) Update(newVal string) error
Description:
A routine that updates the value stored in the ephemeral key. It's done by sending the new value on the @updateCh channel which will be read by the go-routine created by the Create API. As a side effect the TTL also gets renewed.
Parameters:
@newVal - A new user defined value that will be set for the ephemeral key.
Return value:
- Error object describing the error.
type EtcdConnector ¶
type EtcdConnector struct { // etcd client API Interface. This is used as an anonymous field. client.KeysAPI // contains filtered or unexported fields }
Etcd is a distributed key-value store which can be used for the following purposes:
[1] To store cluster wide configuration information. Hence the name "EtcdConnector". [2] To achieve distributed coordination.
This structure acts as a handle to the etcd service. The handle can be used to perform all the client operations (like set, get, watch etc...) on the etcd service. It can also be used to make use of some common recipes like leader election, service discovery etc... on the etcd service.
func NewEtcdConnector ¶
func NewEtcdConnector(servers []string, name string) (*EtcdConnector, error)
Description:
A constructor routine to instantiate a connection to the etcd service.
Parameters:
@servers - Array of server host:port pairs to which a client connection will be attempted. @name - A string that identifies the namespace under which all the keys will be created. For Ex: If @name is set to 'abc' and a key named 'hosts' is created then 'hosts' would be present at '/abc/hosts'.
Return values:
- A pointer to an EtcdConnector structure on success, nil otherwise.
- An error object on failure, nil otherise.
func (*EtcdConnector) ComputeServerRTT ¶
func (ec *EtcdConnector) ComputeServerRTT() error
Description:
A helper routine to approximate the time required for a request to reach one of the etcd servers. This needs to be accounted as it will be crucial for picking up a time interval to update the TTL of a key. At the end of this routine the approximate RTT value will be stored in the EtcdConnector structure.
Parameters:
None
Return value:
- Corresponding error object, if any.
func (*EtcdConnector) ConstructPath ¶
func (ec *EtcdConnector) ConstructPath(dir string, key string) string
Description:
A helper routine to construct a path under the namespace identified by @name field in EtcdConnector structure.
Parameters:
@dir - A directory (already existing) under which @key will be created. @key - A key to be created.
Return value:
- A string that takes following form: /@EtcdConnector.name/@dir/@key
func (*EtcdConnector) NewEphemeralKey ¶
func (ec *EtcdConnector) NewEphemeralKey(path string) *EphemeralKey
Description:
A constructor routine to instantiate an EphemeralKey structure.
Parameters:
@path - Path in etcd namespace where the ephemeral key will be created.
Return value:
- A pointer to EphemeralKey structure.
func (*EtcdConnector) NewHealthMonitor ¶
func (ec *EtcdConnector) NewHealthMonitor() *HealthMonitor
Description:
A constructor routine to instantiate the HealthMonitor structure.
Parameters:
None
Return value:
- A pointer to HealthMonitor structure.
func (*EtcdConnector) NewLeaderElector ¶
func (ec *EtcdConnector) NewLeaderElector(key, val string, interval time.Duration) LeaderElector
Description:
A constructor method used to instantiate a leader election participant.
Parameters:
@key - key path that will be used as a lock for leader election. @val - Value that will be stored in the key.
NOTE: @val is the value that will be returned back when a follower
calls the "GetLeader" method. So the user will have to choose the value in a way that will be easy for the followers to identify the leader instance. (Example value : <IP addr:Port>)
Return value:
- A LeaderElector interface.
func (*EtcdConnector) NewObserver ¶
func (ec *EtcdConnector) NewObserver(key string) *Observer
Description:
A constructor method used to instantiate a new Observer structure.
Parameters:
@key - Path to the key that needs to be observed. This could be a directory or a key.
Return value:
- A pointer to an Observer structure.
func (*EtcdConnector) NewServiceTracker ¶
func (ec *EtcdConnector) NewServiceTracker(path string) ServiceTracker
Description:
A constructor routine to instantiate a service tracker.
Parameters:
@path - A path in the etcd namespace under which the instances will be tracked.
Return value:
- A pointer to the ServiceTracker instance.
type HealthMonitor ¶
type HealthMonitor struct {
// contains filtered or unexported fields
}
A descriptor structure for the Health Monitor.
func (*HealthMonitor) Start ¶
func (hm *HealthMonitor) Start(once bool, scanFreq time.Duration) <-chan ClusterStatus
Description:
A routine that starts the etcd cluster health monitor. The "/health" endpoint of a client URL shall be probed to check the status of the cluster. The logic of this routine is very similar to the implementation of "cluster-health" command of the etcdctl tool provided by CoreOS. It's just that the functionality is being provided in the form of an API. The caller gets a channel, as a return value, on which the status will be posted.
Parameters:
@once - A flag to indicate to check the status once and exit. @scanFreq - A time interval after which the status needs to be checked in a loop. This field makes sense when @once is set to false.
Return value:
- A channel on which ClusterStatus will be notified.
func (*HealthMonitor) Stop ¶
func (hm *HealthMonitor) Stop()
Description:
A routine that stops the health monitor. The stop channel will be written to signal the go-routine to exit.
Parameters:
None
Return value:
None
type LeaderElector ¶
type LeaderElector interface { // Start participating in the election process. A channel shall be returned // on which election status shall be reported back to the user. Start() (<-chan ElectionResponse, error) // Stop particpating in the election process. Stop() // Get the identity of the leader instance. This is a method via which // the followers can learn who the current leader is. GetLeader() string }
LeaderElector interface to be used by the users of the recipe.
type LeaderElectorStatus ¶
type LeaderElectorStatus int32
A type to describe the status of the leader election operation.
const ( // Indicates that the caller has become the leader. LEStatusLeader LeaderElectorStatus = iota // Indicates that the caller has lost leaderhip. LEStatusFollower )
type Observer ¶
type Observer struct {
// contains filtered or unexported fields
}
A descriptor structure for the Observer operation.
func (*Observer) Start ¶
func (o *Observer) Start(waitIndex uint64, recursive bool) (<-chan ObserverResponse, error)
Description:
A routine that starts the watch on the key identified by @key member Observer structure. The caller gets a channel, as a return value, on which ObserverResponse will be sent out.
Parameters:
@waitIndex - The index of the key from which we intend to wait for changes. If waitIndex is zero that means that we wait for any change. @recursive - A flag to indicate to look for changes recursively in a directory structure.
Return values:
- A channel on which responses will be sent.
- Error info, if any while starting the operation, will be returned.
type ObserverResponse ¶
type ObserverResponse struct { // An etcd response object received when a watch triggers. Response *client.Response // An error object, if any. Err error }
A wrapper structure that will be sent back to caller as a response whenever a watch triggers or an error occurs.
type ServiceData ¶
type ServiceData struct { // A map of active services with service name as key and its content // as value. Services map[string]string // Error information, if any. Err error }
A structure that will be sent back to the caller whenever a change is observed under @servicePath.
type ServiceTracker ¶
type ServiceTracker interface { // Start tracking the instances that form a given service. A channel shall // be returned on which the details about the service instances will be sent. Start() (<-chan ServiceData, error) // Stop tracking for changes. Stop() }
ServiceTracker interface to be used by the users of this recipe.