← Back to Pull requests

fix(metadata): drop removed schema ids from the builder's schema index #1012

Closed
unknown closed this pull request without merging on Oct 21, 2026 16:03 UTC
View on GitHub
unknown unknown commented on Oct 14, 2026 05:05 UTC
Author

What

TableMetadataBuilder::Impl::RemoveSchemas removed schemas from metadata_.schemas but left them in schemas_by_id_, so later calls on the same builder still resolved the removed ids.

Transaction applies all of its updates to one builder, so this was reachable through the public API. Take a table whose current schema is 0 and whose schema 1 is unused, for example because a column was added and then dropped. In one transaction, ExpireSnapshots with CleanExpiredMetadata(true) removes schema 1, and UpdateSchema::AddColumn then produces a new schema that gets the freed id 1. AddSchema finds id 1 in the stale index and does not add the new schema to schemas, and SetCurrentSchema(1) picks up the removed schema instead. Without this fix the commit succeeds and writes current-schema-id: 1 with only schema 0 in schemas, and the next LoadTable fails with Cannot find schema with current-schema-id=1.

The same stale entry let SetCurrentSchema accept a removed id directly, so a catalog commit carrying [remove-schemas, set-current-schema] for that id wrote the same kind of file.

Closes #1011.

How

Erase the removed ids from schemas_by_id_ alongside the existing filter of metadata_.schemas.

This is stricter than Java. Java's Builder.removeSchemas leaves schemasById stale, so setCurrentSchema on a removed id still succeeds there, and build() returns metadata whose current-schema-id is not in schemas. In C++ the same sequence makes Build() fail with Cannot set current schema to unknown schema.

Testing

  • ExpireUnusedSchemaThenAddColumn in transaction_test.cc runs the transaction above against InMemoryCatalog. Without the fix Commit() succeeds and reloading the table fails with Cannot find schema with current-schema-id=1. With the fix the reloaded current schema is 1 and has the added column.

  • RemoveSchemasDropsIndexEntry in table_metadata_builder_test.cc: after RemoveSchemas({1}), SetCurrentSchema(1) makes Build() fail with Cannot set current schema to unknown schema: 1. Without the fix Build() returns metadata with the dangling id.

  • AddSchemaAfterRemoveNotConfusedByStaleIndex in table_metadata_builder_test.cc: re-adding the removed schema puts it back in schemas. Without the fix the stale index entry makes AddSchema skip it and schemas stays at one entry.
  • RemovePartitionSpecs has the same gap with specs_by_id_; I'll send that separately.

    Diff: 309 lines (+231 / -78) across 3 files Reviewer: LuciferYang Review duration: 10737m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 309 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.343
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1012"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.2% (MEDIUM) · Higher = larger blast radius
    40.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.4% · Safe to merge
    17.4%