etcd

package
v2.19.6 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStore

func NewStore(opts ...store.Option) store.Store

NewStore creates a new go-micro store backed by etcd

Types

type Store

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

Store is a store implementation which uses etcd to store the data

func (*Store) Close

func (es *Store) Close() error

Close the client

func (*Store) Delete

func (es *Store) Delete(key string, opts ...store.DeleteOption) error

Delete the record containing the key provided. Database and Table options are highly recommended, otherwise we'll use a default one (which might not have the requested keys)

Since the Write method inserts 2 entries for a given key, those both entries will also be removed using the same key. This is handled transparently.

func (*Store) Init

func (es *Store) Init(opts ...store.Option) error

Init initializes the go-micro store implementation. Currently, only the nodes are configurable, the rest of the options will be ignored.

func (*Store) List

func (es *Store) List(opts ...store.ListOption) ([]string, error)

List the keys available in the etcd server. Database and Table options are highly recommended, otherwise we'll use a default one (which might not have the requested keys)

With the Database and Table options, all the keys returned will be within that database and table. Each service is expected to use a different database + table, so using those options will list only the keys used by that particular service.

Prefix and suffix options are available along with the limit and offset ones.

Using prefix and suffix options at the same time is discourage because the suffix matching will be done on our side, and we'll likely need to perform multiple requests to get the requested results. Note that using just the suffix option is fine. In addition, using the offset option is also discouraged because we'll need to request additional keys that will be skipped on our side.

func (*Store) Options

func (es *Store) Options() store.Options

Options returns the store options

func (*Store) Read

func (es *Store) Read(key string, opts ...store.ReadOption) ([]*store.Record, error)

Read records from the etcd server based in the key. Database and Table options are highly recommended, otherwise we'll use a default one (which might not have the requested keys)

If no prefix or suffix option is provided, we'll read the record matching the provided key. Note that a list of records will be provided anyway, likely with only one record (the one requested)

Prefix and suffix options are supported and should perform fine even with a large amount of data. Note that the limit option should also be included in order to limit the amount of records we need to fetch.

Note that using both prefix and suffix options at the same time is possible but discouraged. A prefix search will be send to the etcd server, and from there we'll manually pick the records matching the suffix. This might become very inefficient since we might need to request more data to the etcd multiple times in order to provide the results asked. Usage of the offset option is also discouraged because we'll have to request records that we'll have to skip manually on our side.

Don't rely on any particular order of the keys. The records are expected to be sorted by key except if the suffix option (suffix without prefix) is used. In this case, the keys will be sorted based on the reversed key

func (*Store) String

func (es *Store) String() string

Return the service name

func (*Store) Write

func (es *Store) Write(r *store.Record, opts ...store.WriteOption) error

Write the record into the etcd. The record will be duplicated in order to find it by prefix or by suffix. This means that it will take double space. Note that this is an implementation detail and it will be handled transparently.

Database and Table options will be used to provide a different prefix to the key. Each service using this store should use a different database+table combination in order to prevent key collisions.

Due to how TTLs are implemented in etcd, the minimum valid TTL seems to be 2 secs. Using lower values or even negative values will force the etcd server to use the minimum value instead. In addition, getting a lease for the TTL and attach it to the target key are 2 different operations that can't be sent as part of a transaction. This means that it's possible to get a lease and have that lease expire before attaching it to the key. Errors are expected to happen if this is the case, and no key will be inserted. According to etcd documentation, the key is guaranteed to be available AT LEAST the TTL duration. This means that the key might be available for a longer period of time in special circumstances.

It's recommended to use a minimum TTL of 10 secs or higher (or not to use TTL) in order to prevent problematic scenarios.

Jump to

Keyboard shortcuts

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