From 27f38a7913ac5c10b9a995f0ab7675a9518bdfd9 Mon Sep 17 00:00:00 2001 From: storyicon Date: Thu, 4 Jun 2020 20:19:21 +0800 Subject: [PATCH] improve query speed when does not enable caching (#2645) * improve query speed when does not enable caching Signed-off-by: storyicon * Update pkg/chunk/cache/tiered.go Co-authored-by: Ganesh Vernekar <15064823+codesome@users.noreply.github.com> Signed-off-by: storyicon * simplify optimization Signed-off-by: storyicon Co-authored-by: Ganesh Vernekar <15064823+codesome@users.noreply.github.com> --- cache/tiered.go | 6 ++++++ storage/caching_index_client.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cache/tiered.go b/cache/tiered.go index 27e2310cadead..bb2012ac3181b 100644 --- a/cache/tiered.go +++ b/cache/tiered.go @@ -13,6 +13,12 @@ func NewTiered(caches []Cache) Cache { return tiered(caches) } +// IsEmptyTieredCache is used to determine whether the current Cache is implemented by an empty tiered. +func IsEmptyTieredCache(cache Cache) bool { + c, ok := cache.(tiered) + return ok && len(c) == 0 +} + func (t tiered) Store(ctx context.Context, keys []string, bufs [][]byte) { for _, c := range []Cache(t) { c.Store(ctx, keys, bufs) diff --git a/storage/caching_index_client.go b/storage/caching_index_client.go index a536f5ab243c3..cf9e37f1ca8d0 100644 --- a/storage/caching_index_client.go +++ b/storage/caching_index_client.go @@ -49,7 +49,7 @@ type cachingIndexClient struct { } func newCachingIndexClient(client chunk.IndexClient, c cache.Cache, validity time.Duration, limits StoreLimits) chunk.IndexClient { - if c == nil { + if c == nil || cache.IsEmptyTieredCache(c) { return client }