From: Cory Snyder Date: Thu, 6 Jan 2022 18:55:48 +0000 (-0500) Subject: rgw: reopen ops log file on sighup X-Git-Tag: v16.2.11~494^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F46619%2Fhead;p=ceph.git 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) Conflicts: src/rgw/rgw_main.cc Cherry-pick notes: - OpsLogRados initialized differently in Pacific --- diff --git a/src/rgw/rgw_log.cc b/src/rgw/rgw_log.cc index efd36ef241e1..b22f437be554 100644 --- a/src/rgw/rgw_log.cc +++ b/src/rgw/rgw_log.cc @@ -342,10 +342,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() { { @@ -357,6 +361,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 8eeda49ab321..7b384c2d854c 100644 --- a/src/rgw/rgw_log.h +++ b/src/rgw/rgw_log.h @@ -171,6 +171,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: @@ -182,6 +184,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 3a5e15dcc941..f7a477954f28 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -129,6 +129,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); @@ -314,7 +323,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); @@ -510,12 +518,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(); @@ -681,7 +689,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);