Documentation ¶
Overview ¶
Package etcd implements the distributed key value store integration. This also takes care of managing and clustering the embedded etcd server. The elastic etcd algorithm works in the following way: * When you start up mgmt, you can pass it a list of seeds. * If no seeds are given, then assume you are the first server and startup. * If a seed is given, connect as a client, and optionally volunteer to be a server. * All volunteering clients should listen for a message from the master for nomination. * If a client has been nominated, it should startup a server. * All servers should list for their nomination to be removed and shutdown if so. * The elected leader should decide who to nominate/unnominate to keep the right number of servers.
Smoke testing: ./mgmt run --file examples/etcd1a.yaml --hostname h1 ./mgmt run --file examples/etcd1b.yaml --hostname h2 --tmp-prefix --seeds http://127.0.0.1:2379 --client-urls http://127.0.0.1:2381 --server-urls http://127.0.0.1:2382 ./mgmt run --file examples/etcd1c.yaml --hostname h3 --tmp-prefix --seeds http://127.0.0.1:2379 --client-urls http://127.0.0.1:2383 --server-urls http://127.0.0.1:2384 ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 put /_mgmt/idealClusterSize 3 ./mgmt run --file examples/etcd1d.yaml --hostname h4 --tmp-prefix --seeds http://127.0.0.1:2379 --client-urls http://127.0.0.1:2385 --server-urls http://127.0.0.1:2386 ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 member list ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2381 put /_mgmt/idealClusterSize 5 ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2381 member list
Index ¶
- Constants
- func ApplyDeltaEvents(re *RE, urlsmap etcdtypes.URLsMap) (etcdtypes.URLsMap, error)
- func EtcdAddHostnameConvergedWatcher(obj *EmbdEtcd, callbackFn func(map[string]bool) error) (func(), error)
- func EtcdAdvertiseEndpoints(obj *EmbdEtcd, urls etcdtypes.URLs) error
- func EtcdEndpoints(obj *EmbdEtcd) (etcdtypes.URLsMap, error)
- func EtcdGetClusterSize(obj *EmbdEtcd) (uint16, error)
- func EtcdGetResources(obj *EmbdEtcd, hostnameFilter, kindFilter []string) ([]resources.Res, error)
- func EtcdHostnameConverged(obj *EmbdEtcd) (map[string]bool, error)
- func EtcdLeader(obj *EmbdEtcd) (string, error)
- func EtcdMemberAdd(obj *EmbdEtcd, peerURLs etcdtypes.URLs) (*etcd.MemberAddResponse, error)
- func EtcdMemberRemove(obj *EmbdEtcd, mID uint64) (bool, error)
- func EtcdMembers(obj *EmbdEtcd) (map[uint64]string, error)
- func EtcdNominate(obj *EmbdEtcd, hostname string, urls etcdtypes.URLs) error
- func EtcdNominated(obj *EmbdEtcd) (etcdtypes.URLsMap, error)
- func EtcdSetClusterSize(obj *EmbdEtcd, value uint16) error
- func EtcdSetHostnameConverged(obj *EmbdEtcd, hostname string, isConverged bool) error
- func EtcdSetResources(obj *EmbdEtcd, hostname string, resourceList []resources.Res) error
- func EtcdVolunteer(obj *EmbdEtcd, urls etcdtypes.URLs) error
- func EtcdVolunteers(obj *EmbdEtcd) (etcdtypes.URLsMap, error)
- func EtcdWatch(obj *EmbdEtcd) chan bool
- type AW
- type CtxDelayErr
- type CtxPermanentErr
- type CtxReconnectErr
- type CtxRetriesErr
- type DL
- type EmbdEtcd
- func (obj *EmbdEtcd) AddWatcher(path string, callback func(re *RE) error, errCheck bool, skipConv bool, ...) (func(), error)
- func (obj *EmbdEtcd) CancelCtx(ctx context.Context) (context.Context, func())
- func (obj *EmbdEtcd) CbLoop()
- func (obj *EmbdEtcd) ComplexGet(path string, skipConv bool, opts ...etcd.OpOption) (map[string]string, error)
- func (obj *EmbdEtcd) Connect(reconnect bool) error
- func (obj *EmbdEtcd) CtxError(ctx context.Context, err error) (context.Context, error)
- func (obj *EmbdEtcd) Delete(path string, opts ...etcd.OpOption) (int64, error)
- func (obj *EmbdEtcd) Destroy() error
- func (obj *EmbdEtcd) DestroyServer() error
- func (obj *EmbdEtcd) Get(path string, opts ...etcd.OpOption) (map[string]string, error)
- func (obj *EmbdEtcd) GetConfig() etcd.Config
- func (obj *EmbdEtcd) LocalhostClientURLs() etcdtypes.URLs
- func (obj *EmbdEtcd) Loop()
- func (obj *EmbdEtcd) Set(key, value string, opts ...etcd.OpOption) error
- func (obj *EmbdEtcd) StartServer(newCluster bool, peerURLsMap etcdtypes.URLsMap) error
- func (obj *EmbdEtcd) Startup() error
- func (obj *EmbdEtcd) TimeoutCtx(ctx context.Context, t time.Duration) (context.Context, func())
- func (obj *EmbdEtcd) Txn(ifcmps []etcd.Cmp, thenops, elseops []etcd.Op) (*etcd.TxnResponse, error)
- type GQ
- type KV
- type RE
- type TN
Constants ¶
const ( NS = "_mgmt" // root namespace for mgmt operations DefaultIdealClusterSize = 5 // default ideal cluster size target for initial seed DefaultClientURL = "127.0.0.1:2379" DefaultServerURL = "127.0.0.1:2380" )
constant parameters which may need to be tweaked or customized
Variables ¶
This section is empty.
Functions ¶
func ApplyDeltaEvents ¶
ApplyDeltaEvents modifies a URLsMap with the deltas from a WatchResponse
func EtcdAddHostnameConvergedWatcher ¶
func EtcdAddHostnameConvergedWatcher(obj *EmbdEtcd, callbackFn func(map[string]bool) error) (func(), error)
EtcdAddHostnameConvergedWatcher adds a watcher with a callback that runs on hostname state changes.
func EtcdAdvertiseEndpoints ¶
EtcdAdvertiseEndpoints advertises the list of available client endpoints
func EtcdEndpoints ¶
EtcdEndpoints returns a urls map of available etcd server endpoints
func EtcdGetClusterSize ¶
EtcdGetClusterSize gets the ideal target cluster size of etcd peers
func EtcdGetResources ¶
EtcdGetResources collects all of the resources which match a filter from etcd If the kindfilter or hostnameFilter is empty, then it assumes no filtering... TODO: Expand this with a more powerful filter based on what we eventually support in our collect DSL. Ideally a server side filter like WithFilter() We could do this if the pattern was /$NS/exported/$kind/$hostname/$uuid = $data
func EtcdHostnameConverged ¶
EtcdHostnameConverged returns a map of every hostname's converged state.
func EtcdLeader ¶
EtcdLeader returns the current leader of the etcd server cluster
func EtcdMemberAdd ¶
EtcdMemberAdd adds a member to the cluster.
func EtcdMemberRemove ¶
EtcdMemberRemove removes a member by mID and returns if it worked, and also if there was an error. This is because it might have run without error, but the member wasn't found, for example.
func EtcdMembers ¶
EtcdMembers returns information on cluster membership. The member ID's are the keys, because an empty names means unstarted! TODO: consider queueing this through the main loop with CtxError(ctx, err)
func EtcdNominate ¶
EtcdNominate nominates a particular client to be a server (peer)
func EtcdNominated ¶
EtcdNominated returns a urls map of nominated etcd server volunteers NOTE: I know 'nominees' might be more correct, but is less consistent here
func EtcdSetClusterSize ¶
EtcdSetClusterSize sets the ideal target cluster size of etcd peers
func EtcdSetHostnameConverged ¶
EtcdSetHostnameConverged sets whether a specific hostname is converged.
func EtcdSetResources ¶
EtcdSetResources exports all of the resources which we pass in to etcd
func EtcdVolunteer ¶
EtcdVolunteer offers yourself up to be a server if needed
func EtcdVolunteers ¶
EtcdVolunteers returns a urls map of available etcd server volunteers
Types ¶
type AW ¶
type AW struct {
// contains filtered or unexported fields
}
AW is a struct for the AddWatcher queue
type CtxDelayErr ¶
CtxDelayErr requests a retry in Delta duration
func (*CtxDelayErr) Error ¶
func (obj *CtxDelayErr) Error() string
type CtxPermanentErr ¶
type CtxPermanentErr struct {
Message string
}
CtxPermanentErr is a permanent failure error to notify about borkage.
func (*CtxPermanentErr) Error ¶
func (obj *CtxPermanentErr) Error() string
type CtxReconnectErr ¶
type CtxReconnectErr struct {
Message string
}
CtxReconnectErr requests a client reconnect to the new endpoint list
func (*CtxReconnectErr) Error ¶
func (obj *CtxReconnectErr) Error() string
type CtxRetriesErr ¶
CtxRetriesErr lets you retry as long as you have retries available TODO: consider combining this with CtxDelayErr
func (*CtxRetriesErr) Error ¶
func (obj *CtxRetriesErr) Error() string
type DL ¶
type DL struct {
// contains filtered or unexported fields
}
DL is a struct for the delete queue
type EmbdEtcd ¶
type EmbdEtcd struct {
// contains filtered or unexported fields
}
EmbdEtcd provides the embedded server and client etcd functionality
func NewEmbdEtcd ¶
func NewEmbdEtcd(hostname string, seeds, clientURLs, serverURLs etcdtypes.URLs, noServer bool, idealClusterSize uint16, prefix string, converger converger.Converger) *EmbdEtcd
NewEmbdEtcd creates the top level embedded etcd struct client and server obj
func (*EmbdEtcd) AddWatcher ¶
func (obj *EmbdEtcd) AddWatcher(path string, callback func(re *RE) error, errCheck bool, skipConv bool, opts ...etcd.OpOption) (func(), error)
AddWatcher queues up an add watcher request and returns a cancel function Remember to add the etcd.WithPrefix() option if you want to watch recursively
func (*EmbdEtcd) CbLoop ¶
func (obj *EmbdEtcd) CbLoop()
CbLoop is the loop where callback execution is serialized
func (*EmbdEtcd) ComplexGet ¶
func (obj *EmbdEtcd) ComplexGet(path string, skipConv bool, opts ...etcd.OpOption) (map[string]string, error)
ComplexGet performs a get operation and waits for an ACK to continue. It can accept more arguments that are useful for the less common operations. TODO: perhaps a get should never cause an un-converge ?
func (*EmbdEtcd) Connect ¶
Connect connects the client to a server, and then builds the *API structs. If reconnect is true, it will force a reconnect with new config endpoints.
func (*EmbdEtcd) CtxError ¶
CtxError is called whenever there is a connection or other client problem that needs to be resolved before we can continue, eg: connection disconnected, change of server to connect to, etc... It modifies the context if needed.
func (*EmbdEtcd) Destroy ¶
Destroy cleans up the entire embedded etcd system. Use DestroyServer if you only want to shutdown the embedded server portion.
func (*EmbdEtcd) DestroyServer ¶
DestroyServer shuts down the embedded etcd server portion
func (*EmbdEtcd) GetConfig ¶
GetConfig returns the config struct to be used for the etcd client connect
func (*EmbdEtcd) LocalhostClientURLs ¶
LocalhostClientURLs returns the most localhost like URLs for direct connection this gets clients to talk to the local servers first before searching remotely
func (*EmbdEtcd) Loop ¶
func (obj *EmbdEtcd) Loop()
Loop is the main loop where everything is serialized
func (*EmbdEtcd) StartServer ¶
StartServer kicks of a new embedded etcd server.
func (*EmbdEtcd) Startup ¶
Startup is the main entry point to kick off the embedded etcd client & server
func (*EmbdEtcd) TimeoutCtx ¶
TimeoutCtx adds a tracked cancel function with timeout around an existing context
type GQ ¶
type GQ struct {
// contains filtered or unexported fields
}
GQ is a struct for the get queue
type KV ¶
type KV struct {
// contains filtered or unexported fields
}
KV is a key + value struct to hold the two items together