core/rawdb: fix size counting in memory freezer (#33344)
Some checks are pending
/ Keeper Build (push) Waiting to run
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

This commit is contained in:
Bashmunta 2025-12-10 10:09:24 +02:00 committed by GitHub
parent 13a8798fa3
commit b98b255449
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -91,6 +91,13 @@ func (t *memoryTable) truncateHead(items uint64) error {
if items < t.offset {
return errors.New("truncation below tail")
}
for i := int(items - t.offset); i < len(t.data); i++ {
if t.size > uint64(len(t.data[i])) {
t.size -= uint64(len(t.data[i]))
} else {
t.size = 0
}
}
t.data = t.data[:items-t.offset]
t.items = items
return nil
@ -108,6 +115,13 @@ func (t *memoryTable) truncateTail(items uint64) error {
if t.items < items {
return errors.New("truncation above head")
}
for i := uint64(0); i < items-t.offset; i++ {
if t.size > uint64(len(t.data[i])) {
t.size -= uint64(len(t.data[i]))
} else {
t.size = 0
}
}
t.data = t.data[items-t.offset:]
t.offset = items
return nil