From 1e74c155eb3ff4980928d63d7ce861304957325f Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Mon, 26 Jun 2017 14:58:00 +0200 Subject: [PATCH] Return empty string to signal non-caching --- db.go | 4 ++++ head.go | 6 ++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/db.go b/db.go index 80a335c17..17f3e5f5f 100644 --- a/db.go +++ b/db.go @@ -80,6 +80,7 @@ type Appender interface { // Returned reference numbers are ephemeral and may be rejected in calls // to AddFast() at any point. Adding the sample via Add() returns a new // reference number. + // If the reference is the empty string it must not be used for caching. Add(l labels.Labels, t int64, v float64) (string, error) // Add adds a sample pair for the referenced series. It is generally faster @@ -616,6 +617,9 @@ func (a *dbAppender) Add(lset labels.Labels, t int64, v float64) (string, error) } a.samples++ + if ref == "" { + return "", nil + } return string(append(h.meta.ULID[:], ref...)), nil } diff --git a/head.go b/head.go index d64c4eda5..90e03f727 100644 --- a/head.go +++ b/head.go @@ -450,7 +450,7 @@ func (a *headAppender) Add(lset labels.Labels, t int64, v float64) (string, erro // XXX(fabxc): there's no fast path for multiple samples for the same new series // in the same transaction. We always return the invalid empty ref. It's has not // been a relevant use case so far and is not worth the trouble. - return nullRef, a.AddFast(string(refb), t, v) + return "", a.AddFast(string(refb), t, v) } // The series is completely new. @@ -471,11 +471,9 @@ func (a *headAppender) Add(lset labels.Labels, t int64, v float64) (string, erro a.newHashes[hash] = ref binary.BigEndian.PutUint64(refb, ref) - return nullRef, a.AddFast(string(refb), t, v) + return "", a.AddFast(string(refb), t, v) } -var nullRef = string([]byte{0, 0, 0, 0, 0, 0, 0, 0}) - func (a *headAppender) AddFast(ref string, t int64, v float64) error { if len(ref) != 8 { return errors.Wrap(ErrNotFound, "invalid ref length")