Skip to content

Feature/179 single node - #181

Merged
JoshuaChi merged 2 commits into
developfrom
feature/179_single_node
Nov 26, 2025
Merged

JoshuaChi merged 2 commits into
developfrom
feature/179_single_node

Conversation

@JoshuaChi

@JoshuaChi JoshuaChi commented Nov 26, 2025 •

Copy link
Copy Markdown
Contributor

Type

  • New feature
  • Bug Fix

Description

#179

Related Issues

Checklist

  • The code has been tested locally (unit test or integration test)
  • Squash down commits to one or two logical commits which clearly describe the work you've done.

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.
Copilot AI review requested due to automatic review settings November 26, 2025 13:56
@coderabbitai

coderabbitai Bot commented Nov 26, 2025

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/179_single_node

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.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

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.

❤️ Share

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

@JoshuaChi
JoshuaChi merged commit 6c90b57 into develop Nov 26, 2025
9 of 10 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() and is_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.

@JoshuaChi
JoshuaChi deleted the feature/179_single_node branch December 5, 2025 02:01
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.

2 participants