#pragma once
#include <assert.h>
#include <functional>
#include <mutex>
#include <string>
#include <thread>
#include <vector>
#include "rocksdb/rocksdb_namespace.h"
extern int rocksdb_kill_odds;
extern std::vector<std::string> rocksdb_kill_exclude_prefixes;
#ifdef NDEBUG
#define TEST_KILL_RANDOM(kill_point, rocksdb_kill_odds)
#else
namespace ROCKSDB_NAMESPACE {
extern void TestKillRandom(std::string kill_point, int odds,
const std::string& srcfile, int srcline);
#define REDUCE_ODDS 2
#define REDUCE_ODDS2 4
#define TEST_KILL_RANDOM(kill_point, rocksdb_kill_odds) \
{ \
if (rocksdb_kill_odds > 0) { \
TestKillRandom(kill_point, rocksdb_kill_odds, __FILE__, __LINE__); \
} \
}
} #endif
#ifdef NDEBUG
#define TEST_SYNC_POINT(x)
#define TEST_IDX_SYNC_POINT(x, index)
#define TEST_SYNC_POINT_CALLBACK(x, y)
#define INIT_SYNC_POINT_SINGLETONS()
#else
namespace ROCKSDB_NAMESPACE {
class SyncPoint {
public:
static SyncPoint* GetInstance();
SyncPoint(const SyncPoint&) = delete;
SyncPoint& operator=(const SyncPoint&) = delete;
~SyncPoint();
struct SyncPointPair {
std::string predecessor;
std::string successor;
};
void LoadDependency(const std::vector<SyncPointPair>& dependencies);
void LoadDependencyAndMarkers(const std::vector<SyncPointPair>& dependencies,
const std::vector<SyncPointPair>& markers);
void SetCallBack(const std::string& point,
const std::function<void(void*)>& callback);
void ClearCallBack(const std::string& point);
void ClearAllCallBacks();
void EnableProcessing();
void DisableProcessing();
void ClearTrace();
void Process(const std::string& point, void* cb_arg = nullptr);
struct Data;
private:
SyncPoint();
Data* impl_;
};
void SetupSyncPointsToMockDirectIO();
}
#define TEST_SYNC_POINT(x) \
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->Process(x)
#define TEST_IDX_SYNC_POINT(x, index) \
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->Process(x + \
std::to_string(index))
#define TEST_SYNC_POINT_CALLBACK(x, y) \
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->Process(x, y)
#define INIT_SYNC_POINT_SINGLETONS() \
(void)ROCKSDB_NAMESPACE::SyncPoint::GetInstance();
#endif
#ifdef NDEBUG
#define IGNORE_STATUS_IF_ERROR(_status_)
#else
#define IGNORE_STATUS_IF_ERROR(_status_) \
{ \
if (!_status_.ok()) { \
TEST_SYNC_POINT("FaultInjectionIgnoreError"); \
} \
}
#endif