// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
-// This source code is licensed under the BSD-style license found in the
-// LICENSE file in the root directory of this source tree. An additional grant
-// of patent rights can be found in the PATENTS file in the same directory.
+// This source code is licensed under both the GPLv2 (found in the
+// COPYING file in the root directory) and Apache 2.0 License
+// (found in the LICENSE.Apache file in the root directory).
#pragma once
#include <assert.h>
-#include <condition_variable>
#include <functional>
#include <mutex>
#include <string>
#include <thread>
-#include <unordered_map>
-#include <unordered_set>
#include <vector>
// This is only set from db_stress.cc and for testing only.
#else
namespace rocksdb {
-// Kill the process with probablity 1/odds for testing.
+// Kill the process with probability 1/odds for testing.
extern void TestKillRandom(std::string kill_point, int odds,
const std::string& srcfile, int srcline);
#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 {
public:
static SyncPoint* GetInstance();
+ SyncPoint(const SyncPoint&) = delete;
+ SyncPoint& operator=(const SyncPoint&) = delete;
+ ~SyncPoint();
+
struct SyncPointPair {
std::string predecessor;
std::string successor;
void LoadDependencyAndMarkers(const std::vector<SyncPointPair>& dependencies,
const std::vector<SyncPointPair>& markers);
- // Set up a call back function in sync point.
- void SetCallBack(const std::string point,
- std::function<void(void*)> callback);
+ // The argument to the callback is passed through from
+ // TEST_SYNC_POINT_CALLBACK(); nullptr if TEST_SYNC_POINT or
+ // TEST_IDX_SYNC_POINT was used.
+ void SetCallBack(const std::string& point,
+ const std::function<void(void*)>& callback);
+
+ // Clear callback function by point
+ void ClearCallBack(const std::string& point);
+
// Clear all call back functions.
void ClearAllCallBacks();
// triggered by TEST_SYNC_POINT, blocking execution until all predecessors
// are executed.
- // And/or call registered callback functionn, with argument `cb_arg`
+ // And/or call registered callback function, with argument `cb_arg`
void Process(const std::string& point, void* cb_arg = nullptr);
// TODO: it might be useful to provide a function that blocks until all
// sync points are cleared.
+ // We want this to be public so we can
+ // subclass the implementation
+ struct Data;
+
private:
- bool PredecessorsAllCleared(const std::string& point);
- bool DisabledByMarker(const std::string& point, std::thread::id thread_id);
-
- // successor/predecessor map loaded from LoadDependency
- std::unordered_map<std::string, std::vector<std::string>> successors_;
- std::unordered_map<std::string, std::vector<std::string>> predecessors_;
- std::unordered_map<std::string, std::function<void(void*)> > callbacks_;
- std::unordered_map<std::string, std::vector<std::string> > markers_;
- std::unordered_map<std::string, std::thread::id> marked_thread_id_;
-
- std::mutex mutex_;
- std::condition_variable cv_;
- // sync points that have been passed through
- std::unordered_set<std::string> cleared_points_;
- bool enabled_ = false;
- int num_callbacks_running_ = 0;
+ // Singleton
+ SyncPoint();
+ Data* impl_;
};
} // namespace rocksdb
// See TransactionLogIteratorRace in db_test.cc for an example use case.
// TEST_SYNC_POINT is no op in release build.
#define TEST_SYNC_POINT(x) rocksdb::SyncPoint::GetInstance()->Process(x)
+#define TEST_IDX_SYNC_POINT(x, index) \
+ rocksdb::SyncPoint::GetInstance()->Process(x + std::to_string(index))
#define TEST_SYNC_POINT_CALLBACK(x, y) \
rocksdb::SyncPoint::GetInstance()->Process(x, y)
+#define INIT_SYNC_POINT_SINGLETONS() \
+ (void)rocksdb::SyncPoint::GetInstance();
#endif // NDEBUG