Repository navigation
fix(ingestion): cache Query and User lookups during usage ingestion - #32254
Conversation
…ap _get_or_create_query with a SkipNoneLRUCache keyed by query hash sorepeated tables referencing the same SQL skip the redundant GET/PUT, whilenever caching a miss (another table may have just created the Query).Add get_cached_user_reference, backed by an LRUCache keyed by username,shared between the staging get_by_name(User) call and the lifecycleget_entity_reference(User) call, caching misses too since a user absentat the start of a run will not appear mid-run.Fixes open-metadata#32210
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
|
Hi maintainers, the PR checklist is blocked on the linked issue (#32210) being added to the Shipping project, which I don't have permission to do myself. Could someone add it when you get a chance? Happy to push a follow-up commit to re-trigger the check once that's done. |
…cached User EntityReference in staging, fixing a bug where a model object was passed to CreateQueryRequest(users=...) instead of a string.- Scope Query and User reference caches per-OpenMetadata-client-instance instead of at the class level, so multiple clients/catalogs in the same process never share cached data.- Reduce cache sizes from 4096 to 1000 to match repo convention.
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
Cover failed query lookup and creation retries, and align the cache changes with current Python formatting.
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
🚦 Removed from the merge queue —
|
🚦 Removed from the merge queue —
|
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
Code Review ✅ Approved 2 closed / 2 findings🟡 Medium risk · Usage ingestion caches Query and User lookups, altering repeated entity resolution. Adds LRU caching for Query and User lookups during usage ingestion to eliminate redundant API calls. The implementation correctly scopes caches to individual OpenMetadata clients, handles cache misses appropriately for Queries, and fixes the EntityReference.fullyQualifiedName issue and class-level cache persistence that were blocking this change. ✅ 2 closed✅ Bug: Missing .root on EntityReference.fullyQualifiedName in _get_user_entity
✅ Bug: Class-level caches persist across ingestion runs, leaking stale data
OptionsDisplay: compact → Counting what did not apply, without listing it. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|
1d71430



Fixes #32210
Summary
_get_or_create_querywith aSkipNoneLRUCachekeyed by query hash, so repeated tables referencing the same SQL skip the redundant GET/PUT. A miss is never cached, since another table in the same run may create the Query moments later.get_cached_user_reference, backed by anLRUCachekeyed by username, shared between the stagingget_by_name(User)call intable_usage.pyand the lifecycleget_entity_reference(User)call inmetadata_usage.py. Misses are cached too, since a user absent from OpenMetadata at the start of a run won't appear mid-run.Both use the existing
metadata.utils.lru_cacheutilities as suggested in the issue, rather than adding a new dependency.Note on a deliberate tradeoff
The Query cache's key function excludes
self, so the cache is shared process-wide across allOMetaQueryMixin/OpenMetadatainstances rather than per-instance (unlike the existing__get_query_by_hash, which uses plain@lru_cacheand is per-instance sinceselfis part of the key). In practice a usage run typically uses a singleOpenMetadataclient, so this should be a non-issue, but flagging it explicitly in case a different approach is preferred.Tests
tests/unit/metadata/ingestion/ometa/test_usage_caching.pycovering: Query cache hit on repeat lookup, miss-not-cached behavior for Queries, User cache hit and miss-cached behavior, and independent caching per name.test_metadata_usage.py(21 passed),test_user_mixin.py(included above),test_life_cycle_query_mixin.py(4 passed).The cache implementation appears functionally safe, but the repository’s explicit testing requirement must be satisfied before merging.
Findings
Summary
This PR reduces redundant OpenMetadata API calls during usage ingestion by adding bounded, client-scoped caches for Query entities and User references.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR U[Usage record] --> Q{Query cached?} Q -->|Yes| QE[Reuse Query entity] Q -->|No| QL[Lookup or create Query] QL -->|Found or created| QC[Cache per client] QL -->|Missing| QN[Return None without caching] U --> R{User reference cached?} R -->|Yes| UR[Reuse reference or cached miss] R -->|No| UL[Lookup User reference] UL --> UC[Cache result per client]Reviews (4) · Last reviewed commit: "Merge branch 'main' into fix-usage-cachi..."