summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_model.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_model.h')
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_model.h51
1 files changed, 43 insertions, 8 deletions
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_model.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_model.h
index c9562954bfd..f6b8b152f22 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_model.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_model.h
@@ -29,6 +29,7 @@
#ifndef DATABASE_MODEL_H
#define DATABASE_MODEL_H
+#include <atomic>
#include <map>
#include <string>
@@ -56,6 +57,41 @@ struct collection_t {
/* Representation of the collections in memory. */
class database {
public:
+ /*
+ * Add a new collection following the standard naming pattern. Currently this is the only way to
+ * add collections which is supported by all components.
+ */
+ std::string
+ add_collection()
+ {
+ std::lock_guard<std::mutex> lg(_mtx);
+ std::string collection_name = build_collection_name(_next_collection_id);
+ _collections[collection_name] = {};
+ ++_next_collection_id;
+ return (collection_name);
+ }
+
+ /*
+ * Retrieve the current collection count, collection names are indexed from 0 so when using this
+ * take care to avoid an off by one error.
+ */
+ uint64_t
+ get_collection_count() const
+ {
+ return (_next_collection_id);
+ }
+
+ /*
+ * Get a single collection name by id.
+ */
+ std::string
+ get_collection_name(uint64_t id)
+ {
+ if (_next_collection_id <= id)
+ testutil_die(id, "requested the id, %lu, of a collection that doesn't exist", id);
+ return (build_collection_name(id));
+ }
+
std::vector<std::string>
get_collection_names()
{
@@ -75,14 +111,6 @@ class database {
return (_collections.at(collection_name).keys);
}
- void
- add_collection(const std::string &collection_name)
- {
- std::lock_guard<std::mutex> lg(_mtx);
- testutil_assert(_collections.find(collection_name) == _collections.end());
- _collections[collection_name] = {};
- }
-
value_t
get_record(const std::string &collection_name, const char *key)
{
@@ -119,6 +147,13 @@ class database {
}
private:
+ /* Take a const id, not a reference as we're copying in an atomic. */
+ std::string
+ build_collection_name(const uint64_t id)
+ {
+ return (std::string("table:collection_" + std::to_string(id)));
+ }
+ std::atomic<uint64_t> _next_collection_id{0};
std::map<std::string, collection_t> _collections;
std::mutex _mtx;
};