Skip to content
Closed
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
11 changes: 11 additions & 0 deletions router/core/graph_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,8 @@ type graphMux struct {
mux *chi.Mux
reused atomic.Bool

planCacheOnEvictEnabled atomic.Bool

planCache *ristretto.Cache[uint64, *planWithMetaData]
planFallbackCache *slowplancache.Cache[*planWithMetaData]
persistedOperationCache *ristretto.Cache[uint64, NormalizationCacheEntry]
Expand Down Expand Up @@ -721,10 +723,14 @@ func (s *graphMux) buildOperationCaches(srv *graphServer) (computeSha256 bool, e
BufferItems: 64,
}
if srv.cacheWarmup != nil && srv.cacheWarmup.Enabled && srv.cacheWarmup.InMemoryFallback {
s.planCacheOnEvictEnabled.Store(true)
planCacheConfig.OnEvict = func(item *ristretto.Item[*planWithMetaData]) {
// This could be called before planFallbackCache is set, but it's not a problem
// because there is a nil guard inside, as well as items should not really be evicted
// on startup
if !s.planCacheOnEvictEnabled.Load() {
return
}
s.planFallbackCache.Set(item.Key, item.Value, item.Value.planningDuration)
}
}
Expand Down Expand Up @@ -961,6 +967,11 @@ func (s *graphMux) Shutdown(ctx context.Context) error {
// cancel the graph muxes context to close its resources like websocket connections, resolvers, etc.
s.cancel()

// ristretto Close() invokes OnEvict for every entry; skip slow-cache migration during shutdown.
s.planCacheOnEvictEnabled.Store(false)
if s.planFallbackCache != nil {
s.planFallbackCache.Wait()
}
Comment on lines +972 to +974

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I don't think we need to wait for pending writes to the cache at this point because we are about to delete the cache anyways.

s.planCache.Close()
s.planFallbackCache.Close()
s.persistedOperationCache.Close()
Expand Down
Loading