diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 799a17777..d3fb67f0a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,6 +5,7 @@ add_subdirectory(lisp) add_subdirectory(utils) add_subdirectory(requests) add_subdirectory(io) +add_subdirectory(kvstore) add_subdirectory(telemetry) add_subdirectory(communication) add_subdirectory(auth) @@ -123,14 +124,6 @@ add_subdirectory(query) string(TOLOWER ${CMAKE_BUILD_TYPE} lower_build_type) -# STATIC library used to store key-value pairs -add_library(kvstore_lib STATIC storage/common/kvstore/kvstore.cpp) -target_link_libraries(kvstore_lib stdc++fs mg-utils rocksdb bzip2 zlib glog gflags) - -# STATIC library for dummy key-value storage -# add_library(kvstore_dummy_lib STATIC storage/common/kvstore/kvstore_dummy.cpp) -# target_link_libraries(kvstore_dummy_lib mg-utils) - # Generate a version.hpp file set(VERSION_STRING ${memgraph_VERSION}) configure_file(version.hpp.in version.hpp @ONLY) @@ -244,7 +237,7 @@ install(DIRECTORY ${examples}/build/ DESTINATION share/memgraph/examples) ## memgraph single node high availability executable #add_executable(memgraph_ha memgraph_ha.cpp) -#target_link_libraries(memgraph_ha mg-single-node-ha kvstore_lib telemetry_lib) +#target_link_libraries(memgraph_ha mg-single-node-ha mg-kvstore telemetry_lib) #set_target_properties(memgraph_ha PROPERTIES # # Set the executable output name to include version information. # OUTPUT_NAME "memgraph_ha-${memgraph_VERSION}-${COMMIT_HASH}_${CMAKE_BUILD_TYPE}" diff --git a/src/auth/CMakeLists.txt b/src/auth/CMakeLists.txt index 12295db27..b8418ce90 100644 --- a/src/auth/CMakeLists.txt +++ b/src/auth/CMakeLists.txt @@ -8,7 +8,7 @@ find_package(Seccomp REQUIRED) add_library(mg-auth STATIC ${auth_src_files}) target_link_libraries(mg-auth json libbcrypt glog gflags fmt) -target_link_libraries(mg-auth mg-utils kvstore_lib) +target_link_libraries(mg-auth mg-utils mg-kvstore) target_link_libraries(mg-auth ${Seccomp_LIBRARIES}) target_include_directories(mg-auth SYSTEM PRIVATE ${Seccomp_INCLUDE_DIRS}) diff --git a/src/auth/auth.cpp b/src/auth/auth.cpp index 53046d158..bfd75c4bc 100644 --- a/src/auth/auth.cpp +++ b/src/auth/auth.cpp @@ -45,7 +45,7 @@ const std::string kLinkPrefix = "link:"; /** * All data stored in the `Auth` storage is stored in an underlying - * `storage::KVStore`. Because we are using a key-value store to store the data, + * `kvstore::KVStore`. Because we are using a key-value store to store the data, * the data has to be encoded. The encoding used is as follows: * * User: key="user:", value="" diff --git a/src/auth/auth.hpp b/src/auth/auth.hpp index 23c6b6bcc..1c56851db 100644 --- a/src/auth/auth.hpp +++ b/src/auth/auth.hpp @@ -7,7 +7,7 @@ #include "auth/exceptions.hpp" #include "auth/models.hpp" #include "auth/module.hpp" -#include "storage/common/kvstore/kvstore.hpp" +#include "kvstore/kvstore.hpp" namespace auth { @@ -158,9 +158,9 @@ class Auth final { std::mutex &WithLock(); private: - storage::KVStore storage_; + kvstore::KVStore storage_; auth::Module module_; - // Even though the `storage::KVStore` class is guaranteed to be thread-safe we + // Even though the `kvstore::KVStore` class is guaranteed to be thread-safe we // use a mutex to lock all operations on the `User` and `Role` storage because // some operations on the users and/or roles may require more than one // operation on the storage. diff --git a/src/kvstore/CMakeLists.txt b/src/kvstore/CMakeLists.txt new file mode 100644 index 000000000..1043a9e8b --- /dev/null +++ b/src/kvstore/CMakeLists.txt @@ -0,0 +1,8 @@ +# STATIC library used to store key-value pairs +add_library(mg-kvstore STATIC kvstore.cpp) +target_link_libraries(mg-kvstore stdc++fs mg-utils rocksdb bzip2 zlib glog gflags) + +# TODO: ZAKOMENTIRAJ! +# STATIC library for dummy key-value storage +add_library(mg-kvstore-dummy STATIC kvstore_dummy.cpp) +target_link_libraries(mg-kvstore-dummy mg-utils) diff --git a/src/storage/common/kvstore/kvstore.cpp b/src/kvstore/kvstore.cpp similarity index 98% rename from src/storage/common/kvstore/kvstore.cpp rename to src/kvstore/kvstore.cpp index 7ee35feb5..d350bef09 100644 --- a/src/storage/common/kvstore/kvstore.cpp +++ b/src/kvstore/kvstore.cpp @@ -1,10 +1,10 @@ #include #include -#include "storage/common/kvstore/kvstore.hpp" +#include "kvstore/kvstore.hpp" #include "utils/file.hpp" -namespace storage { +namespace kvstore { struct KVStore::impl { std::filesystem::path storage; @@ -175,4 +175,4 @@ bool KVStore::CompactRange(const std::string &begin_prefix, return s.ok(); } -} // namespace storage +} // namespace kvstore diff --git a/src/storage/common/kvstore/kvstore.hpp b/src/kvstore/kvstore.hpp similarity index 99% rename from src/storage/common/kvstore/kvstore.hpp rename to src/kvstore/kvstore.hpp index dced49e35..c2453d4e7 100644 --- a/src/storage/common/kvstore/kvstore.hpp +++ b/src/kvstore/kvstore.hpp @@ -9,7 +9,7 @@ #include "utils/exceptions.hpp" -namespace storage { +namespace kvstore { class KVStoreError : public utils::BasicException { public: @@ -204,4 +204,4 @@ class KVStore final { std::unique_ptr pimpl_; }; -} // namespace storage +} // namespace kvstore diff --git a/src/storage/common/kvstore/kvstore_dummy.cpp b/src/kvstore/kvstore_dummy.cpp similarity index 97% rename from src/storage/common/kvstore/kvstore_dummy.cpp rename to src/kvstore/kvstore_dummy.cpp index 80414fc25..44f95a559 100644 --- a/src/storage/common/kvstore/kvstore_dummy.cpp +++ b/src/kvstore/kvstore_dummy.cpp @@ -1,10 +1,10 @@ -#include "storage/common/kvstore/kvstore.hpp" +#include "kvstore/kvstore.hpp" #include #include "utils/file.hpp" -namespace storage { +namespace kvstore { struct KVStore::impl {}; @@ -102,4 +102,4 @@ bool KVStore::CompactRange(const std::string &begin_prefix, "dummy kvstore"; } -} // namespace storage +} // namespace kvstore diff --git a/src/raft/raft_server.hpp b/src/raft/raft_server.hpp index 5fe34e19f..e430cd74f 100644 --- a/src/raft/raft_server.hpp +++ b/src/raft/raft_server.hpp @@ -9,6 +9,7 @@ #include #include "durability/single_node_ha/state_delta.hpp" +#include "kvstore/kvstore.hpp" #include "raft/config.hpp" #include "raft/coordination.hpp" #include "raft/log_entry.hpp" @@ -16,7 +17,6 @@ #include "raft/raft_rpc_messages.hpp" #include "raft/replication_log.hpp" #include "raft/replication_timeout_map.hpp" -#include "storage/common/kvstore/kvstore.hpp" #include "transactions/type.hpp" #include "utils/scheduler.hpp" @@ -233,7 +233,7 @@ class RaftServer final : public RaftInterface { // a separate key within KVStore. ////////////////////////////////////////////////////////////////////////////// - storage::KVStore disk_storage_; + kvstore::KVStore disk_storage_; std::optional voted_for_; diff --git a/src/storage/common/types/property_value_store.cpp b/src/storage/common/types/property_value_store.cpp index 1c80bc4c8..27bfb13fb 100644 --- a/src/storage/common/types/property_value_store.cpp +++ b/src/storage/common/types/property_value_store.cpp @@ -38,7 +38,7 @@ PropertyValueStore::PropertyValueStore(const PropertyValueStore &old) // constructor due to mvcc. if (!FLAGS_properties_on_disk.empty()) { version_key_ = global_key_cnt_++; - storage::KVStore::iterator old_disk_it( + kvstore::KVStore::iterator old_disk_it( &DiskStorage(), DiskKeyPrefix(std::to_string(old.version_key_))); iterator it(&old, old.props_.end(), std::move(old_disk_it)); @@ -134,7 +134,7 @@ void PropertyValueStore::clear() { } } -storage::KVStore &PropertyValueStore::DiskStorage() const { +kvstore::KVStore &PropertyValueStore::DiskStorage() const { static auto disk_storage = ConstructDiskStorage(); return disk_storage; } @@ -147,7 +147,7 @@ PropertyValueStore::iterator::iterator( PropertyValueStore::iterator::iterator( const PropertyValueStore *pvs, std::vector>::const_iterator memory_it, - storage::KVStore::iterator disk_it) + kvstore::KVStore::iterator disk_it) : pvs_(pvs), memory_it_(memory_it), disk_it_(std::move(disk_it)) {} PropertyValueStore::iterator &PropertyValueStore::iterator::operator++() { @@ -233,8 +233,8 @@ PropertyValue PropertyValueStore::DeserializeProp( return glue::ToPropertyValue(dv); } -storage::KVStore PropertyValueStore::ConstructDiskStorage() const { +kvstore::KVStore PropertyValueStore::ConstructDiskStorage() const { auto storage_path = fs::path() / FLAGS_durability_directory / "properties"; if (fs::exists(storage_path)) fs::remove_all(storage_path); - return storage::KVStore(storage_path); + return kvstore::KVStore(storage_path); } diff --git a/src/storage/common/types/property_value_store.hpp b/src/storage/common/types/property_value_store.hpp index 8a6218f20..efef3baea 100644 --- a/src/storage/common/types/property_value_store.hpp +++ b/src/storage/common/types/property_value_store.hpp @@ -5,7 +5,7 @@ #include #include -#include "storage/common/kvstore/kvstore.hpp" +#include "kvstore/kvstore.hpp" #include "storage/common/types/property_value.hpp" #include "storage/common/types/types.hpp" @@ -75,11 +75,11 @@ class PropertyValueStore { void clear(); /** - * Returns a static storage::KVStore instance used for storing properties on + * Returns a static kvstore::KVStore instance used for storing properties on * disk. This hack is needed due to statics that are internal to RocksDB and * availability of durability_directory flag. */ - storage::KVStore &DiskStorage() const; + kvstore::KVStore &DiskStorage() const; /** * Custom PVS iterator behaves as if all properties are stored in a single @@ -103,7 +103,7 @@ class PropertyValueStore { iterator(const PropertyValueStore *pvs, std::vector>::const_iterator memory_it, - storage::KVStore::iterator disk_it); + kvstore::KVStore::iterator disk_it); iterator(const iterator &other) = delete; @@ -126,7 +126,7 @@ class PropertyValueStore { private: const PropertyValueStore *pvs_; std::vector>::const_iterator memory_it_; - std::optional disk_it_; + std::optional disk_it_; std::optional> disk_prop_; }; @@ -160,5 +160,5 @@ class PropertyValueStore { */ PropertyValue DeserializeProp(const std::string &serialized_prop) const; - storage::KVStore ConstructDiskStorage() const; + kvstore::KVStore ConstructDiskStorage() const; }; diff --git a/src/storage/single_node_ha/storage.hpp b/src/storage/single_node_ha/storage.hpp index 7a573cae8..d88064c51 100644 --- a/src/storage/single_node_ha/storage.hpp +++ b/src/storage/single_node_ha/storage.hpp @@ -4,8 +4,8 @@ #include #include "data_structures/concurrent/concurrent_map.hpp" +#include "kvstore/kvstore.hpp" #include "storage/common/constraints/unique_constraints.hpp" -#include "storage/common/kvstore/kvstore.hpp" #include "storage/common/types/types.hpp" #include "storage/single_node_ha/edge.hpp" #include "storage/single_node_ha/indexes/key_index.hpp" diff --git a/src/telemetry/CMakeLists.txt b/src/telemetry/CMakeLists.txt index ae7841d21..da4c75930 100644 --- a/src/telemetry/CMakeLists.txt +++ b/src/telemetry/CMakeLists.txt @@ -4,4 +4,4 @@ set(telemetry_src_files system_info.cpp) add_library(telemetry_lib STATIC ${telemetry_src_files}) -target_link_libraries(telemetry_lib glog mg-requests kvstore_lib) +target_link_libraries(telemetry_lib glog mg-requests mg-kvstore) diff --git a/src/telemetry/telemetry.hpp b/src/telemetry/telemetry.hpp index 39880bd58..7af598a91 100644 --- a/src/telemetry/telemetry.hpp +++ b/src/telemetry/telemetry.hpp @@ -5,7 +5,7 @@ #include -#include "storage/common/kvstore/kvstore.hpp" +#include "kvstore/kvstore.hpp" #include "utils/scheduler.hpp" #include "utils/timer.hpp" @@ -58,7 +58,7 @@ class Telemetry final { std::vector>> collectors_; - storage::KVStore storage_; + kvstore::KVStore storage_; }; } // namespace telemetry diff --git a/tests/manual/CMakeLists.txt b/tests/manual/CMakeLists.txt index 742bf7ae7..9cb2a44b1 100644 --- a/tests/manual/CMakeLists.txt +++ b/tests/manual/CMakeLists.txt @@ -38,7 +38,7 @@ target_include_directories(${test_prefix}ha_proxy PRIVATE ${CMAKE_BINARY_DIR}/sr target_link_libraries(${test_prefix}ha_proxy mg-utils mg-communication) add_manual_test(kvstore_console.cpp) -target_link_libraries(${test_prefix}kvstore_console kvstore_lib gflags glog) +target_link_libraries(${test_prefix}kvstore_console mg-kvstore gflags glog) add_manual_test(query_hash.cpp) target_link_libraries(${test_prefix}query_hash mg-query) diff --git a/tests/manual/kvstore_console.cpp b/tests/manual/kvstore_console.cpp index d032b05f7..ae99904ee 100644 --- a/tests/manual/kvstore_console.cpp +++ b/tests/manual/kvstore_console.cpp @@ -1,7 +1,7 @@ #include #include -#include "storage/common/kvstore/kvstore.hpp" +#include "kvstore/kvstore.hpp" #include "utils/string.hpp" DEFINE_string(path, "", "Path to the storage directory."); @@ -13,7 +13,7 @@ int main(int argc, char **argv) { CHECK(FLAGS_path != "") << "Please specify a path to the KVStore!"; - storage::KVStore kvstore(std::filesystem::path{FLAGS_path}); + kvstore::KVStore kvstore(std::filesystem::path{FLAGS_path}); while (true) { std::string s; diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 0850bc20f..1e29622af 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -25,10 +25,10 @@ add_unit_test(commit_log_v2.cpp) target_link_libraries(${test_prefix}commit_log_v2 glog gflags) add_unit_test(kvstore.cpp) -target_link_libraries(${test_prefix}kvstore kvstore_lib glog) +target_link_libraries(${test_prefix}kvstore mg-kvstore glog) #add_unit_test(replication_log.cpp) -#target_link_libraries(${test_prefix}replication_log mg-single-node-ha kvstore_lib glog) +#target_link_libraries(${test_prefix}replication_log mg-single-node-ha mg-kvstore glog) # Test mg-query @@ -114,7 +114,7 @@ target_link_libraries(${test_prefix}skip_list mg-utils) ## TODO: REPLACE single-node-ha #add_unit_test(slk_advanced.cpp) -#target_link_libraries(${test_prefix}slk_advanced mg-single-node-ha kvstore_dummy_lib) +#target_link_libraries(${test_prefix}slk_advanced mg-single-node-ha mg-kvstore-dummy) add_unit_test(slk_core.cpp) target_link_libraries(${test_prefix}slk_core mg-slk glog gflags fmt) diff --git a/tests/unit/kvstore.cpp b/tests/unit/kvstore.cpp index f78f8b037..244325fa9 100644 --- a/tests/unit/kvstore.cpp +++ b/tests/unit/kvstore.cpp @@ -3,7 +3,7 @@ #include #include -#include "storage/common/kvstore/kvstore.hpp" +#include "kvstore/kvstore.hpp" #include "utils/file.hpp" namespace fs = std::filesystem; @@ -20,20 +20,20 @@ class KVStore : public ::testing::Test { }; TEST_F(KVStore, PutGet) { - storage::KVStore kvstore(test_folder_ / "PutGet"); + kvstore::KVStore kvstore(test_folder_ / "PutGet"); ASSERT_TRUE(kvstore.Put("key", "value")); ASSERT_EQ(kvstore.Get("key").value(), "value"); } TEST_F(KVStore, PutMultipleGet) { - storage::KVStore kvstore(test_folder_ / "PutMultipleGet"); + kvstore::KVStore kvstore(test_folder_ / "PutMultipleGet"); ASSERT_TRUE(kvstore.PutMultiple({{"key1", "value1"}, {"key2", "value2"}})); ASSERT_EQ(kvstore.Get("key1").value(), "value1"); ASSERT_EQ(kvstore.Get("key2").value(), "value2"); } TEST_F(KVStore, PutGetDeleteGet) { - storage::KVStore kvstore(test_folder_ / "PutGetDeleteGet"); + kvstore::KVStore kvstore(test_folder_ / "PutGetDeleteGet"); ASSERT_TRUE(kvstore.Put("key", "value")); ASSERT_EQ(kvstore.Get("key").value(), "value"); ASSERT_TRUE(kvstore.Delete("key")); @@ -41,7 +41,7 @@ TEST_F(KVStore, PutGetDeleteGet) { } TEST_F(KVStore, PutMultipleGetDeleteMultipleGet) { - storage::KVStore kvstore(test_folder_ / "PutMultipleGetDeleteMultipleGet"); + kvstore::KVStore kvstore(test_folder_ / "PutMultipleGetDeleteMultipleGet"); ASSERT_TRUE(kvstore.PutMultiple({{"key1", "value1"}, {"key2", "value2"}})); ASSERT_EQ(kvstore.Get("key1").value(), "value1"); ASSERT_EQ(kvstore.Get("key2").value(), "value2"); @@ -52,7 +52,7 @@ TEST_F(KVStore, PutMultipleGetDeleteMultipleGet) { } TEST_F(KVStore, PutMultipleGetPutAndDeleteMultipleGet) { - storage::KVStore kvstore(test_folder_ / + kvstore::KVStore kvstore(test_folder_ / "PutMultipleGetPutAndDeleteMultipleGet"); ASSERT_TRUE(kvstore.PutMultiple({{"key1", "value1"}, {"key2", "value2"}})); ASSERT_EQ(kvstore.Get("key1").value(), "value1"); @@ -66,17 +66,17 @@ TEST_F(KVStore, PutMultipleGetPutAndDeleteMultipleGet) { TEST_F(KVStore, Durability) { { - storage::KVStore kvstore(test_folder_ / "Durability"); + kvstore::KVStore kvstore(test_folder_ / "Durability"); ASSERT_TRUE(kvstore.Put("key", "value")); } { - storage::KVStore kvstore(test_folder_ / "Durability"); + kvstore::KVStore kvstore(test_folder_ / "Durability"); ASSERT_EQ(kvstore.Get("key").value(), "value"); } } TEST_F(KVStore, Size) { - storage::KVStore kvstore(test_folder_ / "Size"); + kvstore::KVStore kvstore(test_folder_ / "Size"); ASSERT_TRUE(kvstore.Put("prefix_1", "jedan")); ASSERT_TRUE(kvstore.Put("prefix_2", "dva")); @@ -106,7 +106,7 @@ TEST_F(KVStore, Size) { } TEST_F(KVStore, DeletePrefix) { - storage::KVStore kvstore(test_folder_ / "DeletePrefix"); + kvstore::KVStore kvstore(test_folder_ / "DeletePrefix"); ASSERT_TRUE(kvstore.Put("prefix_1", "jedan")); ASSERT_TRUE(kvstore.Put("prefix_2", "dva")); @@ -144,7 +144,7 @@ TEST_F(KVStore, DeletePrefix) { } TEST_F(KVStore, Iterator) { - storage::KVStore kvstore(test_folder_ / "Iterator"); + kvstore::KVStore kvstore(test_folder_ / "Iterator"); for (int i = 1; i <= 4; ++i) ASSERT_TRUE( @@ -175,7 +175,7 @@ TEST_F(KVStore, Iterator) { } TEST_F(KVStore, IteratorPrefix) { - storage::KVStore kvstore(test_folder_ / "Iterator"); + kvstore::KVStore kvstore(test_folder_ / "Iterator"); ASSERT_TRUE(kvstore.Put("a_1", "value1")); ASSERT_TRUE(kvstore.Put("a_2", "value2"));