-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.go
More file actions
50 lines (40 loc) · 1.06 KB
/
Copy pathcommand.go
File metadata and controls
50 lines (40 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package lockd
import (
"context"
"time"
"github.com/imharjot/lockd/lease"
)
// op is the kind of command sent to a key actor.
type op int
const (
opAcquire op = iota
opRenew
opRelease
opExpire // internal, emitted by the timing wheel
opSnapshot
opDrain // internal, prunes cancelled waiters from the queue
opInstall // internal, restores a recovered lease during WAL replay
)
// result is the reply a caller receives from a command.
type result struct {
lease lease.Lease
held bool
err error
}
// command is a single unit of work handed to a key actor. Exactly one actor
// goroutine processes commands for a given key, so the actor body needs no
// locks to mutate its lease.Key.
type command struct {
op op
holder string
token lease.Token
ttl time.Duration
// ctx lets a queued acquire be cancelled while it waits its turn.
ctx context.Context
// installLease carries a recovered lease for opInstall.
installLease lease.Lease
reply chan result
}
func newCommand(o op) *command {
return &command{op: o, reply: make(chan result, 1)}
}