2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2015-02-02 22:49:22 +00:00
|
|
|
// 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
|
|
|
|
|
2015-02-26 23:19:17 +00:00
|
|
|
#include <cstdlib>
|
2015-02-02 22:49:22 +00:00
|
|
|
#include <string>
|
|
|
|
|
2016-01-25 21:27:50 +00:00
|
|
|
#include "rocksdb/options.h"
|
|
|
|
|
2015-02-02 22:49:22 +00:00
|
|
|
namespace rocksdb {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If ROCKSDB_XFTEST_FORCE has a value of 1, XFUNC is forced to be defined.
|
|
|
|
* If ROCKSDB_XFTEST_FORCE has a value other than 1,
|
|
|
|
* XFUNC is forced to be undefined.
|
|
|
|
* If ROCKSDB_XFTEST_FORCE is undefined, XFUNC is defined based on NDEBUG,
|
|
|
|
* with XFUNC only being set for debug builds.
|
|
|
|
*/
|
|
|
|
#if defined(ROCKSDB_XFTEST_FORCE)
|
2015-04-10 04:05:09 +00:00
|
|
|
#ifndef ROCKSDB_LITE
|
2015-02-02 22:49:22 +00:00
|
|
|
#if (ROCKSDB_XFTEST_FORCE == 1)
|
|
|
|
#define XFUNC
|
2015-04-10 04:05:09 +00:00
|
|
|
#endif // ROCKSDB_XFTEST_FORCE == 1
|
2015-03-17 11:04:05 +00:00
|
|
|
#elif defined(NDEBUG)
|
2015-02-02 22:49:22 +00:00
|
|
|
#else
|
|
|
|
#define XFUNC
|
2015-04-10 04:05:09 +00:00
|
|
|
#endif // defined(ROCKSDB_XFTEST_FORCE)
|
|
|
|
#endif // !ROCKSDB_LITE
|
2015-02-02 22:49:22 +00:00
|
|
|
|
|
|
|
#ifndef XFUNC
|
|
|
|
#define XFUNC_TEST(condition, location, lfname, fname, ...)
|
|
|
|
#else
|
|
|
|
|
|
|
|
void GetXFTestOptions(Options* options, int skip_policy);
|
2015-02-18 19:49:31 +00:00
|
|
|
void xf_manage_options(ReadOptions* read_options);
|
Support saving history in memtable_list
Summary:
For transactions, we are using the memtables to validate that there are no write conflicts. But after flushing, we don't have any memtables, and transactions could fail to commit. So we want to someone keep around some extra history to use for conflict checking. In addition, we want to provide a way to increase the size of this history if too many transactions fail to commit.
After chatting with people, it seems like everyone prefers just using Memtables to store this history (instead of a separate history structure). It seems like the best place for this is abstracted inside the memtable_list. I decide to create a separate list in MemtableListVersion as using the same list complicated the flush/installalflushresults logic too much.
This diff adds a new parameter to control how much memtable history to keep around after flushing. However, it sounds like people aren't too fond of adding new parameters. So I am making the default size of flushed+not-flushed memtables be set to max_write_buffers. This should not change the maximum amount of memory used, but make it more likely we're using closer the the limit. (We are now postponing deleting flushed memtables until the max_write_buffer limit is reached). So while we might use more memory on average, we are still obeying the limit set (and you could argue it's better to go ahead and use up memory now instead of waiting for a write stall to happen to test this limit).
However, if people are opposed to this default behavior, we can easily set it to 0 and require this parameter be set in order to use transactions.
Test Plan: Added a xfunc test to play around with setting different values of this parameter in all tests. Added testing in memtablelist_test and planning on adding more testing here.
Reviewers: sdong, rven, igor
Reviewed By: igor
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D37443
2015-05-28 23:34:24 +00:00
|
|
|
void xf_transaction_set_memtable_history(
|
|
|
|
int32_t* max_write_buffer_number_to_maintain);
|
|
|
|
void xf_transaction_clear_memtable_history(
|
|
|
|
int32_t* max_write_buffer_number_to_maintain);
|
2015-02-02 22:49:22 +00:00
|
|
|
|
|
|
|
// This class provides the facility to run custom code to test a specific
|
|
|
|
// feature typically with all existing unit tests.
|
|
|
|
// A developer could specify cross functional test points in the codebase
|
|
|
|
// via XFUNC_TEST.
|
|
|
|
// Each xfunc test represents a position in the execution stream of a thread.
|
|
|
|
// Whenever that particular piece of code is called, the given cross-functional
|
|
|
|
// test point is executed.
|
|
|
|
// eg. on DBOpen, a particular option can be set.
|
|
|
|
// on Get, a particular option can be set, or a specific check can be invoked.
|
|
|
|
// XFUNC_TEST(TestName, location, lfname, FunctionName, Args)
|
|
|
|
// Turn on a specific cross functional test by setting the environment variable
|
|
|
|
// ROCKSDB_XFUNC_TEST
|
|
|
|
|
|
|
|
class XFuncPoint {
|
|
|
|
public:
|
|
|
|
// call once at the beginning of a test to get the test name
|
|
|
|
static void Init() {
|
|
|
|
char* s = getenv("ROCKSDB_XFUNC_TEST");
|
|
|
|
if (s == nullptr) {
|
|
|
|
xfunc_test_ = "";
|
|
|
|
enabled_ = false;
|
|
|
|
} else {
|
|
|
|
xfunc_test_ = s;
|
|
|
|
enabled_ = true;
|
|
|
|
}
|
|
|
|
initialized_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Initialized() { return initialized_; }
|
|
|
|
|
|
|
|
static bool Check(std::string test) {
|
|
|
|
return (enabled_ &&
|
|
|
|
((test.compare("") == 0) || (test.compare(xfunc_test_) == 0)));
|
|
|
|
}
|
|
|
|
|
2015-02-18 19:49:31 +00:00
|
|
|
static void SetSkip(int skip) { skip_policy_ = skip; }
|
|
|
|
static int GetSkip(void) { return skip_policy_; }
|
|
|
|
|
2015-02-02 22:49:22 +00:00
|
|
|
private:
|
|
|
|
static std::string xfunc_test_;
|
|
|
|
static bool initialized_;
|
|
|
|
static bool enabled_;
|
2015-02-18 19:49:31 +00:00
|
|
|
static int skip_policy_;
|
2015-02-02 22:49:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Use XFUNC_TEST to specify cross functional test points inside the code base.
|
|
|
|
// By setting ROCKSDB_XFUNC_TEST, all XFUNC_TEST having that
|
|
|
|
// value in the condition field will be executed.
|
|
|
|
// The second argument specifies a string representing the calling location
|
|
|
|
// The third argument, lfname, is the name of the function which will be created
|
|
|
|
// and called.
|
|
|
|
// The fourth argument fname represents the function to be called
|
|
|
|
// The arguments following that are the arguments to fname
|
|
|
|
// See Options::Options in options.h for an example use case.
|
|
|
|
// XFUNC_TEST is no op in release build.
|
|
|
|
#define XFUNC_TEST(condition, location, lfname, fname, ...) \
|
|
|
|
{ \
|
|
|
|
if (!XFuncPoint::Initialized()) { \
|
|
|
|
XFuncPoint::Init(); \
|
|
|
|
} \
|
|
|
|
if (XFuncPoint::Check(condition)) { \
|
|
|
|
std::function<void()> lfname = std::bind(fname, __VA_ARGS__); \
|
|
|
|
lfname(); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // XFUNC
|
|
|
|
|
|
|
|
enum SkipPolicy { kSkipNone = 0, kSkipNoSnapshot = 1, kSkipNoPrefix = 2 };
|
|
|
|
} // namespace rocksdb
|