From e0f21c3bd528d2daa26875af352e27efb07ecedf Mon Sep 17 00:00:00 2001 From: Cory Snyder Date: Thu, 6 Jan 2022 13:55:48 -0500 Subject: [PATCH] rgw: reopen ops log file on sighup Handles radosgw SIGHUP such that ops log file is reopened if applicable. Fixes: https://tracker.ceph.com/issues/53788 Signed-off-by: Cory Snyder (cherry picked from commit f26523f59add768d3d2305642bb641d6675f8f82) --- src/rgw/rgw_log.cc | 11 ++++++++++- src/rgw/rgw_log.h | 3 +++ src/rgw/rgw_main.cc | 14 +++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_log.cc b/src/rgw/rgw_log.cc index 33b161a45f9f9..01789bd4e04f3 100644 --- a/src/rgw/rgw_log.cc +++ b/src/rgw/rgw_log.cc @@ -344,10 +344,14 @@ int OpsLogManifold::log(struct req_state* s, struct rgw_log_entry& entry) } OpsLogFile::OpsLogFile(CephContext* cct, std::string& path, uint64_t max_data_size) : - cct(cct), file(path, std::ofstream::app), data_size(0), max_data_size(max_data_size) + cct(cct), data_size(0), max_data_size(max_data_size), path(path), need_reopen(false) { } +void OpsLogFile::reopen() { + need_reopen = true; +} + void OpsLogFile::flush() { { @@ -359,6 +363,11 @@ void OpsLogFile::flush() for (auto bl : flush_buffer) { int try_num = 0; while (true) { + if (!file.is_open() || need_reopen) { + need_reopen = false; + file.close(); + file.open(path, std::ofstream::app); + } bl.write_stream(file); if (!file) { ldpp_dout(this, 0) << "ERROR: failed to log RGW ops log file entry" << dendl; diff --git a/src/rgw/rgw_log.h b/src/rgw/rgw_log.h index 7bcb62b18579c..874f97079c793 100644 --- a/src/rgw/rgw_log.h +++ b/src/rgw/rgw_log.h @@ -173,6 +173,8 @@ class OpsLogFile : public JsonOpsLogSink, public Thread, public DoutPrefixProvid bool stopped; uint64_t data_size; uint64_t max_data_size; + std::string path; + std::atomic_bool need_reopen; void flush(); protected: @@ -184,6 +186,7 @@ public: CephContext *get_cct() const override { return cct; } unsigned get_subsys() const override { return dout_subsys; } std::ostream& gen_prefix(std::ostream& out) const override { return out << "rgw OpsLogFile: "; } + void reopen(); void start(); void stop(); }; diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index 8d6555a2b7fa0..a346b33b7c004 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -131,6 +131,15 @@ static void handle_sigterm(int signum) } +static OpsLogFile* ops_log_file = nullptr; + +static void rgw_sighup_handler(int signum) { + if (ops_log_file != nullptr) { + ops_log_file->reopen(); + } + sighup_handler(signum); +} + static void godown_alarm(int signum) { _exit(0); @@ -315,7 +324,6 @@ int radosgw_Main(int argc, const char **argv) common_init_finish(g_ceph_context); init_async_signal_handler(); - register_async_signal_handler(SIGHUP, sighup_handler); TracepointProvider::initialize(g_ceph_context); TracepointProvider::initialize(g_ceph_context); @@ -546,12 +554,12 @@ int radosgw_Main(int argc, const char **argv) olog_socket->init(g_conf()->rgw_ops_log_socket_path); olog->add_sink(olog_socket); } - OpsLogFile* ops_log_file; if (!g_conf()->rgw_ops_log_file_path.empty()) { ops_log_file = new OpsLogFile(g_ceph_context, g_conf()->rgw_ops_log_file_path, g_conf()->rgw_ops_log_data_backlog); ops_log_file->start(); olog->add_sink(ops_log_file); } + register_async_signal_handler(SIGHUP, rgw_sighup_handler); olog->add_sink(new OpsLogRados(store)); r = signal_fd_init(); @@ -693,7 +701,7 @@ int radosgw_Main(int argc, const char **argv) delete fec; } - unregister_async_signal_handler(SIGHUP, sighup_handler); + unregister_async_signal_handler(SIGHUP, rgw_sighup_handler); unregister_async_signal_handler(SIGTERM, handle_sigterm); unregister_async_signal_handler(SIGINT, handle_sigterm); unregister_async_signal_handler(SIGUSR1, handle_sigterm); -- 2.47.3