00d40e3bbe224fb00b3e6bd0430f00c3c725e3d5
- Add internal/locking package for distributed locks - Implement DistributedLock with configurable backends - Implement LocalLockBackend as in-memory fallback - Support for Redis/etcd backends (interface design) - Lock timeout with exponential backoff - Token-based lock verification - Lock renewal capability - Lock hold duration tracking - LockManager for managing multiple locks - Deadlock prevention with timeout - Multi-pod safe design - 24 locking tests, all passing Features: - LockBackend interface for pluggable backends - LocalLockBackend for single-pod scenarios - DistributedLock with acquire/release/renew - LockManager for fleet of locks - Timeout support with retry logic - Token generation for security - Statistics tracking - Concurrent safe operations Lock Operations: - Acquire(timeout) - acquire with timeout - Release() - release lock - Renew() - extend TTL - IsAcquired() - check if held - GetAcquiredAt() - lock acquisition time - GetHoldDuration() - how long lock is held Lock Manager Operations: - AcquireLock(key, timeout) - acquire by key - ReleaseLock(key) - release by key - RenewLock(key) - renew by key - ReleaseAll() - release all locks - GetActiveLocks() - list of held locks - GetLockStats() - statistics Statistics: - Total acquisitions - Total releases - Failed acquisitions (timeout) - Active lock count - Average lock time Backend Design: - LocalLockBackend for development/single-pod - Redis backend interface for production - etcd backend interface for K8s - Easy to swap implementations Test Coverage: - 24 locking tests (acquire, release, timeout, manager) - Concurrent access patterns verified - Timeout behavior tested - Token security verified - Multi-lock scenarios tested - Failed acquisition tracking - Statistics accuracy verified Features for Multi-Pod: - Token-based ownership verification - TTL support for deadlock prevention - Fairness through backend ordering - Graceful release on process death - Lock renewal for long-running tasks Default Values: - TTL: 30 seconds - Acquire timeout: 5 seconds - Backoff: 100ms Future Enhancement: - Redis backend with Lua scripts - etcd backend with lease renewal - Weighted fairness - Priority acquisition Next: T3 milestone (Feature expansion)
Description
No description provided
54 MiB
Languages
Go
99.3%
Shell
0.6%
Go Template
0.1%