Skip to content

Fixes #35041: Batch the 2.1.0 creation-audit and DQ dimension backfills by entity id - #35043

Merged
Shreyansh100704 merged 6 commits into
mainfrom
fix/v210-migration-batching-and-adopt
Oct 10, 2026
Merged

Shreyansh100704 merged 6 commits into
mainfrom
fix/v210-migration-batching-and-adopt

Conversation

@Shreyansh100704

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #35041

The 2.1.0 creation-audit backfill now runs in batches of 500 entity ids instead of one statement per table, so the upgrade finishes on large tenants. The 2.1.0 data-quality dimension backfill, which had the same single-statement shape, uses the same batching.

On sandbox-beta (about 115k tables) the backfill's single UPDATE … JOIN (ROW_NUMBER() OVER …) over every table.version.% row in entity_extension ran for minutes and was killed by the database (MySQLQueryInterruptedException: Query execution was interrupted) at the same point on every attempt, because a killed statement keeps none of its work. Under migrate --force the failure is recorded as a step failure, 2.1.0 is still written to SERVER_CHANGE_LOG, but the data migration's identity is not, so the server then refuses to start with "pending migrations: 2.1.0" and no re-run gets past the statement. Some production tenants are larger than sandbox-beta.

Type of change:

  • Bug fix

High-level design:

  • migration/utils/IdBatches (new): fold(handle, table, identity, step) walks a table's ids by primary-key keyset (id > :afterId ORDER BY id LIMIT 500, never OFFSET) and folds step over each non-empty batch. One place owns the walk, the batch size and the empty-batch guard (a JDBI bindList on an empty list throws).
  • v210/CreationAuditMigration: per batch, one read finds the ids still missing createdAt; only those get the two existing passes (oldest version from entity_extension, then current state), each restricted to id IN (<ids>) so the history read is a primary-key range read. History is ordered by the stored entity_extension.updatedAt column (added in 1.12.0 on both engines, same expression as before) instead of parsing every version's JSON. A batch an earlier, interrupted run already filled costs one read and no history read, so a re-run resumes cheaply.
  • v210/DataQualityDimensionMigration: the existing INSERT … SELECT gains AND tc.id IN (<ids>) and runs once per batch of test case ids. Its non-fatal catch is unchanged.
  • Commit boundary: the migration handle is autocommit, so every per-batch statement commits on its own; a killed run keeps every finished batch.
  • Failure policy unchanged: the creation-audit backfill stays fatal (it fails the data migration and is retried by DataMigrationStep.runOnce); batching removes the reason it failed.
  • Alternatives rejected: OFFSET paging (re-reads skipped rows, so later pages slow down again); EntityDAO.listAfter (loads every row's full JSON just for the id, and filters on deleted, while soft-deleted entities need the fields too); per-entity Java like v205 OverrideMetadataRestore (one query per entity); making the step non-fatal (hides missing data).
  • Rollout: changing v210 helpers changes the 2.1.0 data-migration fingerprint, so environments that already recorded 2.1.0 re-run its data migration on upgrade; both backfills are idempotent and the creation-audit step stays skipped once its runOnce marker exists. ConversationMigration keeps its own loop (it reads JSON and filters on type).
  • Decision record: docs/decisions/2026-10-09-data-migration-backfills-walk-ids-in-batches.md (ADR:2026-10-09-data-migration-backfills-walk-ids-in-batches), cited from IdBatches.

Tests:

Use cases covered

  • A tenant with more than one batch of tables is backfilled across page boundaries, every id exactly once, on MySQL and Postgres.
  • A table holding an exact multiple of the batch size ends without handing an empty batch to the step; an empty table issues no IN () statement.
  • createdAt/createdBy come from the oldest stored version, and fall back to the entity's own updatedAt/updatedBy when it has no history.
  • A soft-deleted table is backfilled too.
  • Re-running leaves populated values alone; a batch with nothing missing never reads version history.
  • Existing test cases still get their test definition's dimension after the DQ backfill moved to batches.

Unit tests

  • I added unit tests for the new/changed logic.
  • Files added/updated: openmetadata-service/src/test/java/org/openmetadata/service/migration/utils/IdBatchesTest.java (new), openmetadata-service/src/test/java/org/openmetadata/service/migration/utils/v210/CreationAuditMigrationTest.java (new).
  • Coverage % (JaCoCo, unit tests only): IdBatches 100% (17/17 lines), CreationAuditMigration 93% (50/54; its Backfilled and AuditedEntity records 100%), DataQualityDimensionMigration 0% (covered by DataQualityDimensionMigrationIT, see below).
  • Guards checked by breaking the code: dropping the empty-batch guard fails IdBatchesTest.anEmptyTableNeverReachesTheStep and CreationAuditMigrationTest.anEmptyTableIssuesNoBatchStatement; dropping the per-batch "missing" check fails aBatchWithNothingMissingNeverReadsVersionHistory.
  • DataQualityDimensionMigration has no unit test: its behavior is unchanged and its SQL runs on both engines in DataQualityDimensionMigrationIT; the batching it now uses is IdBatchesTest's and IdBatchesIT's.

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/.
  • Files added/updated: IdBatchesIT.java (new: walks a scratch table of 1,001 and 1,000 UUID ids across batch boundaries), CreationAuditMigrationIT.java (adds backfillReachesSoftDeletedEntities).
  • Run by hand in addition to the block below, on both engines (-Pmysql-elasticsearch default and -P postgres-opensearch):
    • CreationAuditMigrationIT 5/5 and DataQualityDimensionMigrationIT 2/2 on MySQL and on Postgres.
    • IdBatchesIT 2/2 on MySQL and on Postgres; changing the cursor to id >= :afterId makes it fail.

Local Java test run: PASSED

  • Commit: 63147b702b03 (base origin/main)
  • Finished: 2026-10-09 17:04 UTC · 9.7 min
Step Scope Classes Tests Failed Skipped Min Result
unit openmetadata-service (2 classes) 2 4 0 0 1.2 passed
integration mysql-elasticsearch · parallel 19 1010 0 60 5.6 passed
integration mysql-elasticsearch · isolated 2 6 0 0 2.9 passed

Tests run locally

  • unit · openmetadata-service (2 classes): CreationAuditMigrationTest (2 passed), IdBatchesTest (2 passed)
  • integration · mysql-elasticsearch · parallel: AlertBacklogMigrationIT (2 passed), BaseEntityIT$ListEntityHistoryByTimestampPaginationTest (16 passed, 4 skipped), ConfigResourceIT (13 passed), ContextMemoryStatusMigrationIT (1 passed), ContinuousMigrationIT (3 passed, 1 skipped), CreationAuditMigrationIT (116 passed, 17 skipped), DataProductDomainMigrationIT (41 passed, 2 skipped), DataQualityDimensionMigrationIT (2 passed), DatabaseSmokeIT (1 passed), DbTuneIT (20 passed), GlossaryTermResourceIT (192 passed, 6 skipped), IdBatchesIT (56 passed, 6 skipped), LifeCycleCreatedSentinelMigrationIT (17 passed), OpenMetadataOperationsIT (6 passed), OverrideMetadataRestoreMigrationIT (20 passed, 1 skipped), SampleDataStorageMigrationIT (3 passed), SeedDataPresenceIT (1 passed), ServiceLineagePipelineRoutingMigrationIT (8 passed), TableResourceIT (163 passed, 4 skipped), UserResourceIT (202 passed, 12 skipped)
  • integration · mysql-elasticsearch · isolated: ConversationSchemaMigrationIT (2 passed), MetricMigrationIT (4 passed)

Per-class counts come from the test reports, which can credit a test to the wrong class when classes run concurrently, and keep only the last run of a nested class that several test classes inherit. The step totals above are Maven's own counts.

Why these tests
  • area migrations-seed-data ← openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/IdBatches.java, openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/CreationAuditMigration.java, openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/DataQualityDimensionMigration.java
  • changed test ← openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/CreationAuditMigrationIT.java, openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/IdBatchesIT.java, openmetadata-service/src/test/java/org/openmetadata/service/migration/utils/IdBatchesTest.java, openmetadata-service/src/test/java/org/openmetadata/service/migration/utils/v210/CreationAuditMigrationTest.java
  • smoke ← code other than a test class changed
Commands
mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=CreationAuditMigrationTest,IdBatchesTest -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel -Dit.test=AlertBacklogMigrationIT,ConfigResourceIT,ContextMemoryStatusMigrationIT,ContinuousMigrationIT,CreationAuditMigrationIT,DataProductDomainMigrationIT,DataQualityDimensionMigrationIT,DatabaseSmokeIT,DbTuneIT,GlossaryTermResourceIT,IdBatchesIT,LifeCycleCreatedSentinelMigrationIT,OpenMetadataOperationsIT,OverrideMetadataRestoreMigrationIT,SampleDataStorageMigrationIT,SeedDataPresenceIT,ServiceLineagePipelineRoutingMigrationIT,TableResourceIT,UserResourceIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=global-state -Dit.test=ConversationSchemaMigrationIT,MetricMigrationIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes). The planner selects its canary and smoke specs for these files only because backend migration code has no entry in .github/playwright/impact-map.json; nothing here reaches the UI, so they were not run.

Manual testing performed

  1. Scale check on a throwaway MySQL 8.0.46 (--memory=2g, 512 MB buffer pool) seeded with 115,000 table_entity rows and 345,000 table.version.* rows of about 2 KB JSON each.
  2. One batch from the middle of the table: EXPLAIN of the history read shows type: range, key: PRIMARY (1,500 rows); the history UPDATE sets 500 rows in 0.05 s, and the batch's "missing" count goes 500 → 0.
  3. The previous single statement on the same data: 115,000 rows in 29.55 s. This synthetic data is far lighter than real table JSON and version history, so it does not reproduce the minutes-long run sandbox-beta hit; what it shows is that each batched statement's cost is independent of table size.

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: I updated the migration scripts or explained why it is not needed. (No schema change.)
  • For UI changes: I attached a screen recording and/or screenshots above. (No UI change.)
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Decision check: ADR:2026-10-09-data-migration-backfills-walk-ids-in-batches records the batching rule and the batch size of 500.

@Shreyansh100704
Shreyansh100704 requested a review from a team as a code owner October 9, 2026 17:07
Copilot AI balanced review requested due to automatic review settings October 9, 2026 17:07

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions github-actions Bot added the safe to test Add this label to run secure Github workflows on PRs label Oct 9, 2026
@Shreyansh100704
Shreyansh100704 added this pull request to the merge queue Oct 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-10-10T19:04:55Z)

Blocked the queue: playwright-summary

Failed Playwright tests:

  • Features/AIMode/PersonaSettings.spec.ts › Data Assets → Table: a new tab is saved

Copilot AI balanced review requested due to automatic review settings October 10, 2026 19:46

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gitar-bot

gitar-bot Bot commented Oct 10, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🔴 High risk · The 2.1.0 batched backfills populate creation-audit fields and dimension relationships, so incorrect ID selection could leave persistent entity metadata inaccurate or incomplete.

Batches the 2.1.0 creation-audit and data quality dimension backfills by entity id in groups of 500 via a shared keyset walk, so large tenants no longer hit a single long-running statement that gets killed. No issues found.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

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

Compact
gitar display:verbose         

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

@Shreyansh100704
Shreyansh100704 added this pull request to the merge queue Oct 10, 2026
Merged via the queue into main with commit b7641e8 Oct 10, 2026
71 checks passed
@Shreyansh100704
Shreyansh100704 deleted the fix/v210-migration-batching-and-adopt branch October 10, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2.1.0 creation-audit backfill runs as one unbatched UPDATE and gets killed on large tenants

3 participants