Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit edf7987

Browse files
committedSep 8, 2017
minor cache delete improvements
1 parent a77179e commit edf7987

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed
 

‎mdata/cache/ccache.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,10 @@ func (c *CCache) evict(target *accnt.EvictTarget) {
183183
if length == 0 {
184184
delete(c.metricCache, target.Metric)
185185

186-
if ccms, ok := c.metricRawKeys[ccm.RawMetric]; ok {
187-
if _, ok := ccms[ccm.Cons]; ok {
188-
delete(ccms, ccm.Cons)
189-
if len(ccms) == 0 {
190-
delete(c.metricRawKeys, ccm.RawMetric)
191-
}
192-
}
186+
// this key should alway be present, if not there there is a corruption of the state
187+
delete(c.metricRawKeys[ccm.RawMetric], ccm.Cons)
188+
if len(c.metricRawKeys[ccm.RawMetric]) == 0 {
189+
delete(c.metricRawKeys, ccm.RawMetric)
193190
}
194191
}
195192
}

‎mdata/cache/ccache_metric.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,16 @@ func (mc *CCacheMetric) Del(ts uint32) int {
4848
prev := mc.chunks[ts].Prev
4949
next := mc.chunks[ts].Next
5050

51-
if _, ok := mc.chunks[prev]; prev != 0 && ok {
52-
mc.chunks[prev].Next = 0
51+
if prev != 0 {
52+
if _, ok := mc.chunks[prev]; ok {
53+
mc.chunks[prev].Next = 0
54+
}
5355
}
54-
if _, ok := mc.chunks[next]; next != 0 && ok {
55-
mc.chunks[next].Prev = 0
56+
57+
if next != 0 {
58+
if _, ok := mc.chunks[next]; ok {
59+
mc.chunks[next].Prev = 0
60+
}
5661
}
5762

5863
delete(mc.chunks, ts)

0 commit comments

Comments
 (0)