Skip to content

Conversation

@oneonestar
Copy link
Member

Description

Migrate from Guava Cache to Caffeine.

Motivation:
#783 (comment)

Additional context and related issues

Removed the call to setRoutingGroupForQueryId() and setExternalUrlForQueryId() because cache.get() already insert the value into the cache if absent.

Release notes

(x) This is not user-visible or is docs only, and no release notes are required.

@oneonestar oneonestar requested a review from Copilot December 12, 2025 05:40
@cla-bot cla-bot bot added the cla-signed label Dec 12, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the caching implementation from Guava Cache to Caffeine, a modern caching library with better performance characteristics. The migration affects two main classes: TrinoRequestUser and BaseRoutingManager, where cache loading logic is simplified and exception handling is updated to catch RuntimeException instead of ExecutionException.

Key Changes:

  • Replaced Guava Cache imports with Caffeine cache imports
  • Simplified cache loading syntax using method references
  • Updated exception handling from ExecutionException to RuntimeException

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
gateway-ha/src/main/java/io/trino/gateway/ha/router/TrinoRequestUser.java Updated imports and simplified cache builder initialization with method reference
gateway-ha/src/main/java/io/trino/gateway/ha/router/BaseRoutingManager.java Migrated cache implementation, removed redundant cache insertion calls, and simplified cache loader using method reference
gateway-ha/pom.xml Added Caffeine dependency version 3.2.3

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@Peiyingy Peiyingy left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks so much for making this change

Copy link
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

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

In Trino, we intentionally avoid Caffeine (see trinodb/trino#10512 (comment)). Please hold off on this PR until we reach consensus.

@xkrogen
Copy link
Member

xkrogen commented Dec 12, 2025

@ebyhr I don't think the discussion from that issue is relevant here. GW cache doesn't have any invalidations to be concerned about. Even if we did have such concerns, GW is using the plain Guava cache, not Trino's EvictableCache, so (a) we are already not standardized, and (b) the behavior will at least be improved when moving from Guava to Caffeine.

I see two options here:

  • Move to Caffeine -- This lets GW use the current best known in-memory Java caching solution, at the cost of some divergence from Trino (though no worse than the current situation).
  • Move to EvictableCache -- trino-cache is already exposed as a separate module which we could pull in here. This at least unifies the implementation, so that any future improvements in Trino (e.g. moving the underlying implementation to Caffeine) will benefit GW as well.

Leaving things as-is only provides the illusion of standardization across Trino / GW ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants