diff options
author | Luke Chen <luke.chen@mongodb.com> | 2021-03-02 15:52:29 +1100 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-03-02 05:20:09 +0000 |
commit | 10acb172d03732bda1b04b9bb1dbde750bdd18ad (patch) | |
tree | 5b62718215b34dced12afd997a049b998b6a2000 | |
parent | 8082beefe8259cbd909fcaab4b8a1fcf3eae7cb1 (diff) | |
download | mongo-10acb172d03732bda1b04b9bb1dbde750bdd18ad.tar.gz |
Import wiredtiger: b7739a65158c1f58ff29c2b0bcc9a9d2c16af71c from branch mongodb-5.0
ref: b2d2b648ec..b7739a6515
for: 4.9.0
WT-6853 Add workload operation tracking
8 files changed, 133 insertions, 21 deletions
diff --git a/src/third_party/wiredtiger/import.data b/src/third_party/wiredtiger/import.data index 9c9bab66df8..8acf3b567b1 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": "b2d2b648ecec2e26664832fe62edfa285d4af640" + "commit": "b7739a65158c1f58ff29c2b0bcc9a9d2c16af71c" } diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/api_const.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/api_const.h index 8dd5bcf01c8..ef867adf885 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/api_const.h +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/api_const.h @@ -10,6 +10,7 @@ static const char *DURATION_SECONDS = "duration_seconds"; static const char *KEY_COUNT = "key_count"; static const char *READ_THREADS = "read_threads"; static const char *VALUE_SIZE = "value_size"; +static const char *TRACKING_COLLECTION = "table:tracking"; } // namespace test_harness diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/debug_utils.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/debug_utils.h index 3d062d950eb..1938aabfb5e 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/debug_utils.h +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/debug_utils.h @@ -5,7 +5,7 @@ #include <iostream> #include <string> -/* Define helpful functions. */ +/* Define helpful functions related to debugging. */ namespace test_harness { #define DEBUG_ABORT -1 diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/thread_context.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/thread_context.h index 4b446b75c1f..50802893355 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/thread_context.h +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/thread_context.h @@ -6,7 +6,9 @@ #include "wiredtiger.h" namespace test_harness { +/* Define the different thread operations. */ enum class thread_operation { INSERT, UPDATE, READ, REMOVE, CHECKPOINT, TIMESTAMP, MONITOR }; +/* Container class for a thread and any data types it may need to interact with the database. */ class thread_context { public: thread_context( 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 85d842d1dcf..b8e4e0528a9 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 @@ -4,6 +4,7 @@ #include "thread_context.h" namespace test_harness { +/* Class that handles threads, from their initialization to their deletion. */ class thread_manager { public: ~thread_manager() 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 78b53475e58..a73adf8810e 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 @@ -2,21 +2,24 @@ #define WORKLOAD_GENERATOR_H #include "api_const.h" -#include "configuration_settings.h" #include "random_generator.h" #include "debug_utils.h" #include "thread_manager.h" +#include "workload_tracking.h" namespace test_harness { +/* Class that can execute operations based on a given configuration. */ class workload_generator { public: - workload_generator(configuration *configuration) + workload_generator(configuration *configuration, bool enable_tracking) + : _configuration(configuration), _enable_tracking(enable_tracking) { - _configuration = configuration; } ~workload_generator() { + delete _workload_tracking; + if (_session != nullptr) { if (_session->close(_session, NULL) != 0) /* Failing to close session is not blocking. */ @@ -46,7 +49,7 @@ class workload_generator { * defined by the configuration. */ int - load(const char *home = DEFAULT_DIR) + load(const std::string &home = DEFAULT_DIR) { WT_CURSOR *cursor; int64_t collection_count, key_count, value_size; @@ -57,10 +60,16 @@ class workload_generator { collection_name = ""; /* Create the working dir. */ - testutil_make_work_dir(home); + testutil_make_work_dir(home.c_str()); /* Open connection. */ - testutil_check(wiredtiger_open(home, NULL, CONNECTION_CREATE, &_conn)); + testutil_check(wiredtiger_open(home.c_str(), NULL, CONNECTION_CREATE, &_conn)); + + /* Create the activity tracker if required. */ + if (_enable_tracking) { + _workload_tracking = new workload_tracking(_conn, TRACKING_COLLECTION); + _workload_tracking->load(); + } /* Open session. */ testutil_check(_conn->open_session(_conn, NULL, NULL, &_session)); @@ -71,6 +80,9 @@ class workload_generator { collection_name = "table:collection" + std::to_string(i); testutil_check( _session->create(_session, collection_name.c_str(), DEFAULT_TABLE_SCHEMA)); + if (_enable_tracking) + testutil_check( + _workload_tracking->save(tracking_operation::CREATE, collection_name, "", "")); _collection_names.push_back(collection_name); } debug_info( @@ -85,17 +97,14 @@ class workload_generator { testutil_check( _session->open_cursor(_session, collection_name.c_str(), NULL, NULL, &cursor)); for (size_t j = 0; j < key_count; ++j) { - cursor->set_key(cursor, j); /* Generation of a random string value using the size defined in the test * configuration. */ std::string generated_value = random_generator::random_generator::get_instance().generate_string(value_size); - cursor->set_value(cursor, generated_value.c_str()); - testutil_check(cursor->insert(cursor)); + testutil_check( + insert(cursor, collection_name, j, generated_value.c_str(), _enable_tracking)); } } - debug_info( - std::to_string(collection_count) + " key/value inserted", _trace_level, DEBUG_INFO); debug_info("Load stage done", _trace_level, DEBUG_INFO); return (0); } @@ -189,12 +198,28 @@ class workload_generator { } /* WiredTiger APIs wrappers for single operations. */ - static int - insert(WT_CURSOR *cursor) + template <typename K, typename V> + int + insert(WT_CURSOR *cursor, const std::string &collection_name, K key, V value, bool save) { + int error_code; + if (cursor == nullptr) throw std::invalid_argument("Failed to call insert, invalid cursor"); - return (cursor->insert(cursor)); + + cursor->set_key(cursor, key); + cursor->set_value(cursor, value); + error_code = cursor->insert(cursor); + + if (error_code == 0) { + debug_info("key/value inserted", _trace_level, DEBUG_INFO); + if (save) + error_code = + _workload_tracking->save(tracking_operation::INSERT, collection_name, key, value); + } else + debug_info("key/value insertion failed", _trace_level, DEBUG_ERROR); + + return error_code; } static int @@ -225,8 +250,10 @@ class workload_generator { std::vector<std::string> _collection_names; configuration *_configuration = nullptr; WT_CONNECTION *_conn = nullptr; + bool _enable_tracking = false; WT_SESSION *_session = nullptr; thread_manager _thread_manager; + workload_tracking *_workload_tracking; }; } // namespace test_harness 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 new file mode 100644 index 00000000000..0811ce5e201 --- /dev/null +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload_tracking.h @@ -0,0 +1,80 @@ +#ifndef WORKLOAD_TRACKING_H +#define WORKLOAD_TRACKING_H + +/* Default schema for tracking table + * key_format : Collection name / Key + * value_format : Operation type / Value / Timestamp + */ +#define DEFAULT_TRACKING_KEY_FORMAT WT_UNCHECKED_STRING(Si) +#define DEFAULT_TRACKING_VALUE_FORMAT WT_UNCHECKED_STRING(iSi) +#define DEFAULT_TRACKING_TABLE_SCHEMA \ + "key_format=" DEFAULT_TRACKING_KEY_FORMAT ",value_format=" DEFAULT_TRACKING_VALUE_FORMAT + +namespace test_harness { +/* Tracking operations. */ +enum class tracking_operation { CREATE, INSERT }; +/* Class used to track operations performed on collections */ +class workload_tracking { + + public: + workload_tracking(WT_CONNECTION *conn, const std::string &collection_name) + : _collection_name(collection_name), _conn(conn), _timestamp(0U) + { + } + + ~workload_tracking() + { + if (_session != nullptr) { + if (_session->close(_session, NULL) != 0) + /* Failing to close session is not blocking. */ + debug_info( + "Failed to close session, shutting down uncleanly", _trace_level, DEBUG_ERROR); + _session = nullptr; + } + } + + int + load(const std::string &table_schema = DEFAULT_TRACKING_TABLE_SCHEMA) + { + /* Open session. */ + testutil_check(_conn->open_session(_conn, NULL, NULL, &_session)); + + /* Create tracking collection. */ + testutil_check(_session->create(_session, _collection_name.c_str(), table_schema.c_str())); + testutil_check( + _session->open_cursor(_session, _collection_name.c_str(), NULL, NULL, &_cursor)); + debug_info("Tracking collection created", _trace_level, DEBUG_INFO); + + return (0); + } + + template <typename K, typename V> + int + save(const tracking_operation &operation, const std::string &collection_name, const K &key, + const V &value) + { + int error_code; + + _cursor->set_key(_cursor, collection_name.c_str(), key); + _cursor->set_value(_cursor, static_cast<int>(operation), value, _timestamp++); + error_code = _cursor->insert(_cursor); + + if (error_code == 0) { + debug_info("Workload tracking saved operation.", _trace_level, DEBUG_INFO); + } else { + debug_info("Workload tracking failed to save operation !", _trace_level, DEBUG_ERROR); + } + + return error_code; + } + + private: + WT_CONNECTION *_conn = nullptr; + const std::string _collection_name; + WT_CURSOR *_cursor = nullptr; + WT_SESSION *_session = nullptr; + uint64_t _timestamp; +}; +} // namespace test_harness + +#endif diff --git a/src/third_party/wiredtiger/test/cppsuite/tests/poc.cxx b/src/third_party/wiredtiger/test/cppsuite/tests/poc.cxx index 73156b737f6..ea8a49b9a8b 100755 --- a/src/third_party/wiredtiger/test/cppsuite/tests/poc.cxx +++ b/src/third_party/wiredtiger/test/cppsuite/tests/poc.cxx @@ -7,10 +7,10 @@ class poc_test : public test_harness::test { public: - poc_test(const std::string &config, int64_t trace_level) : test(config) + poc_test(const std::string &config, int64_t trace_level, bool enable_tracking) : test(config) { test_harness::_trace_level = trace_level; - _wl = new test_harness::workload_generator(_configuration); + _wl = new test_harness::workload_generator(_configuration, enable_tracking); _rm = new test_harness::runtime_monitor(); } @@ -39,8 +39,9 @@ class poc_test : public test_harness::test { }; const std::string poc_test::test::_name = "poc_test"; -const std::string poc_test::test::_default_config = "collection_count=2,key_count=5,value_size=20," - "read_threads=1,duration_seconds=1"; +const std::string poc_test::test::_default_config = + "collection_count=2,key_count=5,value_size=20," + "read_threads=1,duration_seconds=1"; int main(int argc, char *argv[]) @@ -77,7 +78,7 @@ main(int argc, char *argv[]) std::cout << "Configuration\t:" << cfg << std::endl; std::cout << "Tracel level\t:" << trace_level << std::endl; - error_code = poc_test(cfg, trace_level).run(); + error_code = poc_test(cfg, trace_level, true).run(); if (error_code == 0) std::cout << "SUCCESS" << std::endl; |