From ea8ad4f6780509ef50a3e0e051aed0ae4a0a1d22 Mon Sep 17 00:00:00 2001 From: Islam AbdelRahman Date: Mon, 24 Jul 2017 11:53:03 -0700 Subject: [PATCH] Fix compaction div by zero logging Summary: We will divide by zero if `stats.micros` is zero, just add a simple check This happens sometimes during running tests and UBSAN complains Closes https://github.com/facebook/rocksdb/pull/2631 Differential Revision: D5481455 Pulled By: IslamAbdelRahman fbshipit-source-id: 69aa24e64e21de15d9e2b8009adf01675fcc6598 --- db/compaction_job.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/db/compaction_job.cc b/db/compaction_job.cc index 636cdbea1..75f5ab6c8 100644 --- a/db/compaction_job.cc +++ b/db/compaction_job.cc @@ -594,6 +594,9 @@ Status CompactionJob::Install(const MutableCFOptions& mutable_cf_options) { double read_write_amp = 0.0; double write_amp = 0.0; + double bytes_read_per_sec = 0; + double bytes_written_per_sec = 0; + if (stats.bytes_read_non_output_levels > 0) { read_write_amp = (stats.bytes_written + stats.bytes_read_output_level + stats.bytes_read_non_output_levels) / @@ -601,17 +604,22 @@ Status CompactionJob::Install(const MutableCFOptions& mutable_cf_options) { write_amp = stats.bytes_written / static_cast(stats.bytes_read_non_output_levels); } + if (stats.micros > 0) { + bytes_read_per_sec = + (stats.bytes_read_non_output_levels + stats.bytes_read_output_level) / + static_cast(stats.micros); + bytes_written_per_sec = + stats.bytes_written / static_cast(stats.micros); + } + ROCKS_LOG_BUFFER( log_buffer_, "[%s] compacted to: %s, MB/sec: %.1f rd, %.1f wr, level %d, " "files in(%d, %d) out(%d) " "MB in(%.1f, %.1f) out(%.1f), read-write-amplify(%.1f) " "write-amplify(%.1f) %s, records in: %d, records dropped: %d\n", - cfd->GetName().c_str(), vstorage->LevelSummary(&tmp), - (stats.bytes_read_non_output_levels + stats.bytes_read_output_level) / - static_cast(stats.micros), - stats.bytes_written / static_cast(stats.micros), - compact_->compaction->output_level(), + cfd->GetName().c_str(), vstorage->LevelSummary(&tmp), bytes_read_per_sec, + bytes_written_per_sec, compact_->compaction->output_level(), stats.num_input_files_in_non_output_levels, stats.num_input_files_in_output_level, stats.num_output_files, stats.bytes_read_non_output_levels / 1048576.0,