ClickHouse/src/Common/FailPoint.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.5 KiB
C++
Raw Normal View History

#pragma once
2024-02-14 13:00:22 +00:00
#include "config.h"
2024-02-14 13:19:34 +00:00
#include <Common/Exception.h>
#include <Core/Types.h>
#include <Poco/Util/AbstractConfiguration.h>
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation"
#pragma clang diagnostic ignored "-Wreserved-macro-identifier"
#endif
#include <fiu.h>
#include <fiu-control.h>
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#include <unordered_map>
namespace DB
{
2023-05-10 11:56:17 +00:00
/// This is a simple named failpoint library inspired by https://github.com/pingcap/tiflash
/// The usage is simple:
/// 1. define failpoint with a 'failpoint_name' in FailPoint.cpp
/// 2. inject failpoint in normal code
/// 2.1 use fiu_do_on which can inject any code blocks, when it is a regular-triggered / once-triggered failpoint
/// 2.2 use pauseFailPoint when it is a pausable failpoint
/// 3. in test file, we can use system failpoint enable/disable 'failpoint_name'
class FailPointChannel;
2023-05-08 21:02:36 +00:00
class FailPointInjection
{
public:
2023-05-10 11:56:17 +00:00
static void pauseFailPoint(const String & fail_point_name);
2023-05-08 21:02:36 +00:00
static void enableFailPoint(const String & fail_point_name);
static void enablePauseFailPoint(const String & fail_point_name, UInt64 time);
static void disableFailPoint(const String & fail_point_name);
static void wait(const String & fail_point_name);
static void enableFromGlobalConfig(const Poco::Util::AbstractConfiguration & config);
private:
2023-05-08 21:02:36 +00:00
static std::mutex mu;
static std::unordered_map<String, std::shared_ptr<FailPointChannel>> fail_point_wait_channels;
};
}