1 // Copyright (c) 2018-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
7 #include "monitoring/instrumented_mutex.h"
8 #include "options/db_options.h"
9 #include "rocksdb/listener.h"
10 #include "rocksdb/status.h"
12 namespace ROCKSDB_NAMESPACE
{
18 ErrorHandler(DBImpl
* db
, const ImmutableDBOptions
& db_options
,
19 InstrumentedMutex
* db_mutex
)
21 db_options_(db_options
),
22 bg_error_(Status::OK()),
23 recovery_error_(Status::OK()),
25 auto_recovery_(false),
26 recovery_in_prog_(false) {}
29 void EnableAutoRecovery() { auto_recovery_
= true; }
31 Status::Severity
GetErrorSeverity(BackgroundErrorReason reason
,
33 Status::SubCode subcode
);
35 Status
SetBGError(const Status
& bg_err
, BackgroundErrorReason reason
);
37 Status
GetBGError() { return bg_error_
; }
39 Status
GetRecoveryError() { return recovery_error_
; }
41 Status
ClearBGError();
44 return !bg_error_
.ok() &&
45 bg_error_
.severity() >= Status::Severity::kHardError
;
48 bool IsBGWorkStopped() {
49 return !bg_error_
.ok() &&
50 (bg_error_
.severity() >= Status::Severity::kHardError
||
54 bool IsRecoveryInProgress() { return recovery_in_prog_
; }
56 Status
RecoverFromBGError(bool is_manual
= false);
57 void CancelErrorRecovery();
61 const ImmutableDBOptions
& db_options_
;
63 // A separate Status variable used to record any errors during the
64 // recovery process from hard errors
65 Status recovery_error_
;
66 InstrumentedMutex
* db_mutex_
;
67 // A flag indicating whether automatic recovery from errors is enabled
69 bool recovery_in_prog_
;
71 Status
OverrideNoSpaceError(Status bg_error
, bool* auto_recovery
);
72 void RecoverFromNoSpace();
75 } // namespace ROCKSDB_NAMESPACE