Skip to content

Commit 184cc2e

Browse files
authored
Merge pull request ClickHouse#79864 from filimonov/patch-16
Fix LogSeriesLimiter cleanup logic to run only once per interval
2 parents 439a651 + 3dd94e0 commit 184cc2e

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/Common/LoggingFormatStringHelpers.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,18 @@ LogSeriesLimiter::LogSeriesLimiter(LoggerPtr logger_, size_t allowed_count_, tim
9090
}
9191

9292
time_t now = time(nullptr);
93+
static const time_t cleanup_delay_s = 600;
94+
time_t cutoff_time = now - cleanup_delay_s; // entries older than this are stale
95+
9396
UInt128 name_hash = sipHash128(logger->name().c_str(), logger->name().size());
9497

9598
std::lock_guard lock(mutex);
9699

97-
if (last_cleanup == 0)
98-
last_cleanup = now;
99-
100100
auto & series_records = getSeriesRecords();
101101

102-
static const time_t cleanup_delay_s = 600;
103-
if (last_cleanup + cleanup_delay_s >= now)
102+
if (last_cleanup < cutoff_time) // will also be triggered when last_cleanup is zero
104103
{
105-
time_t old = now - cleanup_delay_s;
106-
std::erase_if(series_records, [old](const auto & elem) { return get<0>(elem.second) < old; });
104+
std::erase_if(series_records, [cutoff_time](const auto & elem) { return get<0>(elem.second) < cutoff_time; });
107105
last_cleanup = now;
108106
}
109107

0 commit comments

Comments
 (0)