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

Improve cache getter retry #539

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/query/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ func NewCacheRequest(method string, params any, metaKey string) CacheRequest {
}
}

func (c *QueryCache) Retrieve(query *Query, metaKey string, getter func() (any, error)) (*CachedResponse, error) {
func (c *QueryCache) Retrieve(query *Query, getter func() (any, error)) (*CachedResponse, error) {
log := logger.Log()

cacheReq := NewCacheRequest(query.Method(), query.Params(), metaKey)
cacheReq := NewCacheRequest(query.Method(), query.Params(), "")

ctx, cancel := context.WithTimeout(context.Background(), 5000*time.Millisecond)
defer cancel()
Expand Down
15 changes: 7 additions & 8 deletions app/query/processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,31 +663,30 @@ func preflightCacheHook(caller *Caller, ctx context.Context) (*jsonrpc.RPCRespon
case err == nil && resp.Error == nil:
if attempt > 0 {
log.Infof(
"cache retriever %s attempt #%d succeeded (after spending %.2f seconds)",
query.Method(), attempt, time.Since(totalStart).Seconds(),
"cache retriever %s attempt #%d succeeded (after spending %.2f seconds) for %d@%s",
query.Method(), attempt, time.Since(totalStart).Seconds(), caller.userID, caller.Endpoint(),
)
QueryCacheRetrySuccesses.Observe(float64(attempt))
}
return resp, err
case err != nil:
QueryCacheRetrievalFailures.WithLabelValues(CacheRetrievalErrorNet, query.Method()).Inc()
log.Infof(
"cache retriever %s attempt #%d failed after %.3fs, err=%+v @ %s",
query.Method(), attempt, duration, err, caller.Endpoint(),
"cache retriever %s attempt #%d failed after %.3fs, err=%+v for %d@%s",
query.Method(), attempt, duration, err, caller.userID, caller.Endpoint(),
)
case resp.Error != nil:
QueryCacheRetrievalFailures.WithLabelValues(CacheRetrievalErrorSdk, query.Method()).Inc()
log.Infof(
"cache retriever %s attempt #%d failed after %.3fs, resp=%+v @ %s",
query.Method(), attempt, duration, resp.Error, caller.Endpoint(),
"cache retriever %s attempt #%d failed after %.3fs, resp=%+v @ %d@%s",
query.Method(), attempt, duration, resp.Error, caller.userID, caller.Endpoint(),
)
}
}
return resp, err
}

metaKey := fmt.Sprintf("%d@%s", caller.userID, caller.Endpoint())
cachedResp, err := caller.Cache.Retrieve(query, metaKey, getter)
cachedResp, err := caller.Cache.Retrieve(query, getter)
if err != nil {
return nil, rpcerrors.NewSDKError(err)
}
Expand Down
Loading