Skip to content

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

Merged
StephenHinck merged 5 commits into
mainfrom
BED-8832
Aug 7, 2026
Merged

StephenHinck merged 5 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 uses faster bulk operations when supported, improving cleanup speed for large datasets.
  • Bug Fixes
    • Improved fallback deletion for environments without bulk-delete support.
    • More reliably removes nodes and relationships while preserving required migration data.
    • Expanded node filtering to cover source-based and sourceless data consistently.
    • Improved handling of combined node and relationship cleanup requests, including deletion errors.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

DeleteCollectedGraphData now selects capability-based deletion when supported and uses extracted streaming fallbacks otherwise. Node filtering preserves MigrationData, and shared draining logic deletes streamed node and relationship IDs.

Changes

Graph Data Deletion Refactor

Layer / File(s) Summary
Deletion orchestration
cmd/api/src/daemons/datapipe/delete.go, cmd/api/src/daemons/datapipe/delete_internal_test.go
DeleteCollectedGraphData converts source kinds and selects capability-based or streaming deletion for nodes and relationships. Tests provide a fake deleter for dispatch validation.
Capability-based node deletion
cmd/api/src/daemons/datapipe/delete.go, cmd/api/src/daemons/datapipe/delete_internal_test.go
Adds node set deletion for full-graph, source-kind, and sourceless criteria while preserving MigrationData. Tests cover request combinations and precedence.
Streaming deletion fallbacks
cmd/api/src/daemons/datapipe/delete.go, cmd/api/src/daemons/datapipe/delete_internal_test.go
Extracts filtered node and relationship operations and uses drainAndDelete for streamed ID deletion and error handling. Tests cover draining, early errors, empty channels, and wrapped errors.

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

Sequence Diagram(s)

sequenceDiagram
  participant DeleteCollectedGraphData
  participant GraphDeletionCapability
  participant StreamingFallback
  DeleteCollectedGraphData->>GraphDeletionCapability: delete supported node or relationship sets
  DeleteCollectedGraphData->>StreamingFallback: stream IDs when capability is unavailable
  StreamingFallback->>StreamingFallback: drain IDs and delete each item
  StreamingFallback-->>DeleteCollectedGraphData: return completion or first deletion error
Loading

Possibly related PRs

Suggested labels: go

🚥 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 identifies the optimized source-kind and relationship deletion change and includes the associated ticket.
Description check ✅ Passed The description covers the change, motivation, testing, ticket, change type, performance results, and completed checklist.
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 💡 1
📝 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

@zinic zinic 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.

Nothing stood directly out. Type assertions read fine. Operation usage ensures Done is called after launching - may want to investigate a defer if we were being pedantic but I think this is fine as-is.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot added the go Pull requests that update go code label Aug 6, 2026
@StephenHinck
StephenHinck merged commit 80f7cb4 into main Aug 7, 2026
13 checks passed
@StephenHinck
StephenHinck deleted the BED-8832 branch August 7, 2026 15:40
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants