GithubHelp home page GithubHelp logo

Comments (8)

greensky00 avatar greensky00 commented on June 28, 2024

From NuRaft's point of view, appending multiple logs doesn't need to be atomic as long as succeeded logs are consecutive.

"All or nothing" is up to you; if you want to make 10 logs atomic, you should make append_entries fail on the 6th log failure. Otherwise, it is OK for NuRaft to move forward with the succeeded 5 logs.

from nuraft.

kishorekrd avatar kishorekrd commented on June 28, 2024

Thanks for the response. Irrespective of the number of logs submitted to append_entries, handle_result() is called once. If partial number of logs append fails, How to handle it? What is the error that handle_result() gets in this case?

from nuraft.

greensky00 avatar greensky00 commented on June 28, 2024

If failure is detected so that you want to make the call fail, you can return ReturnNull in the callback AppendLogs.

CbReturnCode rc = ctx_->cb_func_.call(cb_func::AppendLogs, &param);
if (rc == CbReturnCode::ReturnNull) return nullptr;

then it will make append_entries call fail with BAD_REQUEST code.

from nuraft.

kishorekrd avatar kishorekrd commented on June 28, 2024

In case of raft_params::async_handler,
// Async mode:
// append_entries returns immediately.
// handle_result will be invoked asynchronously,
// after getting a consensus.

While appending 10 (multiple) logs, after appending 5 logs successfully, if leader change happens, remaining 5 logs will fail.
How do the caller come to know this failure, so that he can either

  1. make first 5 logs also as failed and retry all again.
  2. retry the failed 5 logs again.

I see that caller comes to know result with handle_result(), which shows whether it succeeded or failed?
https://github.com/eBay/NuRaft/blob/7ce0ef89775c0976c98381b3d5eda93cea6dca37/examples/calculator/calc_server.cxx#L47

Is there any other way to find this and return ReturnNull in the callback AppendLogs as you mentioned?

from nuraft.

greensky00 avatar greensky00 commented on June 28, 2024
  • If the leader changes before committing 5 appended logs, those logs are invalid and will be rolled back by the new leader.
  • YOU are the one who implements log store, so you are responsible for detecting such errors, not NuRaft. So any error happens in YOUR LOG STORE, you should remember it, and in YOUR callback function for AppendLogs, you should return ReturnNull. Then handle_result will check it by result.get_result_code() != cmd_result_code::BAD_REQUEST.

from nuraft.

kishorekrd avatar kishorekrd commented on June 28, 2024

OK that means, out of 10 logs, if leader change happens after appending 5 logs, logs 6 to 10 get the leader change error in the handle_result(), and also the new leader will rollback logs 1 to 5. Is this correct?
If so, All I need to do is tell the caller that logs 1 to 10 failed and it can retry.

AppendLogs callback is for having custom checks on the appended logs.

Thanks for the help.

from nuraft.

greensky00 avatar greensky00 commented on June 28, 2024

OK that means, out of 10 logs, if leader change happens after appending 5 logs, logs 6 to 10 get the leader change error in the handle_result(), and also the new leader will rollback logs 1 to 5. Is this correct?

Yes, that's correct.

from nuraft.

kishorekrd avatar kishorekrd commented on June 28, 2024

Thanks a lot for your help

from nuraft.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.