Skip to main content

Etcd Lock Plugin

The Etcd Lock plugin is a distributed lock layer that depends on the Etcd plugin's client resource. It is not an independent storage connector.

Runtime Facts

ItemValue
Go modulegithub.com/go-lynx/lynx-etcd-lock
Config prefixlynx.etcd-lock
Runtime plugin nameetcd.distributed.lock
Dependencyruntime resource etcd.config.center
Public APIsLock, LockWithOptions, LockWithRetry, NewLockFromClient, GetStats()

What The Implementation Provides

From the code, this plugin:

  • resolves the Etcd client from the Etcd plugin during initialization
  • exposes helper APIs for lock acquisition and automatic release
  • supports retry strategy and operation timeout
  • supports automatic renewal for long-running locks
  • maintains global lock-manager stats

The lock helper API is intentionally business-facing; you do not need to work with raw Etcd leases for common cases.

Usage Pattern

err := etcdlock.Lock(ctx, "order:123", 15*time.Second, func() error {
return doBusinessWork()
})

For more control:

opts := etcdlock.DefaultLockOptions
opts.RenewalEnabled = true
opts.RetryStrategy.MaxRetries = 3

err := etcdlock.LockWithOptions(ctx, "order:123", opts, fn)

Important Constraint

This plugin fails initialization if etcd.config.center is not loaded first, because it reads the shared Etcd client from that runtime resource.