Skip to content

Commit

Permalink
Merge pull request #31577 from ClickHouse/backport/21.3/31337
Browse files Browse the repository at this point in the history
Backport #31337 to 21.3: fix: quota limit was not reached, but the limit was exceeded
  • Loading branch information
Vitaly Baranov committed Nov 21, 2021
2 parents 44a001c + 8d4e92f commit b50786d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Access/EnabledQuota.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ struct EnabledQuota::Impl
return end;
}

/// We reset counters only if the interval's end has been calculated before.
/// If it hasn't we just calculate the interval's end for the first time and don't reset counters yet.
bool need_reset_counters = (end_loaded.count() != 0);
bool need_reset_counters = false;

do
{
Expand All @@ -66,7 +64,12 @@ struct EnabledQuota::Impl
UInt64 n = static_cast<UInt64>((current_time - end + duration) / duration);
end = end + duration * n;
if (end_of_interval.compare_exchange_strong(end_loaded, end.time_since_epoch()))
{
/// We reset counters only if the interval's end has been calculated before.
/// If it hasn't we just calculate the interval's end for the first time and don't reset counters yet.
need_reset_counters = (end_loaded.count() != 0);
break;
}
end = std::chrono::system_clock::time_point{end_loaded};
}
while (current_time >= end);
Expand Down

0 comments on commit b50786d

Please sign in to comment.