core/rawdb: add resetTo() for empty table

This commit is contained in:
healthykim 2026-06-29 20:16:34 +02:00
parent 9700b5b10e
commit 65c0ea433a

View file

@ -611,9 +611,17 @@ func (t *freezerTable) truncateHead(items uint64) error {
if existing <= items { if existing <= items {
return nil return nil
} }
if items < t.itemHidden.Load() {
return errors.New("truncation below tail") hidden := t.itemHidden.Load()
if items < hidden {
if existing == hidden {
// Empty table means that it is newly added. Its tail would be
// at the head, so we have to align the table down to the new head.
return t.resetTo(items)
} }
}
// We need to truncate, save the old size for metrics tracking // We need to truncate, save the old size for metrics tracking
oldSize, err := t.sizeNolock() oldSize, err := t.sizeNolock()
if err != nil { if err != nil {