2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// 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).
|
2014-03-24 04:49:14 +00:00
|
|
|
#pragma once
|
|
|
|
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-17 23:16:11 +00:00
|
|
|
#include <assert.h>
|
2016-12-16 19:17:26 +00:00
|
|
|
#include <functional>
|
2014-03-24 04:49:14 +00:00
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
2016-07-07 18:29:14 +00:00
|
|
|
#include <thread>
|
2014-03-24 04:49:14 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
#include "rocksdb/rocksdb_namespace.h"
|
|
|
|
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-17 23:16:11 +00:00
|
|
|
// This is only set from db_stress.cc and for testing only.
|
|
|
|
// If non-zero, kill at various points in source code with probability 1/this
|
|
|
|
extern int rocksdb_kill_odds;
|
2015-10-14 21:08:50 +00:00
|
|
|
// If kill point has a prefix on this list, will skip killing.
|
|
|
|
extern std::vector<std::string> rocksdb_kill_prefix_blacklist;
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-17 23:16:11 +00:00
|
|
|
|
|
|
|
#ifdef NDEBUG
|
|
|
|
// empty in release build
|
2015-10-14 21:08:50 +00:00
|
|
|
#define TEST_KILL_RANDOM(kill_point, rocksdb_kill_odds)
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-17 23:16:11 +00:00
|
|
|
#else
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2018-03-08 18:18:34 +00:00
|
|
|
// Kill the process with probability 1/odds for testing.
|
2015-10-14 21:08:50 +00:00
|
|
|
extern void TestKillRandom(std::string kill_point, int odds,
|
|
|
|
const std::string& srcfile, int srcline);
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-17 23:16:11 +00:00
|
|
|
|
|
|
|
// To avoid crashing always at some frequently executed codepaths (during
|
|
|
|
// kill random test), use this factor to reduce odds
|
|
|
|
#define REDUCE_ODDS 2
|
|
|
|
#define REDUCE_ODDS2 4
|
|
|
|
|
2015-10-14 21:08:50 +00:00
|
|
|
#define TEST_KILL_RANDOM(kill_point, rocksdb_kill_odds) \
|
|
|
|
{ \
|
|
|
|
if (rocksdb_kill_odds > 0) { \
|
|
|
|
TestKillRandom(kill_point, rocksdb_kill_odds, __FILE__, __LINE__); \
|
|
|
|
} \
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-17 23:16:11 +00:00
|
|
|
}
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-17 23:16:11 +00:00
|
|
|
#endif
|
|
|
|
|
2014-04-17 17:49:58 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
#define TEST_SYNC_POINT(x)
|
2017-08-31 16:27:14 +00:00
|
|
|
#define TEST_IDX_SYNC_POINT(x, index)
|
2015-04-14 08:55:19 +00:00
|
|
|
#define TEST_SYNC_POINT_CALLBACK(x, y)
|
2018-06-04 22:52:31 +00:00
|
|
|
#define INIT_SYNC_POINT_SINGLETONS()
|
2014-04-17 17:49:58 +00:00
|
|
|
#else
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2014-04-17 21:29:06 +00:00
|
|
|
|
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.
|
2015-12-10 16:54:48 +00:00
|
|
|
// Refer to (DBTest,TransactionLogIteratorRace), for an example use case.
|
2014-03-24 04:49:14 +00:00
|
|
|
|
|
|
|
class SyncPoint {
|
|
|
|
public:
|
|
|
|
static SyncPoint* GetInstance();
|
|
|
|
|
2018-03-23 19:48:45 +00:00
|
|
|
SyncPoint(const SyncPoint&) = delete;
|
|
|
|
SyncPoint& operator=(const SyncPoint&) = delete;
|
|
|
|
~SyncPoint();
|
|
|
|
|
2016-07-07 18:29:14 +00:00
|
|
|
struct SyncPointPair {
|
2014-03-24 04:49:14 +00:00
|
|
|
std::string predecessor;
|
|
|
|
std::string successor;
|
|
|
|
};
|
2016-07-07 18:29:14 +00:00
|
|
|
|
2014-03-24 04:49:14 +00:00
|
|
|
// call once at the beginning of a test to setup the dependency between
|
|
|
|
// sync points
|
2016-07-07 18:29:14 +00:00
|
|
|
void LoadDependency(const std::vector<SyncPointPair>& dependencies);
|
|
|
|
|
|
|
|
// call once at the beginning of a test to setup the dependency between
|
|
|
|
// sync points and setup markers indicating the successor is only enabled
|
|
|
|
// when it is processed on the same thread as the predecessor.
|
|
|
|
// When adding a marker, it implicitly adds a dependency for the marker pair.
|
|
|
|
void LoadDependencyAndMarkers(const std::vector<SyncPointPair>& dependencies,
|
|
|
|
const std::vector<SyncPointPair>& markers);
|
2014-03-24 04:49:14 +00:00
|
|
|
|
2018-02-03 05:16:26 +00:00
|
|
|
// 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.
|
2018-03-23 19:48:45 +00:00
|
|
|
void SetCallBack(const std::string& point,
|
|
|
|
const std::function<void(void*)>& callback);
|
2017-05-23 01:40:41 +00:00
|
|
|
|
|
|
|
// Clear callback function by point
|
2018-03-23 19:48:45 +00:00
|
|
|
void ClearCallBack(const std::string& point);
|
2017-05-23 01:40:41 +00:00
|
|
|
|
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.
|
2018-03-08 18:18:34 +00:00
|
|
|
// And/or call registered callback function, with argument `cb_arg`
|
2015-04-14 08:55:19 +00:00
|
|
|
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.
|
|
|
|
|
2018-03-23 19:48:45 +00:00
|
|
|
// We want this to be public so we can
|
|
|
|
// subclass the implementation
|
|
|
|
struct Data;
|
|
|
|
|
2014-03-24 04:49:14 +00:00
|
|
|
private:
|
2018-03-23 19:48:45 +00:00
|
|
|
// Singleton
|
|
|
|
SyncPoint();
|
|
|
|
Data* impl_;
|
2014-03-24 04:49:14 +00:00
|
|
|
};
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2014-03-24 04:49:14 +00:00
|
|
|
|
|
|
|
// Use TEST_SYNC_POINT to specify sync points inside code base.
|
2018-03-23 19:48:45 +00:00
|
|
|
// Sync points can have happens-after depedency on other sync points,
|
2014-03-24 04:49:14 +00:00
|
|
|
// 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.
|
2020-02-20 20:07:53 +00:00
|
|
|
#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))
|
2015-04-14 08:55:19 +00:00
|
|
|
#define TEST_SYNC_POINT_CALLBACK(x, y) \
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->Process(x, y)
|
2018-06-04 22:52:31 +00:00
|
|
|
#define INIT_SYNC_POINT_SINGLETONS() \
|
2020-02-20 20:07:53 +00:00
|
|
|
(void)ROCKSDB_NAMESPACE::SyncPoint::GetInstance();
|
2014-04-17 17:49:58 +00:00
|
|
|
#endif // NDEBUG
|