Repository navigation
Conversation
get_dataset_obj was a single-slot cache with no key: once populated it ignored schema_name and returned the previously fetched dataset. Its only invalidation lived in the table node's producer, which runs after the schema node has already emitted that schema's description and tags, so every schema was stored with the previous dataset's description and labels. Key both caches by fully qualified name using the existing thread-safe bounded LRUCache, and drop the manual invalidations: they caused the off-by-one and, being unsynchronized, could wipe a concurrent thread's entry while the schema node runs multi-threaded. get_table_obj is now keyed by project.dataset.table so same-named tables in different schemas no longer share a cached object. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
There was a problem hiding this comment.
Pull request overview
This PR fixes a BigQuery ingestion bug where schema (dataset) descriptions and labels could be shifted onto the next schema due to effectively unkeyed single-slot caching, and updates unit tests to assert correct per-schema/per-table cache behavior (including concurrent schema processing).
Changes:
- Replace
_current_dataset_objand_current_schema_tableswith boundedLRUCacheinstances keyed by fully-qualified names (project.datasetandproject.dataset.table). - Remove per-schema manual cache invalidations that caused off-by-one behavior and were unsafe under
threads=True. - Add/adjust unit tests to validate correct cache scoping and that API-call savings are preserved.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| ingestion/src/metadata/ingestion/source/database/bigquery/metadata.py | Key dataset/table object caches by fully-qualified name using bounded LRUCache; remove unsafe invalidation logic. |
| ingestion/tests/unit/topology/database/test_bigquery.py | Update existing tests to clear the new caches; add a new test class covering the off-by-one regression, per-schema scoping, and cache hit behavior. |
Suppressed comments (1)
ingestion/src/metadata/ingestion/source/database/bigquery/metadata.py:767
- Same
LRUCacherace as inget_dataset_obj:if cache_key in self._table_obj_cachefollowed byget()can raiseKeyErrorif another thread evicts the entry between the two calls. Usingtry/except KeyErroraround a singleget()avoids intermittent ingestion failures under concurrent schema processing.
cache_key = f"{database}.{schema_name}.{table_name}"
if cache_key in self._table_obj_cache:
return self._table_obj_cache.get(cache_key)
logger.debug(f"Fetching table object for {cache_key} using BigQuery API")
bq_table_fqn = fqn._build(database, schema_name, table_name)
table_obj = self.client.get_table(bq_table_fqn)
self._table_obj_cache.put(cache_key, table_obj)
Both accesses existed before and were grandfathered in .basedpyright/baseline.json; rewriting the method moved them, so they no longer matched the baseline and static-checks failed on 3.10. Suppress inline with the idiom already used elsewhere in this file rather than regenerating the baseline. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
ingestion/src/metadata/ingestion/source/database/bigquery/metadata.py:762
- Same concurrency issue as
get_dataset_obj: usingif cache_key in self._table_obj_cachefollowed byget()can raiseKeyErrorif another thread evicts the key between the two calls. Use a singleget()guarded bytry/except KeyErrorto make the cache read atomic.
cache_key = f"{database}.{schema_name}.{table_name}"
if cache_key in self._table_obj_cache:
return self._table_obj_cache.get(cache_key)
✅ Playwright Results — workflow succeededValidated commit ✅ 107 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky PerformanceBlocking targets: ✅ met · Optimization targets: 🟡 in progress Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting. 🕒 Full workflow signal wall (to summary) 51m 0s ⏱️ Max setup 3m 3s · max shard execution 11m 42s · max shard-job elapsed before upload 16m 31s · reporting 4s 🌐 211.75 requests/attempt · 1.76 app boots/UI scenario · 0.00% common-shard skew Optimization targets still in progress:
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
Addresses review feedback from copilot-pull-request-reviewer and gitar-bot. LRUCache locks each operation separately, so the check-then-get pattern left a window where a concurrent put that triggers eviction could drop the key between __contains__ and get, making get raise KeyError. yield_database_schema calls get_dataset_obj outside a try block, so that would have failed the whole schema. Fetch once and catch KeyError instead. Adds a test per cache that drives the eviction window deterministically, since real threads cannot reproduce it reliably. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Thanks both — @copilot-pull-request-reviewer and @gitar-bot independently flagged the same check-then-get race, and it's a valid finding. Fixed in d100bdb. Confirming the mechanism: Both methods now fetch once and catch try:
return self._dataset_obj_cache.get(dataset_ref)
except KeyError:
passI kept the fix local rather than adding a Added a regression test per cache ( One note on severity for anyone reading the thread: the window is narrower than it looks, because |
Confirmed — the fix in d100bdb matches the description: Agreed on keeping this fix local rather than widening The severity note is a fair callout — the impact here was real (unhandled |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)
ingestion/src/metadata/ingestion/source/database/bigquery/metadata.py:256
_table_obj_cache/_dataset_obj_cacheare now thread-safe and keyed by fully qualified name, but_table_ddl_cacheremains a shared dict that getsclear()ed per schema in_prefetch_table_ddls()and is later read byget_schema_definition()via_table_ddl_cache.get(table_name). With the schema node runningthreads=True, concurrent schemas can wipe/overwrite each other’s DDL entries and return the wrong DDL for a table.
Consider keying the DDL cache by fully qualified name (e.g., project.dataset.table) and avoiding per-schema clear(), or converting _table_ddl_cache to an LRUCache as well.
self._table_obj_cache: LRUCache = LRUCache(capacity=TABLE_OBJ_CACHE_SIZE)
self._dataset_obj_cache: LRUCache = LRUCache(capacity=DATASET_OBJ_CACHE_SIZE)
self._policy_tag_cache = {}
self._taxonomy_cache = {}
self._taxonomy_to_tags = {}
self._table_ddl_cache = {}
self._policy_tag_client = None
ingestion/tests/unit/topology/database/test_bigquery.py:997
- The
_EvictedOnReadCachedocstring says entries “vanish between the lookup and the read”, but the override makesget()always raiseKeyError. Rewording avoids implying a specific two-step access pattern that the production code no longer uses (it callsLRUCache.get()directly).
"""An LRUCache whose entries vanish between the lookup and the read.
Stands in for another ingestion thread evicting the key in that window, which is not
reproducible deterministically with real threads.
"""
|
Code Review ✅ Approved 1 resolved / 1 findingsKeys BigQuery dataset and table object caches per schema using thread-safe LRUCache instances, addressing the check-then-get race condition. No issues found. ✅ 1 resolved✅ Edge Case: Check-then-get on LRUCache is not atomic under threads
OptionsDisplay: compact → Showing less information. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar | Powered by Gitar — free for open source |
…#30974) * Fixes #30973: key BigQuery dataset and table object caches per schema get_dataset_obj was a single-slot cache with no key: once populated it ignored schema_name and returned the previously fetched dataset. Its only invalidation lived in the table node's producer, which runs after the schema node has already emitted that schema's description and tags, so every schema was stored with the previous dataset's description and labels. Key both caches by fully qualified name using the existing thread-safe bounded LRUCache, and drop the manual invalidations: they caused the off-by-one and, being unsynchronized, could wipe a concurrent thread's entry while the schema node runs multi-threaded. get_table_obj is now keyed by project.dataset.table so same-named tables in different schemas no longer share a cached object. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * Suppress basedpyright errors surfaced by the reworked get_dataset_obj Both accesses existed before and were grandfathered in .basedpyright/baseline.json; rewriting the method moved them, so they no longer matched the baseline and static-checks failed on 3.10. Suppress inline with the idiom already used elsewhere in this file rather than regenerating the baseline. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * Read the BigQuery object caches in a single locked operation Addresses review feedback from copilot-pull-request-reviewer and gitar-bot. LRUCache locks each operation separately, so the check-then-get pattern left a window where a concurrent put that triggers eviction could drop the key between __contains__ and get, making get raise KeyError. yield_database_schema calls get_dataset_obj outside a try block, so that would have failed the whole schema. Fetch once and catch KeyError instead. Adds a test per cache that drives the eviction window deterministically, since real threads cannot reproduce it reliably. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit 13acb7f)
…#30974) * Fixes #30973: key BigQuery dataset and table object caches per schema get_dataset_obj was a single-slot cache with no key: once populated it ignored schema_name and returned the previously fetched dataset. Its only invalidation lived in the table node's producer, which runs after the schema node has already emitted that schema's description and tags, so every schema was stored with the previous dataset's description and labels. Key both caches by fully qualified name using the existing thread-safe bounded LRUCache, and drop the manual invalidations: they caused the off-by-one and, being unsynchronized, could wipe a concurrent thread's entry while the schema node runs multi-threaded. get_table_obj is now keyed by project.dataset.table so same-named tables in different schemas no longer share a cached object. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * Suppress basedpyright errors surfaced by the reworked get_dataset_obj Both accesses existed before and were grandfathered in .basedpyright/baseline.json; rewriting the method moved them, so they no longer matched the baseline and static-checks failed on 3.10. Suppress inline with the idiom already used elsewhere in this file rather than regenerating the baseline. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * Read the BigQuery object caches in a single locked operation Addresses review feedback from copilot-pull-request-reviewer and gitar-bot. LRUCache locks each operation separately, so the check-then-get pattern left a window where a concurrent put that triggers eviction could drop the key between __contains__ and get, making get raise KeyError. yield_database_schema calls get_dataset_obj outside a try block, so that would have failed the whole schema. Fetch once and catch KeyError instead. Adds a test per cache that drives the eviction window deterministically, since real threads cannot reproduce it reliably. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit 13acb7f)
…es per schema (open-metadata#30974) * Fixes open-metadata#30973: key BigQuery dataset and table object caches per schema get_dataset_obj was a single-slot cache with no key: once populated it ignored schema_name and returned the previously fetched dataset. Its only invalidation lived in the table node's producer, which runs after the schema node has already emitted that schema's description and tags, so every schema was stored with the previous dataset's description and labels. Key both caches by fully qualified name using the existing thread-safe bounded LRUCache, and drop the manual invalidations: they caused the off-by-one and, being unsynchronized, could wipe a concurrent thread's entry while the schema node runs multi-threaded. get_table_obj is now keyed by project.dataset.table so same-named tables in different schemas no longer share a cached object. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * Suppress basedpyright errors surfaced by the reworked get_dataset_obj Both accesses existed before and were grandfathered in .basedpyright/baseline.json; rewriting the method moved them, so they no longer matched the baseline and static-checks failed on 3.10. Suppress inline with the idiom already used elsewhere in this file rather than regenerating the baseline. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * Read the BigQuery object caches in a single locked operation Addresses review feedback from copilot-pull-request-reviewer and gitar-bot. LRUCache locks each operation separately, so the check-then-get pattern left a window where a concurrent put that triggers eviction could drop the key between __contains__ and get, making get raise KeyError. yield_database_schema calls get_dataset_obj outside a try block, so that would have failed the whole schema. Fetch once and catch KeyError instead. Adds a test per cache that drives the eviction window deterministically, since real threads cannot reproduce it reliably. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>



Describe your changes:
Fixes #30973
I keyed the BigQuery
get_dataset_objandget_table_objcaches by fully qualified name because both were effectively unkeyed, so every database schema was ingested with the previous dataset's description and labels.get_dataset_objwas documented as "per-schema caching" but held a single slot with no key — once_current_dataset_objwas set it ignoredschema_nameentirely. Its only invalidation lived inquery_table_names_and_types(), the table node's producer, which runs after thedatabaseSchemanode has already emitted that schema's tags and description; the table/stored-procedure stage then refilled the slot with the current schema, so the next schema read the previous one's dataset object. Regression from #25471.Both caches now use the existing thread-safe bounded
LRUCache(metadata/utils/lru_cache.py), and the manual invalidations are gone: they caused the off-by-one and, being unsynchronized instance attributes, could wipe a concurrent thread's entry while the schema node runsthreads=True.get_table_objis keyed byproject.dataset.table(was baretable_name), so same-named tables in different schemas no longer share a cached object. Fixing the keying rather than moving the reset earlier is deliberate — moving it would leave the thread-safety hole. The per-call API savings the original optimization added are preserved:get_datasetis still called exactly once per schema.Type of change:
High-level design:
N/A — small change (2 files, one connector).
Tests:
Use cases covered
includeTagsstores each schema's own dataset labels, instead of inheriting tags that do not exist on that dataset in BigQueryUnit tests
ingestion/tests/unit/topology/database/test_bigquery.py— newTestBigqueryPerSchemaCaching(6 tests)clean_mac→"Clean Identity Resolution data"andclean_recon→"Clean MAC data". The 2 remaining tests guard the caching behaviour itself so a future "just drop the cache" fix cannot regress the API-call savings._current_dataset_obj = Noneto call_dataset_obj_cache.clear(); left alone they would have become silent no-ops that stop invalidating.__init__cache setup,get_dataset_obj,get_table_obj) are covered — verified with--cov-report=term-missing. Module-wide coverage ofbigquery/metadata.pyis 38%, which is pre-existing and unchanged by this PR.test_bigquery.py: 32 passed. All four BigQuery test files: 81 passed.Backend integration tests
Ingestion integration tests
Not added — the fix is in per-schema cache keying, which the unit tests cover deterministically by driving the real
BigquerySourcethrough the topology call order. An integration test would need a live multi-dataset BigQuery project.Playwright (UI) tests
Manual testing performed
No live BigQuery run — I do not have access to the reporter's project. Verification was a standalone reproduction script that drives the real
BigquerySourcethrough the topology's call order (schema stages → table producer) against a mockedbigquery.Client:client.get_datasetis called exactly once per schema.UI screen recording / screenshots:
Not applicable.
Checklist:
I have read the CONTRIBUTING document.
My PR title is
Fixes <issue-number>: <short explanation>My PR is linked to a GitHub issue via
Fixes #<issue-number>above.I have commented on my code, particularly in hard-to-understand areas.
For JSON Schema changes: not applicable, no schema changes.
For UI changes: not applicable, no UI changes.
I have added tests (unit / integration / Playwright as applicable) and listed them above.
I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.
Notes for the reviewer
Two related items I deliberately left out of this PR, happy to fold either in:
_table_ddl_cachehas the identical defect — keyed by baretable_nameandclear()ed per schema — so atthreads > 1it can serve one schema's DDL for a same-named table in another. Outside the reported symptoms; same one-line keying change.BIGQUERY_SCHEMA_DESCRIPTIONinbigquery/queries.pyis the correct pre-Fixes #25359: Bigquery Ingestion Optimization #25471 SQL lookup and is now dead code.Deploying this fix stops new corruption, but existing wrong values need one re-ingestion with Override Metadata enabled to be rewritten. The phantom tags will not clear themselves —
overrideMetadatadeliberately skips REMOVE operations ontags, so already-attached wrong tags need a manual cleanup pass.