mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-11 18:46:38 +00:00
core/rawdb: fix size counting in memory freezer (#33344)
This commit is contained in:
parent
13a8798fa3
commit
b98b255449
1 changed files with 14 additions and 0 deletions
|
|
@ -91,6 +91,13 @@ func (t *memoryTable) truncateHead(items uint64) error {
|
||||||
if items < t.offset {
|
if items < t.offset {
|
||||||
return errors.New("truncation below tail")
|
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.data = t.data[:items-t.offset]
|
||||||
t.items = items
|
t.items = items
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -108,6 +115,13 @@ func (t *memoryTable) truncateTail(items uint64) error {
|
||||||
if t.items < items {
|
if t.items < items {
|
||||||
return errors.New("truncation above head")
|
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.data = t.data[items-t.offset:]
|
||||||
t.offset = items
|
t.offset = items
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue