Skip to content

Commit e99a83c

Browse files
authored
Flush logs before shutdown (#13065)
1 parent 52688fe commit e99a83c

3 files changed

Lines changed: 29 additions & 6 deletions

File tree

include/proxy/logging/Log.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ class Log
173173
static int va_error(const char *format, va_list ap);
174174
static int error(const char *format, ...) TS_PRINTFLIKE(1, 2);
175175

176+
static void flush_all_objects();
177+
176178
// public data members
177179
static LogObject *error_log;
178180
/** The latest fully initialized LogConfig.

src/proxy/logging/Log.cc

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,14 @@ Log::va_error(const char *format, va_list ap)
13251325
return ret_val;
13261326
}
13271327

1328+
void
1329+
Log::flush_all_objects()
1330+
{
1331+
if (config) {
1332+
config->log_object_manager.flush_all_objects();
1333+
}
1334+
}
1335+
13281336
/*-------------------------------------------------------------------------
13291337
Log::preproc_thread_main
13301338
@@ -1343,9 +1351,6 @@ Log::preproc_thread_main(void *args)
13431351
Log::preproc_notify[idx].lock();
13441352

13451353
while (true) {
1346-
if (TSSystemState::is_event_system_shut_down()) {
1347-
return nullptr;
1348-
}
13491354
LogConfig *current = static_cast<LogConfig *>(configProcessor.get(log_configid));
13501355

13511356
if (likely(current)) {
@@ -1360,6 +1365,13 @@ Log::preproc_thread_main(void *args)
13601365
configProcessor.release(log_configid, current);
13611366
}
13621367

1368+
// Drain any remaining buffers before exiting on shutdown.
1369+
if (TSSystemState::is_event_system_shut_down()) {
1370+
// Signal flush thread to drain data we just pushed.
1371+
Log::flush_notify->signal();
1372+
return nullptr;
1373+
}
1374+
13631375
// wait for more work; a spurious wake-up is ok since we'll just
13641376
// check the queue and find there is nothing to do, then wait
13651377
// again.
@@ -1384,9 +1396,6 @@ Log::flush_thread_main(void * /* args ATS_UNUSED */)
13841396
Log::flush_notify->lock();
13851397

13861398
while (true) {
1387-
if (TSSystemState::is_event_system_shut_down()) {
1388-
return nullptr;
1389-
}
13901399
fdata = static_cast<LogFlushData *>(ink_atomiclist_popall(flush_data_list));
13911400

13921401
// invert the list
@@ -1478,6 +1487,10 @@ Log::flush_thread_main(void * /* args ATS_UNUSED */)
14781487
// check the queue and find there is nothing to do, then wait
14791488
// again.
14801489
//
1490+
if (TSSystemState::is_event_system_shut_down()) {
1491+
return nullptr;
1492+
}
1493+
14811494
Log::flush_notify->wait();
14821495
}
14831496

src/traffic_server/traffic_server.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,15 @@ struct AutoStopCont : public Continuation {
287287
jsonrpcServer->stop_thread();
288288
}
289289

290+
// Push buffered log entries into the preproc queue before shutdown.
291+
Log::flush_all_objects();
292+
290293
TSSystemState::shut_down_event_system();
294+
295+
// Wake preproc threads to drain remaining log buffers before exit.
296+
for (int i = 0; i < Log::preproc_threads; i++) {
297+
Log::preproc_notify[i].signal();
298+
}
291299
delete this;
292300
return EVENT_CONT;
293301
}

0 commit comments

Comments
 (0)