Skip to content

Commit

Permalink
asio_service support stream mode (#527)
Browse files Browse the repository at this point in the history
* asio_service support stream mode
1. set TCP_NODELAY = true this can be set after the socket open. So we can't set it in constructor. (async_connect will open the socket)
2. does the order of calling all the when_done matter when error occur? in write path when_done(error triggered) -> close_socket(in destructor) in read path close_socket(directly call) -> when_done(error triggered)
3. keep the old path for all request if stream_mode_ = false

already addressed all the comment.

* handle comments

* fix error

* error handle

* move all function call out of lock

* [Refactoring] renaming, comments, indent

---------

Co-authored-by: lihzeng <[email protected]>
Co-authored-by: Jung-Sang Ahn <[email protected]>
  • Loading branch information
3 people authored Aug 16, 2024
1 parent 0a754e0 commit 680fbdf
Show file tree
Hide file tree
Showing 6 changed files with 517 additions and 108 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
pull_request:
branches:
- master
- streaming

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand Down
8 changes: 8 additions & 0 deletions include/libnuraft/asio_service_options.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ struct asio_service_options {
, crc_on_entire_message_(false)
, crc_on_payload_(false)
, corrupted_msg_handler_(nullptr)
, streaming_mode_(false)
{}

/**
Expand Down Expand Up @@ -276,6 +277,13 @@ struct asio_service_options {
*/
std::function< void( std::shared_ptr<buffer>,
std::shared_ptr<buffer> ) > corrupted_msg_handler_;

/**
* If `true`, NuRaft will use streaming mode, which allows it to send
* subsequent requests without waiting for the response to previous requests.
* The order of responses will be identical to the order of requests.
*/
bool streaming_mode_;
};

}
Expand Down
1 change: 1 addition & 0 deletions scripts/test/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ set -e
./tests/raft_server_test --abort-on-failure
./tests/failure_test --abort-on-failure
./tests/asio_service_test --abort-on-failure
./tests/asio_service_stream_test --abort-on-failure
Loading

0 comments on commit 680fbdf

Please sign in to comment.