posixage: make lock timeouts configurable#523
Conversation
e1655c6 to
06a3dbd
Compare
There was a problem hiding this comment.
The capability is right, but the API shape needs rework before merging.
Drop WithLockTimeout and flock.Config.LockTimeout. context.Context already expresses "how long to wait" — callers who want a bounded wait pass context.WithTimeout; callers who want no timeout pass a ctx without a deadline. That gives you the disable-timeout case for free, no new option needed.
Keep WithStaleLockTimeout only. It's a file-age threshold, not a wait duration — semantically distinct, belongs as a store-level option.
Move stale recovery trigger off LockTimeout. With LockTimeout gone, trigger recovery on first-attempt failure instead (try once → on fail, attempt recovery if StaleLockTimeout > 0 and ctx not canceled → retry until ctx done).
Proposed signature:
func TryLock(ctx context.Context, root *os.Root, staleAfter time.Duration) (UnlockFunc, error)Defaults stay (no deadline = wait forever; 30s stale). Drops one option, one struct, and the LockTimeout/StaleLockTimeout coupling.
store/posixage/internal/flock/flock.go:
- tryLock — drop cfg Config param, take staleAfter time.Duration; restructure to "first-attempt → recover → retry til ctx done"
- retryLock — drop timeout param, retry purely against ctx
- TryLock / TryRLock — new signatures (ctx, root, staleAfter)
- Delete Config, DefaultConfig, defaultLockTimeout const
store/posixage/store.go:
- fileStore.tryLock / tryRLock — pass f.staleLockTimeout instead of f.lockConfig
- config struct — replace lockConfig flock.Config with staleLockTimeout time.Duration
- Delete WithLockTimeout
- WithStaleLockTimeout — stays, writes to new field
- New — init default staleLockTimeout = 30 * time.Second (move const from flock pkg or expose getter)
store/posixage/internal/flock/flock_test.go:
- All tests passing Config{...} — rewrite to pass staleAfter directly; tests covering LockTimeout behavior become ctx-deadline
tests
store/posixage/store_test.go:
- Any test exercising WithLockTimeout — remove or convert to ctx-deadline
store/posixage/README.md:
- Update the new lock-config section
| func DefaultConfig() Config { | ||
| return Config{ | ||
| LockTimeout: defaultLockTimeout, | ||
| StaleLockTimeout: defaultStaleLockTimeout, | ||
| } | ||
| } |
There was a problem hiding this comment.
make this a var, no need to have a function
Uh oh!
There was an error while loading. Please reload this page.