Skip to content

Commit 8cbfc82

Browse files
Bashmuntaucwong
authored andcommitted
core/rawdb: fix size counting in memory freezer (#33344)
1 parent 7455462 commit 8cbfc82

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

core/rawdb/freezer_memory.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ func (t *memoryTable) truncateHead(items uint64) error {
9191
if items < t.offset {
9292
return errors.New("truncation below tail")
9393
}
94+
for i := int(items - t.offset); i < len(t.data); i++ {
95+
if t.size > uint64(len(t.data[i])) {
96+
t.size -= uint64(len(t.data[i]))
97+
} else {
98+
t.size = 0
99+
}
100+
}
94101
t.data = t.data[:items-t.offset]
95102
t.items = items
96103
return nil
@@ -108,6 +115,13 @@ func (t *memoryTable) truncateTail(items uint64) error {
108115
if t.items < items {
109116
return errors.New("truncation above head")
110117
}
118+
for i := uint64(0); i < items-t.offset; i++ {
119+
if t.size > uint64(len(t.data[i])) {
120+
t.size -= uint64(len(t.data[i]))
121+
} else {
122+
t.size = 0
123+
}
124+
}
111125
t.data = t.data[items-t.offset:]
112126
t.offset = items
113127
return nil

0 commit comments

Comments
 (0)