]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
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). | |
5 | #pragma once | |
6 | ||
7 | #include "monitoring/instrumented_mutex.h" | |
8 | #include "options/db_options.h" | |
9 | #include "rocksdb/listener.h" | |
10 | #include "rocksdb/status.h" | |
11 | ||
12 | namespace rocksdb { | |
13 | ||
14 | class DBImpl; | |
15 | ||
16 | class ErrorHandler { | |
17 | public: | |
18 | ErrorHandler(DBImpl* db, const ImmutableDBOptions& db_options, | |
19 | InstrumentedMutex* db_mutex) | |
20 | : db_(db), | |
21 | db_options_(db_options), | |
22 | bg_error_(Status::OK()), | |
23 | recovery_error_(Status::OK()), | |
24 | db_mutex_(db_mutex), | |
25 | auto_recovery_(false), | |
26 | recovery_in_prog_(false) {} | |
27 | ~ErrorHandler() {} | |
28 | ||
29 | void EnableAutoRecovery() { auto_recovery_ = true; } | |
30 | ||
31 | Status::Severity GetErrorSeverity(BackgroundErrorReason reason, | |
32 | Status::Code code, | |
33 | Status::SubCode subcode); | |
34 | ||
35 | Status SetBGError(const Status& bg_err, BackgroundErrorReason reason); | |
36 | ||
37 | Status GetBGError() { return bg_error_; } | |
38 | ||
39 | Status GetRecoveryError() { return recovery_error_; } | |
40 | ||
41 | Status ClearBGError(); | |
42 | ||
43 | bool IsDBStopped() { | |
44 | return !bg_error_.ok() && | |
45 | bg_error_.severity() >= Status::Severity::kHardError; | |
46 | } | |
47 | ||
48 | bool IsBGWorkStopped() { | |
49 | return !bg_error_.ok() && | |
50 | (bg_error_.severity() >= Status::Severity::kHardError || | |
51 | !auto_recovery_); | |
52 | } | |
53 | ||
54 | bool IsRecoveryInProgress() { return recovery_in_prog_; } | |
55 | ||
56 | Status RecoverFromBGError(bool is_manual = false); | |
57 | void CancelErrorRecovery(); | |
58 | ||
59 | private: | |
60 | DBImpl* db_; | |
61 | const ImmutableDBOptions& db_options_; | |
62 | Status bg_error_; | |
494da23a | 63 | // A separate Status variable used to record any errors during the |
11fdf7f2 TL |
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 | |
68 | bool auto_recovery_; | |
69 | bool recovery_in_prog_; | |
70 | ||
71 | Status OverrideNoSpaceError(Status bg_error, bool* auto_recovery); | |
72 | void RecoverFromNoSpace(); | |
73 | }; | |
74 | ||
75 | } |