MCPcopy
hub / github.com/prometheus/prometheus / gc

Method gc

tsdb/head.go:1760–1798  ·  view source on GitHub ↗

gc removes data before the minimum timestamp from the head. It returns * The actual min times of the chunks present in the Head. * The min OOO time seen during the GC. * Min mmap file number seen in the series (in-order and out-of-order) after gc'ing the series.

()

Source from the content-addressed store, hash-verified

1758// * The min OOO time seen during the GC.
1759// * Min mmap file number seen in the series (in-order and out-of-order) after gc'ing the series.
1760func (h *Head) gc() (actualInOrderMint, minOOOTime int64, minMmapFile int) {
1761 // Only data strictly lower than this timestamp must be deleted.
1762 mint := h.MinTime()
1763 // Only ooo m-map chunks strictly lower than or equal to this ref
1764 // must be deleted.
1765 minOOOMmapRef := chunks.ChunkDiskMapperRef(h.minOOOMmapRef.Load())
1766
1767 // Drop old chunks and remember series IDs and hashes if they can be
1768 // deleted entirely.
1769 deleted, affected, chunksRemoved, staleSeriesDeleted, actualInOrderMint, minOOOTime, minMmapFile := h.series.gc(mint, minOOOMmapRef)
1770 seriesRemoved := len(deleted)
1771
1772 h.metrics.seriesRemoved.Add(float64(seriesRemoved))
1773 h.metrics.chunksRemoved.Add(float64(chunksRemoved))
1774 h.metrics.chunks.Sub(float64(chunksRemoved))
1775 h.numSeries.Sub(uint64(seriesRemoved))
1776 h.numStaleSeries.Sub(uint64(staleSeriesDeleted))
1777
1778 // Remove deleted series IDs from the postings lists.
1779 h.postings.Delete(deleted, affected)
1780
1781 // Remove tombstones referring to the deleted series.
1782 h.tombstones.DeleteTombstones(deleted)
1783 h.tombstones.TruncateBefore(mint)
1784
1785 if h.wal != nil {
1786 h.walExpiriesMtx.Lock()
1787 // Samples for deleted series are likely still in the WAL, so flag that the deleted series records should be kept during
1788 // WAL checkpointing while the WAL contains data through actualInOrderMint.
1789 // If we didn't keep these series records then on start up when we replay the WAL, or any other code that reads the WAL,
1790 // wouldn't be able to use those samples since we would have no labels for that ref ID.
1791 for ref := range deleted {
1792 h.walExpiries[chunks.HeadSeriesRef(ref)] = actualInOrderMint
1793 }
1794 h.walExpiriesMtx.Unlock()
1795 }
1796
1797 return actualInOrderMint, minOOOTime, minMmapFile
1798}
1799
1800// Tombstones returns a new reader over the head's tombstones.
1801func (h *Head) Tombstones() (tombstones.Reader, error) {

Calls 10

MinTimeMethod · 0.95
ChunkDiskMapperRefTypeAlias · 0.92
HeadSeriesRefTypeAlias · 0.92
DeleteTombstonesMethod · 0.80
TruncateBeforeMethod · 0.80
LockMethod · 0.80
LoadMethod · 0.65
AddMethod · 0.65
DeleteMethod · 0.65
SubMethod · 0.45