block

package
v0.13.0-rc.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2020 License: Apache-2.0 Imports: 33 Imported by: 23

Documentation

Overview

Package block contains common functionality for interacting with TSDB blocks in the context of Thanos.

Index

Constants

View Source
const (
	// MetaFilename is the known JSON filename for meta information.
	MetaFilename = "meta.json"
	// IndexFilename is the known index file for block index.
	IndexFilename = "index"
	// IndexCacheFilename is the canonical name for json index cache file that stores essential information.
	IndexCacheFilename = "index.cache.json"
	// IndexHeaderFilename is the canonical name for binary index header file that stores essential information.
	IndexHeaderFilename = "index-header"
	// ChunksDirname is the known dir name for chunks with compressed samples.
	ChunksDirname = "chunks"

	// DebugMetas is a directory for debug meta files that happen in the past. Useful for debugging.
	DebugMetas = "debug/metas"
)

Variables

View Source
var (
	ErrorSyncMetaNotFound  = errors.New("meta.json not found")
	ErrorSyncMetaCorrupted = errors.New("meta.json corrupted")
)

Functions

func Delete

func Delete(ctx context.Context, logger log.Logger, bkt objstore.Bucket, id ulid.ULID) error

Delete removes directory that is meant to be block directory. NOTE: Always prefer this method for deleting blocks.

  • We have to delete block's files in the certain order (meta.json first) to ensure we don't end up with malformed partial blocks. Thanos system handles well partial blocks only if they don't have meta.json. If meta.json is present Thanos assumes valid block.
  • This avoids deleting empty dir (whole bucket) by mistake.

func Download

func Download(ctx context.Context, logger log.Logger, bucket objstore.Bucket, id ulid.ULID, dst string) error

Download downloads directory that is mean to be block directory.

func DownloadMeta

func DownloadMeta(ctx context.Context, logger log.Logger, bkt objstore.Bucket, id ulid.ULID) (metadata.Meta, error)

DownloadMeta downloads only meta file from bucket by block ID. TODO(bwplotka): Differentiate between network error & partial upload.

func IgnoreCompleteOutsideChunk

func IgnoreCompleteOutsideChunk(mint int64, maxt int64, _ *chunks.Meta, curr *chunks.Meta) (bool, error)

func IgnoreDuplicateOutsideChunk

func IgnoreDuplicateOutsideChunk(_ int64, _ int64, last *chunks.Meta, curr *chunks.Meta) (bool, error)

func IgnoreIssue347OutsideChunk

func IgnoreIssue347OutsideChunk(_ int64, maxt int64, _ *chunks.Meta, curr *chunks.Meta) (bool, error)

func IsBlockDir

func IsBlockDir(path string) (id ulid.ULID, ok bool)

func MarkForDeletion added in v0.12.0

func MarkForDeletion(ctx context.Context, logger log.Logger, bkt objstore.Bucket, id ulid.ULID, markedForDeletion prometheus.Counter) error

MarkForDeletion creates a file which stores information about when the block was marked for deletion.

func Repair

func Repair(logger log.Logger, dir string, id ulid.ULID, source metadata.SourceType, ignoreChkFns ...ignoreFnType) (resid ulid.ULID, err error)

Repair open the block with given id in dir and creates a new one with fixed data. It: - removes out of order duplicates - all "complete" outsiders (they will not accessed anyway) - removes all near "complete" outside chunks introduced by https://github.com/prometheus/tsdb/issues/347. Fixable inconsistencies are resolved in the new block. TODO(bplotka): https://github.com/thanos-io/thanos/issues/378.

func Upload

func Upload(ctx context.Context, logger log.Logger, bkt objstore.Bucket, bdir string) error

Upload uploads block from given block dir that ends with block id. It makes sure cleanup is done on error to avoid partial block uploads. It also verifies basic features of Thanos block. TODO(bplotka): Ensure bucket operations have reasonable backoff retries.

func VerifyIndex

func VerifyIndex(logger log.Logger, fn string, minTime int64, maxTime int64) error

VerifyIndex does a full run over a block index and verifies that it fulfills the order invariants.

Types

type BaseFetcher added in v0.12.0

type BaseFetcher struct {
	// contains filtered or unexported fields
}

BaseFetcher is a struct that synchronizes filtered metadata of all block in the object storage with the local state. Go-routine safe.

func NewBaseFetcher added in v0.12.0

func NewBaseFetcher(logger log.Logger, concurrency int, bkt objstore.InstrumentedBucketReader, dir string, reg prometheus.Registerer) (*BaseFetcher, error)

NewBaseFetcher constructs BaseFetcher.

func (*BaseFetcher) NewMetaFetcher added in v0.12.0

func (f *BaseFetcher) NewMetaFetcher(reg prometheus.Registerer, filters []MetadataFilter, modifiers []MetadataModifier, logTags ...interface{}) *MetaFetcher

NewMetaFetcher transforms BaseFetcher into actually usable *MetaFetcher.

type ConsistencyDelayMetaFilter added in v0.11.0

type ConsistencyDelayMetaFilter struct {
	// contains filtered or unexported fields
}

ConsistencyDelayMetaFilter is a BaseFetcher filter that filters out blocks that are created before a specified consistency delay. Not go-routine safe.

func NewConsistencyDelayMetaFilter added in v0.11.0

func NewConsistencyDelayMetaFilter(logger log.Logger, consistencyDelay time.Duration, reg prometheus.Registerer) *ConsistencyDelayMetaFilter

NewConsistencyDelayMetaFilter creates ConsistencyDelayMetaFilter.

func (*ConsistencyDelayMetaFilter) Filter added in v0.11.0

Filter filters out blocks that filters blocks that have are created before a specified consistency delay.

type DeduplicateFilter added in v0.11.0

type DeduplicateFilter struct {
	// contains filtered or unexported fields
}

DeduplicateFilter is a BaseFetcher filter that filters out older blocks that have exactly the same data. Not go-routine safe.

func NewDeduplicateFilter added in v0.11.0

func NewDeduplicateFilter() *DeduplicateFilter

NewDeduplicateFilter creates DeduplicateFilter.

func (*DeduplicateFilter) DuplicateIDs added in v0.11.0

func (f *DeduplicateFilter) DuplicateIDs() []ulid.ULID

DuplicateIDs returns slice of block ids that are filtered out by DeduplicateFilter.

func (*DeduplicateFilter) Filter added in v0.11.0

func (f *DeduplicateFilter) Filter(_ context.Context, metas map[ulid.ULID]*metadata.Meta, synced *extprom.TxGaugeVec) error

Filter filters out duplicate blocks that can be formed from two or more overlapping blocks that fully submatches the source blocks of the older blocks.

type IgnoreDeletionMarkFilter added in v0.12.0

type IgnoreDeletionMarkFilter struct {
	// contains filtered or unexported fields
}

IgnoreDeletionMarkFilter is a filter that filters out the blocks that are marked for deletion after a given delay. The delay duration is to make sure that the replacement block can be fetched before we filter out the old block. Delay is not considered when computing DeletionMarkBlocks map. Not go-routine safe.

func NewIgnoreDeletionMarkFilter added in v0.12.0

func NewIgnoreDeletionMarkFilter(logger log.Logger, bkt objstore.InstrumentedBucketReader, delay time.Duration) *IgnoreDeletionMarkFilter

NewIgnoreDeletionMarkFilter creates IgnoreDeletionMarkFilter.

func (*IgnoreDeletionMarkFilter) DeletionMarkBlocks added in v0.12.0

func (f *IgnoreDeletionMarkFilter) DeletionMarkBlocks() map[ulid.ULID]*metadata.DeletionMark

DeletionMarkBlocks returns block ids that were marked for deletion.

func (*IgnoreDeletionMarkFilter) Filter added in v0.12.0

func (f *IgnoreDeletionMarkFilter) Filter(ctx context.Context, metas map[ulid.ULID]*metadata.Meta, synced *extprom.TxGaugeVec) error

Filter filters out blocks that are marked for deletion after a given delay. It also returns the blocks that can be deleted since they were uploaded delay duration before current time.

type LabelShardedMetaFilter added in v0.10.0

type LabelShardedMetaFilter struct {
	// contains filtered or unexported fields
}

LabelShardedMetaFilter represents struct that allows sharding. Not go-routine safe.

func NewLabelShardedMetaFilter added in v0.10.0

func NewLabelShardedMetaFilter(relabelConfig []*relabel.Config) *LabelShardedMetaFilter

NewLabelShardedMetaFilter creates LabelShardedMetaFilter.

func (*LabelShardedMetaFilter) Filter added in v0.10.0

func (f *LabelShardedMetaFilter) Filter(_ context.Context, metas map[ulid.ULID]*metadata.Meta, synced *extprom.TxGaugeVec) error

Filter filters out blocks that have no labels after relabelling of each block external (Thanos) labels.

type MetaFetcher added in v0.10.0

type MetaFetcher struct {
	// contains filtered or unexported fields
}

func NewMetaFetcher added in v0.10.0

func NewMetaFetcher(logger log.Logger, concurrency int, bkt objstore.InstrumentedBucketReader, dir string, reg prometheus.Registerer, filters []MetadataFilter, modifiers []MetadataModifier) (*MetaFetcher, error)

NewMetaFetcher returns meta fetcher.

func (*MetaFetcher) Fetch added in v0.10.0

func (f *MetaFetcher) Fetch(ctx context.Context) (metas map[ulid.ULID]*metadata.Meta, partial map[ulid.ULID]error, err error)

Fetch returns all block metas as well as partial blocks (blocks without or with corrupted meta file) from the bucket. It's caller responsibility to not change the returned metadata files. Maps can be modified.

Returned error indicates a failure in fetching metadata. Returned meta can be assumed as correct, with some blocks missing.

func (*MetaFetcher) UpdateOnChange added in v0.12.0

func (f *MetaFetcher) UpdateOnChange(listener func([]metadata.Meta, error))

UpdateOnChange allows to add listener that will be update on every change.

type MetadataFetcher added in v0.10.0

type MetadataFetcher interface {
	Fetch(ctx context.Context) (metas map[ulid.ULID]*metadata.Meta, partial map[ulid.ULID]error, err error)
	UpdateOnChange(func([]metadata.Meta, error))
}

type MetadataFilter added in v0.12.0

type MetadataFilter interface {
	Filter(ctx context.Context, metas map[ulid.ULID]*metadata.Meta, synced *extprom.TxGaugeVec) error
}

type MetadataModifier added in v0.12.0

type MetadataModifier interface {
	Modify(ctx context.Context, metas map[ulid.ULID]*metadata.Meta, modified *extprom.TxGaugeVec) error
}

type Node added in v0.11.0

type Node struct {
	metadata.Meta
	Children []*Node
}

Node type represents a node of a tree.

func NewNode added in v0.11.0

func NewNode(meta *metadata.Meta) *Node

NewNode creates a new node with children as empty slice.

type ReplicaLabelRemover added in v0.12.0

type ReplicaLabelRemover struct {
	// contains filtered or unexported fields
}

ReplicaLabelRemover is a BaseFetcher modifier modifies external labels of existing blocks, it removes given replica labels from the metadata of blocks that have it.

func NewReplicaLabelRemover added in v0.12.0

func NewReplicaLabelRemover(logger log.Logger, replicaLabels []string) *ReplicaLabelRemover

NewReplicaLabelRemover creates a ReplicaLabelRemover.

func (*ReplicaLabelRemover) Modify added in v0.12.0

func (r *ReplicaLabelRemover) Modify(_ context.Context, metas map[ulid.ULID]*metadata.Meta, modified *extprom.TxGaugeVec) error

Modify modifies external labels of existing blocks, it removes given replica labels from the metadata of blocks that have it.

type Stats

type Stats struct {
	// TotalSeries represents total number of series in block.
	TotalSeries int
	// OutOfOrderSeries represents number of series that have out of order chunks.
	OutOfOrderSeries int

	// OutOfOrderChunks represents number of chunks that are out of order (older time range is after younger one).
	OutOfOrderChunks int
	// DuplicatedChunks represents number of chunks with same time ranges within same series, potential duplicates.
	DuplicatedChunks int
	// OutsideChunks represents number of all chunks that are before or after time range specified in block meta.
	OutsideChunks int
	// CompleteOutsideChunks is subset of OutsideChunks that will be never accessed. They are completely out of time range specified in block meta.
	CompleteOutsideChunks int
	// Issue347OutsideChunks represents subset of OutsideChunks that are outsiders caused by https://github.com/prometheus/tsdb/issues/347
	// and is something that Thanos handle.
	//
	// Specifically we mean here chunks with minTime == block.maxTime and maxTime > block.MaxTime. These are
	// are segregated into separate counters. These chunks are safe to be deleted, since they are duplicated across 2 blocks.
	Issue347OutsideChunks int
	// OutOfOrderLabels represents the number of postings that contained out
	// of order labels, a bug present in Prometheus 2.8.0 and below.
	OutOfOrderLabels int
}

func GatherIndexIssueStats

func GatherIndexIssueStats(logger log.Logger, fn string, minTime int64, maxTime int64) (stats Stats, err error)

GatherIndexIssueStats returns useful counters as well as outsider chunks (chunks outside of block time range) that helps to assess index health. It considers https://github.com/prometheus/tsdb/issues/347 as something that Thanos can handle. See Stats.Issue347OutsideChunks for details.

func (Stats) AnyErr

func (i Stats) AnyErr() error

AnyErr returns error if stats indicates any block issue.

func (Stats) CriticalErr

func (i Stats) CriticalErr() error

CriticalErr returns error if stats indicates critical block issue, that might solved only by manual repair procedure.

func (Stats) Issue347OutsideChunksErr

func (i Stats) Issue347OutsideChunksErr() error

Issue347OutsideChunksErr returns error if stats indicates issue347 block issue, that is repaired explicitly before compaction (on plan block).

func (Stats) PrometheusIssue5372Err added in v0.7.0

func (i Stats) PrometheusIssue5372Err() error

PrometheusIssue5372Err returns an error if the Stats object indicates postings with out of order labels. This is corrected by Prometheus Issue #5372 and affects Prometheus versions 2.8.0 and below.

type TimePartitionMetaFilter added in v0.10.0

type TimePartitionMetaFilter struct {
	// contains filtered or unexported fields
}

TimePartitionMetaFilter is a BaseFetcher filter that filters out blocks that are outside of specified time range. Not go-routine safe.

func NewTimePartitionMetaFilter added in v0.10.0

func NewTimePartitionMetaFilter(MinTime, MaxTime model.TimeOrDurationValue) *TimePartitionMetaFilter

NewTimePartitionMetaFilter creates TimePartitionMetaFilter.

func (*TimePartitionMetaFilter) Filter added in v0.10.0

Filter filters out blocks that are outside of specified time range.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL