Skip to content

Commit

Permalink
protocol_server: add per-protocol is_server_running method
Browse files Browse the repository at this point in the history
Change b0a2a97 broke
the generic api implementation of
is_native_transport_running that relied on
the addresses list being empty agter the server is stopped.

To fix that, this change introduces a pure virtual method:
protocol_server::is_server_running that can be implemented
by each derived class.

Test: unit(dev)
DTest: nodetool_additional_test.py:TestNodetool.binary_test

Signed-off-by: Benny Halevy <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
bhalevy authored and avikivity committed Nov 14, 2021
1 parent c9b8b84 commit 9d4262e
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions alternator/controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ std::vector<socket_address> controller::listen_addresses() const {
return _listen_addresses;
}

bool controller::is_server_running() const {
return !_listen_addresses.empty();
}

future<> controller::start_server() {
return seastar::async([this] {
_listen_addresses.clear();
Expand Down
1 change: 1 addition & 0 deletions alternator/controller.hh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public:
virtual sstring protocol() const override;
virtual sstring protocol_version() const override;
virtual std::vector<socket_address> listen_addresses() const override;
virtual bool is_server_running() const override;
virtual future<> start_server() override;
virtual future<> stop_server() override;
virtual future<> request_stop_server() override;
Expand Down
2 changes: 1 addition & 1 deletion api/storage_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void set_transport_controller(http_context& ctx, routes& r, cql_transport::contr

ss::is_native_transport_running.set(r, [&ctl] (std::unique_ptr<request> req) {
return smp::submit_to(0, [&] {
return !ctl.listen_addresses().empty();
return ctl.is_server_running();
}).then([] (bool running) {
return make_ready_future<json::json_return_type>(running);
});
Expand Down
2 changes: 2 additions & 0 deletions protocol_server.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public:
virtual sstring protocol_version() const = 0;
/// Addresses the server is listening on, should be empty when server is not running.
virtual std::vector<socket_address> listen_addresses() const = 0;
/// Check if the server is running.
virtual bool is_server_running() const = 0;
/// Start the server.
/// Can be called multiple times, in any state of the server.
virtual future<> start_server() = 0;
Expand Down
4 changes: 4 additions & 0 deletions redis/service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ std::vector<socket_address> redis_service::listen_addresses() const {
return _listen_addresses;
}

bool redis_service::is_server_running() const {
return !_listen_addresses.empty();
}

future<> redis_service::start_server()
{
// 1. Create keyspace/tables used by redis API if not exists.
Expand Down
1 change: 1 addition & 0 deletions redis/service.hh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public:
virtual sstring protocol() const override;
virtual sstring protocol_version() const override;
virtual std::vector<socket_address> listen_addresses() const override;
virtual bool is_server_running() const override;
virtual future<> start_server() override;
virtual future<> stop_server() override;
virtual future<> request_stop_server() override;
Expand Down
4 changes: 4 additions & 0 deletions thrift/controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ std::vector<socket_address> thrift_controller::listen_addresses() const {
return {};
}

bool thrift_controller::is_server_running() const {
return bool(_server);
}

future<> thrift_controller::start_server() {
if (!_ops_sem.try_wait()) {
throw std::runtime_error(format("Thrift server is stopping, try again later"));
Expand Down
1 change: 1 addition & 0 deletions thrift/controller.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public:
virtual sstring protocol() const override;
virtual sstring protocol_version() const override;
virtual std::vector<socket_address> listen_addresses() const override;
virtual bool is_server_running() const override;
virtual future<> start_server() override;
virtual future<> stop_server() override;
virtual future<> request_stop_server() override;
Expand Down
4 changes: 4 additions & 0 deletions transport/controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ std::vector<socket_address> controller::listen_addresses() const {
return _listen_addresses;
}

bool controller::is_server_running() const {
return bool(_server);
}

future<> controller::start_server() {
if (!_ops_sem.try_wait()) {
throw std::runtime_error(format("CQL server is stopping, try again later"));
Expand Down
1 change: 1 addition & 0 deletions transport/controller.hh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public:
virtual sstring protocol() const override;
virtual sstring protocol_version() const override;
virtual std::vector<socket_address> listen_addresses() const override;
virtual bool is_server_running() const override;
virtual future<> start_server() override;
virtual future<> stop_server() override;
virtual future<> request_stop_server() override;
Expand Down

0 comments on commit 9d4262e

Please sign in to comment.