Repository navigation
Feature/179 single node - #181
Conversation
Add configuration-based single-node cluster detection to enable zero-cost startup with a single node and later expansion to multi-node clusters without data loss. ## Core Changes ### Membership Layer - Add `initial_cluster_size` field to `RaftMembership` to track initial cluster configuration - Implement `initial_cluster_size()` and `is_single_node_cluster()` trait methods - Cluster size remains immutable after node addition/removal (config-based, not runtime-based) ### Election Handler - Single-node clusters automatically win elections without RPC calls - Skip vote request broadcast when `is_single_node_cluster()` returns true - Multi-node behavior unchanged ### Replication Handler - Single-node clusters automatically achieve quorum without replication - Skip replication peers check when `is_single_node_cluster()` returns true - Multi-node behavior unchanged ## Safety Features - **Network partition protection**: 3-node cluster with empty peers correctly reports `NoPeerFound` error, not treated as single-node - **Configuration-based detection**: Uses immutable `initial_cluster_size` from config, not runtime state like `voters()` or `replication_peers()` - **Immutability**: Cluster size remains constant after add/remove operations ## Testing - Add 19 comprehensive unit tests (3 election + 12 membership + 4 replication) - Test coverage >90% for all new code - Fix existing tests to mock `is_single_node_cluster()` - All 269 integration tests pass ## Documentation - Add single-node startup command to Makefile - Update README with single-node mode usage and limitations - Add example config file for single-node deployment ## Breaking Changes None. This is a backward-compatible addition.
…tus printer Add comprehensive example demonstrating dynamic cluster expansion from single-node to three-node cluster without downtime. Major changes: - Add examples/single-node-expansion/ with complete test setup * Makefile with commands to start node1/2/3 and test expansion * Detailed README.md with architecture and test results * Configuration files (n1.toml, n2.toml, n3.toml) for each node * Demo application showcasing single-node bootstrap and learner join - Add cluster_printer utility module in d-engine-core/src/utils/ * Print formatted cluster status, node startup, and role transitions * Comprehensive unit tests (9 tests) covering all role/status variants - Integrate printer calls in leader_state.rs and learner_state.rs * Print messages when leader accepts new nodes * Print messages when leader promotes learners to voters * Print messages when learner joins and gets promoted - Update Cargo.toml to exclude single-node-expansion from workspace - All tests passing, clippy checks passed This example validates Issue #179: single-node cluster support and dynamic expansion without downtime.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR implements single-node cluster support with dynamic expansion capability (Issue #179), allowing d-engine to start as a standalone node and later expand to a multi-node cluster without downtime or data loss.
Key changes:
- Added
initial_cluster_size()andis_single_node_cluster()methods to the Membership trait to detect single-node clusters based on immutable configuration - Modified election and replication handlers to skip unnecessary operations in single-node mode
- Added comprehensive user-friendly cluster status printing utilities with emojis for better visibility
- Created extensive test coverage for single-node scenarios and test updates to handle new membership mocking requirements
Reviewed changes
Copilot reviewed 25 out of 26 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| d-engine-core/src/membership.rs | Added trait methods for single-node cluster detection |
| d-engine-server/src/membership/raft_membership.rs | Implemented initial_cluster_size tracking (immutable configuration) |
| d-engine-core/src/election/election_handler.rs | Added early return for single-node elections |
| d-engine-core/src/replication/replication_handler.rs | Added single-node replication optimization |
| d-engine-core/src/utils/cluster_printer.rs | New utility for user-friendly cluster status output |
| d-engine-core/src/raft_role/learner_state.rs | Added cluster printer calls for learner events |
| d-engine-core/src/raft_role/leader_state.rs | Added cluster printer calls for leader events |
| d-engine-server/tests/components/replication/replication_handler_test.rs | Updated tests with single-node detection mocks |
| d-engine-server/tests/components/election/election_handler_test.rs | Added mock expectations for membership |
| d-engine-server/src/membership/raft_membership_test.rs | Added comprehensive single-node cluster tests |
| d-engine-core/src/election/election_handler_test.rs | Added single-node election tests |
| d-engine-core/src/test_utils/mock/mock_raft_builder.rs | Updated mock_membership with default mocks |
| examples/three-nodes-cluster/* | Added single-node configuration and updated documentation |
| examples/single-node-expansion/* | New example demonstrating dynamic cluster expansion |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Type
Description
#179
Related Issues
Checklist