Repository: prometheus/prometheus
File: tsdb/db.go (Go)

Code before:
	// When set to false, delayed compaction is disabled, unless CompactionDelay is set directly.
	EnableDelayedCompaction bool
	// CompactionDelay delays the start time of auto compactions.
	// It can be increased by up to one minute if the DB does not commit too often.
	CompactionDelay time.Duration
	// CompactionDelayMaxPercent is the upper limit for CompactionDelay, specified as a percentage of the head chunk range.
	CompactionDelayMaxPercent int

	// NewCompactorFunc is a function that returns a TSDB compactor.
	NewCompactorFunc NewCompactorFunc

	// BlockQuerierFunc is a function to return storage.Querier from a BlockReader.
	BlockQuerierFunc BlockQuerierFunc

	// BlockChunkQuerierFunc is a function to return storage.ChunkQuerier from a BlockReader.
	BlockChunkQuerierFunc BlockChunkQuerierFunc

	// PostingsDecoderFactory allows users to customize postings decoders based on BlockMeta.
	// By default, DefaultPostingsDecoderFactory will be used to create raw posting decoder.
	PostingsDecoderFactory PostingsDecoderFactory

	// UseUncachedIO allows bypassing the page cache when appropriate.
	UseUncachedIO bool

	// BlockReloadInterval is the interval at which blocks are reloaded.
	BlockReloadInterval int64
}

type NewCompactorFunc func(ctx context.Context, r prometheus.Registerer, l *slog.Logger, ranges []int64, pool chunkenc.Pool, opts *Options) (Compactor, error)

type BlocksToDeleteFunc func(blocks []*Block) map[ulid.ULID]struct{}

type BlockQuerierFunc func(b BlockReader, mint, maxt int64) (storage.Querier, error)

type BlockChunkQuerierFunc func(b BlockReader, mint, maxt int64) (storage.ChunkQuerier, error)

// DB handles reads and writes of time series falling into
// a hashed partition of a seriedb.
type DB struct {
	dir    string
	locker *tsdbutil.DirLocker

	logger         *slog.Logger
	metrics        *dbMetrics
	opts           *Options
	chunkPool      chunkenc.Pool
	compactor      Compactor
	blocksToDelete BlocksToDeleteFunc

	// mtx must be held when modifying the general block layout or lastGarbageCollectedMmapRef.
	mtx    sync.RWMutex

Review comment (suggestion):
This is a real-world time so should be a `time.Duration`.  See `CompactionDelay` which is similar.
(Different to `OutOfOrderTimeWindow` which is in the same units as metric timestamps, which TSDB is deliberately ignorant of)

Code after:
	// CompactionDelay delays the start time of auto compactions.
	// It can be increased by up to one minute if the DB does not commit too often.
	CompactionDelay time.Duration
	// CompactionDelayMaxPercent is the upper limit for CompactionDelay, specified as a percentage of the head chunk range.
	CompactionDelayMaxPercent int

	// NewCompactorFunc is a function that returns a TSDB compactor.
	NewCompactorFunc NewCompactorFunc

	// BlockQuerierFunc is a function to return storage.Querier from a BlockReader.
	BlockQuerierFunc BlockQuerierFunc

	// BlockChunkQuerierFunc is a function to return storage.ChunkQuerier from a BlockReader.
	BlockChunkQuerierFunc BlockChunkQuerierFunc

	// PostingsDecoderFactory allows users to customize postings decoders based on BlockMeta.
	// By default, DefaultPostingsDecoderFactory will be used to create raw posting decoder.
	PostingsDecoderFactory PostingsDecoderFactory

	// UseUncachedIO allows bypassing the page cache when appropriate.
	UseUncachedIO bool

	// EnableSTAsZeroSample represents 'created-timestamp-zero-ingestion' feature flag.
	// If true, ST, if non-zero and earlier than sample timestamp, will be stored
	// as a zero sample before the actual sample.
	//
	// The zero sample is best-effort, only debug log on failure is emitted.
	// NOTE(bwplotka): This feature might be deprecated and removed once PROM-60
	// is implemented.
	EnableSTAsZeroSample bool

	// EnableMetadataWALRecords represents 'metadata-wal-records' feature flag.
	// NOTE(bwplotka): This feature might be deprecated and removed once PROM-60
	// is implemented.
	EnableMetadataWALRecords bool

	// BlockCompactionExcludeFunc is a function which returns true for blocks that should NOT be compacted.
	// It's passed down to the TSDB compactor.
	BlockCompactionExcludeFunc BlockExcludeFilterFunc

	// BlockReloadInterval is the interval at which blocks are reloaded.
	BlockReloadInterval time.Duration

	// FeatureRegistry is used to register TSDB features.
	FeatureRegistry features.Collector
}

type NewCompactorFunc func(ctx context.Context, r prometheus.Registerer, l *slog.Logger, ranges []int64, pool chunkenc.Pool, opts *Options) (Compactor, error)

type BlocksToDeleteFunc func(blocks []*Block) map[ulid.ULID]struct{}