Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(OraklNode) Track peers manually #1572

Merged
merged 4 commits into from
Jun 10, 2024

Conversation

nick-bisonai
Copy link
Collaborator

Description

Track cluster peers manually instead of using built in function pubsub.ListPeers

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.

Deployment

  • Should publish npm package
  • Should publish Docker image

@nick-bisonai nick-bisonai self-assigned this Jun 8, 2024
@nick-bisonai nick-bisonai requested a review from a team as a code owner June 8, 2024 11:14
Copy link
Contributor

coderabbitai bot commented Jun 8, 2024

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.

Walkthrough

The recent changes enhance the Raft consensus algorithm in the node package by introducing heartbeat handling and peer set management. The accessors.go file was refactored to streamline peer size retrieval. New methods and fields were added to manage heartbeats and peers in raft.go. Additionally, a set data structure was implemented in node/pkg/utils/set to support these changes, accompanied by corresponding tests in set_test.go.

Changes

File(s) Summary
node/pkg/raft/accessors.go Removed unused import and refactored Subscribers method to use Peers.Size() for peer count.
node/pkg/raft/raft.go, node/pkg/raft/types.go Added heartbeat handling methods, peer set management fields, and new message type ReplyHeartbeat.
node/pkg/utils/set/set.go Introduced a Set data structure for managing unique elements with basic set operations.
node/pkg/utils/tests/set_test.go Added test cases for the Set data structure, covering add, remove, and containment operations.

Sequence Diagram(s)

sequenceDiagram
    participant Leader
    participant Follower
    participant Raft
    participant Peers

    Leader->>Raft: sendHeartbeat()
    Raft->>Peers: Update Peers Set
    Raft->>Follower: sendReplyHeartbeat()
    Follower->>Raft: handleReplyHeartbeat()
    Raft->>Leader: Acknowledge Heartbeat
Loading

Poem

In the code where Raft does dwell,
Heartbeats now are handled well.
Peers are tracked in sets so neat,
Ensuring consensus is complete.
With tests to check each tiny part,
Our system's strong, a work of art.
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nick-bisonai
Copy link
Collaborator Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jun 8, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0ced283 and f07bbe5.

Files selected for processing (5)
  • node/pkg/raft/accessors.go (2 hunks)
  • node/pkg/raft/raft.go (7 hunks)
  • node/pkg/raft/types.go (4 hunks)
  • node/pkg/utils/set/set.go (1 hunks)
  • node/pkg/utils/tests/set_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • node/pkg/utils/set/set.go
Additional comments not posted (2)
node/pkg/raft/types.go (1)

24-24: Addition of ReplyHeartbeat type and related struct.

Ensure that all new types are properly used and integrated in message handling.

Also applies to: 46-47

Verification successful

The ReplyHeartbeatMessage type is defined and instantiated in node/pkg/raft/types.go and node/pkg/raft/raft.go. Additionally, it is used in JSON unmarshalling and marshalling operations, indicating its integration into the message handling logic.

  • node/pkg/raft/raft.go:
    • Line: var replyHeartbeatMessage ReplyHeartbeatMessage
    • Line: err := json.Unmarshal(msg.Data, &replyHeartbeatMessage)
    • Line: replyHeartbeatMessage := ReplyHeartbeatMessage{}
    • Line: marshalledReplyHeartbeatMsg, err := json.Marshal(replyHeartbeatMessage)

These usages confirm that ReplyHeartbeatMessage is being properly handled in the message processing flow.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `ReplyHeartbeatMessage` across the system.

# Test: Search for the instantiation and handling of `ReplyHeartbeatMessage`. Expect: Proper usage in message handling.
rg --type go $'ReplyHeartbeatMessage'

Length of output: 238



Script:

#!/bin/bash
# Description: Verify the usage of `replyHeartbeatMessage` in message handling.

# Test: Search for the usage of `replyHeartbeatMessage` in the context of message handling.
rg --type go 'replyHeartbeatMessage'

Length of output: 353

node/pkg/raft/raft.go (1)

111-112: Handling of ReplyHeartbeat messages and peer set management.

Ensure thorough testing of these new functionalities to maintain system stability.

Also applies to: 119-121, 163-163, 228-237

node/pkg/utils/tests/set_test.go Show resolved Hide resolved
node/pkg/raft/accessors.go Show resolved Hide resolved
* feat: default to udp - quic

* test: prevent possible duplicate port err

* test: fix port error

* test: fix test err

* fix: remove listen port, add missing `HOST_IP` reference

* fix: rollback listen port

* fix: update based on feedback
@nick-bisonai nick-bisonai merged commit c4c8298 into feat/update-host-init Jun 10, 2024
2 checks passed
@nick-bisonai nick-bisonai deleted the feat/track-cluster-peers branch June 10, 2024 01:22
nick-bisonai added a commit that referenced this pull request Jun 10, 2024
…among peers (#1571)

* wip

* fix: vet err

* fix: update based on feedbacks

* fix: remove boot api property for testing purpose

* feat: boot api follow previous behavior

* (OraklNode) Track peers manually (#1572)

* feat: implement peer count into raft pkg

* fix: remove unused property

* test: add cases to test based on feedback

* (OraklNode) Default to udp - quic (#1573)

* feat: default to udp - quic

* test: prevent possible duplicate port err

* test: fix port error

* test: fix test err

* fix: remove listen port, add missing `HOST_IP` reference

* fix: rollback listen port

* fix: update based on feedback
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.

1 participant