2014-03-24 04:49:14 +00:00
|
|
|
// Copyright (c) 2014, 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.
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <condition_variable>
|
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_set>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
|
2014-04-17 17:49:58 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
#define TEST_SYNC_POINT(x)
|
2015-04-14 08:55:19 +00:00
|
|
|
#define TEST_SYNC_POINT_CALLBACK(x, y)
|
2014-04-17 17:49:58 +00:00
|
|
|
#else
|
|
|
|
|
2014-04-17 21:29:06 +00:00
|
|
|
namespace rocksdb {
|
|
|
|
|
2014-03-24 04:49:14 +00:00
|
|
|
// This class provides facility to reproduce race conditions deterministically
|
|
|
|
// in unit tests.
|
|
|
|
// Developer could specify sync points in the codebase via TEST_SYNC_POINT.
|
|
|
|
// Each sync point represents a position in the execution stream of a thread.
|
|
|
|
// In the unit test, 'Happens After' relationship among sync points could be
|
|
|
|
// setup via SyncPoint::LoadDependency, to reproduce a desired interleave of
|
|
|
|
// threads execution.
|
|
|
|
// Refer to (DBTest,TransactionLogIteratorRace), for an exmaple use case.
|
|
|
|
|
|
|
|
class SyncPoint {
|
|
|
|
public:
|
|
|
|
static SyncPoint* GetInstance();
|
|
|
|
|
|
|
|
struct Dependency {
|
|
|
|
std::string predecessor;
|
|
|
|
std::string successor;
|
|
|
|
};
|
|
|
|
// call once at the beginning of a test to setup the dependency between
|
|
|
|
// sync points
|
|
|
|
void LoadDependency(const std::vector<Dependency>& dependencies);
|
|
|
|
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 19:44:17 +00:00
|
|
|
// Set up a call back function in sync point.
|
2015-04-14 08:55:19 +00:00
|
|
|
void SetCallBack(const std::string point,
|
|
|
|
std::function<void(void*)> callback);
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 19:44:17 +00:00
|
|
|
// Clear all call back functions.
|
|
|
|
void ClearAllCallBacks();
|
|
|
|
|
2014-03-24 04:49:14 +00:00
|
|
|
// enable sync point processing (disabled on startup)
|
|
|
|
void EnableProcessing();
|
|
|
|
|
|
|
|
// disable sync point processing
|
|
|
|
void DisableProcessing();
|
|
|
|
|
|
|
|
// remove the execution trace of all sync points
|
|
|
|
void ClearTrace();
|
|
|
|
|
|
|
|
// triggered by TEST_SYNC_POINT, blocking execution until all predecessors
|
|
|
|
// are executed.
|
2015-04-14 08:55:19 +00:00
|
|
|
// And/or call registered callback functionn, with argument `cb_arg`
|
|
|
|
void Process(const std::string& point, void* cb_arg = nullptr);
|
2014-03-24 04:49:14 +00:00
|
|
|
|
|
|
|
// TODO: it might be useful to provide a function that blocks until all
|
|
|
|
// sync points are cleared.
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool PredecessorsAllCleared(const std::string& point);
|
|
|
|
|
|
|
|
// 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_;
|
2015-04-14 08:55:19 +00:00
|
|
|
std::unordered_map<std::string, std::function<void(void*)> > callbacks_;
|
2014-03-24 04:49:14 +00:00
|
|
|
|
|
|
|
std::mutex mutex_;
|
|
|
|
std::condition_variable cv_;
|
|
|
|
// sync points that have been passed through
|
|
|
|
std::unordered_set<std::string> cleared_points_;
|
|
|
|
bool enabled_ = false;
|
options.level_compaction_dynamic_level_bytes to allow RocksDB to pick size bases of levels dynamically.
Summary:
When having fixed max_bytes_for_level_base, the ratio of size of largest level and the second one can range from 0 to the multiplier. This makes LSM tree frequently irregular and unpredictable. It can also cause poor space amplification in some cases.
In this improvement (proposed by Igor Kabiljo), we introduce a parameter option.level_compaction_use_dynamic_max_bytes. When turning it on, RocksDB is free to pick a level base in the range of (options.max_bytes_for_level_base/options.max_bytes_for_level_multiplier, options.max_bytes_for_level_base] so that real level ratios are close to options.max_bytes_for_level_multiplier.
Test Plan: New unit tests and pass tests suites including valgrind.
Reviewers: MarkCallaghan, rven, yhchiang, igor, ikabiljo
Reviewed By: ikabiljo
Subscribers: yoshinorim, ikabiljo, dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D31437
2015-02-05 19:44:17 +00:00
|
|
|
int num_callbacks_running_ = 0;
|
2014-03-24 04:49:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace rocksdb
|
|
|
|
|
|
|
|
// Use TEST_SYNC_POINT to specify sync points inside code base.
|
|
|
|
// Sync points can have happens-after depedency on other sync points,
|
|
|
|
// configured at runtime via SyncPoint::LoadDependency. This could be
|
|
|
|
// utilized to re-produce race conditions between threads.
|
|
|
|
// 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)
|
2015-04-14 08:55:19 +00:00
|
|
|
#define TEST_SYNC_POINT_CALLBACK(x, y) \
|
|
|
|
rocksdb::SyncPoint::GetInstance()->Process(x, y)
|
2014-04-17 17:49:58 +00:00
|
|
|
#endif // NDEBUG
|