Skip to content

Commit

Permalink
adjust WriteStallNotification object to not depend upon pointer (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewvon authored Dec 21, 2021
1 parent bb90933 commit 30ad741
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
26 changes: 13 additions & 13 deletions db/job_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <string>
#include <vector>

#include "db/log_writer.h"
#include "db/column_family.h"
#include "db/log_writer.h"

namespace ROCKSDB_NAMESPACE {

Expand All @@ -23,7 +23,7 @@ struct SuperVersion;
struct SuperVersionContext {
struct WriteStallNotification {
WriteStallInfo write_stall_info;
const ImmutableCFOptions* immutable_cf_options;
std::vector<std::shared_ptr<EventListener>> immutable_options_listeners;
};

autovector<SuperVersion*> superversions_to_free;
Expand All @@ -34,7 +34,7 @@ struct SuperVersionContext {
new_superversion; // if nullptr no new superversion

explicit SuperVersionContext(bool create_superversion = false)
: new_superversion(create_superversion ? new SuperVersion() : nullptr) {}
: new_superversion(create_superversion ? new SuperVersion() : nullptr) {}

explicit SuperVersionContext(SuperVersionContext&& other)
: superversions_to_free(std::move(other.superversions_to_free)),
Expand All @@ -50,36 +50,37 @@ struct SuperVersionContext {

inline bool HaveSomethingToDelete() const {
#ifndef ROCKSDB_DISABLE_STALL_NOTIFICATION
return !superversions_to_free.empty() ||
!write_stall_notifications.empty();
return !superversions_to_free.empty() || !write_stall_notifications.empty();
#else
return !superversions_to_free.empty();
#endif
}

void PushWriteStallNotification(
WriteStallCondition old_cond, WriteStallCondition new_cond,
const std::string& name, const ImmutableCFOptions* ioptions) {
void PushWriteStallNotification(WriteStallCondition old_cond,
WriteStallCondition new_cond,
const std::string& name,
const ImmutableCFOptions* ioptions) {
#if !defined(ROCKSDB_LITE) && !defined(ROCKSDB_DISABLE_STALL_NOTIFICATION)
WriteStallNotification notif;
notif.write_stall_info.cf_name = name;
notif.write_stall_info.condition.prev = old_cond;
notif.write_stall_info.condition.cur = new_cond;
notif.immutable_cf_options = ioptions;
notif.immutable_options_listeners = ioptions->listeners;
write_stall_notifications.push_back(notif);
#else
(void)old_cond;
(void)new_cond;
(void)name;
(void)ioptions;
#endif // !defined(ROCKSDB_LITE) && !defined(ROCKSDB_DISABLE_STALL_NOTIFICATION)
#endif // !defined(ROCKSDB_LITE) &&
// !defined(ROCKSDB_DISABLE_STALL_NOTIFICATION)
}

void Clean() {
#if !defined(ROCKSDB_LITE) && !defined(ROCKSDB_DISABLE_STALL_NOTIFICATION)
// notify listeners on changed write stall conditions
for (auto& notif : write_stall_notifications) {
for (auto& listener : notif.immutable_cf_options->listeners) {
for (auto& listener : notif.immutable_options_listeners) {
listener->OnStallConditionsChanged(notif.write_stall_info);
}
}
Expand Down Expand Up @@ -126,8 +127,7 @@ struct JobContext {
CandidateFileInfo(std::string name, std::string path)
: file_name(std::move(name)), file_path(std::move(path)) {}
bool operator==(const CandidateFileInfo& other) const {
return file_name == other.file_name &&
file_path == other.file_path;
return file_name == other.file_name && file_path == other.file_path;
}
};

Expand Down
4 changes: 1 addition & 3 deletions monitoring/iostats_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ __thread IOStatsContext iostats_context;
"No thread-local support. Disable iostats context with -DNIOSTATS_CONTEXT."
#endif

IOStatsContext* get_iostats_context() {
return &iostats_context;
}
IOStatsContext* get_iostats_context() { return &iostats_context; }

void IOStatsContext::Reset() {
#ifndef NIOSTATS_CONTEXT
Expand Down
28 changes: 13 additions & 15 deletions monitoring/perf_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ thread_local PerfContext perf_context;
#error "No thread-local support. Disable perf context with -DNPERF_CONTEXT."
#endif

PerfContext* get_perf_context() {
return &perf_context;
}
PerfContext* get_perf_context() { return &perf_context; }

PerfContext::~PerfContext() {
#if !defined(NPERF_CONTEXT) && defined(ROCKSDB_SUPPORT_THREAD_LOCAL) && !defined(OS_SOLARIS)
#if !defined(NPERF_CONTEXT) && defined(ROCKSDB_SUPPORT_THREAD_LOCAL) && \
!defined(OS_SOLARIS)
ClearPerLevelPerfContext();
#endif
}
Expand Down Expand Up @@ -422,15 +421,14 @@ void PerfContext::Reset() {
ss << #counter << " = " << counter << ", "; \
}

#define PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(counter) \
if (per_level_perf_context_enabled && \
level_to_perf_context) { \
ss << #counter << " = "; \
for (auto& kv : *level_to_perf_context) { \
if (!exclude_zero_counters || (kv.second.counter > 0)) { \
ss << kv.second.counter << "@level" << kv.first << ", "; \
} \
} \
#define PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(counter) \
if (per_level_perf_context_enabled && level_to_perf_context) { \
ss << #counter << " = "; \
for (auto& kv : *level_to_perf_context) { \
if (!exclude_zero_counters || (kv.second.counter > 0)) { \
ss << kv.second.counter << "@level" << kv.first << ", "; \
} \
} \
}

void PerfContextByLevel::Reset() {
Expand Down Expand Up @@ -546,11 +544,11 @@ void PerfContext::EnablePerLevelPerfContext() {
per_level_perf_context_enabled = true;
}

void PerfContext::DisablePerLevelPerfContext(){
void PerfContext::DisablePerLevelPerfContext() {
per_level_perf_context_enabled = false;
}

void PerfContext::ClearPerLevelPerfContext(){
void PerfContext::ClearPerLevelPerfContext() {
if (level_to_perf_context != nullptr) {
level_to_perf_context->clear();
delete level_to_perf_context;
Expand Down

0 comments on commit 30ad741

Please sign in to comment.