Skip to content
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

fix(carbonserver): grpc find - avoid unnecessary glob expansions upon responseCache hit #529

Merged
merged 1 commit into from
Feb 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 12 additions & 8 deletions carbonserver/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,19 +460,20 @@ func (listener *CarbonserverListener) Find(ctx context.Context, req *protov2.Glo
fromCache := false
var finalRes *protov2.GlobResponse
var lookups uint32
expandedGlobs, _, err := listener.getExpandedGlobsWithCache(ctx, logger, "find", []string{query})
if err != nil {
return nil, err
}

if listener.findCacheEnabled {
key := query + "&" + format + "grpc"
size := uint64(100 * 1024 * 1024)
var result interface{}
result, fromCache, err = getWithCache(logger, listener.findCache, key, size, 300,
func() (interface{}, error) {
finalRes = getProtoV2FindResponse(expandedGlobs[0], query)
expandedGlobs, _, err := listener.getExpandedGlobsWithCache(ctx, logger, "find", []string{query})
if err != nil {
return nil, err
}
listener.populateMetricsFoundStat(expandedGlobs)
lookups = expandedGlobs[0].Lookups
finalRes = getProtoV2FindResponse(expandedGlobs[0], query)
return finalRes, nil
})
if err == nil {
Expand All @@ -485,8 +486,13 @@ func (listener *CarbonserverListener) Find(ctx context.Context, req *protov2.Glo
finalRes = result.(*protov2.GlobResponse)
}
} else if err == nil {
finalRes = getProtoV2FindResponse(expandedGlobs[0], query)
expandedGlobs, _, err := listener.getExpandedGlobsWithCache(ctx, logger, "find", []string{query})
if err != nil {
return nil, err
}
listener.populateMetricsFoundStat(expandedGlobs)
lookups = expandedGlobs[0].Lookups
finalRes = getProtoV2FindResponse(expandedGlobs[0], query)
}

if len(finalRes.Matches) == 0 {
Expand Down Expand Up @@ -519,8 +525,6 @@ func (listener *CarbonserverListener) Find(ctx context.Context, req *protov2.Glo
atomic.AddUint64(&listener.metrics.FindZero, 1)
}

listener.populateMetricsFoundStat(expandedGlobs)

accessLogger.Info("find success",
zap.Duration("runtime_seconds", time.Since(t0)),
zap.Int("Files", len(finalRes.Matches)),
Expand Down