2023-04-25 20:07:04 +00:00
|
|
|
#pragma once
|
2024-02-14 13:00:22 +00:00
|
|
|
#include "config.h"
|
2024-02-14 13:19:34 +00:00
|
|
|
|
2023-04-25 20:07:04 +00:00
|
|
|
#include <Common/Exception.h>
|
|
|
|
#include <Core/Types.h>
|
2023-08-31 11:33:52 +00:00
|
|
|
#include <Poco/Util/AbstractConfiguration.h>
|
2023-04-25 20:07:04 +00:00
|
|
|
|
|
|
|
#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'
|
2023-04-25 20:07:04 +00:00
|
|
|
|
|
|
|
class FailPointChannel;
|
2023-05-08 21:02:36 +00:00
|
|
|
class FailPointInjection
|
2023-04-25 20:07:04 +00:00
|
|
|
{
|
|
|
|
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);
|
2023-04-25 20:07:04 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-08-31 11:33:52 +00:00
|
|
|
static void enableFromGlobalConfig(const Poco::Util::AbstractConfiguration & config);
|
|
|
|
|
2023-04-25 20:07:04 +00:00
|
|
|
private:
|
2023-05-08 21:02:36 +00:00
|
|
|
static std::mutex mu;
|
2023-04-25 20:07:04 +00:00
|
|
|
static std::unordered_map<String, std::shared_ptr<FailPointChannel>> fail_point_wait_channels;
|
|
|
|
};
|
|
|
|
}
|