Skip to content

Commit 7eaed47

Browse files
authored
Merge pull request ceph#44488 from cfsnyder/wip-53788-reopen-ops-log-sighup
rgw: reopen ops log file on sighup Reviewed-by: Casey Bodley <[email protected]>
2 parents e11e62e + f26523f commit 7eaed47

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
@@ -131,6 +131,15 @@ static void handle_sigterm(int signum)
131131

132132
}
133133

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

317326
init_async_signal_handler();
318-
register_async_signal_handler(SIGHUP, sighup_handler);
319327

320328
TracepointProvider::initialize<rgw_rados_tracepoint_traits>(g_ceph_context);
321329
TracepointProvider::initialize<rgw_op_tracepoint_traits>(g_ceph_context);
@@ -552,12 +560,12 @@ int radosgw_Main(int argc, const char **argv)
552560
olog_socket->init(g_conf()->rgw_ops_log_socket_path);
553561
olog->add_sink(olog_socket);
554562
}
555-
OpsLogFile* ops_log_file;
556563
if (!g_conf()->rgw_ops_log_file_path.empty()) {
557564
ops_log_file = new OpsLogFile(g_ceph_context, g_conf()->rgw_ops_log_file_path, g_conf()->rgw_ops_log_data_backlog);
558565
ops_log_file->start();
559566
olog->add_sink(ops_log_file);
560567
}
568+
register_async_signal_handler(SIGHUP, rgw_sighup_handler);
561569
olog->add_sink(new OpsLogRados(store));
562570

563571
r = signal_fd_init();
@@ -699,7 +707,7 @@ int radosgw_Main(int argc, const char **argv)
699707
delete fec;
700708
}
701709

702-
unregister_async_signal_handler(SIGHUP, sighup_handler);
710+
unregister_async_signal_handler(SIGHUP, rgw_sighup_handler);
703711
unregister_async_signal_handler(SIGTERM, handle_sigterm);
704712
unregister_async_signal_handler(SIGINT, handle_sigterm);
705713
unregister_async_signal_handler(SIGUSR1, handle_sigterm);

0 commit comments

Comments
 (0)