diff --git a/src/kv/kv.cpp b/src/kv/kv.cpp index 95b19ca8590..6928497cc60 100644 --- a/src/kv/kv.cpp +++ b/src/kv/kv.cpp @@ -14,7 +14,6 @@ int64_t KV::lastTimestamp_ = 0; uint64_t KV::counter_ = 0; -std::mutex KV::mutex_ = {}; KVStore &KVStore::getInstance() { return inject(); @@ -31,7 +30,6 @@ void KVStore::set(const std::string &key, const std::initializer_list KVStore::get(const std::string &key, bool forceLoad /*= false */) { logger.trace("KVStore::get({})", key); - std::scoped_lock lock(mutex_); if (forceLoad || !store_.contains(key)) { auto value = load(key); if (value) { @@ -77,7 +74,6 @@ std::optional KVStore::get(const std::string &key, bool forceLoad } std::unordered_set KVStore::keys(const std::string &prefix /*= ""*/) { - std::scoped_lock lock(mutex_); std::unordered_set keys; for (const auto &[key, value] : store_) { if (key.find(prefix) == 0) { diff --git a/src/kv/kv.hpp b/src/kv/kv.hpp index eefc97d83c5..ad019f3dc85 100644 --- a/src/kv/kv.hpp +++ b/src/kv/kv.hpp @@ -11,9 +11,7 @@ #ifndef USE_PRECOMPILED_HEADERS #include - #include #include - #include #include #include #include @@ -47,8 +45,6 @@ class KV : public std::enable_shared_from_this { } static std::string generateUUID() { - std::lock_guard lock(mutex_); - const auto now = std::chrono::system_clock::now().time_since_epoch(); const auto milliseconds = std::chrono::duration_cast(now).count(); @@ -69,7 +65,6 @@ class KV : public std::enable_shared_from_this { private: static int64_t lastTimestamp_; static uint64_t counter_; - static std::mutex mutex_; }; class KVStore : public KV { @@ -87,7 +82,6 @@ class KVStore : public KV { std::optional get(const std::string &key, bool forceLoad = false) override; void flush() override { - std::scoped_lock lock(mutex_); KV::flush(); store_.clear(); } @@ -96,13 +90,8 @@ class KVStore : public KV { std::unordered_set keys(const std::string &prefix = "") override; protected: - phmap::parallel_flat_hash_map::iterator>> getStore() { - std::scoped_lock lock(mutex_); - phmap::parallel_flat_hash_map::iterator>> copy; - for (const auto &[key, value] : store_) { - copy.try_emplace(key, value); - } - return copy; + const std::unordered_map::iterator>> &getStore() { + return store_; } protected: @@ -115,9 +104,8 @@ class KVStore : public KV { private: void setLocked(const std::string &key, const ValueWrapper &value); - phmap::parallel_flat_hash_map::iterator>> store_; + std::unordered_map::iterator>> store_; std::list lruQueue_; - std::mutex mutex_; }; class ScopedKV final : public KV { diff --git a/src/kv/kv_definitions.hpp b/src/kv/kv_definitions.hpp index e53c8b0f24a..915e42c7275 100644 --- a/src/kv/kv_definitions.hpp +++ b/src/kv/kv_definitions.hpp @@ -16,7 +16,6 @@ class ValueWrapper; #include #include #include - #include #endif using StringType = std::string; @@ -24,6 +23,6 @@ using BooleanType = bool; using IntType = int; using DoubleType = double; using ArrayType = std::vector; -using MapType = phmap::flat_hash_map>; +using MapType = std::unordered_map>; using ValueVariant = std::variant; diff --git a/src/kv/value_wrapper.cpp b/src/kv/value_wrapper.cpp index 69fb942bab4..444a0835cd9 100644 --- a/src/kv/value_wrapper.cpp +++ b/src/kv/value_wrapper.cpp @@ -29,7 +29,7 @@ ValueWrapper::ValueWrapper(int value, uint64_t timestamp) : ValueWrapper::ValueWrapper(double value, uint64_t timestamp) : data_(value), timestamp_(timestamp == 0 ? getTimeMsNow() : timestamp) { } -ValueWrapper::ValueWrapper(const phmap::flat_hash_map &value, uint64_t timestamp) : +ValueWrapper::ValueWrapper(const std::unordered_map &value, uint64_t timestamp) : data_(createMapFromRange(value.begin(), value.end(), timestamp)), timestamp_(timestamp == 0 ? getTimeMsNow() : timestamp) { } diff --git a/src/kv/value_wrapper.hpp b/src/kv/value_wrapper.hpp index 4bb844dcb97..05d0591ebd2 100644 --- a/src/kv/value_wrapper.hpp +++ b/src/kv/value_wrapper.hpp @@ -29,7 +29,7 @@ class ValueWrapper { explicit(false) ValueWrapper(bool value, uint64_t timestamp = 0); explicit(false) ValueWrapper(int value, uint64_t timestamp = 0); explicit(false) ValueWrapper(double value, uint64_t timestamp = 0); - explicit(false) ValueWrapper(const phmap::flat_hash_map &value, uint64_t timestamp = 0); + explicit(false) ValueWrapper(const std::unordered_map &value, uint64_t timestamp = 0); explicit(false) ValueWrapper(const std::initializer_list> &init_list, uint64_t timestamp = 0); static ValueWrapper deleted() { diff --git a/src/kv/value_wrapper_proto.hpp b/src/kv/value_wrapper_proto.hpp index 9d5a61865ab..f64b1ed5744 100644 --- a/src/kv/value_wrapper_proto.hpp +++ b/src/kv/value_wrapper_proto.hpp @@ -9,14 +9,7 @@ #pragma once -class ValueWrapper; - -using StringType = std::string; -using BooleanType = bool; -using IntType = int; -using DoubleType = double; -using ArrayType = std::vector; -using MapType = phmap::flat_hash_map>; +#include "kv/kv_definitions.hpp" using ValueVariant = std::variant; diff --git a/src/lua/functions/core/libs/kv_functions.hpp b/src/lua/functions/core/libs/kv_functions.hpp index 4ef47333f2f..e50b4c94893 100644 --- a/src/lua/functions/core/libs/kv_functions.hpp +++ b/src/lua/functions/core/libs/kv_functions.hpp @@ -10,8 +10,7 @@ #pragma once #include "lua/scripts/luascript.hpp" - -class ValueWrapper; +#include "kv/kv_definitions.hpp" #ifndef USE_PRECOMPILED_HEADERS #include @@ -21,8 +20,6 @@ class ValueWrapper; #include #endif -using MapType = phmap::flat_hash_map>; - struct lua_State; class KVFunctions final : LuaScriptInterface {