Skip to content

Commit

Permalink
Merge pull request #539 from OdyseeTeam/improve-cache-getter-retry
Browse files Browse the repository at this point in the history
Improve cache getter retry
  • Loading branch information
anbsky authored Jan 24, 2025
2 parents 087513e + 9eb16cc commit 8e3cc91
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
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

0 comments on commit 8e3cc91

Please sign in to comment.