Documentation ¶
Overview ¶
Copyright 2016 ~ 2018 AlexStocks(https://github.com/AlexStocks). All rights reserved. Use of this source code is governed by Apache License 2.0.
gxetcd encapsulate a etcd lease client
Copyright 2016 ~ 2018 AlexStocks(https://github.com/AlexStocks). All rights reserved. Use of this source code is governed by Apache License 2.0.
gxetcd encapsulate a etcd lease client
Index ¶
- Variables
- type Client
- func (c *Client) Campaign(basePath string, timeout time.Duration) (ElectionSession, error)
- func (c *Client) CheckLeadership(basePath string) bool
- func (c *Client) Close() error
- func (c *Client) Done() <-chan struct{}
- func (c *Client) EtcdClient() *ecv3.Client
- func (c *Client) IsClosed() bool
- func (c *Client) KeepAlive() (<-chan *ecv3.LeaseKeepAliveResponse, error)
- func (c *Client) Lease() ecv3.LeaseID
- func (c *Client) Lock(basePath string) error
- func (c *Client) Resign(basePath string, stop bool) error
- func (c *Client) Stop()
- func (c *Client) TTL() int64
- func (c *Client) Unlock(basePath string) error
- type ClientOption
- type ElectionSession
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDeadlock is returned by Lock when trying to lock twice without unlocking first ErrDeadlock = jerrors.New("etcd: trying to acquire a lock twice") // ErrNotLocked is returned by Unlock when trying to release a lock that has not first be acquired. ErrNotLocked = jerrors.New("etcd: not locked") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a lease kept alive for the lifetime of a client. Fault-tolerant applications may use sessions to reason about liveness.
func NewClient ¶
func NewClient(client *ecv3.Client, options ...ClientOption) (*Client, error)
NewClient gets the leased session for a client.
func (*Client) Campaign ¶ added in v0.3.2
if @timeout <= 0, Campaign will loop to get the leadership until success.
func (*Client) CheckLeadership ¶ added in v0.3.2
func (*Client) Done ¶
func (c *Client) Done() <-chan struct{}
Done returns a channel that closes when the lease is orphaned, expires, or is otherwise no longer being refreshed.
func (*Client) EtcdClient ¶
Client is the etcd client that is attached to the session.
func (*Client) KeepAlive ¶
func (c *Client) KeepAlive() (<-chan *ecv3.LeaseKeepAliveResponse, error)
type ClientOption ¶
type ClientOption func(*clientOptions)
ClientOption configures Client.
func WithContext ¶
func WithContext(ctx context.Context) ClientOption
WithContext assigns a context to the session instead of defaulting to using the client context. This is useful for canceling NewClient and Close operations immediately without having to close the client. If the context is canceled before Close() completes, the session's lease will be abandoned and left to expire instead of being revoked.
func WithLease ¶
func WithLease(leaseID ecv3.LeaseID) ClientOption
WithLease specifies the existing leaseID to be used for the session. This is useful in process restart scenario, for example, to reclaim leadership from an election prior to restart.
func WithTTL ¶
func WithTTL(ttl time.Duration) ClientOption
WithTTL configures the session's TTL in seconds. If TTL is <= 0, the default 60 seconds TTL will be used.
type ElectionSession ¶ added in v0.3.2
type ElectionSession struct { Path string Session *concurrency.Session Election *concurrency.Election }