Skip to content
Open
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
24 changes: 14 additions & 10 deletions core/impl/cluster.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -371,18 +371,21 @@ class cluster_impl : public std::enable_shared_from_this<cluster_impl>
if (event == fork_event::prepare) {
io_.stop();
io_thread_.join();
io_.notify_fork(fork_event_to_asio(event));
if (transactions_) {
transactions_->notify_fork(event);
}
} else {
// TODO(SA): close all sockets in fork_event::child
io_.restart();
io_.notify_fork(fork_event_to_asio(event));
if (event == fork_event::parent && transactions_) {
transactions_->notify_fork(event);
}
io_thread_ = std::thread{ [&io = io_] {
io.run();
} };
}
io_.notify_fork(fork_event_to_asio(event));

if (event != fork_event::child && transactions_) {
transactions_->notify_fork(event);
}
}

void close(core::utils::movable_function<void()> handler)
Expand Down Expand Up @@ -599,9 +602,9 @@ cluster::notify_fork(fork_event event) -> void
if (err.ec()) {
// TODO(SA): we should fall to background reconnect loop similar to Columnar build
CB_LOG_ERROR("Unable to reconnect instance after fork: {}", err.ec().message());
return;
} else {
impl_ = new_impl;
}
impl_ = new_impl;
barrier->set_value();
});

Expand All @@ -612,10 +615,11 @@ cluster::notify_fork(fork_event event) -> void
void
cluster::close(std::function<void()>&& handler)
{
if (!impl_) {
return handler();
if (auto impl = std::move(impl_); impl) {
impl->close(std::move(handler));
} else {
handler();
}
impl_->close(std::move(handler));
}

auto
Expand Down
20 changes: 10 additions & 10 deletions test/test_integration_examples.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ namespace start_using
#include <tao/json.hpp>
#include <tao/json/contrib/traits.hpp>

int
main(int argc, const char* argv[])
auto
main(int argc, const char* argv[]) -> int
{
if (argc != 4) {
fmt::print("USAGE: ./start_using couchbase://127.0.0.1 Administrator password\n");
Expand Down Expand Up @@ -284,8 +284,8 @@ class github_actions_configuration_profile : public couchbase::configuration_pro
}
};

int
main(int argc, const char* argv[])
auto
main(int argc, const char* argv[]) -> int
{
if (argc != 4) {
fmt::print("USAGE: ./example_search couchbase://127.0.0.1 Administrator password\n");
Expand Down Expand Up @@ -594,8 +594,8 @@ namespace example_buckets
//! [example-buckets]
#include <couchbase/cluster.hxx>

int
main(int argc, const char* argv[])
auto
main(int argc, const char* argv[]) -> int
{
if (argc != 4) {
fmt::print("USAGE: ./example_buckets couchbase://127.0.0.1 Administrator password\n");
Expand Down Expand Up @@ -725,8 +725,8 @@ namespace example_fork

#include <sys/wait.h>

int
main(int argc, const char* argv[])
auto
main(int argc, const char* argv[]) -> int
{
if (argc != 4) {
fmt::print("USAGE: ./example_fork couchbase://127.0.0.1 Administrator password\n");
Expand All @@ -747,14 +747,13 @@ main(int argc, const char* argv[])
return 1;
}

auto bucket = cluster.bucket(bucket_name);

cluster.notify_fork(couchbase::fork_event::prepare);
auto child_pid = fork();
if (child_pid == 0) {
cluster.notify_fork(couchbase::fork_event::child);

fmt::print("CHILD(pid={}): continue after fork()\n", getpid());
auto bucket = cluster.bucket(bucket_name);
auto collection = bucket.scope("tenant_agent_00").collection("users");

{
Expand Down Expand Up @@ -790,6 +789,7 @@ main(int argc, const char* argv[])
cluster.notify_fork(couchbase::fork_event::parent);
fmt::print("PARENT(pid={}): continue after fork() child_pid={}\n", getpid(), child_pid);

auto bucket = cluster.bucket(bucket_name);
{
auto collection = bucket.scope("tenant_agent_00").collection("users");
std::string doc_id = "tenant_agent_00";
Expand Down
Loading