gxetcd

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func (c *Client) Campaign(basePath string, timeout time.Duration) (ElectionSession, error)

if @timeout <= 0, Campaign will loop to get the leadership until success.

func (*Client) CheckLeadership added in v0.3.2

func (c *Client) CheckLeadership(basePath string) bool

func (*Client) Close

func (c *Client) Close() error

Close orphans the session and revokes the session lease.

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

func (c *Client) EtcdClient() *ecv3.Client

Client is the etcd client that is attached to the session.

func (*Client) IsClosed

func (c *Client) IsClosed() bool

check whether the session has been closed.

func (*Client) KeepAlive

func (c *Client) KeepAlive() (<-chan *ecv3.LeaseKeepAliveResponse, error)

func (*Client) Lease

func (c *Client) Lease() ecv3.LeaseID

Lease is the lease ID for keys bound to the session.

func (*Client) Lock added in v0.3.2

func (c *Client) Lock(basePath string) error

func (*Client) Resign added in v0.3.2

func (c *Client) Resign(basePath string, stop bool) error

func (*Client) Stop

func (c *Client) Stop()

Stop ends the refresh for the session lease. This is useful in case the state of the client connection is indeterminate (revoke would fail) or when transferring lease ownership.

func (*Client) TTL

func (c *Client) TTL() int64

TTL return the ttl of Client's lease

func (*Client) Unlock added in v0.3.2

func (c *Client) Unlock(basePath string) 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
}

Jump to

Keyboard shortcuts

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