Skip to content

Commit

Permalink
Throttle error messages that can happen too frequently
Browse files Browse the repository at this point in the history
Summary: Make sure that file that have badly formatted records don't spew too many times the same warning in a very short amount of times.

Reviewed By: kiminoue7

Differential Revision: D53068724

fbshipit-source-id: 0232fc48fb72c7d686fb9d16760b31d47ee9324f
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Jan 25, 2024
1 parent 077e323 commit 3d14d48
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions vrs/RecordReaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,20 @@
#include <logging/Verify.h>

#include <vrs/helpers/FileMacros.h>
#include <vrs/helpers/Throttler.h>

#include "ErrorCode.h"
#include "FileHandler.h"

namespace {

vrs::utils::Throttler& getThrottler() {
static vrs::utils::Throttler sThrottler{20 /*instances*/, 10 /*seconds*/};
return sThrottler;
}

} // namespace

namespace vrs {

RecordReader::~RecordReader() = default;
Expand All @@ -38,7 +49,8 @@ RecordReader* RecordReader::init(FileHandler& file, uint32_t diskSize, uint32_t
int UncompressedRecordReader::read(DataReference& destination, uint32_t& outReadSize) {
outReadSize = 0;
if (remainingUncompressedSize_ < destination.getSize()) {
XR_LOGE(
THROTTLED_LOGE(
file_,
"Tried to read {} bytes when at most {} are available.",
destination.getSize(),
remainingUncompressedSize_);
Expand All @@ -57,7 +69,8 @@ void CompressedRecordReader::initCompressionType(CompressionType compressionType
int CompressedRecordReader::read(DataReference& destination, uint32_t& outReadSize) {
outReadSize = 0;
if (remainingUncompressedSize_ < destination.getSize()) {
XR_LOGE(
THROTTLED_LOGE(
file_,
"Tried to read {} bytes when at most {} are available.",
destination.getSize(),
remainingUncompressedSize_);
Expand Down

0 comments on commit 3d14d48

Please sign in to comment.