mirror of
https://github.com/ClusterCockpit/cc-metric-store.git
synced 2024-11-10 05:07:25 +01:00
Reset buffer size when reused
The buffers data slice size needs to be reset to 0 before it can be reused. Also, buffers that come from the archive should not be reused as they might have strange capacities.
This commit is contained in:
parent
fee0061172
commit
becf41f98c
11
memstore.go
11
memstore.go
@ -10,7 +10,7 @@ import (
|
|||||||
// in the buffer chain will be created if needed so that no copying
|
// in the buffer chain will be created if needed so that no copying
|
||||||
// of data or reallocation needs to happen on writes.
|
// of data or reallocation needs to happen on writes.
|
||||||
const (
|
const (
|
||||||
BUFFER_CAP int = 1024
|
BUFFER_CAP int = 512
|
||||||
)
|
)
|
||||||
|
|
||||||
// So that we can reuse allocations
|
// So that we can reuse allocations
|
||||||
@ -46,6 +46,7 @@ func newBuffer(ts, freq int64) *buffer {
|
|||||||
b.prev = nil
|
b.prev = nil
|
||||||
b.next = nil
|
b.next = nil
|
||||||
b.archived = false
|
b.archived = false
|
||||||
|
b.data = b.data[:0]
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,11 +153,11 @@ func (b *buffer) free(t int64) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
n += 1
|
n += 1
|
||||||
b.frequency = 0
|
// Buffers that come from the
|
||||||
b.start = 0
|
// archive should not be reused.
|
||||||
b.next = nil
|
if cap(b.data) == BUFFER_CAP {
|
||||||
b.prev = nil
|
|
||||||
bufferPool.Put(b)
|
bufferPool.Put(b)
|
||||||
|
}
|
||||||
b = prev
|
b = prev
|
||||||
}
|
}
|
||||||
return n, nil
|
return n, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user