-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlm.go
41 lines (33 loc) · 976 Bytes
/
dlm.go
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
package dlm
import (
"errors"
"log/slog"
"time"
)
var (
ErrExpiredLease = errors.New("dlm: lease expires")
ErrNoLease = errors.New("dlm: no lease")
ErrNotYourLease = errors.New("dlm: not your lease")
ErrLeaseExists = errors.New("dlm: lease exists")
ErrFrozenTopic = errors.New("dlm: topic is frozen")
ErrBadDatabase = errors.New("dlm: bad database operation")
)
var (
DefaultTimeout = 3 * time.Second
DefaultLeaseTerm = 5 * time.Second
DefaultKeepAlive = 1 * time.Second
Logger = slog.Default()
)
const (
CreateTableLease = "CREATE TABLE IF NOT EXISTS dlm_lease(" +
"`topic` varchar(20) NOT NULL," +
"`key` varchar(50) NOT NULL," +
"`lessee` varchar(36) NOT NULL," +
"`since` int NOT NULL DEFAULT '0'," +
"`ttl` int NOT NULL DEFAULT '0'," +
"PRIMARY KEY (topic, key));"
CreateTableTopic = "CREATE TABLE IF NOT EXISTS dlm_topic(" +
"`topic` varchar(20) NOT NULL," +
"`ttl` int NOT NULL DEFAULT '0'," +
"PRIMARY KEY (topic));"
)