From 107b7a9cf52b608ef48f7a6ed62d62157ec8162f Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 25 Jun 2019 15:59:50 +0000 Subject: [PATCH] Avoid writing duplicate chunks by checking the cache first Signed-off-by: Bryan Boreham --- pkg/chunk/series_store.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/chunk/series_store.go b/pkg/chunk/series_store.go index 11ac736a144..5462a0fc38f 100644 --- a/pkg/chunk/series_store.go +++ b/pkg/chunk/series_store.go @@ -341,6 +341,12 @@ func (c *seriesStore) Put(ctx context.Context, chunks []Chunk) error { // PutOne implements ChunkStore func (c *seriesStore) PutOne(ctx context.Context, from, through model.Time, chunk Chunk) error { + // If this chunk is in cache it must already be in the database so we don't need to write it again + found, _, _ := c.cache.Fetch(ctx, []string{chunk.ExternalKey()}) + if len(found) > 0 { + return nil + } + chunks := []Chunk{chunk} writeReqs, keysToCache, err := c.calculateIndexEntries(from, through, chunk)