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

Confusing Behaviour of Single Node Scenario #1162

Open
Luncert opened this issue Nov 19, 2024 · 3 comments
Open

Confusing Behaviour of Single Node Scenario #1162

Luncert opened this issue Nov 19, 2024 · 3 comments

Comments

@Luncert
Copy link

Luncert commented Nov 19, 2024

Your question

What's the expected behaviour of single node scenario?

Your scenes

I'm building a distributed system using JRaft and currently I'm trying to start only one instance for testing. The logic is simple as the counter example, a task is emitted somewhere and the state machine consume the task and execute responsive operation. But the fact is after emitting a task, the apply function in state machine is invoked multiple times
which causes repeat consumption. At the same time, the term keeps increasing until the hook onLeaderStart is invoked.

Another problem is, in the apply function, the task data is incorrect and can't be deserialized until the hook onLeaderStart is invoked.

I'm just a begniner of JRaft and not sure if it's a limitation of JRaft or caused by some incorrect coding by me. Thanks in advance for reply.

Your advice

Environment

  • SOFAJRaft version: 1.3.15

  • JVM version (e.g. java -version): jbr-17

  • OS version (e.g. uname -a): Darwin HNWYJ3K2W5 24.0.0 Darwin Kernel Version 24.0.0: Mon Aug 12 20:51:54 PDT 2024; root:xnu-11215.1.10~2/RELEASE_ARM64_T6000 arm64

  • Maven version: 3.8.6

  • IDE version: Idea

@fengjiachun
Copy link
Contributor

the apply function in state machine is invoked multiple times

This will not happen unless the client initiates the same request multiple times.
If your client automatically retries after a failure, jraft cannot detect it. This can usually be resolved by including an ID with each client request and using this ID in your state machine to identify duplicate requests.

Another problem is, in the apply function, the task data is incorrect and can't be deserialized until the hook onLeaderStart is invoked.

I didn't understand, could you show me the code?

@killme2008
Copy link
Contributor

killme2008 commented Nov 20, 2024

It seems there may be some misunderstanding regarding the state machine and log application.

Each time a node restarts, its state machine must reset to an empty(initial) state, and the logs in the Raft log storage are replayed to restore its last state before the restart.

When snapshots are enabled, the node loads the snapshot and replays the logs after the snapshot's log index.

Please read the JRaft user guide thoroughly, and consider reading RAFT algorithm papers or articles to enhance your understanding of JRaft.

@Luncert
Copy link
Author

Luncert commented Nov 25, 2024

It's possibly the result of logs replay. I'll check it later and thanks for reply.

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

No branches or pull requests

3 participants