generated from openacid/gotmpl
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrecord.go
68 lines (54 loc) · 1.22 KB
/
record.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package traft
import (
fmt "fmt"
"strings"
)
// NewRecord: without Overrides yet!!! TODO
func NewRecord(leader *LeaderId, seq int64, cmd *Cmd) *LogRecord {
rec := &LogRecord{
Author: leader,
Seq: seq,
Cmd: cmd,
}
return rec
}
func NewRecordOverride(leader *LeaderId, seq int64, cmd *Cmd, override *TailBitmap) *LogRecord {
rec := NewRecord(leader,seq,cmd)
rec.Overrides = NewTailBitmap(0, seq)
rec.Overrides.Union(override)
return rec
}
// gogoproto would panic if a []*LogRecord has a nil in it.
// Thus we use r.Cmd == nil to indicate an absent log record.
func (r *LogRecord) Empty() bool {
return r == nil || r.Cmd == nil
}
func (a *LogRecord) Interfering(b *LogRecord) bool {
if a == nil || b == nil {
return false
}
return a.Cmd.Interfering(b.Cmd)
}
func (r *LogRecord) ShortStr() string {
if r.Empty() {
return "<>"
}
return fmt.Sprintf("<%s:%03d{%s}-%s→%s>",
r.Author.ShortStr(),
r.Seq,
r.Cmd.ShortStr(),
r.Overrides.ShortStr(),
r.Depends.ShortStr(),
)
}
func RecordsShortStr(rs []*LogRecord, sep ...string) string {
s := ", "
if len(sep) > 0 {
s = sep[0]
}
rst := []string{}
for _, r := range rs {
rst = append(rst, r.ShortStr())
}
return "[" + strings.Join(rst, s) + "]"
}