Skip to content

fix(migrations): read the 2.1.0 lineage clean-up scan as a primary key range on Postgres - #37560

Merged
manerow merged 1 commit into
mainfrom
fix/lineage-cleanup-migration-keyset-scan
Nov 11, 2026
Merged

manerow merged 1 commit into
mainfrom
fix/lineage-cleanup-migration-keyset-scan

Conversation

@manerow

@manerow manerow commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

No linked issue, by choice. Backport to 2.1: #37561.

Problem. The 2.1.0 step that clears non-pipeline references from lineage edges (LineageEdgePipelineCleanupMigration) reads all of entity_relationship, 500 rows at a time. Its query wrote the cursor as four ORed conditions. Postgres cannot use that as a range on the primary key, so every batch re-reads the table up to the cursor and the step grows with the square of the table. One batch mid-table on 931k rows: 923 ms.

Fix. The step carries its own SQL instead of the shared getAllRelationshipsAfter:

  • Postgres: a row comparison, (fromId, toId, relation, relationType) > (...), which is a primary key range (0.6 ms for that batch).
  • MySQL: a copy of today's OR query, which MySQL already reads as a range.
  • Lineage edges are still picked in Java: a relation = 13 filter made Postgres use another index and sort each batch.
  • A cleared edge is written with an UPDATE on its full key. The old shared insert always wrote relationType = '', so it could overwrite or add the wrong row.

The shared query and its other callers are out of scope and unchanged. The step keeps its runOnce guard.

Type of change:

  • Bug fix

High-level design:

Recorded in ADR:2026-11-11-a-composite-keyset-page-is-a-row-comparison-on-postgres-and-an-or-chain-on-mysql.

Tests:

Use cases covered

  • Real MySQL and Postgres with the production indexes: the walk crosses batches, clears only non-pipeline lineage references, adds no rows, and a second run changes nothing.
  • Each engine's batch query plan is a primary key range. Swapping the two queries makes both plan tests fail.

Unit tests

  • LineageEdgePipelineCleanupMigrationTest (rewritten), IngestionPipelineMigrationEntryPointTest (updated).

Backend integration tests

  • Not applicable (no API changes).

Local Java test run: PASSED

  • Commit: c99c51d3e86f (base origin/main)
  • Finished: 2026-11-11 10:42 UTC · 1.4 min
  • Scope: focused; merge readiness is not established. Broader steps deferred: 5 (run --scope full).
Step Scope Classes Tests Failed Skipped Min Result
unit openmetadata-service (3 classes) 3 10 0 0 1.4 passed

Manual testing performed

migrate on restored 2.0.7 dumps, with the 2.1 nightly and the same nightly plus only this change:

Database Step before Step after Cleared
Postgres, 931k rows 355.5 s (migrate 433 s) 7.9 s (migrate 84 s) same 7,001 edges
MySQL, 904k rows 8.7 to 9.4 s 9.5 to 10.8 s same 7,000 planted edges

On MySQL the scan alone is unchanged (about 3.3 s both ways); the extra second is the 7,000 keyed UPDATEs. Rerun on Postgres: with the step's marker removed, the fix cleared 0 and the table checksum did not change.

UI screen recording:

Not applicable: backend migration only.

Checklist:

  • I have read the CONTRIBUTING document.
  • Title and Fixes # (no issue, by choice)
  • I have commented on my code.
  • I have added tests and listed them above.
  • Self-review against REVIEW.md on c99c51d3e86. Answered: the shared query stays slow for its other callers; out of scope, named in the record.
  • Decision check: adds the record above.

@manerow
manerow requested a review from a team as a code owner November 11, 2026 10:46
@manerow
manerow requested a review from TeddyCr November 11, 2026 10:46
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

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.

@manerow

manerow commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Local Java test run: PASSED — details

  • Commit: c99c51d3e86f (base origin/main)
  • The summary is in the PR description.

Tests run locally

  • unit · openmetadata-service (3 classes): IngestionPipelineMigrationEntryPointTest (2 passed), LineageEdgePipelineCleanupMigrationTest (4 passed), MigrationTest (4 passed)

Broader coverage not executed by this focused run

  • mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=IngestionPipelineMigrationEntryPointTest,LineageEdgePipelineCleanupMigrationTest,MigrationCodeFingerprintTest,MigrationTest,MigrationUtilDataConsumerPolicyCacheTest,MigrationWiringTest,MigrationWorkflowDataMigrationTest,MigrationWorkflowTest,OpenSearchVectorServiceChunkStagingTest,WorkflowHandlerSchemaUpdateTest,WorkflowRedeployEntryPointTest -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel '-Dit.test=<33 classes>' -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
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Ppostgres-opensearch -DintegrationTests.lane=parallel '-Dit.test=<33 classes>' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Ppostgres-opensearch -DintegrationTests.lane=global-state -Dit.test=ConversationSchemaMigrationIT,MetricMigrationIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
Commands
mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=IngestionPipelineMigrationEntryPointTest,LineageEdgePipelineCleanupMigrationTest,MigrationTest -Dsurefire.failIfNoSpecifiedTests=false

@gitar-bot

gitar-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk

Updating stored lineage-edge JSON and its keyset scan could clear or overwrite the wrong relationship data if key handling is incorrect.

Rewrites the 2.1.0 lineage clean-up migration to use a primary key range scan on Postgres (row comparison) and a copied OR query on MySQL, with cleared edges updated by full key. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

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

@manerow
manerow merged commit 2fdaa0a into main Nov 11, 2026
63 of 65 checks passed
@manerow
manerow deleted the fix/lineage-cleanup-migration-keyset-scan branch November 11, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants