Closed kishorekrd closed 2 years ago
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.
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?
If failure is detected so that you want to make the call fail, you can return ReturnNull
in the callback AppendLogs
.
https://github.com/eBay/NuRaft/blob/7ce0ef89775c0976c98381b3d5eda93cea6dca37/src/handle_client_request.cxx#L146-L147
then it will make append_entries
call fail with BAD_REQUEST
code.
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
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?
AppendLogs
, you should return ReturnNull
. Then handle_result
will check it by result.get_result_code() != cmd_result_code::BAD_REQUEST
.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.
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.
Thanks a lot for your help
end_of_append_batch() is called for disk flush after processing all the log records passed to append_entries(). I see that append_entries takes vector of log records. Is this operation atomic, as all or none? If I submit 10 records to it, what happens if 5 log records get appended and then 6th one fails? How is this handled?