Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
CorruptionDetector.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "etl/SystemState.hpp"
23#include "util/log/Logger.hpp"
24
25#include <functional>
26
27namespace etl {
28
34template <typename CacheType>
36 std::reference_wrapper<SystemState> state_;
37 std::reference_wrapper<CacheType> cache_;
38
39 util::Logger log_{"ETL"};
40
41public:
48 CorruptionDetector(SystemState& state, CacheType& cache) : state_{std::ref(state)}, cache_{std::ref(cache)}
49 {
50 }
51
55 void
57 {
58 if (not state_.get().isCorruptionDetected) {
59 state_.get().isCorruptionDetected = true;
60
61 LOG(log_.error()) << "Disabling the cache to avoid corrupting the DB further. Please investigate.";
62 cache_.get().setDisabled();
63 }
64 }
65};
66
67} // namespace etl
A helper to notify Clio operator about a corruption in the DB.
Definition CorruptionDetector.hpp:35
CorruptionDetector(SystemState &state, CacheType &cache)
Construct a new Corruption Detector object.
Definition CorruptionDetector.hpp:48
void onCorruptionDetected()
Notify the operator about a corruption in the DB.
Definition CorruptionDetector.hpp:56
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:110
Pump error(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::ERR severity.
Definition Logger.cpp:215
This namespace contains everything to do with the ETL and ETL sources.
Definition CacheLoader.hpp:36
Represents the state of the ETL subsystem.
Definition SystemState.hpp:33