summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger
diff options
context:
space:
mode:
authorLuke Chen <luke.chen@mongodb.com>2021-06-04 17:19:50 +1000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-04 07:43:51 +0000
commit87b705ea55fa4e659c5ae92305bb8239d2d7f953 (patch)
treedae76488e3d97bf8026cc37c97c55c621d741122 /src/third_party/wiredtiger
parent8ad39138a406caa424d069b5b604c92c42167466 (diff)
downloadmongo-87b705ea55fa4e659c5ae92305bb8239d2d7f953.tar.gz
Import wiredtiger: a904812218233b904162a601d52af591a1fdd480 from branch mongodb-5.0
ref: 89b4e77eab..a904812218 for: 5.0.0-rc1 WT-7480 Cleanup thread_contexts in the test framework
Diffstat (limited to 'src/third_party/wiredtiger')
-rw-r--r--src/third_party/wiredtiger/dist/test_data.py45
-rw-r--r--src/third_party/wiredtiger/import.data2
-rw-r--r--src/third_party/wiredtiger/src/config/test_config.c59
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/configs/config_poc_test_default.txt3
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/configs/config_poc_test_stress.txt8
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/checkpoint_manager.h8
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/runtime_monitor.h4
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/thread_manager.h30
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/timestamp_manager.h4
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/util/api_const.h4
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_operation.h64
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/workload/thread_context.h198
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/workload/workload_tracking.h4
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/workload_generator.h69
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/tests/example_test.cxx13
15 files changed, 219 insertions, 296 deletions
diff --git a/src/third_party/wiredtiger/dist/test_data.py b/src/third_party/wiredtiger/dist/test_data.py
index a2ad0f343a0..b13906c22ed 100644
--- a/src/third_party/wiredtiger/dist/test_data.py
+++ b/src/third_party/wiredtiger/dist/test_data.py
@@ -56,9 +56,9 @@ throttle_config = [
]
#
-# Record config specifies the format of the keys and values used in the database
+# Record config specifies the size of the keys and values to be generated by default.
#
-record_config = throttle_config + [
+record_config = [
Config('key_size', 5, r'''
The size of the keys created''', min=0, max=10000),
Config('value_size', 5, r'''
@@ -68,7 +68,7 @@ record_config = throttle_config + [
#
# The populate config defines how large the initially loaded database will be.
#
-populate_config = [
+populate_config = record_config + [
Config('collection_count', 1, r'''
The number of collections the workload generator operates over''', min=0, max=200000),
Config('key_count', 0, r'''
@@ -105,7 +105,7 @@ range_config = [
The maximum a value can be in a range''')
]
-component_config = enabled_config_true + throttle_config
+component_config = throttle_config
transaction_config = [
Config('ops_per_transaction', '', r'''
@@ -114,16 +114,24 @@ transaction_config = [
type='category',subconfig=range_config),
]
+thread_count = [
+ Config('thread_count', 1, r'''
+ Specifies the number of threads that will be used to perform a certain function.''')
+]
+
+read_thread_config = thread_count + throttle_config + transaction_config
+update_insert_thread_config = thread_count + transaction_config + throttle_config + record_config
+
#
# Configuration for the checkpoint_manager component.
#
-checkpoint_manager = component_config
+checkpoint_manager = enabled_config_false + component_config
#
# Configuration that applies to the runtime monitor component, this should be a list of statistics
# that need to be checked by the component.
#
-runtime_monitor = component_config + [
+runtime_monitor = enabled_config_true + component_config + [
Config('stat_cache_size', '', '''
The maximum cache percentage that can be hit while running.''',
type='category', subconfig=limit_stat)
@@ -132,7 +140,7 @@ runtime_monitor = component_config + [
#
# Configuration that applies to the timestamp_manager component.
#
-timestamp_manager = component_config + [
+timestamp_manager = enabled_config_true + component_config + [
Config('oldest_lag', 1, r'''
The duration between the stable and oldest timestamps''', min=0, max=1000000),
Config('stable_lag', 1, r'''
@@ -142,26 +150,21 @@ timestamp_manager = component_config + [
#
# Configuration that applies to the workload tracking component.
#
-workload_tracking = component_config
+workload_tracking = enabled_config_true + component_config
#
# Configuration that applies to the workload_generator component.
#
-workload_generator = component_config + transaction_config + record_config + populate_config + [
- Config('read_threads', 0, r'''
- The number of threads performing read operations''', min=0, max=100),
- Config('insert_threads', 0, r'''
- The number of threads performing insert operations''', min=0, max=20),
+workload_generator = enabled_config_true + component_config + populate_config + [
+ Config('read_config', '', r'''
+ Config that specifies the number of read threads and their behaviour.''',
+ type='category', subconfig=read_thread_config),
Config('insert_config', '', r'''
- The definition of the record being inserted, if record config is empty the top level
- record_config will be used.''',
- type='category', subconfig=record_config),
- Config('update_threads', 0, r'''
- The number of threads performing update operations''', min=0, max=20),
+ Config that specifies the number of insert threads and their behaviour.''',
+ type='category', subconfig=update_insert_thread_config),
Config('update_config', '',r'''
- The definition of the record being updated, if record config is empty the top level
- record_config will be used.''',
- type='category', subconfig=record_config)
+ Config that specifies the number of update threads and their behaviour.''',
+ type='category', subconfig=update_insert_thread_config)
]
test_config = [
diff --git a/src/third_party/wiredtiger/import.data b/src/third_party/wiredtiger/import.data
index c1bd077a1ad..975452812e7 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": "89b4e77eab280a0569126d205cd35201bb5180f5"
+ "commit": "a904812218233b904162a601d52af591a1fdd480"
}
diff --git a/src/third_party/wiredtiger/src/config/test_config.c b/src/third_party/wiredtiger/src/config/test_config.c
index b3ac1be8251..ed314e7e1b3 100644
--- a/src/third_party/wiredtiger/src/config/test_config.c
+++ b/src/third_party/wiredtiger/src/config/test_config.c
@@ -25,37 +25,42 @@ static const WT_CONFIG_CHECK confchk_timestamp_manager_subconfigs[] = {
{"op_count", "int", NULL, "min=1,max=10000", NULL, 0},
{"stable_lag", "int", NULL, "min=0,max=1000000", NULL, 0}, {NULL, NULL, NULL, NULL, NULL, 0}};
+static const WT_CONFIG_CHECK confchk_ops_per_transaction_subconfigs[] = {
+ {"max", "string", NULL, NULL, NULL, 0}, {"min", "int", NULL, "min=0", NULL, 0},
+ {NULL, NULL, NULL, NULL, NULL, 0}};
+
static const WT_CONFIG_CHECK confchk_insert_config_subconfigs[] = {
{"interval", "string", NULL, "choices=[\"s\",\"m\",\"h\"]", NULL, 0},
{"key_size", "int", NULL, "min=0,max=10000", NULL, 0},
{"op_count", "int", NULL, "min=1,max=10000", NULL, 0},
+ {"ops_per_transaction", "category", NULL, NULL, confchk_ops_per_transaction_subconfigs, 2},
+ {"thread_count", "string", NULL, NULL, NULL, 0},
{"value_size", "int", NULL, "min=0,max=1000000000", NULL, 0}, {NULL, NULL, NULL, NULL, NULL, 0}};
-static const WT_CONFIG_CHECK confchk_ops_per_transaction_subconfigs[] = {
- {"max", "string", NULL, NULL, NULL, 0}, {"min", "int", NULL, "min=0", NULL, 0},
- {NULL, NULL, NULL, NULL, NULL, 0}};
+static const WT_CONFIG_CHECK confchk_read_config_subconfigs[] = {
+ {"interval", "string", NULL, "choices=[\"s\",\"m\",\"h\"]", NULL, 0},
+ {"op_count", "int", NULL, "min=1,max=10000", NULL, 0},
+ {"ops_per_transaction", "category", NULL, NULL, confchk_ops_per_transaction_subconfigs, 2},
+ {"thread_count", "string", NULL, NULL, NULL, 0}, {NULL, NULL, NULL, NULL, NULL, 0}};
static const WT_CONFIG_CHECK confchk_update_config_subconfigs[] = {
{"interval", "string", NULL, "choices=[\"s\",\"m\",\"h\"]", NULL, 0},
{"key_size", "int", NULL, "min=0,max=10000", NULL, 0},
{"op_count", "int", NULL, "min=1,max=10000", NULL, 0},
+ {"ops_per_transaction", "category", NULL, NULL, confchk_ops_per_transaction_subconfigs, 2},
+ {"thread_count", "string", NULL, NULL, NULL, 0},
{"value_size", "int", NULL, "min=0,max=1000000000", NULL, 0}, {NULL, NULL, NULL, NULL, NULL, 0}};
static const WT_CONFIG_CHECK confchk_workload_generator_subconfigs[] = {
{"collection_count", "int", NULL, "min=0,max=200000", NULL, 0},
{"enabled", "boolean", NULL, NULL, NULL, 0},
- {"insert_config", "category", NULL, NULL, confchk_insert_config_subconfigs, 4},
- {"insert_threads", "int", NULL, "min=0,max=20", NULL, 0},
- {"interval", "string", NULL, "choices=[\"s\",\"m\",\"h\"]", NULL, 0},
+ {"insert_config", "category", NULL, NULL, confchk_insert_config_subconfigs, 6},
{"interval", "string", NULL, "choices=[\"s\",\"m\",\"h\"]", NULL, 0},
{"key_count", "int", NULL, "min=0,max=1000000", NULL, 0},
{"key_size", "int", NULL, "min=0,max=10000", NULL, 0},
{"op_count", "int", NULL, "min=1,max=10000", NULL, 0},
- {"op_count", "int", NULL, "min=1,max=10000", NULL, 0},
- {"ops_per_transaction", "category", NULL, NULL, confchk_ops_per_transaction_subconfigs, 2},
- {"read_threads", "int", NULL, "min=0,max=100", NULL, 0},
- {"update_config", "category", NULL, NULL, confchk_update_config_subconfigs, 4},
- {"update_threads", "int", NULL, "min=0,max=20", NULL, 0},
+ {"read_config", "category", NULL, NULL, confchk_read_config_subconfigs, 4},
+ {"update_config", "category", NULL, NULL, confchk_update_config_subconfigs, 6},
{"value_size", "int", NULL, "min=0,max=1000000000", NULL, 0}, {NULL, NULL, NULL, NULL, NULL, 0}};
static const WT_CONFIG_CHECK confchk_workload_tracking_subconfigs[] = {
@@ -70,7 +75,7 @@ static const WT_CONFIG_CHECK confchk_example_test[] = {
{"enable_logging", "boolean", NULL, NULL, NULL, 0},
{"runtime_monitor", "category", NULL, NULL, confchk_runtime_monitor_subconfigs, 4},
{"timestamp_manager", "category", NULL, NULL, confchk_timestamp_manager_subconfigs, 5},
- {"workload_generator", "category", NULL, NULL, confchk_workload_generator_subconfigs, 15},
+ {"workload_generator", "category", NULL, NULL, confchk_workload_generator_subconfigs, 10},
{"workload_tracking", "category", NULL, NULL, confchk_workload_tracking_subconfigs, 3},
{NULL, NULL, NULL, NULL, NULL, 0}};
@@ -81,38 +86,42 @@ static const WT_CONFIG_CHECK confchk_poc_test[] = {
{"enable_logging", "boolean", NULL, NULL, NULL, 0},
{"runtime_monitor", "category", NULL, NULL, confchk_runtime_monitor_subconfigs, 4},
{"timestamp_manager", "category", NULL, NULL, confchk_timestamp_manager_subconfigs, 5},
- {"workload_generator", "category", NULL, NULL, confchk_workload_generator_subconfigs, 15},
+ {"workload_generator", "category", NULL, NULL, confchk_workload_generator_subconfigs, 10},
{"workload_tracking", "category", NULL, NULL, confchk_workload_tracking_subconfigs, 3},
{NULL, NULL, NULL, NULL, NULL, 0}};
static const WT_CONFIG_ENTRY config_entries[] = {
{"example_test",
- "cache_size_mb=0,checkpoint_manager=(enabled=true,interval=s,"
+ "cache_size_mb=0,checkpoint_manager=(enabled=false,interval=s,"
"op_count=1),duration_seconds=0,enable_logging=false,"
"runtime_monitor=(enabled=true,interval=s,op_count=1,"
"stat_cache_size=(enabled=false,limit=0)),"
"timestamp_manager=(enabled=true,interval=s,oldest_lag=1,"
"op_count=1,stable_lag=1),workload_generator=(collection_count=1,"
"enabled=true,insert_config=(interval=s,key_size=5,op_count=1,"
- "value_size=5),insert_threads=0,interval=s,interval=s,key_count=0"
- ",key_size=5,op_count=1,op_count=1,ops_per_transaction=(max=1,"
- "min=0),read_threads=0,update_config=(interval=s,key_size=5,"
- "op_count=1,value_size=5),update_threads=0,value_size=5),"
- "workload_tracking=(enabled=true,interval=s,op_count=1)",
+ "ops_per_transaction=(max=1,min=0),thread_count=1,value_size=5),"
+ "interval=s,key_count=0,key_size=5,op_count=1,"
+ "read_config=(interval=s,op_count=1,ops_per_transaction=(max=1,"
+ "min=0),thread_count=1),update_config=(interval=s,key_size=5,"
+ "op_count=1,ops_per_transaction=(max=1,min=0),thread_count=1,"
+ "value_size=5),value_size=5),workload_tracking=(enabled=true,"
+ "interval=s,op_count=1)",
confchk_example_test, 8},
{"poc_test",
- "cache_size_mb=0,checkpoint_manager=(enabled=true,interval=s,"
+ "cache_size_mb=0,checkpoint_manager=(enabled=false,interval=s,"
"op_count=1),duration_seconds=0,enable_logging=false,"
"runtime_monitor=(enabled=true,interval=s,op_count=1,"
"stat_cache_size=(enabled=false,limit=0)),"
"timestamp_manager=(enabled=true,interval=s,oldest_lag=1,"
"op_count=1,stable_lag=1),workload_generator=(collection_count=1,"
"enabled=true,insert_config=(interval=s,key_size=5,op_count=1,"
- "value_size=5),insert_threads=0,interval=s,interval=s,key_count=0"
- ",key_size=5,op_count=1,op_count=1,ops_per_transaction=(max=1,"
- "min=0),read_threads=0,update_config=(interval=s,key_size=5,"
- "op_count=1,value_size=5),update_threads=0,value_size=5),"
- "workload_tracking=(enabled=true,interval=s,op_count=1)",
+ "ops_per_transaction=(max=1,min=0),thread_count=1,value_size=5),"
+ "interval=s,key_count=0,key_size=5,op_count=1,"
+ "read_config=(interval=s,op_count=1,ops_per_transaction=(max=1,"
+ "min=0),thread_count=1),update_config=(interval=s,key_size=5,"
+ "op_count=1,ops_per_transaction=(max=1,min=0),thread_count=1,"
+ "value_size=5),value_size=5),workload_tracking=(enabled=true,"
+ "interval=s,op_count=1)",
confchk_poc_test, 8},
{NULL, NULL, NULL, 0}};
diff --git a/src/third_party/wiredtiger/test/cppsuite/configs/config_poc_test_default.txt b/src/third_party/wiredtiger/test/cppsuite/configs/config_poc_test_default.txt
index a53844d00a7..c4631b6e7be 100644
--- a/src/third_party/wiredtiger/test/cppsuite/configs/config_poc_test_default.txt
+++ b/src/third_party/wiredtiger/test/cppsuite/configs/config_poc_test_default.txt
@@ -5,7 +5,8 @@ duration_seconds=10,
cache_size_mb=1000,
checkpoint_manager=
(
- op_count=30,
+ enabled=true,
+ op_count=20,
interval=m,
),
runtime_monitor=
diff --git a/src/third_party/wiredtiger/test/cppsuite/configs/config_poc_test_stress.txt b/src/third_party/wiredtiger/test/cppsuite/configs/config_poc_test_stress.txt
index 6eeda0ab7c0..bfc0c962ae3 100644
--- a/src/third_party/wiredtiger/test/cppsuite/configs/config_poc_test_stress.txt
+++ b/src/third_party/wiredtiger/test/cppsuite/configs/config_poc_test_stress.txt
@@ -4,6 +4,12 @@
duration_seconds=10,
cache_size_mb=5000,
enable_logging=true,
+checkpoint_manager=
+(
+ enabled=true,
+ interval=m,
+ op_count=20
+),
runtime_monitor=
(
stat_cache_size=
@@ -25,4 +31,4 @@ workload_generator=
read_threads=1,
update_threads=1,
value_size=2000
-), \ No newline at end of file
+),
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/checkpoint_manager.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/checkpoint_manager.h
index dc7133f6ca9..d5396737c43 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/checkpoint_manager.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/checkpoint_manager.h
@@ -37,7 +37,7 @@ namespace test_harness {
class checkpoint_manager : public component {
public:
explicit checkpoint_manager(configuration *configuration)
- : component(CHECKPOINT_MANAGER, configuration), _session(nullptr)
+ : component(CHECKPOINT_MANAGER, configuration)
{
}
virtual ~checkpoint_manager() = default;
@@ -47,7 +47,7 @@ class checkpoint_manager : public component {
checkpoint_manager &operator=(const checkpoint_manager &) = delete;
void
- load() override
+ load() override final
{
/* Load the general component things. */
component::load();
@@ -58,14 +58,14 @@ class checkpoint_manager : public component {
}
void
- do_work() override
+ do_work() override final
{
debug_print("Running checkpoint", DEBUG_INFO);
testutil_check(_session->checkpoint(_session, nullptr));
}
private:
- WT_SESSION *_session;
+ WT_SESSION *_session = nullptr;
};
} // namespace test_harness
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 bc559a03104..d24317b7352 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
@@ -129,7 +129,7 @@ class runtime_monitor : public component {
runtime_monitor &operator=(const runtime_monitor &) = delete;
void
- load()
+ load() override final
{
configuration *sub_config;
std::string statistic_list;
@@ -151,7 +151,7 @@ class runtime_monitor : public component {
}
void
- do_work()
+ do_work() override final
{
for (const auto &it : _stats) {
if (it->enabled())
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/thread_manager.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/thread_manager.h
index b7f736c169d..d15d935584a 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/thread_manager.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/thread_manager.h
@@ -31,9 +31,6 @@
#include <thread>
-#include "workload/database_operation.h"
-#include "workload/thread_context.h"
-
namespace test_harness {
/* Class that handles threads, from their initialization to their deletion. */
class thread_manager {
@@ -52,27 +49,13 @@ class thread_manager {
}
/*
- * Generic function to create threads that take contexts, typically these will be static
- * functions.
- */
- template <typename Callable>
- void
- add_thread(thread_context *tc, database_operation *db_operation, Callable &&fct)
- {
- tc->set_running(true);
- std::thread *t = new std::thread(fct, std::ref(*tc), std::ref(*db_operation));
- _workers.push_back(t);
- }
-
- /*
- * Generic function to create threads that do not take thread contexts but take a single
- * argument, typically these threads are calling non static member function of classes.
+ * Generic function to create threads that call member function of classes.
*/
- template <typename Callable, typename Args>
+ template <typename Callable, typename... Args>
void
- add_thread(Callable &&fct, Args &&args)
+ add_thread(Callable &&fct, Args &&... args)
{
- std::thread *t = new std::thread(fct, args);
+ std::thread *t = new std::thread(fct, args...);
_workers.push_back(t);
}
@@ -83,8 +66,9 @@ class thread_manager {
join()
{
for (const auto &it : _workers) {
- if (it->joinable())
- it->join();
+ while (!it->joinable()) {
+ }
+ it->join();
}
}
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 96b5f6bc69c..adc5b734c05 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
@@ -47,7 +47,7 @@ class timestamp_manager : public component {
timestamp_manager(configuration *config) : component("timestamp_manager", config) {}
void
- load()
+ load() override final
{
component::load();
@@ -58,7 +58,7 @@ class timestamp_manager : public component {
}
void
- do_work()
+ do_work() override final
{
std::string config;
/* latest_ts_s represents the time component of the latest timestamp provided. */
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/util/api_const.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/util/api_const.h
index 70d94cd3596..495989407c1 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/util/api_const.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/util/api_const.h
@@ -55,10 +55,10 @@ static const char *MIN = "min";
static const char *OLDEST_LAG = "oldest_lag";
static const char *OP_COUNT = "op_count";
static const char *OPS_PER_TRANSACTION = "ops_per_transaction";
-static const char *READ_THREADS = "read_threads";
+static const char *READ_CONFIG = "read_config";
static const char *STABLE_LAG = "stable_lag";
static const char *STAT_CACHE_SIZE = "stat_cache_size";
-static const char *UPDATE_THREADS = "update_threads";
+static const char *THREAD_COUNT = "thread_count";
static const char *UPDATE_CONFIG = "update_config";
static const char *VALUE_SIZE = "value_size";
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_operation.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_operation.h
index fc97c1e381c..ab192f798b1 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_operation.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_operation.h
@@ -122,19 +122,18 @@ class database_operation {
/* Basic read operation that walks a cursors across all collections. */
virtual void
- read_operation(thread_context &context, WT_SESSION *session)
+ read_operation(thread_context *tc)
{
WT_CURSOR *cursor;
std::vector<WT_CURSOR *> cursors;
- testutil_assert(session != nullptr);
/* Get a cursor for each collection in collection_names. */
- for (const auto &it : context.get_collection_names()) {
- testutil_check(session->open_cursor(session, it.c_str(), NULL, NULL, &cursor));
+ for (const auto &it : tc->database.get_collection_names()) {
+ testutil_check(tc->session->open_cursor(tc->session, it.c_str(), NULL, NULL, &cursor));
cursors.push_back(cursor);
}
- while (!cursors.empty() && context.is_running()) {
+ while (!cursors.empty() && tc->running()) {
/* Walk each cursor. */
for (const auto &it : cursors) {
if (it->next(it) != 0)
@@ -147,30 +146,28 @@ class database_operation {
* Basic update operation that updates all the keys to a random value in each collection.
*/
virtual void
- update_operation(thread_context &context, WT_SESSION *session)
+ update_operation(thread_context *tc)
{
- WT_DECL_RET;
WT_CURSOR *cursor;
+ WT_DECL_RET;
wt_timestamp_t ts;
std::vector<WT_CURSOR *> cursors;
- std::vector<std::string> collection_names = context.get_collection_names();
+ std::vector<std::string> collection_names = tc->database.get_collection_names();
key_value_t key, generated_value;
const char *key_tmp;
- int64_t value_size = context.get_value_size();
- uint64_t i;
+ uint64_t i = 0;
+ bool using_timestamps = tc->timestamp_manager->enabled();
- testutil_assert(session != nullptr);
/* Get a cursor for each collection in collection_names. */
for (const auto &it : collection_names) {
- testutil_check(session->open_cursor(session, it.c_str(), NULL, NULL, &cursor));
+ testutil_check(tc->session->open_cursor(tc->session, it.c_str(), NULL, NULL, &cursor));
cursors.push_back(cursor);
}
/*
* Update each collection while the test is running.
*/
- i = 0;
- while (context.is_running() && !collection_names.empty()) {
+ while (tc->running() && !collection_names.empty()) {
if (i >= collection_names.size())
i = 0;
ret = cursors[i]->next(cursors[i]);
@@ -190,35 +187,30 @@ class database_operation {
*/
key = key_value_t(key_tmp);
generated_value =
- random_generator::random_generator::instance().generate_string(value_size);
- ts = context.get_timestamp_manager()->get_next_ts();
+ random_generator::random_generator::instance().generate_string(tc->value_size);
- /* Start a transaction if possible. */
- if (!context.is_in_transaction()) {
- context.begin_transaction(session, "");
- context.set_commit_timestamp(session, ts);
- }
+ /* Start a transaction. */
+ if (!tc->transaction.active())
+ tc->transaction.begin(tc->session, "");
+
+ ts = tc->timestamp_manager->get_next_ts();
+ if (using_timestamps)
+ tc->transaction.set_commit_timestamp(
+ tc->session, timestamp_manager::decimal_to_hex(ts));
- update(context.get_tracking(), cursors[i], collection_names[i], key.c_str(),
+ update(tc->tracking, cursors[i], collection_names[i], key.c_str(),
generated_value.c_str(), ts);
- /* Commit the current transaction if possible. */
- context.increment_operation_count();
- if (context.can_commit_transaction())
- context.commit_transaction(session, "");
+ /* Commit the current transaction. */
+ tc->transaction.op_count++;
+ if (tc->transaction.can_commit())
+ tc->transaction.commit(tc->session, "");
}
+ tc->sleep();
}
-
- /*
- * The update operations will be later on inside a loop that will be managed through
- * throttle management.
- */
- while (context.is_running())
- context.sleep();
-
/* Make sure the last operation is committed now the work is finished. */
- if (context.is_in_transaction())
- context.commit_transaction(session, "");
+ if (tc->transaction.active())
+ tc->transaction.commit(tc->session, "");
}
private:
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/thread_context.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/thread_context.h
index 2cf20066504..47f0453512d 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/thread_context.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/thread_context.h
@@ -35,167 +35,131 @@
#include "workload_tracking.h"
namespace test_harness {
-/* Define the different thread operations. */
-enum class thread_operation {
- INSERT,
- UPDATE,
- READ,
- REMOVE,
- CHECKPOINT,
- TIMESTAMP,
- MONITOR,
- COMPONENT
-};
-
-/* Container class for a thread and any data types it may need to interact with the database. */
-class thread_context {
+class transaction_context {
public:
- thread_context(timestamp_manager *timestamp_manager, workload_tracking *tracking, database &db,
- thread_operation type, int64_t max_op, int64_t min_op, int64_t value_size, throttle throttle)
- : _database(db), _min_op(min_op), _max_op(max_op), _timestamp_manager(timestamp_manager),
- _type(type), _tracking(tracking), _value_size(value_size), _throttle(throttle)
+ explicit transaction_context(configuration *config)
{
- }
-
- void
- finish()
- {
- _running = false;
- }
-
- const std::vector<std::string>
- get_collection_names() const
- {
- return (_database.get_collection_names());
- }
-
- thread_operation
- get_thread_operation() const
- {
- return (_type);
- }
-
- timestamp_manager *
- get_timestamp_manager() const
- {
- return (_timestamp_manager);
- }
-
- workload_tracking *
- get_tracking() const
- {
- return (_tracking);
- }
-
- int64_t
- get_value_size() const
- {
- return (_value_size);
- }
-
- bool
- is_running() const
- {
- return (_running);
+ configuration *transaction_config = config->get_subconfig(OPS_PER_TRANSACTION);
+ _min_op_count = transaction_config->get_int(MIN);
+ _max_op_count = transaction_config->get_int(MAX);
+ delete transaction_config;
}
bool
- is_in_transaction() const
+ active() const
{
return (_in_txn);
}
- void
- sleep()
+ /*
+ * The current transaction can be committed if: A transaction has started and the number of
+ * operations executed in the current transaction has exceeded the threshold.
+ */
+ bool
+ can_commit() const
{
- _throttle.sleep();
+ return (_in_txn && op_count >= _target_op_count);
}
void
- set_running(bool running)
+ commit(WT_SESSION *session, const std::string &config)
{
- _running = running;
+ /* A transaction cannot be committed if not started. */
+ testutil_assert(_in_txn);
+ testutil_check(
+ session->commit_transaction(session, config.empty() ? nullptr : config.c_str()));
+ _in_txn = false;
}
void
- begin_transaction(WT_SESSION *session, const std::string &config)
+ begin(WT_SESSION *session, const std::string &config)
{
- if (!_in_txn && _timestamp_manager->enabled()) {
+ if (!_in_txn) {
testutil_check(
session->begin_transaction(session, config.empty() ? nullptr : config.c_str()));
/* This randomizes the number of operations to be executed in one transaction. */
- _max_op_count = random_generator::instance().generate_integer(_min_op, _max_op);
- _current_op_count = 0;
+ _target_op_count =
+ random_generator::instance().generate_integer(_min_op_count, _max_op_count);
+ op_count = 0;
_in_txn = true;
}
}
/*
- * The current transaction can be committed if:
- * - The timestamp manager is enabled and
- * - A transaction has started and
- * - The thread is done working. This is useful when the test is ended and the thread has
- * not reached the maximum number of operations per transaction or
- * - The number of operations executed in the current transaction has exceeded the
- * threshold.
+ * Set a commit timestamp.
*/
- bool
- can_commit_transaction() const
+ void
+ set_commit_timestamp(WT_SESSION *session, const std::string &ts)
{
- return (_timestamp_manager->enabled() && _in_txn &&
- (!_running || (_current_op_count > _max_op_count)));
+ std::string config = std::string(COMMIT_TS) + "=" + ts;
+ testutil_check(session->timestamp_transaction(session, config.c_str()));
}
- void
- commit_transaction(WT_SESSION *session, const std::string &config)
+ /*
+ * op_count is the current number of operations that have been executed in the current
+ * transaction.
+ */
+ int64_t op_count = 0;
+
+ private:
+ /*
+ * _min_op_count and _max_op_count are the minimum and maximum number of operations within one
+ * transaction. is the current maximum number of operations that can be executed in the current
+ * transaction.
+ */
+ int64_t _min_op_count = 0;
+ int64_t _max_op_count = INT64_MAX;
+ int64_t _target_op_count = 0;
+ bool _in_txn = false;
+};
+
+/* Container class for a thread and any data types it may need to interact with the database. */
+class thread_context {
+ public:
+ thread_context(configuration *config, timestamp_manager *timestamp_manager,
+ workload_tracking *tracking, database &db)
+ : database(db), timestamp_manager(timestamp_manager), tracking(tracking),
+ transaction(transaction_context(config))
{
- /* A transaction cannot be committed if not started. */
- testutil_assert(_in_txn);
- testutil_check(
- session->commit_transaction(session, config.empty() ? nullptr : config.c_str()));
- _in_txn = false;
+ session = connection_manager::instance().create_session();
+ _throttle = throttle(config);
+
+ /* These won't exist for read threads which is why we use optional here. */
+ key_size = config->get_optional_int(KEY_SIZE, 1);
+ value_size = config->get_optional_int(VALUE_SIZE, 1);
+
+ testutil_assert(key_size > 0 && value_size > 0);
}
void
- increment_operation_count(uint64_t inc = 1)
+ finish()
{
- _current_op_count += inc;
+ _running = false;
}
- /*
- * Set a commit timestamp if the timestamp manager is enabled.
- */
void
- set_commit_timestamp(WT_SESSION *session, wt_timestamp_t ts)
+ sleep()
{
- if (!_timestamp_manager->enabled())
- return;
+ _throttle.sleep();
+ }
- std::string config = std::string(COMMIT_TS) + "=" + _timestamp_manager->decimal_to_hex(ts);
- testutil_check(session->timestamp_transaction(session, config.c_str()));
+ bool
+ running() const
+ {
+ return (_running);
}
+ WT_SESSION *session;
+ transaction_context transaction;
+ test_harness::timestamp_manager *timestamp_manager;
+ test_harness::workload_tracking *tracking;
+ test_harness::database database;
+ int64_t key_size = 0;
+ int64_t value_size = 0;
+
private:
- /* Representation of the collections and their key/value pairs in memory. */
- database _database;
- /*
- * _current_op_count is the current number of operations that have been executed in the current
- * transaction.
- */
- uint64_t _current_op_count = 0U;
- bool _in_txn = false, _running = false;
- /*
- * _min_op and _max_op are the minimum and maximum number of operations within one transaction.
- * _max_op_count is the current maximum number of operations that can be executed in the current
- * transaction. _max_op_count will always be <= _max_op.
- */
- int64_t _min_op, _max_op, _max_op_count = 0;
- timestamp_manager *_timestamp_manager;
- const thread_operation _type;
throttle _throttle;
- workload_tracking *_tracking;
- /* Temporary member that comes from the test configuration. */
- int64_t _value_size;
+ bool _running = true;
};
} // namespace test_harness
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/workload_tracking.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/workload_tracking.h
index 41efadb440b..d44ee79e563 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/workload_tracking.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/workload_tracking.h
@@ -76,7 +76,7 @@ class workload_tracking : public component {
}
void
- load()
+ load() override final
{
WT_SESSION *session;
@@ -102,7 +102,7 @@ class workload_tracking : public component {
}
void
- run()
+ run() override final
{
/* Does not do anything. */
}
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 5e084229123..bc7b0c45c03 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
@@ -64,57 +64,46 @@ class workload_generator : public component {
/* Do the work of the main part of the workload. */
void
- run()
+ run() override final
{
- configuration *transaction_config, *update_config, *insert_config;
- int64_t min_operation_per_transaction, max_operation_per_transaction, read_threads,
- update_threads, value_size;
+ configuration *read_config, *update_config, *insert_config;
/* Populate the database. */
_database_operation->populate(_database, _timestamp_manager, _config, _tracking);
_db_populated = true;
/* Retrieve useful parameters from the test configuration. */
- transaction_config = _config->get_subconfig(OPS_PER_TRANSACTION);
update_config = _config->get_subconfig(UPDATE_CONFIG);
insert_config = _config->get_subconfig(INSERT_CONFIG);
- read_threads = _config->get_int(READ_THREADS);
- update_threads = _config->get_int(UPDATE_THREADS);
-
- min_operation_per_transaction = transaction_config->get_int(MIN);
- max_operation_per_transaction = transaction_config->get_int(MAX);
- testutil_assert(max_operation_per_transaction >= min_operation_per_transaction);
- value_size = _config->get_int(VALUE_SIZE);
- testutil_assert(value_size >= 0);
+ read_config = _config->get_subconfig(READ_CONFIG);
/* Generate threads to execute read operations on the collections. */
- for (size_t i = 0; i < read_threads && _running; ++i) {
- thread_context *tc = new thread_context(_timestamp_manager, _tracking, _database,
- thread_operation::READ, max_operation_per_transaction, min_operation_per_transaction,
- value_size, throttle());
+ for (size_t i = 0; i < read_config->get_int(THREAD_COUNT) && _running; ++i) {
+ thread_context *tc =
+ new thread_context(read_config, _timestamp_manager, _tracking, _database);
_workers.push_back(tc);
- _thread_manager.add_thread(tc, _database_operation, &execute_operation);
+ _thread_manager.add_thread(
+ &database_operation::read_operation, _database_operation, tc);
}
/* Generate threads to execute update operations on the collections. */
- for (size_t i = 0; i < update_threads && _running; ++i) {
- thread_context *tc = new thread_context(_timestamp_manager, _tracking, _database,
- thread_operation::UPDATE, max_operation_per_transaction,
- min_operation_per_transaction, value_size, throttle(update_config));
+ for (size_t i = 0; i < update_config->get_int(THREAD_COUNT) && _running; ++i) {
+ thread_context *tc =
+ new thread_context(update_config, _timestamp_manager, _tracking, _database);
_workers.push_back(tc);
- _thread_manager.add_thread(tc, _database_operation, &execute_operation);
+ _thread_manager.add_thread(
+ &database_operation::update_operation, _database_operation, tc);
}
- delete transaction_config;
+ delete read_config;
delete update_config;
delete insert_config;
}
void
- finish()
+ finish() override final
{
component::finish();
-
for (const auto &it : _workers)
it->finish();
_thread_manager.join();
@@ -133,34 +122,6 @@ class workload_generator : public component {
return (_db_populated);
}
- /* Workload threaded operations. */
- static void
- execute_operation(thread_context &context, database_operation &db_operation)
- {
- WT_SESSION *session;
-
- session = connection_manager::instance().create_session();
-
- switch (context.get_thread_operation()) {
- case thread_operation::READ:
- db_operation.read_operation(context, session);
- break;
- case thread_operation::REMOVE:
- case thread_operation::INSERT:
- /* Sleep until it is implemented. */
- while (context.is_running())
- std::this_thread::sleep_for(std::chrono::seconds(1));
- break;
- case thread_operation::UPDATE:
- db_operation.update_operation(context, session);
- break;
- default:
- testutil_die(DEBUG_ERROR, "system: thread_operation is unknown : %d",
- static_cast<int>(context.get_thread_operation()));
- break;
- }
- }
-
private:
database _database;
database_operation *_database_operation;
diff --git a/src/third_party/wiredtiger/test/cppsuite/tests/example_test.cxx b/src/third_party/wiredtiger/test/cppsuite/tests/example_test.cxx
index cc08d3d003a..ab8c38dec16 100644
--- a/src/third_party/wiredtiger/test/cppsuite/tests/example_test.cxx
+++ b/src/third_party/wiredtiger/test/cppsuite/tests/example_test.cxx
@@ -36,19 +36,22 @@ class example_test : public test_harness::test {
public:
example_test(const std::string &config, const std::string &name) : test(config, name) {}
- virtual void
+ void
populate(test_harness::database &database, test_harness::timestamp_manager *_timestamp_manager,
test_harness::configuration *_config, test_harness::workload_tracking *tracking)
+ override final
{
std::cout << "populate: nothing done." << std::endl;
}
- virtual void
- read_operation(test_harness::thread_context &context, WT_SESSION *session)
+
+ void
+ read_operation(test_harness::thread_context *context) override final
{
std::cout << "read_operation: nothing done." << std::endl;
}
- virtual void
- update_operation(test_harness::thread_context &context, WT_SESSION *session)
+
+ void
+ update_operation(test_harness::thread_context *context) override final
{
std::cout << "update_operation: nothing done." << std::endl;
}