summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Chen <luke.chen@mongodb.com>2021-05-04 09:58:28 +1000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-04 00:52:35 +0000
commitd87cf262a36fc49a2f4718ac49f1daae2d9063e4 (patch)
tree9e739b5ef100179320d1abc0a4712deee3b31008
parent7d979514eff586d39f090524fe323fb6fe38c791 (diff)
downloadmongo-d87cf262a36fc49a2f4718ac49f1daae2d9063e4.tar.gz
Import wiredtiger: 02f4d1d902131e2a6fd5bf680566db35d8c3a8bf from branch mongodb-5.0
ref: 1a7a783ee4..02f4d1d902 for: 5.0.0 WT-7476 Update configuration handling to allow for optional configuration settings
-rw-r--r--src/third_party/wiredtiger/import.data2
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/component.h1
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/configuration.h121
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/database_operation.h8
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/runtime_monitor.h7
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/test.h31
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/timestamp_manager.h6
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/workload_generator.h10
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/workload_tracking.h2
9 files changed, 111 insertions, 77 deletions
diff --git a/src/third_party/wiredtiger/import.data b/src/third_party/wiredtiger/import.data
index 39745950f49..accf6256d5e 100644
--- a/src/third_party/wiredtiger/import.data
+++ b/src/third_party/wiredtiger/import.data
@@ -2,5 +2,5 @@
"vendor": "wiredtiger",
"github": "wiredtiger/wiredtiger.git",
"branch": "mongodb-5.0",
- "commit": "1a7a783ee4a4c00be029dd58200767d15b8fda00"
+ "commit": "02f4d1d902131e2a6fd5bf680566db35d8c3a8bf"
}
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/component.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/component.h
index 466fdbe890e..fe0deb21880 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/component.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/component.h
@@ -56,6 +56,7 @@ class component {
virtual void
load()
{
+ _enabled = _config->get_optional_bool(ENABLED, true);
_running = true;
}
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/configuration.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/configuration.h
index 5cf3f9f1fbe..5fe9b95c5f8 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/configuration.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/configuration.h
@@ -35,6 +35,8 @@ extern "C" {
#include "test_util.h"
}
+enum class types { BOOL, INT, STRING, STRUCT };
+
namespace test_harness {
class configuration {
public:
@@ -74,68 +76,103 @@ class configuration {
}
/*
- * Wrapper functions for retrieving basic configuration values. Ideally the tests can avoid
- * using the config item struct provided by wiredtiger. However if they still wish to use it the
- * get and next functions can be used.
+ * Wrapper functions for retrieving basic configuration values. Ideally tests can avoid using
+ * the config item struct provided by wiredtiger.
+ *
+ * When getting a configuration value that may not exist for that configuration string or
+ * component, the optional forms of the functions can be used. In this case a default value must
+ * be passed and it will be set to that value.
*/
- int
- get_string(const std::string &key, std::string &value) const
+ std::string
+ get_string(const std::string &key)
{
- WT_CONFIG_ITEM temp_value;
- testutil_check(_config_parser->get(_config_parser, key.c_str(), &temp_value));
- if (temp_value.type != WT_CONFIG_ITEM::WT_CONFIG_ITEM_STRING &&
- temp_value.type != WT_CONFIG_ITEM::WT_CONFIG_ITEM_ID)
- return (-1);
- value = std::string(temp_value.str, temp_value.len);
- return (0);
+ return get<std::string>(key, false, types::STRING, "", config_item_to_string);
}
- int
- get_bool(const std::string &key, bool &value) const
+ std::string
+ get_optional_string(const std::string &key, const std::string &def)
{
- WT_CONFIG_ITEM temp_value;
- testutil_check(_config_parser->get(_config_parser, key.c_str(), &temp_value));
- if (temp_value.type != WT_CONFIG_ITEM::WT_CONFIG_ITEM_BOOL)
- return (-1);
- value = (temp_value.val != 0);
- return (0);
+ return get<std::string>(key, true, types::STRING, def, config_item_to_string);
}
- int
- get_int(const std::string &key, int64_t &value) const
+ bool
+ get_bool(const std::string &key)
{
- WT_CONFIG_ITEM temp_value;
- testutil_check(_config_parser->get(_config_parser, key.c_str(), &temp_value));
- if (temp_value.type != WT_CONFIG_ITEM::WT_CONFIG_ITEM_NUM)
- return (-1);
- value = temp_value.val;
- return (0);
+ return get<bool>(key, false, types::BOOL, false, config_item_to_bool);
}
- configuration *
- get_subconfig(const std::string &key) const
+ bool
+ get_optional_bool(const std::string &key, const bool def)
{
- WT_CONFIG_ITEM subconfig;
- testutil_check(get(key, &subconfig));
- return new configuration(subconfig);
+ return get<bool>(key, true, types::BOOL, def, config_item_to_bool);
}
- /*
- * Basic configuration parsing helper functions.
- */
- int
- next(WT_CONFIG_ITEM *key, WT_CONFIG_ITEM *value) const
+ int64_t
+ get_int(const std::string &key)
+ {
+ return get<int64_t>(key, false, types::INT, 0, config_item_to_int);
+ }
+
+ int64_t
+ get_optional_int(const std::string &key, const int64_t def)
{
- return (_config_parser->next(_config_parser, key, value));
+ return get<int64_t>(key, true, types::INT, def, config_item_to_int);
}
- int
- get(const std::string &key, WT_CONFIG_ITEM *value) const
+ configuration *
+ get_subconfig(const std::string &key)
{
- return (_config_parser->get(_config_parser, key.c_str(), value));
+ return get<configuration *>(key, false, types::STRUCT, nullptr,
+ [](WT_CONFIG_ITEM item) { return new configuration(item); });
}
private:
+ static bool
+ config_item_to_bool(const WT_CONFIG_ITEM item)
+ {
+ return (item.val != 0);
+ }
+
+ static int64_t
+ config_item_to_int(const WT_CONFIG_ITEM item)
+ {
+ return (item.val);
+ }
+
+ static std::string
+ config_item_to_string(const WT_CONFIG_ITEM item)
+ {
+ return std::string(item.str, item.len);
+ }
+
+ template <typename T>
+ T
+ get(const std::string &key, bool optional, types type, T def, T (*func)(WT_CONFIG_ITEM item))
+ {
+ WT_DECL_RET;
+ WT_CONFIG_ITEM value;
+ const char *error_msg = "Configuration value doesn't match requested type";
+
+ ret = _config_parser->get(_config_parser, key.c_str(), &value);
+ if (ret == WT_NOTFOUND && optional)
+ return (def);
+ else if (ret != 0)
+ testutil_die(ret, "Error while finding config");
+
+ if (type == types::STRING &&
+ (value.type != WT_CONFIG_ITEM::WT_CONFIG_ITEM_STRING &&
+ value.type != WT_CONFIG_ITEM::WT_CONFIG_ITEM_ID))
+ testutil_die(-1, error_msg);
+ else if (type == types::BOOL && value.type != WT_CONFIG_ITEM::WT_CONFIG_ITEM_BOOL)
+ testutil_die(-1, error_msg);
+ else if (type == types::INT && value.type != WT_CONFIG_ITEM::WT_CONFIG_ITEM_NUM)
+ testutil_die(-1, error_msg);
+ else if (type == types::STRUCT && value.type != WT_CONFIG_ITEM::WT_CONFIG_ITEM_STRUCT)
+ testutil_die(-1, error_msg);
+
+ return func(value);
+ }
+
std::string _config;
WT_CONFIG_PARSER *_config_parser;
};
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/database_operation.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/database_operation.h
index f7297dbd7a6..8dd3c7b965d 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/database_operation.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/database_operation.h
@@ -66,7 +66,7 @@ class database_operation {
/* Get a session. */
session = connection_manager::instance().create_session();
/* Create n collections as per the configuration and store each collection name. */
- testutil_check(config->get_int(COLLECTION_COUNT, collection_count));
+ collection_count = config->get_int(COLLECTION_COUNT);
for (int i = 0; i < collection_count; ++i) {
collection_name = "table:collection" + std::to_string(i);
database.collections[collection_name] = {};
@@ -78,10 +78,10 @@ class database_operation {
debug_print(std::to_string(collection_count) + " collections created", DEBUG_TRACE);
/* Open a cursor on each collection and use the configuration to insert key/value pairs. */
- testutil_check(config->get_int(KEY_COUNT, key_count));
- testutil_check(config->get_int(VALUE_SIZE, value_size));
+ key_count = config->get_int(KEY_COUNT);
+ value_size = config->get_int(VALUE_SIZE);
testutil_assert(value_size > 0);
- testutil_check(config->get_int(KEY_SIZE, key_size));
+ key_size = config->get_int(KEY_SIZE);
testutil_assert(key_size > 0);
/* Keys must be unique. */
testutil_assert(key_count <= pow(10, key_size));
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/runtime_monitor.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/runtime_monitor.h
index 2ed58c54f40..379248fec2f 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/runtime_monitor.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/runtime_monitor.h
@@ -55,8 +55,7 @@ class statistic {
public:
statistic(configuration *config)
{
- testutil_assert(config != nullptr);
- testutil_check(config->get_bool(ENABLED, _enabled));
+ _enabled = config->get_bool(ENABLED);
}
/* Check that the given statistic is within bounds. */
@@ -79,7 +78,7 @@ class cache_limit_statistic : public statistic {
public:
cache_limit_statistic(configuration *config) : statistic(config)
{
- testutil_check(config->get_int(LIMIT, limit));
+ limit = config->get_int(LIMIT);
}
void
@@ -136,7 +135,7 @@ class runtime_monitor : public component {
configuration *sub_config;
std::string statistic_list;
/* Parse the configuration for the runtime monitor. */
- testutil_check(_config->get_int(RATE_PER_SECOND, _ops));
+ _ops = _config->get_int(RATE_PER_SECOND);
/* Load known statistics. */
sub_config = _config->get_subconfig(STAT_CACHE_SIZE);
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/test.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/test.h
index 51c39958086..3f154a82938 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/test.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/test.h
@@ -58,16 +58,14 @@ class test : public database_operation {
: _runtime_monitor(nullptr), _thread_manager(nullptr), _timestamp_manager(nullptr),
_workload_generator(nullptr), _workload_tracking(nullptr)
{
- _configuration = new configuration(name, config);
- _runtime_monitor = new runtime_monitor(_configuration->get_subconfig(RUNTIME_MONITOR));
- _timestamp_manager =
- new timestamp_manager(_configuration->get_subconfig(TIMESTAMP_MANAGER));
- _workload_tracking = new workload_tracking(_configuration->get_subconfig(WORKLOAD_TRACKING),
+ _config = new configuration(name, config);
+ _runtime_monitor = new runtime_monitor(_config->get_subconfig(RUNTIME_MONITOR));
+ _timestamp_manager = new timestamp_manager(_config->get_subconfig(TIMESTAMP_MANAGER));
+ _workload_tracking = new workload_tracking(_config->get_subconfig(WORKLOAD_TRACKING),
OPERATION_TRACKING_TABLE_CONFIG, TABLE_OPERATION_TRACKING, SCHEMA_TRACKING_TABLE_CONFIG,
TABLE_SCHEMA_TRACKING);
- _workload_generator =
- new workload_generator(_configuration->get_subconfig(WORKLOAD_GENERATOR), this,
- _timestamp_manager, _workload_tracking);
+ _workload_generator = new workload_generator(
+ _config->get_subconfig(WORKLOAD_GENERATOR), this, _timestamp_manager, _workload_tracking);
_thread_manager = new thread_manager();
/*
* Ordering is not important here, any dependencies between components should be resolved
@@ -79,13 +77,13 @@ class test : public database_operation {
~test()
{
- delete _configuration;
+ delete _config;
delete _runtime_monitor;
delete _timestamp_manager;
delete _thread_manager;
delete _workload_generator;
delete _workload_tracking;
- _configuration = nullptr;
+ _config = nullptr;
_runtime_monitor = nullptr;
_timestamp_manager = nullptr;
_thread_manager = nullptr;
@@ -111,9 +109,10 @@ class test : public database_operation {
/* Build the database creation config string. */
std::string db_create_config = CONNECTION_CREATE;
- testutil_check(_configuration->get_int(CACHE_SIZE_MB, cache_size_mb));
+ /* Get the cache size, and turn logging on or off. */
+ cache_size_mb = _config->get_int(CACHE_SIZE_MB);
db_create_config += ",statistics=(fast),cache_size=" + std::to_string(cache_size_mb) + "MB";
- testutil_check(_configuration->get_bool(ENABLE_LOGGING, enable_logging));
+ enable_logging = _config->get_bool(ENABLE_LOGGING);
db_create_config += ",log=(enabled=" + std::string(enable_logging ? "true" : "false") + ")";
/* Set up the test environment. */
@@ -127,12 +126,12 @@ class test : public database_operation {
for (const auto &it : _components)
_thread_manager->add_thread(&component::run, it);
- /* Sleep duration seconds. */
- testutil_check(_configuration->get_int(DURATION_SECONDS, duration_seconds));
+ /* The test will run for the duration as defined in the config. */
+ duration_seconds = _config->get_int(DURATION_SECONDS);
testutil_assert(duration_seconds >= 0);
std::this_thread::sleep_for(std::chrono::seconds(duration_seconds));
- /* End the test. */
+ /* End the test by calling finish on all known components. */
for (const auto &it : _components)
it->finish();
_thread_manager->join();
@@ -179,7 +178,7 @@ class test : public database_operation {
private:
std::string _name;
std::vector<component *> _components;
- configuration *_configuration;
+ configuration *_config;
runtime_monitor *_runtime_monitor;
thread_manager *_thread_manager;
timestamp_manager *_timestamp_manager;
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/timestamp_manager.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/timestamp_manager.h
index 0a72eadc9cf..726330d6ef0 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/timestamp_manager.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/timestamp_manager.h
@@ -54,12 +54,10 @@ class timestamp_manager : public component {
void
load()
{
- testutil_assert(_config != nullptr);
- testutil_check(_config->get_int(OLDEST_LAG, _oldest_lag));
+ _oldest_lag = _config->get_int(OLDEST_LAG);
testutil_assert(_oldest_lag >= 0);
- testutil_check(_config->get_int(STABLE_LAG, _stable_lag));
+ _stable_lag = _config->get_int(STABLE_LAG);
testutil_assert(_stable_lag >= 0);
- testutil_check(_config->get_bool(ENABLED, _enabled));
component::load();
}
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload_generator.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload_generator.h
index d73a30c7bf0..3bdedbf10e4 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload_generator.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload_generator.h
@@ -73,13 +73,13 @@ class workload_generator : public component {
_database_operation->populate(_database, _timestamp_manager, _config, _tracking);
/* Retrieve useful parameters from the test configuration. */
- testutil_check(_config->get_int(READ_THREADS, read_threads));
- testutil_check(_config->get_int(UPDATE_THREADS, update_threads));
+ read_threads = _config->get_int(READ_THREADS);
+ update_threads = _config->get_int(UPDATE_THREADS);
sub_config = _config->get_subconfig(OPS_PER_TRANSACTION);
- testutil_check(sub_config->get_int(MIN, min_operation_per_transaction));
- testutil_check(sub_config->get_int(MAX, max_operation_per_transaction));
+ min_operation_per_transaction = sub_config->get_int(MIN);
+ max_operation_per_transaction = sub_config->get_int(MAX);
testutil_assert(max_operation_per_transaction >= min_operation_per_transaction);
- testutil_check(_config->get_int(VALUE_SIZE, value_size));
+ value_size = _config->get_int(VALUE_SIZE);
testutil_assert(value_size >= 0);
delete sub_config;
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload_tracking.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload_tracking.h
index 241ccf341d7..a44f8a1fd30 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload_tracking.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload_tracking.h
@@ -81,7 +81,7 @@ class workload_tracking : public component {
{
WT_SESSION *session;
- testutil_check(_config->get_bool(ENABLED, _enabled));
+ _enabled = _config->get_bool(ENABLED);
if (!_enabled)
return;