From 5759d97746ee380283475c81034472dc13ba9ebe Mon Sep 17 00:00:00 2001 From: Sergey Avseyev Date: Mon, 22 Apr 2024 11:32:02 -0700 Subject: [PATCH] PCBC-986 restart connections in the child process --- src/wrapper/connection_handle.cxx | 20 +++++++++++--------- src/wrapper/connection_handle.hxx | 2 +- src/wrapper/persistent_connections_cache.cxx | 6 ++++-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/wrapper/connection_handle.cxx b/src/wrapper/connection_handle.cxx index ccafd24..a3a8220 100644 --- a/src/wrapper/connection_handle.cxx +++ b/src/wrapper/connection_handle.cxx @@ -599,7 +599,7 @@ class connection_handle::impl : public std::enable_shared_from_thisctx_.run(); }); - const auto report_id = fmt::format("child-{}", spdlog::details::os::pid()); - - if (auto [err, resp] = diagnostics(report_id); err.ec) { - CB_LOG_DEBUG("Failed to run diagnostics for {} in child process", cluster_->to_string()); - } else { - CB_LOG_DEBUG("State of {} in the child after fork: {}", cluster_->to_string(), core::utils::json::generate(resp)); + CB_LOG_DEBUG("Closing {} in child process", cluster_->to_string()); + cluster_->close([]() { }); + CB_LOG_DEBUG("Starting new connection in child process", cluster_->to_string()); + if (auto err = open(); err.ec) { + CB_LOG_WARNING("Failed to restart connection in child process: {}", err.ec.message()); + return err; } } + return {}; } private: @@ -685,8 +686,9 @@ connection_handle::replicas_configured_for_bucket(const zend_string* bucket_name return impl_->replicas_configured_for_bucket(cb_string_new(bucket_name)); } -void -connection_handle::notify_fork(fork_event event) const +COUCHBASE_API +core_error_info +connection_handle::notify_fork(fork_event event) { return impl_->notify_fork(event); } diff --git a/src/wrapper/connection_handle.hxx b/src/wrapper/connection_handle.hxx index ef6c064..d16a4ce 100644 --- a/src/wrapper/connection_handle.hxx +++ b/src/wrapper/connection_handle.hxx @@ -83,7 +83,7 @@ class connection_handle bool replicas_configured_for_bucket(const zend_string* bucket_name); COUCHBASE_API - void notify_fork(fork_event event) const; + core_error_info notify_fork(fork_event event); COUCHBASE_API core_error_info open(); diff --git a/src/wrapper/persistent_connections_cache.cxx b/src/wrapper/persistent_connections_cache.cxx index dc0a8d8..e95c67d 100644 --- a/src/wrapper/persistent_connections_cache.cxx +++ b/src/wrapper/persistent_connections_cache.cxx @@ -204,8 +204,10 @@ notify_connection(zval* zv, void* event_ptr) const fork_event event = *(static_cast(event_ptr)); if (res->type == persistent_connection_destructor_id_) { - const auto* connection = static_cast(res->ptr); - connection->notify_fork(event); + auto* connection = static_cast(res->ptr); + if (auto err = connection->notify_fork(event); err.ec) { + return ZEND_HASH_APPLY_REMOVE; + } } return ZEND_HASH_APPLY_KEEP; } -- 2.44.0