-
Notifications
You must be signed in to change notification settings - Fork 833
Implement result cache for tenant query federation #3640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package purger | |
import ( | ||
"context" | ||
"sort" | ||
"strconv" | ||
"sync" | ||
"time" | ||
|
||
|
@@ -246,14 +247,64 @@ func (tl *TombstonesLoader) loadPendingTombstones(userID string) error { | |
} | ||
|
||
// GetStoreCacheGenNumber returns store cache gen number for a user | ||
func (tl *TombstonesLoader) GetStoreCacheGenNumber(userID string) string { | ||
return tl.getCacheGenNumbers(userID).store | ||
|
||
func (tl *TombstonesLoader) GetStoreCacheGenNumber(tenantIDs []string) string { | ||
return tl.getCacheGenNumbersPerTenants(tenantIDs).store | ||
} | ||
|
||
// GetResultsCacheGenNumber returns results cache gen number for a user | ||
func (tl *TombstonesLoader) GetResultsCacheGenNumber(userID string) string { | ||
return tl.getCacheGenNumbers(userID).results | ||
func (tl *TombstonesLoader) GetResultsCacheGenNumber(tenantIDs []string) string { | ||
return tl.getCacheGenNumbersPerTenants(tenantIDs).results | ||
} | ||
|
||
func (tl *TombstonesLoader) getCacheGenNumbersPerTenants(tenantIDs []string) *cacheGenNumbers { | ||
var result cacheGenNumbers | ||
|
||
if len(tenantIDs) == 0 { | ||
return &result | ||
} | ||
|
||
// keep the maximum value that's currently in result | ||
var maxResults, maxStore int | ||
|
||
for pos, tenantID := range tenantIDs { | ||
numbers := tl.getCacheGenNumbers(tenantID) | ||
|
||
// handle first tenant in the list | ||
if pos == 0 { | ||
// short cut if there is only one tenant | ||
if len(tenantIDs) == 1 { | ||
return numbers | ||
} | ||
|
||
// set first tenant string whatever happens next | ||
result.results = numbers.results | ||
result.store = numbers.store | ||
} | ||
|
||
// set results number string if it's higher than the ones before | ||
if numbers.results != "" { | ||
results, err := strconv.Atoi(numbers.results) | ||
|
||
if err != nil { | ||
level.Error(util.Logger).Log("msg", "error parsing resultsCacheGenNumber", "tenant", tenantID, "err", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Across the code base, the tenant ID is logged with the field name Same comment applies below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point see: #3680 |
||
} else if maxResults < results { | ||
maxResults = results | ||
result.results = numbers.results | ||
} | ||
} | ||
|
||
// set store number string if it's higher than the ones before | ||
if numbers.store != "" { | ||
store, err := strconv.Atoi(numbers.store) | ||
if err != nil { | ||
level.Error(util.Logger).Log("msg", "error parsing storeCacheGenNumber", "tenant", tenantID, "err", err) | ||
} else if maxStore < store { | ||
maxStore = store | ||
result.store = numbers.store | ||
} | ||
} | ||
} | ||
|
||
return &result | ||
} | ||
|
||
func (tl *TombstonesLoader) getCacheGenNumbers(userID string) *cacheGenNumbers { | ||
|
Uh oh!
There was an error while loading. Please reload this page.