aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Common/FailPoint.h
blob: a1ca9b1a803d6e8edd4bf066cbe1b3146779dd61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once
#include "clickhouse_config.h"

#include <Common/Exception.h>
#include <Core/Types.h>

#if FIU_ENABLE

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation"
#pragma clang diagnostic ignored "-Wreserved-macro-identifier"
#endif

#error #include <fiu.h>
#error #include <fiu-control.h>

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#else
#define fiu_do_on(name, action)
#endif

namespace DB
{

/// 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 FailPointInjection
{
public:

    static void pauseFailPoint(const String & fail_point_name);

    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);
};
}