@@ -291,12 +291,17 @@ func (f *freezer) TruncateHead(items uint64) error {
291291 if atomic .LoadUint64 (& f .frozen ) <= items {
292292 return nil
293293 }
294+ var frozen uint64
294295 for _ , table := range f .tables {
295296 if err := table .truncateHead (items ); err != nil {
296297 return err
297298 }
299+ // Tables should be aligned, only check the first table.
300+ if frozen == 0 {
301+ frozen = atomic .LoadUint64 (& table .items )
302+ }
298303 }
299- atomic .StoreUint64 (& f .frozen , items )
304+ atomic .StoreUint64 (& f .frozen , frozen )
300305 return nil
301306}
302307
@@ -315,12 +320,17 @@ func (f *freezer) TruncateTail(tail uint64) error {
315320 // there will be some or all tables that do not actually perform the truncate
316321 // action because tail deletion can only do in file level. These deletions
317322 // will be delayed until the whole data file is deletable.
323+ var truncated uint64
318324 for _ , table := range f .tables {
319325 if err := table .truncateTail (tail ); err != nil {
320326 return err
321327 }
328+ if truncated == 0 {
329+ itemOffset , hidden := atomic .LoadUint64 (& table .itemOffset ), atomic .LoadUint64 (& table .itemHidden )
330+ truncated = itemOffset + hidden
331+ }
322332 }
323- atomic .StoreUint64 (& f .tail , tail )
333+ atomic .StoreUint64 (& f .tail , truncated )
324334 return nil
325335}
326336
@@ -338,7 +348,7 @@ func (f *freezer) Sync() error {
338348 return nil
339349}
340350
341- // repair truncates all data tables to the same length.
351+ // repair truncates all data tables to the same length, both tail and head .
342352func (f * freezer ) repair () error {
343353 var (
344354 head = uint64 (math .MaxUint64 )
0 commit comments