Skip to content

[Detail Bug] BigQuery ingestion: concurrent dataset processing corrupts or drops table DDL (includeDDL + threads>1) #37316

Closed

Description

@detail-app

Detail Bug Report

https://app.detail.dev/org_3377c26d-da48-4ccd-b83a-22c542f4fe83/bugs/bug_54176485-99c0-4445-a2e2-ee5162928e64

Introduced in #25471 by @keshavmohta09 on Jan 23, 2026

Summary

  • Context: The BigQuery metadata ingestion source pre-fetches, per dataset, the SHOW CREATE TABLE DDL of every table in one INFORMATION_SCHEMA query and attaches those DDLs to the ingested Table entities as their schemaDefinition.
  • Bug: The per-schema prefetch cache BigquerySource._table_ddl_cache is a plain instance-level dict keyed only by bare table name and is wiped with clear() at the start of every schema's prefetch, but the databaseSchema topology node processes multiple datasets concurrently on one shared BigquerySource instance when threads > 1 — so concurrent datasets overwrite each other's DDL cache entries.
  • Actual vs. expected: While a worker is still ingesting dataset A's tables, another worker's prefetch of dataset B clears the shared cache and refills it with B's rows; A's subsequent get_schema_definition calls either return None (DDL silently dropped) or return dataset B's DDL for a same-named table, which is then published as dataset A's table definition — expected behavior is that every table gets its own dataset's DDL, as documented for the sibling caches which are keyed by fully qualified name for exactly this reason.
  • Impact: Silent data-quality corruption in the catalog: with includeDDL enabled and multiple datasets containing same-named tables (e.g. orders in sales and analytics), a table's schemaDefinition can display a CREATE TABLE statement belonging to a different dataset; simultaneously, other tables lose their DDL entirely with no error or warning.

Code with Bug

ingestion/src/metadata/ingestion/source/database/bigquery/metadata.py

def _prefetch_table_ddls(self, schema_name: str):
    """Pre-fetch all table DDLs at schema level using INFORMATION_SCHEMA"""
    if not self.source_config.includeDDL:
        return

    self._table_ddl_cache.clear()  # <-- BUG 🔴 clears shared cache while other schema threads still read it

    ...query INFORMATION_SCHEMA for THIS dataset...

    for row in results:
        self._table_ddl_cache[row.table_name] = row.ddl  # <-- BUG 🔴 key is bare table name (collides across datasets)
if self.source_config.includeDDL:
    if self.sharding_enabled:
        ...
    return self._table_ddl_cache.get(table_name)  # <-- BUG 🔴 lookup by bare name can return None or another dataset's DDL

Explanation

When threads > 1, the databaseSchema topology node processes multiple datasets concurrently using a single shared BigquerySource instance. _prefetch_table_ddls() runs once per dataset and (1) calls clear() on a shared dict and (2) stores DDLs keyed only by table_name. If another thread prefetches a different dataset while the first thread is still ingesting its tables, the second prefetch clears/refills the cache. Subsequent reads in the first thread then either miss (None, dropping DDL silently) or return the wrong dataset’s DDL when table names overlap.

Codebase Inconsistency

The same module documents that caches shared across concurrently processed schemas “must be keyed by the fully qualified name,” and sibling caches were fixed accordingly in 13acb7f0ab (#30974). _table_ddl_cache retains the unsafe wipe-and-refill + bare-name keying pattern.

Recommended Fix

Key the DDL cache by fully qualified name and avoid wiping shared state per schema; mirror the sibling-cache approach by using LRUCache and storing entries under project.dataset.table, then reading by the same FQN in get_schema_definition.

History

This bug was introduced in commit a992867320 ("Fixes #25359: Bigquery Ingestion Optimization (#25471)", 2026-01-23), which added schema-level DDL prefetching backed by a shared dict cleared/refilled per schema. A later commit (13acb7f0ab, #30974) fixed the same concurrency pattern for sibling caches but did not update _table_ddl_cache.

Activity

  1. added a commit that references this issue on Nov 18, 2026
    490513d
  2. added a commit that references this issue on Nov 19, 2026
    dbed533
  3. added a commit that references this issue on Nov 20, 2026
    3d7d95d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

  • Status
    Done ✅
  • Status
    Done ✅

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions