Files
9b4445c2e7 Nexus: Delete state machine on terminal state -- Part 1 (#6837)
## What changed?
<!-- Describe what has changed in this PR -->
Nexus: Delete state machine on terminal state -- Part 1: Add Node
Deletion Support

Add support for deleting nodes in the hierarchical state machine,
including tracking state transitions and deletions for output
collection.

## Key Changes

1. Added deletion interface and implementation:
- Added DeleteChild method to Node for removing nodes and their
descendants
  - Walk-based deletion to mark entire subtrees
  - Cache and persistence cleanup
  
2. Added operation logging for state tracking:
  - New OperationLog type to track transitions and deleted paths
  - Operations stored at root level with path information
  - Centralized output collection

## Technical Details

1. Operation Log:
```go
type OperationLog struct {
   // All transitions, including regular state changes and deletions
   Transitions []TransitionOutputWithCount 
   // Track topmost deleted paths to filter outputs efficiently
   DeletedPaths [][]Key
}
```

2. Node Path Tracking:
```go
type TransitionOutputWithCount struct {
    TransitionOutput
    TransitionCount int64
    NodePath       []Key
}
```

3. Deletion is atomic:
   - Entire subtree marked as deleted
   - Persistence and cache cleaned up
   - Deletion recorded in operation log

## Notes for Reviewers

### Key Areas to Focus On

1. Output Collection:
   - Proper filtering of outputs based on node paths
   - Handling of deleted subtrees
   - Hierarchical output collection preserved

2. Deletion Correctness:
   - Atomic deletion of entire subtrees
   - Proper cache invalidation
   - No orphaned references

### Known Trade-offs

1. Operation Log Location:
   - Stored at root level vs. distributed
   - Centralizes output collection
   - Simplifies deletion tracking
   - Trade-off between centralization and access patterns

### Not Changed

1. Existing state machine behavior untouched
2. Original sync behavior preserved
3. Dirty state tracking maintained

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
No

---------

Co-authored-by: Roey Berman <[email protected]>
2024-11-22 13:13:24 -06:00
..