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:
parent
9d39ecab7b
commit
3079522f47
18
src/storage/v2/config.hpp
Normal file
18
src/storage/v2/config.hpp
Normal 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
|
@ -291,14 +291,14 @@ bool VerticesIterable::Iterator::operator==(const Iterator &other) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Storage::Storage(Config config) : config_(config) {
|
Storage::Storage(Config config) : config_(config) {
|
||||||
if (config_.gc_type == Config::GcType::PERIODIC) {
|
if (config_.gc.type == Config::Gc::Type::PERIODIC) {
|
||||||
gc_runner_.Run("Storage GC", config_.gc_interval,
|
gc_runner_.Run("Storage GC", config_.gc.interval,
|
||||||
[this] { this->CollectGarbage(); });
|
[this] { this->CollectGarbage(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Storage::~Storage() {
|
Storage::~Storage() {
|
||||||
if (config_.gc_type == Config::GcType::PERIODIC) {
|
if (config_.gc.type == Config::Gc::Type::PERIODIC) {
|
||||||
gc_runner_.Stop();
|
gc_runner_.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
|
|
||||||
#include "storage/v2/commit_log.hpp"
|
#include "storage/v2/commit_log.hpp"
|
||||||
|
#include "storage/v2/config.hpp"
|
||||||
#include "storage/v2/constraints.hpp"
|
#include "storage/v2/constraints.hpp"
|
||||||
#include "storage/v2/edge.hpp"
|
#include "storage/v2/edge.hpp"
|
||||||
#include "storage/v2/edge_accessor.hpp"
|
#include "storage/v2/edge_accessor.hpp"
|
||||||
@ -29,15 +30,6 @@ namespace storage {
|
|||||||
const uint64_t kTimestampInitialId = 0;
|
const uint64_t kTimestampInitialId = 0;
|
||||||
const uint64_t kTransactionInitialId = 1ULL << 63U;
|
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.
|
/// Iterable for iterating through all vertices of a Storage.
|
||||||
///
|
///
|
||||||
/// An instance of this will be usually be wrapped inside VerticesIterable for
|
/// An instance of this will be usually be wrapped inside VerticesIterable for
|
||||||
|
@ -16,13 +16,14 @@ DEFINE_int32(num_vertices, kNumVertices, "number of vertices");
|
|||||||
DEFINE_int32(num_iterations, kNumIterations, "number of iterations");
|
DEFINE_int32(num_iterations, kNumIterations, "number of iterations");
|
||||||
|
|
||||||
std::pair<std::string, storage::Config> TestConfigurations[] = {
|
std::pair<std::string, storage::Config> TestConfigurations[] = {
|
||||||
{"NoGc", storage::Config{.gc_type = storage::Config::GcType::NONE}},
|
{"NoGc",
|
||||||
{"100msPeriodicGc",
|
storage::Config{.gc = {.type = storage::Config::Gc::Type::NONE}}},
|
||||||
storage::Config{.gc_type = storage::Config::GcType::PERIODIC,
|
{"100msPeriodicGc",
|
||||||
.gc_interval = std::chrono::milliseconds(100)}},
|
storage::Config{.gc = {.type = storage::Config::Gc::Type::PERIODIC,
|
||||||
{"1000msPeriodicGc",
|
.interval = std::chrono::milliseconds(100)}}},
|
||||||
storage::Config{.gc_type = storage::Config::GcType::PERIODIC,
|
{"1000msPeriodicGc",
|
||||||
.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,
|
void UpdateLabelFunc(int thread_id, storage::Storage *storage,
|
||||||
const std::vector<storage::Gid> &vertices,
|
const std::vector<storage::Gid> &vertices,
|
||||||
|
@ -14,8 +14,8 @@ using testing::UnorderedElementsAre;
|
|||||||
// NOLINTNEXTLINE(hicpp-special-member-functions)
|
// NOLINTNEXTLINE(hicpp-special-member-functions)
|
||||||
TEST(StorageV2Gc, Sanity) {
|
TEST(StorageV2Gc, Sanity) {
|
||||||
storage::Storage storage(
|
storage::Storage storage(
|
||||||
storage::Config{.gc_type = storage::Config::GcType::PERIODIC,
|
storage::Config{.gc = {.type = storage::Config::Gc::Type::PERIODIC,
|
||||||
.gc_interval = std::chrono::milliseconds(100)});
|
.interval = std::chrono::milliseconds(100)}});
|
||||||
|
|
||||||
std::vector<storage::Gid> vertices;
|
std::vector<storage::Gid> vertices;
|
||||||
|
|
||||||
@ -164,8 +164,8 @@ TEST(StorageV2Gc, Sanity) {
|
|||||||
// NOLINTNEXTLINE(hicpp-special-member-functions)
|
// NOLINTNEXTLINE(hicpp-special-member-functions)
|
||||||
TEST(StorageV2Gc, Indices) {
|
TEST(StorageV2Gc, Indices) {
|
||||||
storage::Storage storage(
|
storage::Storage storage(
|
||||||
storage::Config{.gc_type = storage::Config::GcType::PERIODIC,
|
storage::Config{.gc = {.type = storage::Config::Gc::Type::PERIODIC,
|
||||||
.gc_interval = std::chrono::milliseconds(100)});
|
.interval = std::chrono::milliseconds(100)}});
|
||||||
|
|
||||||
{
|
{
|
||||||
auto acc0 = storage.Access();
|
auto acc0 = storage.Access();
|
||||||
|
Loading…
Reference in New Issue
Block a user