Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
Signed-off-by: Little-Wallace <[email protected]>
  • Loading branch information
Little-Wallace committed Feb 21, 2022
1 parent 59ab24b commit 46d7b19
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
5 changes: 4 additions & 1 deletion db/db_impl/db_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,8 @@ class DBImpl : public DB {
// only used for dynamically adjusting max_total_wal_size. it is a sum of
// [write_buffer_size * max_write_buffer_number] over all column families
std::atomic<uint64_t> max_total_in_memory_state_;

std::atomic<uint64_t> max_total_wal_size_;
// If true, we have only one (default) column family. We use this to optimize
// some code-paths
std::atomic<bool> single_column_family_mode_;
Expand Down Expand Up @@ -1131,13 +1133,15 @@ class DBImpl : public DB {
}
}
};

struct LogContext {
explicit LogContext(bool need_sync = false)
: need_log_sync(need_sync), need_log_dir_sync(need_sync) {}
bool need_log_sync;
bool need_log_dir_sync;
log::Writer* writer;
};

struct LogFileNumberSize {
explicit LogFileNumberSize(uint64_t _number) : number(_number) {}
void AddSize(uint64_t new_size) { size += new_size; }
Expand Down Expand Up @@ -1939,7 +1943,6 @@ class DBImpl : public DB {
InstrumentedCondVar atomic_flush_install_cv_;

bool wal_in_db_path_;
std::atomic<uint64_t> max_total_wal_size_;
};

extern Options SanitizeOptions(const std::string& db, const Options& src);
Expand Down
2 changes: 1 addition & 1 deletion db/db_impl/db_impl_write.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ uint64_t DBImpl::GetMaxTotalWalSize() const {
if (max_total_wal_size > 0) {
return max_total_wal_size;
}
return 4 * max_total_in_memory_state_;
return 4 * max_total_in_memory_state_.load(std::memory_order_acquire);
}

// REQUIRES: mutex_ is held
Expand Down
4 changes: 2 additions & 2 deletions db/error_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Status ErrorHandler::SetBGError(const Status& bg_err, BackgroundErrorReason reas
if (!s.ok() && (s.severity() > bg_error_.severity())) {
bg_error_ = s;
if (bg_error_.severity() >= Status::Severity::kHardError) {
stop_state_.store(true, std::memory_order_release);
db_stopped_.store(true, std::memory_order_release);
}
} else {
// This error is less severe than previously encountered error. Don't
Expand Down Expand Up @@ -298,7 +298,7 @@ Status ErrorHandler::ClearBGError() {
if (recovery_error_.ok()) {
Status old_bg_error = bg_error_;
bg_error_ = Status::OK();
stop_state_.store(false, std::memory_order_release);
db_stopped_.store(false, std::memory_order_release);
recovery_in_prog_ = false;
EventHelpers::NotifyOnErrorRecoveryCompleted(db_options_.listeners,
old_bg_error, db_mutex_);
Expand Down
8 changes: 5 additions & 3 deletions db/error_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ErrorHandler {
db_mutex_(db_mutex),
auto_recovery_(false),
recovery_in_prog_(false),
stop_state_(false) {}
db_stopped_(false) {}
~ErrorHandler() {}

void EnableAutoRecovery() { auto_recovery_ = true; }
Expand All @@ -37,8 +37,10 @@ class ErrorHandler {

Status ClearBGError();

bool IsDBStopped() { return stop_state_.load(std::memory_order_acquire); }
// Do not require DB mutex held.
bool IsDBStopped() { return db_stopped_.load(std::memory_order_acquire); }

// Require DB mutex held.
bool IsBGWorkStopped() {
return !bg_error_.ok() &&
(bg_error_.severity() >= Status::Severity::kHardError ||
Expand All @@ -61,7 +63,7 @@ class ErrorHandler {
// A flag indicating whether automatic recovery from errors is enabled
bool auto_recovery_;
bool recovery_in_prog_;
std::atomic<bool> stop_state_;
std::atomic<bool> db_stopped_;

Status OverrideNoSpaceError(Status bg_error, bool* auto_recovery);
void RecoverFromNoSpace();
Expand Down

0 comments on commit 46d7b19

Please sign in to comment.