Make storage v2 config hierarchical

Reviewers: teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2434
This commit is contained in:
Matej Ferencevic 2019-09-23 14:08:48 +02:00
parent 9d39ecab7b
commit 3079522f47
5 changed files with 34 additions and 23 deletions

18
src/storage/v2/config.hpp Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include <chrono>
namespace storage {
/// Pass this class to the \ref Storage constructor to change the behavior of
/// the storage. This class also defines the default behavior.
struct Config {
struct Gc {
enum class Type { NONE, PERIODIC };
Type type{Type::PERIODIC};
std::chrono::milliseconds interval{std::chrono::milliseconds(1000)};
} gc;
};
} // namespace storage

View File

@ -291,14 +291,14 @@ bool VerticesIterable::Iterator::operator==(const Iterator &other) const {
}
Storage::Storage(Config config) : config_(config) {
if (config_.gc_type == Config::GcType::PERIODIC) {
gc_runner_.Run("Storage GC", config_.gc_interval,
if (config_.gc.type == Config::Gc::Type::PERIODIC) {
gc_runner_.Run("Storage GC", config_.gc.interval,
[this] { this->CollectGarbage(); });
}
}
Storage::~Storage() {
if (config_.gc_type == Config::GcType::PERIODIC) {
if (config_.gc.type == Config::Gc::Type::PERIODIC) {
gc_runner_.Stop();
}
}

View File

@ -4,6 +4,7 @@
#include <shared_mutex>
#include "storage/v2/commit_log.hpp"
#include "storage/v2/config.hpp"
#include "storage/v2/constraints.hpp"
#include "storage/v2/edge.hpp"
#include "storage/v2/edge_accessor.hpp"
@ -29,15 +30,6 @@ namespace storage {
const uint64_t kTimestampInitialId = 0;
const uint64_t kTransactionInitialId = 1ULL << 63U;
/// Pass this class to the \ref Storage constructor to change the behavior of
/// the storage. This class also defines the default behavior.
struct Config {
enum class GcType { NONE, PERIODIC };
GcType gc_type{GcType::PERIODIC};
std::chrono::milliseconds gc_interval{std::chrono::milliseconds(1000)};
};
/// Iterable for iterating through all vertices of a Storage.
///
/// An instance of this will be usually be wrapped inside VerticesIterable for

View File

@ -16,13 +16,14 @@ DEFINE_int32(num_vertices, kNumVertices, "number of vertices");
DEFINE_int32(num_iterations, kNumIterations, "number of iterations");
std::pair<std::string, storage::Config> TestConfigurations[] = {
{"NoGc", storage::Config{.gc_type = storage::Config::GcType::NONE}},
{"NoGc",
storage::Config{.gc = {.type = storage::Config::Gc::Type::NONE}}},
{"100msPeriodicGc",
storage::Config{.gc_type = storage::Config::GcType::PERIODIC,
.gc_interval = std::chrono::milliseconds(100)}},
storage::Config{.gc = {.type = storage::Config::Gc::Type::PERIODIC,
.interval = std::chrono::milliseconds(100)}}},
{"1000msPeriodicGc",
storage::Config{.gc_type = storage::Config::GcType::PERIODIC,
.gc_interval = std::chrono::milliseconds(1000)}}};
storage::Config{.gc = {.type = storage::Config::Gc::Type::PERIODIC,
.interval = std::chrono::milliseconds(1000)}}}};
void UpdateLabelFunc(int thread_id, storage::Storage *storage,
const std::vector<storage::Gid> &vertices,

View File

@ -14,8 +14,8 @@ using testing::UnorderedElementsAre;
// NOLINTNEXTLINE(hicpp-special-member-functions)
TEST(StorageV2Gc, Sanity) {
storage::Storage storage(
storage::Config{.gc_type = storage::Config::GcType::PERIODIC,
.gc_interval = std::chrono::milliseconds(100)});
storage::Config{.gc = {.type = storage::Config::Gc::Type::PERIODIC,
.interval = std::chrono::milliseconds(100)}});
std::vector<storage::Gid> vertices;
@ -164,8 +164,8 @@ TEST(StorageV2Gc, Sanity) {
// NOLINTNEXTLINE(hicpp-special-member-functions)
TEST(StorageV2Gc, Indices) {
storage::Storage storage(
storage::Config{.gc_type = storage::Config::GcType::PERIODIC,
.gc_interval = std::chrono::milliseconds(100)});
storage::Config{.gc = {.type = storage::Config::Gc::Type::PERIODIC,
.interval = std::chrono::milliseconds(100)}});
{
auto acc0 = storage.Access();