summaryrefslogtreecommitdiff
path: root/db/merge_helper.cc
diff options
context:
space:
mode:
authormrambacher <mrambach@gmail.com>2021-01-25 22:07:26 -0800
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>2021-01-25 22:09:11 -0800
commit12f11373554af219c519ff60a612e355508518f7 (patch)
treee1acf99491ac29713fe78346f81e41835ab9e6d0 /db/merge_helper.cc
parent1d226018af894c9a6b3ff7e292860779e383085b (diff)
Add a SystemClock class to capture the time functions of an Env (#7858)
Summary: Introduces and uses a SystemClock class to RocksDB. This class contains the time-related functions of an Env and these functions can be redirected from the Env to the SystemClock. Many of the places that used an Env (Timer, PerfStepTimer, RepeatableThread, RateLimiter, WriteController) for time-related functions have been changed to use SystemClock instead. There are likely more places that can be changed, but this is a start to show what can/should be done. Over time it would be nice to migrate most (if not all) of the uses of the time functions from the Env to the SystemClock. There are several Env classes that implement these functions. Most of these have not been converted yet to SystemClock implementations; that will come in a subsequent PR. It would be good to unify many of the Mock Timer implementations, so that they behave similarly and be tested similarly (some override Sleep, some use a MockSleep, etc). Additionally, this change will allow new methods to be introduced to the SystemClock (like https://github.com/facebook/rocksdb/issues/7101 WaitFor) in a consistent manner across a smaller number of classes. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7858 Reviewed By: pdillinger Differential Revision: D26006406 Pulled By: mrambacher fbshipit-source-id: ed10a8abbdab7ff2e23d69d85bd25b3e7e899e90
Diffstat (limited to 'db/merge_helper.cc')
-rw-r--r--db/merge_helper.cc24
1 files changed, 12 insertions, 12 deletions
diff --git a/db/merge_helper.cc b/db/merge_helper.cc
index 8497d23b0..dd9e1c4d3 100644
--- a/db/merge_helper.cc
+++ b/db/merge_helper.cc
@@ -14,6 +14,7 @@
#include "rocksdb/comparator.h"
#include "rocksdb/db.h"
#include "rocksdb/merge_operator.h"
+#include "rocksdb/system_clock.h"
#include "table/format.h"
#include "table/internal_iterator.h"
@@ -28,6 +29,7 @@ MergeHelper::MergeHelper(Env* env, const Comparator* user_comparator,
Statistics* stats,
const std::atomic<bool>* shutting_down)
: env_(env),
+ clock_(env->GetSystemClock()),
user_comparator_(user_comparator),
user_merge_operator_(user_merge_operator),
compaction_filter_(compaction_filter),
@@ -39,7 +41,7 @@ MergeHelper::MergeHelper(Env* env, const Comparator* user_comparator,
snapshot_checker_(snapshot_checker),
level_(level),
keys_(),
- filter_timer_(env_),
+ filter_timer_(clock_),
total_filter_time_(0U),
stats_(stats) {
assert(user_comparator_ != nullptr);
@@ -48,13 +50,11 @@ MergeHelper::MergeHelper(Env* env, const Comparator* user_comparator,
}
}
-Status MergeHelper::TimedFullMerge(const MergeOperator* merge_operator,
- const Slice& key, const Slice* value,
- const std::vector<Slice>& operands,
- std::string* result, Logger* logger,
- Statistics* statistics, Env* env,
- Slice* result_operand,
- bool update_num_ops_stats) {
+Status MergeHelper::TimedFullMerge(
+ const MergeOperator* merge_operator, const Slice& key, const Slice* value,
+ const std::vector<Slice>& operands, std::string* result, Logger* logger,
+ Statistics* statistics, const std::shared_ptr<SystemClock>& clock,
+ Slice* result_operand, bool update_num_ops_stats) {
assert(merge_operator != nullptr);
if (operands.size() == 0) {
@@ -75,7 +75,7 @@ Status MergeHelper::TimedFullMerge(const MergeOperator* merge_operator,
MergeOperator::MergeOperationOutput merge_out(*result, tmp_result_operand);
{
// Setup to time the merge
- StopWatchNano timer(env, statistics != nullptr);
+ StopWatchNano timer(clock, statistics != nullptr);
PERF_TIMER_GUARD(merge_operator_time_nanos);
// Do the merge
@@ -213,7 +213,7 @@ Status MergeHelper::MergeUntil(InternalIterator* iter,
std::string merge_result;
s = TimedFullMerge(user_merge_operator_, ikey.user_key, val_ptr,
merge_context_.GetOperands(), &merge_result, logger_,
- stats_, env_);
+ stats_, clock_);
// We store the result in keys_.back() and operands_.back()
// if nothing went wrong (i.e.: no operand corruption on disk)
@@ -324,7 +324,7 @@ Status MergeHelper::MergeUntil(InternalIterator* iter,
std::string merge_result;
s = TimedFullMerge(user_merge_operator_, orig_ikey.user_key, nullptr,
merge_context_.GetOperands(), &merge_result, logger_,
- stats_, env_);
+ stats_, clock_);
if (s.ok()) {
// The original key encountered
// We are certain that keys_ is not empty here (see assertions couple of
@@ -347,7 +347,7 @@ Status MergeHelper::MergeUntil(InternalIterator* iter,
bool merge_success = false;
std::string merge_result;
{
- StopWatchNano timer(env_, stats_ != nullptr);
+ StopWatchNano timer(clock_, stats_ != nullptr);
PERF_TIMER_GUARD(merge_operator_time_nanos);
merge_success = user_merge_operator_->PartialMergeMulti(
orig_ikey.user_key,