Skip to content

Fix incident cleanup during recursive test-case deletion - #36983

Merged
TeddyCr merged 5 commits into
open-metadata:mainfrom
TeddyCr:MINOR-Incident-CleanUp
Nov 3, 2026
Merged

TeddyCr merged 5 commits into
open-metadata:mainfrom
TeddyCr:MINOR-Incident-CleanUp

Conversation

@TeddyCr

@TeddyCr TeddyCr commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes

Fixes ReindexStatsIT.cleanRunBalancesReaderProcessorSink.

Recursive table or service deletion bypassed TestCaseRepository.deleteChildren, leaving incident rows behind after their parent test cases were removed. Later reindexing could read those orphan incidents and skip them because their parent relationships were missing.

Capture incident IDs and test-case result FQNs before hard deletion, then submit asynchronous cleanup only after the owning database deletion succeeds. An enclosing transaction defers submission through PostCommitActionQueue until commit and discards it on rollback. Both direct and bulk deletion use the same preparePostDeleteCleanup hook.

Incident discovery uses one batched relationship query per chunk, with deduplicated IDs. Each chunk schedules at most one incident-cleanup task and one result-cleanup task. The ancestor regression covers three sibling test cases; strict reader/processor accounting remains intact.

Two transaction-fix commits:

  • 30c6dfdcd43: incident cleanup after successful hard deletion.
  • a7c44338086: test-case result cleanup at the same lifecycle point.

Type of change

  • Bug fix

High-level design

The cleanup preparation hook returns a closure containing the IDs/FQNs needed after relationship removal. Direct and bulk deletion invoke it through the post-commit queue only after their database deletion flush succeeds. This preserves asynchronous batching without treating the base executeEntityWrite hook as a transaction boundary. No schema, migration, or API contract changes.

Tests

Use cases covered

  • Direct test-case hard deletion eventually removes incidents.
  • Recursive ancestor hard deletion eventually removes incident rows and their relationships.
  • Ordered document-survival and reindex-statistics tests retain balanced processing counts.

Unit tests

Current transaction fix: TestCaseRepositoryTest 11 passed, including deferred preparation and batched result deletion. The surrounding compile/verify command was stopped when it unexpectedly started broader integration infrastructure despite its skip flag; the unit-test results were complete.

Historical broader run:

405 passed, 0 failures/errors/skips on merged HEAD e9bb119bc14af67494c0349a3536e4a3ee177989:
CreateTestCaseToolTest (4), MetricObservabilityBuilderTest (22), ODCSImportAnalyzerTest (13), ODCSQualityRuleImporterTest (15), ReindexingUtilDocBuildContextTest (7), SearchIndexFactoryTest (290), SearchRepositoryTest (25), TestCaseIndexTest (13), TestCaseRepositoryTest (11), TestSuiteRepositoryTest (5).

Coverage percentage has not been measured. The cleanup regression is exercised through real API/database integration tests rather than mocked repository interactions.

Backend integration tests

Current HEAD a7c44338086d53676011230914ffd44600287280:

  • EntityHardDeletionAtomicityIT: 18 passed, including direct/bulk × commit/rollback/SQL failure/deadlock retry for incidents and results.
  • TestCaseResourceIT#test_recursiveHardDeleteCascadesPastResolutionStatusChildren+test_hardDeleteReapsResolutionStatusChildren: 2 passed.
  • Ordered ReindexDocSurvivalIT,ReindexStatsIT: 6 passed.
  • All three runs above used PostgreSQL/OpenSearch; zero failures/errors/skips.
  • The eight new transaction cases were run against the previous cleanup implementation: 4 failed, demonstrating lost history after rollback/failure; all eight passed with the fix. The first attempt to establish this regression was blocked by an OpenSearch container OOM; it was rerun after freeing Docker memory.
  • Spotless apply/check, commit hooks, whitespace and impact-map ownership checks passed. Independent review of the final two commits found no blocking issues.

Historical validation:

Before merging upstream/main, the final asynchronous implementation passed:

  • TestCaseResourceIT#test_recursiveHardDeleteCascadesPastResolutionStatusChildren+test_hardDeleteReapsResolutionStatusChildren: 2 passed on PostgreSQL/OpenSearch.
  • ReindexDocSurvivalIT,ReindexStatsIT, alphabetical order: 6 passed on PostgreSQL/OpenSearch.
  • The ancestor-deletion regression failed before the production fix because an incident row remained.
  • mvn -B -pl openmetadata-service,openmetadata-integration-tests spotless:apply spotless:check passed.
  • Current branch diff whitespace and impact-map ownership checks passed.

Earlier batching fix bc58b61d9a94133dc9eb59e26604a6586eb45691:

  • Direct deletion and three-sibling ancestor-deletion regressions: 2 passed, 0 failures/errors/skips, PostgreSQL/OpenSearch.
  • Ordered ReindexDocSurvivalIT,ReindexStatsIT: 6 passed, 0 failures/errors/skips, PostgreSQL/OpenSearch.
  • Spotless apply/check, commit hooks, whitespace check and impact-map ownership passed.
  • Independent review of this commit found no issues.

Broader affected-test validation on the previous commit e9bb119bc14a stopped at MySQL startup (connection refused): 405 unit tests passed; zero integration tests ran. Remaining broad steps were not run. Full affected-suite validation remains incomplete; the current focused results are listed separately above. The full affected suite has not been completed for the new shared lifecycle hook.

Local Java test run: FAILED

  • Commit: e9bb119bc14a (base upstream/main)
  • Finished: 2026-11-03 18:02 UTC · 12.0 min
Step Scope Classes Tests Failed Skipped Min Result
unit openmetadata-mcp (1 class), openmetadata-service (9 classes) 10 405 0 0 1.3 passed
integration mysql-elasticsearch · parallel 0 0 0 0 10.7 no tests ran
integration mysql-elasticsearch · isolated not run
integration mysql-elasticsearch · rdf not run
integration cache-tests · parallel not run
integration postgres-opensearch · search-it not run

Selected but produced no report: ApiLatencyRecorderTest (mysql-elasticsearch · parallel), AppEventSubscriptionRemovalIT (mysql-elasticsearch · parallel), AppTriggerConflictIT (mysql-elasticsearch · parallel), AutoAssignIncidentIT (mysql-elasticsearch · parallel), AutoCloseIncidentIT (mysql-elasticsearch · parallel), ConfigResourceIT (mysql-elasticsearch · parallel), ConnectionSecretsMigrationIT (mysql-elasticsearch · parallel), ContextMemorySearchMatrixIT (mysql-elasticsearch · parallel), DataContractPermissionIT (mysql-elasticsearch · parallel), DataContractResourceIT (mysql-elasticsearch · parallel) and 114 more in the details

  • Impacted, not run locally: 10 classes (listed in the details)

Ingestion integration tests

N/A — no ingestion changes.

Playwright (UI) tests

N/A — no UI changes.

Manual testing performed

No manual UI testing. Automated regressions create a test case and incident, delete either the case or its ancestor through the API, and wait for incident rows and relationships to disappear.

UI screen recording

N/A — backend-only bug fix.

Checklist

  • Test-fix exception: descriptive title, failing test named above, skip-pr-checks label; no separate issue.
  • Comment explains why child IDs must be captured before relationship cleanup.
  • Integration regression strengthened and focused test results listed above.
  • Self-review: independent review of a7c44338086d53676011230914ffd44600287280 against REVIEW.md; no findings.
  • Decision check: no new durable contract or default; restores cleanup through an existing lifecycle hook.
  • Schema/migration and UI recording requirements: not applicable.
  • Full affected Java validation on the merged HEAD completed and recorded.

Summary by Gitar

  • Deferred cleanup:
    • Test case result deletion now runs after hard deletion commits via PostCommitActionQueue.runOrDefer
    • Captures test_case_resolution_status child IDs before relationship removal, so cleanup survives rollback and failure
  • New hook:
    • Added preparePostDeleteCleanup to EntityRepository for capturing cleanup inputs before hard deletion
  • Tests:
    • Added EntityHardDeletionAtomicityIT covering commit, rollback, failure, and retry outcomes
    • ReindexStatsIT now asserts zero reader failures on clean runs

This will update automatically on new commits.

@TeddyCr TeddyCr added the skip-pr-checks Bypass PR metadata validation check label Nov 3, 2026 — with ChatGPT Codex Connector
@github-actions github-actions Bot added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Nov 3, 2026
@TeddyCr
TeddyCr marked this pull request as ready for review November 3, 2026 18:03
Copilot AI balanced review requested due to automatic review settings November 3, 2026 18:03
@TeddyCr
TeddyCr requested a review from a team as a code owner November 3, 2026 18:03
@TeddyCr
TeddyCr requested a review from yan-3005 November 3, 2026 18:03

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 insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 3, 2026 18:10

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 insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs and removed safe to test Add this label to run secure Github workflows on PRs labels Nov 3, 2026
Copilot AI balanced review requested due to automatic review settings November 3, 2026 18:47

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 insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs and removed safe to test Add this label to run secure Github workflows on PRs labels Nov 3, 2026
@gitar-bot

gitar-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 closed / 2 findings

🔴 High risk · The new post-delete hook asynchronously removes incident history and test results during ancestor hard-deletion cascades, potentially erasing records users may need.

Fixes orphaned incident rows left behind by recursive test-case deletion by scheduling incident cleanup from the hard-delete cascade hooks and deferring test case result cleanup until after commit. Resolved the per-test-case relationship query and async task in bulk hard-delete, and queued incident cleanup before the cascade transaction commits. No open issues found.

✅ 2 closed
✅ Performance: Per-test-case relationship query and async task in bulk hard-delete

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseRepository.java:1313-1327
hardDeleteAdditionalChildren is called once per entity from runHardDeleteAdditionalChildren in bulkHardDeleteSubtreeChunk. So a recursive delete of a service or table with N test cases now makes N separate findTo queries and can queue up to N TEST_CASE_CLEANUP tasks. The bulk path is meant to issue one batched read and write per type no matter how many descendants there are, and dispatchToContainedChildren already reads these PARENT_OF time-series rows through findToBatchAllTypes before skipping them. Override bulkEntitySpecificCleanup(List<TestCase>, String) (or batch inside the hook) so one batched relationship query collects every resolution-status id for the chunk and a single async task deletes them. Keep the per-id hook only for the direct-delete path.

✅ Bug: Incident cleanup is queued before the cascade transaction commits

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseRepository.java:1313-1327
Both prepareChildrenForHardDeleteCascade overrides call AsyncService.executeDatabaseTask right away. Both run inside the hard-delete transaction: deleteChildren, or the executeEntityWrite → hardDeleteSubtreeContents → dispatchToContainedChildren chain. The background task deletes rows on its own connection, separately from that transaction. A table or service cascade can roll back after this point: a deadlock that keeps happening after the retries run out, a failing sibling subtree, or a failure in bulkDeleteReferencesAndRows. When that happens the test cases stay, but their incident history and PARENT_OF rows are already gone for good. Also, every deadlock retry runs the hook again and queues another copy of the task. PostCommitActionQueue is already used in this flush (runOrDefer, which is rolled back to a checkpoint on retry), so the delete can be queued there and only run after the commit succeeds.

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

@TeddyCr TeddyCr added the To release Will cherry-pick this PR into the release branch label Nov 3, 2026
@TeddyCr
TeddyCr merged commit 304dabb into open-metadata:main Nov 3, 2026
95 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ingestion safe to test Add this label to run secure Github workflows on PRs skip-pr-checks Bypass PR metadata validation check To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants