Skip to content

Commit

Permalink
Add some comments
Browse files Browse the repository at this point in the history
Signed-off-by: JaySon-Huang <[email protected]>
  • Loading branch information
JaySon-Huang committed Sep 17, 2020
1 parent c9385e2 commit fd082d8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
32 changes: 14 additions & 18 deletions dbms/src/Common/FailPoint.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <Common/FailPoint.h>

#include <boost/core/noncopyable.hpp>
#include <condition_variable>
#include <mutex>
Expand Down Expand Up @@ -31,13 +32,6 @@ APPLY_FOR_FAILPOINTS_WITH_CHANNEL(M)
#undef M
} // namespace FailPoints

#define FAIL_POINT_ENABLE_WITH_CHANNEL(trigger, name) \
else if (trigger == FailPoints::name) \
{ \
fiu_enable(name, 1, nullptr, FIU_ONETIME); \
fail_point_wait_channels.try_emplace(FailPoints::name, std::make_shared<FailPointChannel>()); \
}

class FailPointChannel : private boost::noncopyable
{
public:
Expand All @@ -57,22 +51,24 @@ class FailPointChannel : private boost::noncopyable

void FailPointHelper::enableFailPoint(const String & fail_point_name)
{
#define M(NAME) \
if (fail_point_name == FailPoints::NAME) \
{ \
fiu_enable(FailPoints::NAME, 1, nullptr, FIU_ONETIME); \
return; \
#define M(NAME) \
if (fail_point_name == FailPoints::NAME) \
{ \
/* FIU_ONETIME -- Only fail once; the point of failure will be automatically disabled afterwards.*/ \
fiu_enable(FailPoints::NAME, 1, nullptr, FIU_ONETIME); \
return; \
}

APPLY_FOR_FAILPOINTS(M)
#undef M

#define M(NAME) \
if (fail_point_name == FailPoints::NAME) \
{ \
fiu_enable(FailPoints::NAME, 1, nullptr, FIU_ONETIME); \
fail_point_wait_channels.try_emplace(FailPoints::NAME, std::make_shared<FailPointChannel>()); \
return; \
#define M(NAME) \
if (fail_point_name == FailPoints::NAME) \
{ \
/* FIU_ONETIME -- Only fail once; the point of failure will be automatically disabled afterwards.*/ \
fiu_enable(FailPoints::NAME, 1, nullptr, FIU_ONETIME); \
fail_point_wait_channels.try_emplace(FailPoints::NAME, std::make_shared<FailPointChannel>()); \
return; \
}

APPLY_FOR_FAILPOINTS_WITH_CHANNEL(M)
Expand Down
5 changes: 3 additions & 2 deletions dbms/src/Common/FailPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ namespace ErrorCodes
extern const int FAIL_POINT_ERROR;
};

// Macros to set failpoint
/// Macros to set failpoints.
// When `fail_point` is enabled, throw an exception
#define FAIL_POINT_TRIGGER_EXCEPTION(fail_point) \
fiu_do_on(fail_point, throw Exception("Fail point " #fail_point " is triggered.", ErrorCodes::FAIL_POINT_ERROR);)
// When `fail_point` is enabled, wait till it is disabled
#define FAIL_POINT_PAUSE(fail_point) fiu_do_on(fail_point, FailPointHelper::wait(fail_point);)
// #define FAIL_POINT_TRIGGER_REGION_EXCEPTION(fail_point) fiu_do_on(fail_point, throw RegionException(); )


class FailPointChannel;
Expand Down
8 changes: 6 additions & 2 deletions dbms/src/Debug/dbgFuncFailPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ namespace DB
struct DbgFailPointFunc
{

static void dbgEnableFailPoint(Context & context, const ASTs & args, DBGInvoker::Printer output);

// Init fail point. must be called if you want to enable / disable failpoints
// DBGInvoke init_fail_point()
static void dbgInitFailPoint(Context & context, const ASTs & args, DBGInvoker::Printer output);

// Enable fail point.
// DBGInvoke enable_fail_point(name)
static void dbgEnableFailPoint(Context & context, const ASTs & args, DBGInvoker::Printer output);

// Disable fail point.
// Usage:
// ./stoage-client.sh "DBGInvoke disable_fail_point(name)"
Expand Down

0 comments on commit fd082d8

Please sign in to comment.