MCPcopy Create free account
hub / github.com/cortexproject/cortex / blocksToDelete

Method blocksToDelete

pkg/ingester/ingester.go:579–605  ·  view source on GitHub ↗

blocksToDelete filters the input blocks and returns the blocks which are safe to be deleted from the ingester.

(blocks []*tsdb.Block)

Source from the content-addressed store, hash-verified

577
578// blocksToDelete filters the input blocks and returns the blocks which are safe to be deleted from the ingester.
579func (u *userTSDB) blocksToDelete(blocks []*tsdb.Block) map[ulid.ULID]struct{} {
580 if u.db == nil {
581 return nil
582 }
583 deletable := tsdb.DefaultBlocksToDelete(u.db)(blocks)
584
585 now := time.Now().UnixMilli()
586 for _, b := range blocks {
587 if now-b.MaxTime() >= u.blockRetentionPeriod {
588 deletable[b.Meta().ULID] = struct{}{}
589 }
590 }
591
592 if u.shipper == nil {
593 return deletable
594 }
595
596 shippedBlocks := u.getCachedShippedBlocks()
597
598 result := map[ulid.ULID]struct{}{}
599 for shippedID := range shippedBlocks {
600 if _, ok := deletable[shippedID]; ok {
601 result[shippedID] = struct{}{}
602 }
603 }
604 return result
605}
606
607// updateCachedShippedBlocks reads the shipper meta file and updates the cached shipped blocks.
608func (u *userTSDB) updateCachedShippedBlocks() error {

Callers 1

Calls 1

Tested by 1