@@ -18,6 +18,7 @@ type Queue struct {
18
18
}
19
19
20
20
type PeerSnapshot struct {
21
+ key crypto.Hash
21
22
PeerId crypto.Hash
22
23
Snapshot * common.Snapshot
23
24
}
@@ -55,11 +56,10 @@ func (q *Queue) PutFinal(ps *PeerSnapshot) error {
55
56
q .mutex .Lock ()
56
57
defer q .mutex .Unlock ()
57
58
58
- hash := ps .finalKey ()
59
- if q .finalSet [hash ] {
59
+ if q .finalSet [ps .key ] {
60
60
return nil
61
61
}
62
- q .finalSet [hash ] = true
62
+ q .finalSet [ps . key ] = true
63
63
64
64
for {
65
65
put , err := q .finalRing .Offer (ps )
@@ -79,19 +79,18 @@ func (q *Queue) PopFinal() (*PeerSnapshot, error) {
79
79
return nil , err
80
80
}
81
81
ps := item .(* PeerSnapshot )
82
- delete (q .finalSet , ps .finalKey () )
82
+ delete (q .finalSet , ps .key )
83
83
return ps , nil
84
84
}
85
85
86
86
func (q * Queue ) PutCache (ps * PeerSnapshot ) error {
87
87
q .mutex .Lock ()
88
88
defer q .mutex .Unlock ()
89
89
90
- hash := ps .cacheKey ()
91
- if q .cacheSet [hash ] {
90
+ if q .cacheSet [ps .key ] {
92
91
return nil
93
92
}
94
- q .cacheSet [hash ] = true
93
+ q .cacheSet [ps . key ] = true
95
94
96
95
for {
97
96
put , err := q .cacheRing .Offer (ps )
@@ -111,7 +110,7 @@ func (q *Queue) PopCache() (*PeerSnapshot, error) {
111
110
return nil , err
112
111
}
113
112
ps := item .(* PeerSnapshot )
114
- delete (q .cacheSet , ps .cacheKey () )
113
+ delete (q .cacheSet , ps .key )
115
114
return ps , nil
116
115
}
117
116
@@ -137,8 +136,10 @@ func (s *BadgerStore) QueueAppendSnapshot(peerId crypto.Hash, snap *common.Snaps
137
136
Snapshot : snap ,
138
137
}
139
138
if finalized {
139
+ ps .key = ps .finalKey ()
140
140
return s .queue .PutFinal (ps )
141
141
}
142
+ ps .key = ps .cacheKey ()
142
143
return s .queue .PutCache (ps )
143
144
}
144
145
0 commit comments