Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WatchPrefix ¶
func WatchPrefix[K comparable, V any]( ctx context.Context, client *v3.Client, prefix string, transform KVTransform[K, V], ) <-chan Snapshot[K, V]
WatchPrefix watches a prefix _forever_ until the provided context is cancelled.
The returned channel emits Snapshot's of the tree. The returned channel closes when the provided ctx is cancelled.
Types ¶
type KVTransform ¶
type KVTransform[K comparable, V any] func(k, v []byte) (K, V, error)
KVTransform transforms a <Key, Value> pair from etcd into a <K, V> mapping suitable to the use-case of Snapshot[K, V].
Example: K is the ID of an item, where V is the information about it.
type PersistentLease ¶
type PersistentLease struct {
// contains filtered or unexported fields
}
PersistentLease is "persistent" lease in etcd.
While name sounds contradictory, it's behaviour is that while the PersistentLease is not closed, it will continually try to keep the <key, value> pair present in etcd, _attached_ to a lease. This process will only end when Close() is called.
PersistentLease's are useful in situations where we want to register the presence of a server/node in a cluster. The use of a lease ensures that if the process crashes or becomes partitioned from etcd, the value gets automatically removed. The 'persistent' component ensures that when the network partition is restored (or whatever failure mode that caused the lease to expire recovers), the <key, value> pair will be placed back automatically.
func NewPersistentLease ¶
func NewPersistentLease(client *v3.Client, key, val string, ttl time.Duration) (*PersistentLease, error)
NewPersistentLease creates a new PersistentLease which starts immediately in the background.
func (*PersistentLease) Close ¶
func (pl *PersistentLease) Close()
Close closes the PersistentLease, terminating all background jobs.
Close is idempotent. A PersistentLease cannot be restarted, however.
func (*PersistentLease) Key ¶ added in v1.10.12
func (pl *PersistentLease) Key() string
Key returns the key of the persistent lease.
func (*PersistentLease) SetValue ¶
func (pl *PersistentLease) SetValue(val string)
SetValue sets the new value for the persistent lease.
SetValue is done concurrently, so there are no guarantees for when this will propagate. To wait for the value to be replicated, a Get()/Watch() should be used.
type Snapshot ¶
type Snapshot[K comparable, V any] struct { Tree map[K]V }
Snapshot contains a "tree" at a given point in time.
The tree is all <Key, Value> pairs matching a prefix.