etcd

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KEY_LEASE_ID points to the lease ID in the etcd record metadata
	KEY_LEASE_ID = "lease_id"
	// KEY_COUNT points to the count in the etcd record metadata
	KEY_COUNT = "count"
	// KEY_HEADER points to the header in the etcd record metadata
	KEY_HEADER = "header"
	// KEY_MORE points to the more boolean var in the etcd record metadata
	KEY_MORE = "more"
	// KEY_REVISION points to the revision in the etcd record metadata
	KEY_REVISION = "revision"
	// KEY_VERSION points to the version in the etcd record metadata
	KEY_VERSION = "version"
)

Variables

View Source
var (
	// ErrInvalidLeaseID returned when the leaseID provided is invalid
	ErrInvalidLeaseID = errors.New("invalid etcd leaseID passed")
	// ErrNoResults returned when no results are found
	ErrNoResults = errors.New("no results found for the given key")
	// ErrCreatingEtcdClient returned when creating etcd clientv3 fails
	ErrCreatingEtcdClient = errors.New("error creating kvstore etcd client")
	// ErrInvalidWatchOption returned when the watch option sent to the
	// subscribe function is invalid
	ErrInvalidWatchOption = errors.New("invalid etcd watch option")
	// ErrInvalidGetOption returned when the get option provided is not valid
	ErrInvalidGetOption = errors.New("invalid etcd GET() option")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Endpoints is a comma separated list of etcd URLs
	Endpoints string `env:"KVSTORE_ETCD_ENDPOINTS"`
	// DialTimeout is the timeout for failing to establish a connection
	DialTimeout time.Duration `env:"KVSTORE_ETCD_DIALTIMEOUT,omitempty"`
	// Username is a username for authentication
	Username string `env:"KVSTORE_ETCD_USERNAME,omitempty"`
	// Password is the password for authentication
	Password string `env:"KVSTORE_ETCD_PASSWORD,omitempty"`
}

Config holds the etcd configuration

func NewConfig

func NewConfig() *Config

NewConfig returns the parsed config for jetstream from env

func (*Config) GetEndpoints

func (c *Config) GetEndpoints() []string

GetEndpoints return the etcd server endpoints

func (*Config) UnmarshalEnv

func (c *Config) UnmarshalEnv(es env.EnvSet) error

UnmarshalEnv env.EnvSet to Config

type Etcd

type Etcd struct {
	Client *clientv3.Client
	Config *Config
	// contains filtered or unexported fields
}

Etcd holds our etcd instance

func NewEtcd

func NewEtcd() *Etcd

NewEtcd returns a new instance of etcd with etcd client and config

func (*Etcd) Delete

func (e *Etcd) Delete(ctx context.Context, key string) error

Delete the key from the store

func (*Etcd) Get

func (e *Etcd) Get(ctx context.Context, key string, opts ...kvstore.GetOpt) ([]*kvstore.Record, error)

Get a record by it's key

func (*Etcd) GetMetadataLeaseID

func (e *Etcd) GetMetadataLeaseID(record *kvstore.Record) (clientv3.LeaseID, error)

GetMetadataLeaseID returns the leaseID from the record metadata

func (*Etcd) HasInitializer

func (e *Etcd) HasInitializer() bool

func (*Etcd) Init

func (e *Etcd) Init(opts ...kvstore.Option) error

Init initializes the store with the given options

func (*Etcd) Initializer

func (e *Etcd) Initializer() component.Initializer

func (*Etcd) LeaseID

func (e *Etcd) LeaseID(ctx context.Context, record *kvstore.Record) (clientv3.LeaseID, error)

LeaseID returns the leaseID (if any) to be used by the record If exists, it renews and returns the "lease_id" set in the record metadata If record expiry is set, then it creates a new leaseID and returns it. If it's none of the above, then it returns 0

func (*Etcd) Put

func (e *Etcd) Put(ctx context.Context, record *kvstore.Record, opts ...kvstore.SetOpt) (*kvstore.Record, error)

Put adds the record into the store Get the lease if lease_id is defined in the record metadata, or create new lease if expiry is defined Renew lease using the lease_id in the record metadata, added/used by LeaseID(...) Add the record to the store with the lease_id

func (*Etcd) RenewLease

func (e *Etcd) RenewLease(ctx context.Context, leaseID clientv3.LeaseID) error

RenewLease renews the lease with the given leaseID This renews lease if the lease is valid and not 0

func (*Etcd) String

func (e *Etcd) String() string

String returns the name of the store implementation

func (*Etcd) Subscribe

func (e *Etcd) Subscribe(
	ctx context.Context,
	key string,
	handler kvstore.SubscribeHandler,
	opts ...kvstore.SubscribeOpt,
) error

Subscribe to the changes made to the given key

func (*Etcd) Txn

func (e *Etcd) Txn(ctx context.Context, handler kvstore.TxnHandler) error

Txn handles store transactions

func (*Etcd) Unsubscribe

func (e *Etcd) Unsubscribe(ctx context.Context, key string) error

Unsubscribe from a subscription

type Initializer

type Initializer struct {
	// contains filtered or unexported fields
}

func NewInitializer

func NewInitializer(e *Etcd) *Initializer

NewInitializer returns a new JetStream Initialiazer

func (*Initializer) AddDependency

func (i *Initializer) AddDependency(dep interface{}) error

AddDependency adds necessary service components as dependencies

func (*Initializer) CanRun

func (i *Initializer) CanRun() bool

CanRun returns true if the component has anything to Run

func (*Initializer) CanStop

func (i *Initializer) CanStop() bool

CanRun returns true if the component has anything to Run

func (*Initializer) Dependencies

func (i *Initializer) Dependencies() []string

Dependencies returns the string names of service components that are required as dependencies for this component

func (*Initializer) Run

func (i *Initializer) Run(ctx context.Context) error

Run start the service component

func (*Initializer) Stop

func (i *Initializer) Stop(ctx context.Context) error

Stop - stops the running

Jump to

Keyboard shortcuts

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