Skip to content

Fixes #30973: key BigQuery dataset and table object caches per schema - #30974

Merged
ulixius9 merged 3 commits into
mainfrom
beijing
Aug 5, 2026
Merged

ulixius9 merged 3 commits into
mainfrom
beijing

Conversation

@ulixius9

@ulixius9 ulixius9 commented Aug 5, 2026

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #30973

I keyed the BigQuery get_dataset_obj and get_table_obj caches 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_obj was documented as "per-schema caching" but held a single slot with no key — once _current_dataset_obj was set it ignored schema_name entirely. Its only invalidation lived in query_table_names_and_types(), the table node's producer, which runs after the databaseSchema node 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 runs threads=True. get_table_obj is keyed by project.dataset.table (was bare table_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_dataset is still called exactly once per schema.

Type of change:

  • Bug fix

High-level design:

N/A — small change (2 files, one connector).

Tests:

Use cases covered

  • Ingesting a BigQuery project with multiple datasets stores each schema's own description, instead of the previous dataset's
  • Ingesting with includeTags stores each schema's own dataset labels, instead of inheriting tags that do not exist on that dataset in BigQuery
  • Two schemas in flight concurrently (the schema node is multi-threaded) keep their own descriptions
  • Two same-named tables in different schemas keep their own labels
  • Repeat lookups for the same schema/table still hit the cache (no extra BigQuery API calls)

Unit tests

  • I added unit tests for the new/changed logic.
  • Files updated: ingestion/tests/unit/topology/database/test_bigquery.py — new TestBigqueryPerSchemaCaching (6 tests)
  • Each of the 4 bug tests was confirmed failing before the fix, with the exact off-by-one shift, e.g. clean_mac → "Clean Identity Resolution data" and clean_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.
  • Also updated 6 pre-existing tests that set _current_dataset_obj = None to call _dataset_obj_cache.clear(); left alone they would have become silent no-ops that stop invalidating.
  • Coverage: 100% of the changed lines (__init__ cache setup, get_dataset_obj, get_table_obj) are covered — verified with --cov-report=term-missing. Module-wide coverage of bigquery/metadata.py is 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

  • Not applicable (no backend API changes).

Ingestion integration tests

Not added — the fix is in per-schema cache keying, which the unit tests cover deterministically by driving the real BigquerySource through the topology call order. An integration test would need a live multi-dataset BigQuery project.

Playwright (UI) tests

  • Not applicable (no UI changes).

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 BigquerySource through the topology's call order (schema stages → table producer) against a mocked bigquery.Client:

  1. Before the fix: 4/5 schemas received the wrong description, reproducing the reporter's screenshot value-for-value.
  2. After the fix: 0/5 wrong, and client.get_dataset is called exactly once per schema.
  3. Also confirmed the buggy behaviour returns by temporarily reinstating the unkeyed lookup, so the new tests are known to fail against the old code.

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_cache has the identical defect — keyed by bare table_name and clear()ed per schema — so at threads > 1 it can serve one schema's DDL for a same-named table in another. Outside the reported symptoms; same one-line keying change.
  • BIGQUERY_SCHEMA_DESCRIPTION in bigquery/queries.py is 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 — overrideMetadata deliberately skips REMOVE operations on tags, so already-attached wrong tags need a manual cleanup pass.

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]>
@ulixius9
ulixius9 requested a review from a team as a code owner August 5, 2026 06:04
Copilot AI review requested due to automatic review settings August 5, 2026 06:04
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This 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 skip-pr-checks label.

@github-actions github-actions Bot added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Aug 5, 2026

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.

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_obj and _current_schema_tables with bounded LRUCache instances keyed by fully-qualified names (project.dataset and project.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 LRUCache race as in get_dataset_obj: if cache_key in self._table_obj_cache followed by get() can raise KeyError if another thread evicts the entry between the two calls. Using try/except KeyError around a single get() 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]>
Copilot AI review requested due to automatic review settings August 5, 2026 06:44

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.

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: using if cache_key in self._table_obj_cache followed by get() can raise KeyError if another thread evicts the key between the two calls. Use a single get() guarded by try/except KeyError to 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)

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit 2135201c3f33813ee2a9a0954390fb98546248a0 in Playwright run 30982388651, attempt 1.

✅ 107 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky

Performance

Blocking 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:

  • Browser traffic was 211.75 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 1.76 per UI scenario (208 boots / 118 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard chromium-01 46 0 0 0 0 0
✅ Shard ingestion-01 32 0 0 0 0 0
✅ Shard ingestion-02 29 0 0 0 0 0

📦 Download artifacts

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]>
Copilot AI review requested due to automatic review settings August 5, 2026 07:49
@ulixius9

ulixius9 commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

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: LRUCache.__contains__ and LRUCache.get each acquire self.lock separately, and get calls OrderedDict.move_to_end(key), which raises KeyError when the key is absent. So a concurrent put that trips popitem(last=False) in that window makes the read raise. It matters because yield_database_schema calls get_dataset_obj outside a try block, so a KeyError there would fail the entire schema rather than degrade.

Both methods now fetch once and catch KeyError:

try:
    return self._dataset_obj_cache.get(dataset_ref)
except KeyError:
    pass

I kept the fix local rather than adding a get_or_none/get_or_default to metadata/utils/lru_cache.py — that util is shared with the lineage mixin, Trino profiler and Databricks ownership, so widening its API surface for this seemed like the larger change. Happy to move it there if a maintainer would rather have the atomic accessor available generally, since the same contains-then-get pattern exists in LRUCache.wrap.

Added a regression test per cache (test_dataset_obj_survives_entry_evicted_before_read, test_table_obj_survives_entry_evicted_before_read). Real threads can't hit this window reliably, so the tests substitute a cache subclass whose get raises KeyError to drive the eviction window deterministically; both fail with KeyError against the previous commit and pass now. test_bigquery.py is at 34 passing.

One note on severity for anyone reading the thread: the window is narrower than it looks, because __contains__ itself does move_to_end(key), promoting the key to most-recently-used, while eviction pops the least-recently-used. Evicting it would have required ~512 intervening puts inside that window. Still worth fixing — it's a real regression risk versus the single-slot code it replaced, and the fix also removes one lock acquisition per cache hit.

@gitar-bot

gitar-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

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: LRUCache.__contains__ and LRUCache.get each acquire self.lock separately, and get calls OrderedDict.move_to_end(key), which raises KeyError when the key is absent. So a concurrent put that trips popitem(last=False) in that window makes the read raise. It matters because yield_database_schema calls get_dataset_obj outside a try block, so a KeyError there would fail the entire schema rather than degrade.

Both methods now fetch once and catch KeyError:

try:
    return self._dataset_obj_cache.get(dataset_ref)
except KeyError:
    pass

I kept the fix local rather than adding a get_or_none/get_or_default to metadata/utils/lru_cache.py — that util is shared with the lineage mixin, Trino profiler and Databricks ownership, so widening its API surface for this seemed like the larger change. Happy to move it there if a maintainer would rather have the atomic accessor available generally, since the same contains-then-get pattern exists in LRUCache.wrap.

Added a regression test per cache (test_dataset_obj_survives_entry_evicted_before_read, test_table_obj_survives_entry_evicted_before_read). Real threads can't hit this window reliably, so the tests substitute a cache subclass whose get raises KeyError to drive the eviction window deterministically; both fail with KeyError against the previous commit and pass now. test_bigquery.py is at 34 passing.

One note on severity for anyone reading the thread: the window is narrower than it looks, because __contains__ itself does move_to_end(key), promoting the key to most-recently-used, while eviction pops the least-recently-used. Evicting it would have required ~512 intervening puts inside that window. Still worth fixing — it's a real regression risk versus the single-slot code it replaced, and the fix also removes one lock acquisition per cache hit.

Confirmed — the fix in d100bdb matches the description: get_dataset_obj and get_table_obj now do a single locked fetch-and-catch instead of check-then-get, and the two new regression tests correctly fail against the pre-fix code and pass now.

Agreed on keeping this fix local rather than widening LRUCache. The wrap() method has the same theoretical window, but it's lower priority to touch now since it's shared across the lineage mixin, Trino profiler, and Databricks ownership — changing its API surface for a race this narrow (needs ~512 intervening puts to actually evict the promoted key) isn't worth the blast radius here. If it's ever fixed, it'd make sense to do it as its own PR with test coverage across all wrap() call sites rather than bundling it into this BigQuery-specific change.

The severity note is a fair callout — the impact here was real (unhandled KeyError failing the whole schema) even if the reproduction window is narrow, so fixing it was the right call regardless of exact odds.

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.

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_cache are now thread-safe and keyed by fully qualified name, but _table_ddl_cache remains a shared dict that gets clear()ed per schema in _prefetch_table_ddls() and is later read by get_schema_definition() via _table_ddl_cache.get(table_name). With the schema node running threads=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 _EvictedOnReadCache docstring says entries “vanish between the lookup and the read”, but the override makes get() always raise KeyError. Rewording avoids implying a specific two-step access pattern that the production code no longer uses (it calls LRUCache.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.
    """

@sonarqubecloud

sonarqubecloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

@ulixius9
ulixius9 added this pull request to the merge queue Aug 5, 2026
Merged via the queue into main with commit 13acb7f Aug 5, 2026
111 of 115 checks passed
@ulixius9
ulixius9 deleted the beijing branch August 5, 2026 11:42
@gitar-bot

gitar-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 resolved / 1 findings

Keys 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

📄 ingestion/src/metadata/ingestion/source/database/bigquery/metadata.py:430-435 📄 ingestion/src/metadata/ingestion/source/database/bigquery/metadata.py:759-761
In get_dataset_obj and get_table_obj the pattern if key in cache: return cache.get(key) releases the lock between the __contains__ check and get(). Since the schema node runs multi-threaded, a concurrent put() that triggers LRU eviction (popitem(last=False)) could evict this key in the window, making get() raise KeyError and fail the producer. Probability is low here (dataset count typically << 512 capacity), but it is a real regression risk versus the single-slot code. Consider a get_or_none/try-except-KeyError, or add an atomic get_or_default method to LRUCache.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar | Powered by Gitar — free for open source

@ulixius9 ulixius9 mentioned this pull request Aug 12, 2026
5 tasks done
ulixius9 added a commit that referenced this pull request Aug 12, 2026
…#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)
ulixius9 added a commit that referenced this pull request Aug 12, 2026
…#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)
k-anshul pushed a commit to k-anshul/OpenMetadata that referenced this pull request Aug 12, 2026
…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]>

This branch was previously deployed

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

Labels

Ingestion safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BigQuery: dataset descriptions and labels are ingested one dataset off

3 participants