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

add a process to check if the server is dead or alive when a timeout … #105

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/ogawayama/transport/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class transport {
public:
transport() = delete;

explicit transport(tateyama::common::wire::session_wire_container& wire) : wire_(wire) {
explicit transport(tateyama::common::wire::session_wire_container& wire) : wire_(wire), status_provider_(wire_.get_status_provider()) {
header_.set_service_message_version_major(HEADER_MESSAGE_VERSION_MAJOR);
header_.set_service_message_version_minor(HEADER_MESSAGE_VERSION_MINOR);
header_.set_service_id(SERVICE_ID_SQL);
Expand Down Expand Up @@ -333,6 +333,7 @@ class transport {

private:
tateyama::common::wire::session_wire_container& wire_;
tateyama::common::wire::status_provider &status_provider_;
::tateyama::proto::framework::request::Header header_{};
::tateyama::proto::framework::request::Header bridge_header_{};
::jogasaki::proto::sql::common::Session session_{};
Expand Down Expand Up @@ -414,9 +415,9 @@ class transport {
wire_.receive(response_message, slot_index);
break;
} catch (std::runtime_error &e) {
// if (status_info_->alive()) { // FIXME alive check
// continue;
// }
if (status_provider_.is_alive().empty()) {
continue;
}
std::cerr << e.what() << std::endl;
return std::nullopt;
}
Expand Down Expand Up @@ -492,9 +493,9 @@ class transport {
wire_.receive(response_message, slot_index);
break;
} catch (std::runtime_error &e) {
// if (status_info_->alive()) { // FIXME alive check
// continue;
// }
if (status_provider_.is_alive().empty()) {
continue;
}
std::cerr << e.what() << std::endl;
return std::nullopt;
}
Expand Down
48 changes: 37 additions & 11 deletions src/tateyama/transport/client_wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,23 @@ class session_wire_container
current_wire_ = active_wire();
}
if (current_wire_ != nullptr) {
std::string_view extrusion{};
auto rtnv = current_wire_->get_chunk(current_wire_->get_bip_address(managed_shm_ptr_), extrusion);
if (extrusion.length() == 0) {
return rtnv;
while (true) {
try {
std::string_view extrusion{};
auto rtnv = current_wire_->get_chunk(current_wire_->get_bip_address(managed_shm_ptr_), extrusion);
if (extrusion.length() == 0) {
return rtnv;
}
wrap_around_ = rtnv;
wrap_around_ += extrusion;
return wrap_around_;
} catch (std::runtime_error &ex) {
if (auto err = envelope_->get_status_provider().is_alive(); !err.empty()) {
throw ex; // FIXME handle this
}
continue;
}
}
wrap_around_ = rtnv;
wrap_around_ += extrusion;
return wrap_around_;
}
return {nullptr, 0};
}
Expand Down Expand Up @@ -119,7 +128,8 @@ class session_wire_container
class response_wire_container {
public:
response_wire_container() = default;
response_wire_container(unidirectional_response_wire* wire, char* bip_buffer) noexcept : wire_(wire), bip_buffer_(bip_buffer) {};
response_wire_container(session_wire_container* envelope, unidirectional_response_wire* wire, char* bip_buffer) noexcept
: envelope_(envelope), wire_(wire), bip_buffer_(bip_buffer) {};
[[nodiscard]] response_header::length_type get_length() const noexcept {
return wire_->get_length();
}
Expand All @@ -137,11 +147,21 @@ class session_wire_container
}

private:
session_wire_container* envelope_{};
unidirectional_response_wire* wire_{};
char* bip_buffer_{};

response_header await() {
return wire_->await(bip_buffer_);
while (true) {
try {
return wire_->await(bip_buffer_);
} catch (std::runtime_error &ex) {
if (auto err = envelope_->get_status_provider().is_alive(); !err.empty()) {
throw ex; // FIXME handle this
}
continue;
}
}
}

friend class session_wire_container;
Expand Down Expand Up @@ -216,11 +236,12 @@ class session_wire_container
managed_shared_memory_ = std::make_unique<boost::interprocess::managed_shared_memory>(boost::interprocess::open_only, db_name_.c_str());
auto req_wire = managed_shared_memory_->find<unidirectional_message_wire>(request_wire_name).first;
auto res_wire = managed_shared_memory_->find<unidirectional_response_wire>(response_wire_name).first;
if (req_wire == nullptr || res_wire == nullptr) {
status_provider_ = managed_shared_memory_->find<status_provider>(status_provider_name).first;
if (req_wire == nullptr || res_wire == nullptr || status_provider_ == nullptr) {
throw std::runtime_error("cannot find the session wire");
}
request_wire_ = request_wire_container(req_wire, req_wire->get_bip_address(managed_shared_memory_.get()));
response_wire_ = response_wire_container(res_wire, res_wire->get_bip_address(managed_shared_memory_.get()));
response_wire_ = response_wire_container(this, res_wire, res_wire->get_bip_address(managed_shared_memory_.get()));
}
catch(const boost::interprocess::interprocess_exception& ex) {
throw std::runtime_error("cannot find a session with the specified name");
Expand Down Expand Up @@ -308,11 +329,16 @@ class session_wire_container
return std::make_unique<resultset_wires_container>(this);
}

status_provider& get_status_provider() {
return *status_provider_;
}

private:
std::string db_name_;
std::unique_ptr<boost::interprocess::managed_shared_memory> managed_shared_memory_{};
request_wire_container request_wire_{};
response_wire_container response_wire_{};
status_provider* status_provider_{};
std::array<slot, slot_size> slot_status_{};
std::mutex mtx_send_{};
std::mutex mtx_receive_{};
Expand Down
2 changes: 2 additions & 0 deletions test/ogawayama/stub/server_wires_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ class server_wire_container

request_wire_.initialize(req_wire, req_wire->get_bip_address(managed_shared_memory_.get()));
response_wire_.initialize(res_wire, res_wire->get_bip_address(managed_shared_memory_.get()));
status_provider_ = managed_shared_memory_->construct<tateyama::common::wire::status_provider>(tateyama::common::wire::status_provider_name)(managed_shared_memory_.get(), "dummy_mutex_file");
} catch(const boost::interprocess::interprocess_exception& ex) {
LOG(ERROR) << ex.what() << " on server_wire_container::server_wire_container()";
pthread_exit(nullptr); // FIXME
Expand Down Expand Up @@ -410,6 +411,7 @@ class server_wire_container
std::unique_ptr<boost::interprocess::managed_shared_memory> managed_shared_memory_{};
wire_container request_wire_{};
response_wire_container response_wire_{};
tateyama::common::wire::status_provider* status_provider_{};
bool session_closed_{false};
std::mutex mtx_shm_{};
};
Expand Down