Skip to content

HIVE-29818: ServletSecurity needs a UGI cache - #6704

Open
henrib wants to merge 1 commit into
apache:masterfrom
henrib:HIVE-29818
Open

HIVE-29818: ServletSecurity needs a UGI cache#6704
henrib wants to merge 1 commit into
apache:masterfrom
henrib:HIVE-29818

Conversation

@henrib

@henrib henrib commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

The REST Catalog creates a fresh proxy UserGroupInformation per request via UserGroupInformation.createProxyUser. Hadoop's FileSystem.CACHE retains a reference to every such UGI (and its RPC/IPC resources), so under proxy authentication these short-lived UGIs accumulate and eventually exhaust memory in long-running deployments.

This PR caches the proxy UGI in ServletSecurity using a bounded, idle-evicting Caffeine cache keyed by (realUser, loginUser). Evicted entries release their resources via FileSystem.closeAllForUGI. Two new config vars tune the cache:

  • metastore.catalog.servlet.ugi.cache.size (default 1000)
  • metastore.catalog.servlet.ugi.cache.expiry (default 3600s, 0 disables expiry)

A note in the code documents why eviction-while-in-use is not reference-counted: eviction is idle-based (expireAfterAccess) and both the expiry window and max size are expected to be kept well above the longest operation / peak concurrent distinct users.

Why are the changes needed?

To prevent the OutOfMemoryError caused by unbounded accumulation of proxy UGIs and their associated FileSystem/IPC resources in long-running REST Catalog deployments.

Does this PR introduce any user-facing change?

Two new (optional) metastore configuration properties, both with sensible defaults.

How was this patch tested?

Added TestServletSecurity covering per-user caching, distinct proxies per user, eviction-triggered FileSystem.closeAllForUGI cleanup, and disabled expiry. All 4 tests pass.

The REST Catalog creates a fresh proxy UserGroupInformation per request via
UserGroupInformation.createProxyUser. Hadoop's FileSystem.CACHE retains a
reference to every such UGI (and its RPC/IPC resources), so under proxy
authentication these short-lived UGIs accumulate and eventually exhaust memory
in long-running deployments.

Cache the proxy UGI in ServletSecurity with a bounded, idle-evicting Caffeine
cache keyed by (realUser, loginUser). Evicted entries release their resources
via FileSystem.closeAllForUGI. Two new config vars tune the cache:
  - metastore.catalog.servlet.ugi.cache.size   (default 1000)
  - metastore.catalog.servlet.ugi.cache.expiry (default 3600s, 0 disables)

Add TestServletSecurity covering per-user caching, distinct proxies per user,
eviction-triggered FileSystem cleanup, and disabled expiry.
Copilot AI lite review requested due to automatic review settings August 17, 2026 15:38

Copilot AI left a comment

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants