Skip to content

feat: Optimize PG source_kind, relation deletion using indices - BED-8832 - #2942

Open
StephenHinck wants to merge 3 commits into
mainfrom
BED-8832
Open

feat: Optimize PG source_kind, relation deletion using indices - BED-8832#2942
StephenHinck wants to merge 3 commits into
mainfrom
BED-8832

Conversation

@StephenHinck

@StephenHinck StephenHinck commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Description

Implements the new DeleteNodesByKinds/DeleteRelationshipsByKinds functions supported optionally on DAWGS drivers to execute rapid deletion of objects by kind. Initially, this is supported on PostgreSQL drivers.

Requires SpecterOps/DAWGS#101

Motivation and Context

Resolves BED-8832

Why is this change required? What problem does it solve?

How Has This Been Tested?

Validated locally and confirmed existing tests continue to pass.

Screenshots (optional):

Tested using large OGGen payloads for validation:

Delete by source_kind:
Before:

time=2026-06-30T16:15:45.448Z level=INFO message=DeleteCollectedGraphData delete_all_data=false delete_sourceless_data=false delete_source_kinds=OggenBase delete_relationships="" measurement_id=129 elapsed=1m21.810004664s

After:

time=2026-06-30T16:21:37.337Z level=INFO message=DeleteCollectedGraphData delete_all_data=false delete_sourceless_data=false delete_source_kinds=OggenBase delete_relationships="" measurement_id=129 elapsed=1m14.96949745s

Delete by relationship:
Before:

time=2026-06-30T17:17:54.052Z level=INFO message=DeleteCollectedGraphData delete_all_data=false delete_sourceless_data=false delete_source_kinds="" delete_relationships=HasSession measurement_id=129 elapsed=10.140349088s

After:

time=2026-06-30T17:07:53.310Z level=INFO message=DeleteCollectedGraphData delete_all_data=false delete_sourceless_data=false delete_source_kinds="" delete_relationships=HasSession measurement_id=129 elapsed=453.611584ms

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

Summary by CodeRabbit

  • Performance
    • Graph data deletion now prefers faster bulk, set-based deletes for nodes and relationships when available, significantly speeding up large cleanups.
  • Bug Fixes
    • Improved deletion coverage with consistent fallback to streaming, row-by-row deletion when bulk operations aren’t supported.
  • Observability
    • Enhanced logging and measurement around the deletion flow for better visibility and troubleshooting of cleanup behavior.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 10f52a1b-1303-47d2-8aeb-e28fd4369d81

📥 Commits

Reviewing files that changed from the base of the PR and between feaecfe and 60eaa69.

📒 Files selected for processing (1)
  • cmd/api/src/daemons/datapipe/delete.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/api/src/daemons/datapipe/delete.go

📝 Walkthrough

Walkthrough

DeleteCollectedGraphData now measures deletion execution and selects capability-based or streaming paths for graph nodes and relationships. Streaming helpers filter matching IDs and delete them row by row through a shared drain-and-delete loop.

Changes

Graph Data Deletion Refactor

Layer / File(s) Summary
Deletion orchestration
cmd/api/src/daemons/datapipe/delete.go
DeleteCollectedGraphData measures execution, converts source kinds, and dispatches node and relationship deletion through capability-based or streaming paths.
Capability-based node deletion
cmd/api/src/daemons/datapipe/delete.go
Adds the node deletion capability and maps deletion flags to DeleteNodesByKinds calls while preserving common.MigrationData.
Streaming deletion fallbacks
cmd/api/src/daemons/datapipe/delete.go
Extracted node and relationship operations stream filtered IDs, while drainAndDelete centralizes row-by-row deletion and error handling.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: faster PostgreSQL kind-based deletions.
Description check ✅ Passed The description follows the template and includes the change, ticket, testing, type, and checklist details.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch BED-8832

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
cmd/api/src/daemons/datapipe/delete.go (1)

206-218: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Duplicated drain-and-delete writer loop.

deleteNodesByOperation's writer (Lines 206-218) and deleteRelationshipsByOperation's writer (Lines 248-260) are identical except for the batch.DeleteNode/batch.DeleteRelationship call. Could extract a small generic helper to remove the duplication.

♻️ Proposed shared helper
func drainAndDelete(ctx context.Context, inC <-chan graph.ID, deleteFn func(graph.ID) error) error {
	for {
		if nextID, hasNextID := channels.Receive(ctx, inC); hasNextID {
			if err := deleteFn(nextID); err != nil {
				return err
			}
		} else {
			return nil
		}
	}
}
 nodeOperation.SubmitWriter(func(ctx context.Context, batch graph.Batch, inC <-chan graph.ID) error {
-	for {
-		if nextID, hasNextID := channels.Receive(ctx, inC); hasNextID {
-			if err := batch.DeleteNode(nextID); err != nil {
-				return err
-			}
-		} else {
-			break
-		}
-	}
-
-	return nil
+	return drainAndDelete(ctx, inC, batch.DeleteNode)
 })

Also applies to: 248-260

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/api/src/daemons/datapipe/delete.go` around lines 206 - 218, Extract the
duplicated drain-and-delete loop from the writers in deleteNodesByOperation and
deleteRelationshipsByOperation into a shared drainAndDelete helper accepting the
context, input channel, and deletion callback. Have the helper preserve
channels.Receive termination and error propagation, then invoke it with
batch.DeleteNode or batch.DeleteRelationship respectively.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cmd/api/src/daemons/datapipe/delete.go`:
- Around line 206-218: Extract the duplicated drain-and-delete loop from the
writers in deleteNodesByOperation and deleteRelationshipsByOperation into a
shared drainAndDelete helper accepting the context, input channel, and deletion
callback. Have the helper preserve channels.Receive termination and error
propagation, then invoke it with batch.DeleteNode or batch.DeleteRelationship
respectively.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: af323718-d2b6-42a1-9cd8-fe1af8ba5ddb

📥 Commits

Reviewing files that changed from the base of the PR and between 7dbd228 and feaecfe.

📒 Files selected for processing (1)
  • cmd/api/src/daemons/datapipe/delete.go

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.

1 participant