Skip to content

Commit

Permalink
tsdb creation supports fingerprint overrides (#6178)
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-d authored May 17, 2022
1 parent ead8c34 commit 6b97de7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/storage/stores/tsdb/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,14 @@ func (b *Builder) Build(
for _, s := range b.streams {
streams = append(streams, s)
}

// Use the supplied fingerprints instead of hashing labels for two reasons:
// 1) Correctness: fingerprints differ from label hashes because
// we add a synthesized __loki_tennat__ label, which is eventually compacted away.
// 2) Speed: No hashing required
sort.Slice(streams, func(i, j int) bool {
if a, b := streams[i].labels.Hash(), streams[j].labels.Hash(); a != b {
return a < b
if streams[i].fp != streams[j].fp {
return streams[i].fp < streams[j].fp
}
return labels.Compare(streams[i].labels, streams[j].labels) < 0
})
Expand Down
5 changes: 5 additions & 0 deletions pkg/storage/stores/tsdb/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,12 @@ func (w *Writer) AddSeries(ref storage.SeriesRef, lset labels.Labels, fp model.F
return err
}

// Put the supplied fingerprint instead of the calculated hash.
// This allows us to have a synthetic label (__loki_tenant__) in
// the pre-compacted TSDBs which map to fingerprints (and chunks)
// without this label in storage.
labelHash := uint64(fp)

lastHash := w.lastSeriesHash
// Ensure series are sorted by the priorities: [`hash(labels)`, `labels`]
if (labelHash < lastHash && len(w.lastSeries) > 0) || labelHash == lastHash && labels.Compare(lset, w.lastSeries) < 0 {
Expand Down

0 comments on commit 6b97de7

Please sign in to comment.