miroir/notes/miroir-cdo.2.md
jedarden 8969c44b8b P1.2 Topology type + node state machine - Complete verification
All acceptance criteria met:
- Topology deserializes from plan §4 YAML (RG=2, 6 nodes, RF=2)
- groups() iterator returns RG groups in ascending order
- State-machine tests cover all legal/illegal transitions
- Node::is_write_eligible_for() tests verify correctness table

41 topology tests passing. Implementation complete and verified.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-13 18:55:35 -04:00

61 lines
2.4 KiB
Markdown

# P1.2 Topology type + node state machine - Completion Summary
## Task
Implement `miroir_core::topology` with complete state machine and YAML deserialization support.
## Implementation Status: ✅ COMPLETE
The topology implementation is fully complete with all acceptance criteria met:
### Core Types Implemented
- `Topology` struct with `shards`, `replica_groups`, `rf`, and `nodes`
- `Node` struct with `id`, `address`, `replica_group`, and `status`
- `NodeStatus` enum with all required states: Healthy, Degraded, Draining, Failed, Joining, Active, Removed
### Helper Methods
-`Topology::groups()` - Returns iterator over all replica groups
-`Topology::group(g: u32)` - Get a specific group by ID
-`Group::nodes()` - Get nodes in a group
-`Group::healthy_nodes()` - Get only healthy nodes in a group
### State Machine
Complete state transition validation with all legal transitions:
- (new) → Joining (POST /_miroir/nodes)
- Joining → Active (Migration complete)
- Active → Draining (POST /_miroir/nodes/{id}/drain)
- Draining → Removed (Migration complete)
- Active/Draining → Failed (Health check detects failure)
- Failed → Active (Health check recovery)
- Active/Failed ↔ Degraded (Partial health)
- Healthy ↔ Active (Bidirectional synonyms)
All illegal transitions are rejected (e.g., Joining → Draining, Removed → Active).
### Write Eligibility
`Node::is_write_eligible_for(shard_id, status)` correctly implements routing eligibility:
- Healthy/Active/Degraded: Always eligible
- Joining/Failed/Removed: Never eligible
- Draining: Eligible only for shards not being actively migrated
### Testing
All 41 topology tests pass:
- 13 state transition tests (legal and illegal)
- 8 write eligibility tests covering all statuses
- 4 YAML deserialization tests
- 16 structural and functional tests
### Verification
```bash
cargo test topology --lib
# test result: ok. 41 passed; 0 failed; 0 ignored
```
## Files Modified
- `crates/miroir-core/src/topology.rs` - Complete implementation (41 passing tests)
## Previous Commits
- 7aabf62 "P1.2 Topology type + node state machine - Add YAML deserialization test"
- Earlier commits in Phase 1 (miroir-cdo) series
## Conclusion
The topology implementation is production-ready with comprehensive state machine validation, complete test coverage, and proper YAML deserialization support for the plan §4 configuration format.