mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-30 04:41:49 +00:00
52d4c9b7f6
Summary: Currently, if RocksDB encounters errors during a write operation (user requested or BG operations), it sets DBImpl::bg_error_ and fails subsequent writes. This PR allows the DB to be resumed for certain classes of errors. It consists of 3 parts - 1. Introduce Status::Severity in rocksdb::Status to indicate whether a given error can be recovered from or not 2. Refactor the error handling code so that setting bg_error_ and deciding on severity is in one place 3. Provide an API for the user to clear the error and resume the DB instance This whole change is broken up into multiple PRs. Initially, we only allow clearing the error for Status::NoSpace() errors during background flush/compaction. Subsequent PRs will expand this to include more errors and foreground operations such as Put(), and implement a polling mechanism for out-of-space errors. Closes https://github.com/facebook/rocksdb/pull/3997 Differential Revision: D8653831 Pulled By: anand1976 fbshipit-source-id: 6dc835c76122443a7668497c0226b4f072bc6afd
53 lines
1.2 KiB
C++
53 lines
1.2 KiB
C++
// Copyright (c) 2018-present, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
#pragma once
|
|
|
|
#include "monitoring/instrumented_mutex.h"
|
|
#include "options/db_options.h"
|
|
#include "rocksdb/listener.h"
|
|
#include "rocksdb/status.h"
|
|
|
|
namespace rocksdb {
|
|
|
|
class ErrorHandler {
|
|
public:
|
|
ErrorHandler(const ImmutableDBOptions& db_options,
|
|
InstrumentedMutex* db_mutex)
|
|
: db_options_(db_options),
|
|
bg_error_(Status::OK()),
|
|
db_mutex_(db_mutex)
|
|
{}
|
|
~ErrorHandler() {}
|
|
|
|
Status::Severity GetErrorSeverity(BackgroundErrorReason reason,
|
|
Status::Code code, Status::SubCode subcode);
|
|
|
|
Status SetBGError(const Status& bg_err, BackgroundErrorReason reason);
|
|
|
|
Status GetBGError()
|
|
{
|
|
return bg_error_;
|
|
}
|
|
|
|
void ClearBGError() {
|
|
bg_error_ = Status::OK();
|
|
}
|
|
|
|
bool IsDBStopped() {
|
|
return !bg_error_.ok();
|
|
}
|
|
|
|
bool IsBGWorkStopped() {
|
|
return !bg_error_.ok();
|
|
}
|
|
|
|
private:
|
|
const ImmutableDBOptions& db_options_;
|
|
Status bg_error_;
|
|
InstrumentedMutex* db_mutex_;
|
|
};
|
|
|
|
}
|