Skip to content

Commit f26523f

Browse files
committed
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 <[email protected]>
1 parent f2313ed commit f26523f

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/rgw/rgw_log.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,14 @@ int OpsLogManifold::log(struct req_state* s, struct rgw_log_entry& entry)
344344
}
345345

346346
OpsLogFile::OpsLogFile(CephContext* cct, std::string& path, uint64_t max_data_size) :
347-
cct(cct), file(path, std::ofstream::app), data_size(0), max_data_size(max_data_size)
347+
cct(cct), data_size(0), max_data_size(max_data_size), path(path), need_reopen(false)
348348
{
349349
}
350350

351+
void OpsLogFile::reopen() {
352+
need_reopen = true;
353+
}
354+
351355
void OpsLogFile::flush()
352356
{
353357
std::scoped_lock flush_lock(flush_mutex);
@@ -360,6 +364,11 @@ void OpsLogFile::flush()
360364
for (auto bl : flush_buffer) {
361365
int try_num = 0;
362366
while (true) {
367+
if (!file.is_open() || need_reopen) {
368+
need_reopen = false;
369+
file.close();
370+
file.open(path, std::ofstream::app);
371+
}
363372
bl.write_stream(file);
364373
if (!file) {
365374
ldpp_dout(this, 0) << "ERROR: failed to log RGW ops log file entry" << dendl;

src/rgw/rgw_log.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ class OpsLogFile : public JsonOpsLogSink, public Thread, public DoutPrefixProvid
174174
bool stopped;
175175
uint64_t data_size;
176176
uint64_t max_data_size;
177+
std::string path;
178+
std::atomic_bool need_reopen;
177179

178180
void flush();
179181
protected:
@@ -185,6 +187,7 @@ class OpsLogFile : public JsonOpsLogSink, public Thread, public DoutPrefixProvid
185187
CephContext *get_cct() const override { return cct; }
186188
unsigned get_subsys() const override { return dout_subsys; }
187189
std::ostream& gen_prefix(std::ostream& out) const override { return out << "rgw OpsLogFile: "; }
190+
void reopen();
188191
void start();
189192
void stop();
190193
};

src/rgw/rgw_main.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ static void handle_sigterm(int signum)
130130

131131
}
132132

133+
static OpsLogFile* ops_log_file = nullptr;
134+
135+
static void rgw_sighup_handler(int signum) {
136+
if (ops_log_file != nullptr) {
137+
ops_log_file->reopen();
138+
}
139+
sighup_handler(signum);
140+
}
141+
133142
static void godown_alarm(int signum)
134143
{
135144
_exit(0);
@@ -314,7 +323,6 @@ int radosgw_Main(int argc, const char **argv)
314323
common_init_finish(g_ceph_context);
315324

316325
init_async_signal_handler();
317-
register_async_signal_handler(SIGHUP, sighup_handler);
318326

319327
TracepointProvider::initialize<rgw_rados_tracepoint_traits>(g_ceph_context);
320328
TracepointProvider::initialize<rgw_op_tracepoint_traits>(g_ceph_context);
@@ -541,12 +549,12 @@ int radosgw_Main(int argc, const char **argv)
541549
olog_socket->init(g_conf()->rgw_ops_log_socket_path);
542550
olog->add_sink(olog_socket);
543551
}
544-
OpsLogFile* ops_log_file;
545552
if (!g_conf()->rgw_ops_log_file_path.empty()) {
546553
ops_log_file = new OpsLogFile(g_ceph_context, g_conf()->rgw_ops_log_file_path, g_conf()->rgw_ops_log_data_backlog);
547554
ops_log_file->start();
548555
olog->add_sink(ops_log_file);
549556
}
557+
register_async_signal_handler(SIGHUP, rgw_sighup_handler);
550558
olog->add_sink(new OpsLogRados(store));
551559

552560
r = signal_fd_init();
@@ -688,7 +696,7 @@ int radosgw_Main(int argc, const char **argv)
688696
delete fec;
689697
}
690698

691-
unregister_async_signal_handler(SIGHUP, sighup_handler);
699+
unregister_async_signal_handler(SIGHUP, rgw_sighup_handler);
692700
unregister_async_signal_handler(SIGTERM, handle_sigterm);
693701
unregister_async_signal_handler(SIGINT, handle_sigterm);
694702
unregister_async_signal_handler(SIGUSR1, handle_sigterm);

0 commit comments

Comments
 (0)