Move KVStore to root source directory

Reviewers: teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2640
This commit is contained in:
Matej Ferencevic 2020-01-24 10:45:05 +01:00
parent 0c7313bb5f
commit fd81ebdfe3
18 changed files with 58 additions and 57 deletions

View File

@ -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}"

View File

@ -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})

View File

@ -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:<username>", value="<json_encoded_members_of_user>"

View File

@ -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.

View File

@ -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)

View File

@ -1,10 +1,10 @@
#include <rocksdb/db.h>
#include <rocksdb/options.h>
#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

View File

@ -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<impl> pimpl_;
};
} // namespace storage
} // namespace kvstore

View File

@ -1,10 +1,10 @@
#include "storage/common/kvstore/kvstore.hpp"
#include "kvstore/kvstore.hpp"
#include <glog/logging.h>
#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

View File

@ -9,6 +9,7 @@
#include <vector>
#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<uint16_t> voted_for_;

View File

@ -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<std::pair<Property, PropertyValue>>::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);
}

View File

@ -5,7 +5,7 @@
#include <string>
#include <vector>
#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<std::pair<Property, PropertyValue>>::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<std::pair<Property, PropertyValue>>::const_iterator memory_it_;
std::optional<storage::KVStore::iterator> disk_it_;
std::optional<kvstore::KVStore::iterator> disk_it_;
std::optional<std::pair<Property, PropertyValue>> disk_prop_;
};
@ -160,5 +160,5 @@ class PropertyValueStore {
*/
PropertyValue DeserializeProp(const std::string &serialized_prop) const;
storage::KVStore ConstructDiskStorage() const;
kvstore::KVStore ConstructDiskStorage() const;
};

View File

@ -4,8 +4,8 @@
#include <optional>
#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"

View File

@ -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)

View File

@ -5,7 +5,7 @@
#include <json/json.hpp>
#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<std::pair<std::string, std::function<const nlohmann::json(void)>>>
collectors_;
storage::KVStore storage_;
kvstore::KVStore storage_;
};
} // namespace telemetry

View File

@ -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)

View File

@ -1,7 +1,7 @@
#include <gflags/gflags.h>
#include <glog/logging.h>
#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;

View File

@ -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)

View File

@ -3,7 +3,7 @@
#include <glog/logging.h>
#include <gtest/gtest.h>
#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"));