Skip to content

Commit

Permalink
Merge pull request #529 from go-graphite/atimofieiev/grpc-find-avoid-…
Browse files Browse the repository at this point in the history
…unnecessary-expand

fix(carbonserver): grpc find - avoid unnecessary glob expansions upon responseCache hit
  • Loading branch information
timtofan committed Feb 13, 2023
2 parents 2cb449c + 23be459 commit 85bafd2
Showing 1 changed file with 12 additions and 8 deletions.
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

0 comments on commit 85bafd2

Please sign in to comment.