Skip to content

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

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

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

Conversation

@manerow

@manerow manerow commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Describe your changes:

Cherry-pick of #37560 to 2.1. No linked issue, by choice.

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: 119a15e0c7c3 (base origin/2.1)
  • Finished: 2026-11-11 10:44 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 (main); this is the same change. 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 review from mohityadav766 and removed request for a team 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: 119a15e0c7c3 (base origin/2.1)
  • 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

Rewrites lineage relationship JSON during a data migration; an incorrect key or selection could clear or alter stored lineage metadata.

Replaces the shared lineage cleanup scan in LineageEdgePipelineCleanupMigration with step-specific SQL: a primary key row comparison on Postgres and the existing OR query on MySQL, with edges cleared by keyed UPDATEs. 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 d0d8890 into 2.1 Nov 11, 2026
57 of 58 checks passed
@manerow
manerow deleted the fix/lineage-cleanup-migration-keyset-scan-2.1 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