2023-03-27 21:46:00 +08:00
|
|
|
// Copyright 2023 Memgraph Ltd.
|
2021-10-03 18:07:04 +08:00
|
|
|
//
|
|
|
|
// Use of this software is governed by the Business Source License
|
|
|
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
|
|
|
// License, and you may not use this file except in compliance with the Business Source License.
|
|
|
|
//
|
|
|
|
// As of the Change Date specified in that file, in accordance with
|
|
|
|
// the Business Source License, use of this software will be governed
|
|
|
|
// by the Apache License, Version 2.0, included in the file
|
|
|
|
// licenses/APL.txt.
|
|
|
|
|
2019-06-26 22:01:51 +08:00
|
|
|
#pragma once
|
|
|
|
|
2023-03-30 21:34:34 +08:00
|
|
|
#include <span>
|
2019-06-26 22:01:51 +08:00
|
|
|
|
2020-12-03 20:28:23 +08:00
|
|
|
#include "io/network/endpoint.hpp"
|
2022-07-07 19:30:28 +08:00
|
|
|
#include "kvstore/kvstore.hpp"
|
2023-06-29 17:44:55 +08:00
|
|
|
#include "query/exceptions.hpp"
|
|
|
|
#include "storage/v2/all_vertices_iterable.hpp"
|
[StorageV2] Implement GC
Summary:
Here are some numbers from the benchmark:
```
(TOOLCHAIN) mtomic@poso:~/memgraph/build_release$ tests/benchmark/storage_v2_gc --num-threads 8
Config: NoGc, Time: 25.9836
Config: OnFinishGc, Time: 49.012
Config: 100msPeriodicGc, Time: 45.9856
Config: 1000msPeriodicGc, Time: 40.3094
```
```
(TOOLCHAIN) mtomic@poso:~/memgraph/build_release$ tests/benchmark/storage_v2_gc --num-threads 7
Config: NoGc, Time: 20.4256
Config: OnFinishGc, Time: 39.6669
Config: 100msPeriodicGc, Time: 30.7956
Config: 1000msPeriodicGc, Time: 35.128
```
It is not that bad if there is a core dedicated to doing garbage collection.
Reviewers: mferencevic, teon.banek
Reviewed By: mferencevic, teon.banek
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D2168
2019-07-09 22:34:23 +08:00
|
|
|
#include "storage/v2/commit_log.hpp"
|
2019-09-23 20:08:48 +08:00
|
|
|
#include "storage/v2/config.hpp"
|
2023-06-29 17:44:55 +08:00
|
|
|
#include "storage/v2/durability/paths.hpp"
|
2020-07-25 00:26:36 +08:00
|
|
|
#include "storage/v2/durability/wal.hpp"
|
2019-07-08 21:10:05 +08:00
|
|
|
#include "storage/v2/edge_accessor.hpp"
|
2023-06-29 17:44:55 +08:00
|
|
|
#include "storage/v2/indices/indices.hpp"
|
2019-07-08 21:10:05 +08:00
|
|
|
#include "storage/v2/mvcc.hpp"
|
2023-08-25 17:52:07 +08:00
|
|
|
#include "storage/v2/replication/config.hpp"
|
|
|
|
#include "storage/v2/replication/enums.hpp"
|
2023-08-31 23:06:44 +08:00
|
|
|
#include "storage/v2/replication/replication.hpp"
|
2023-08-25 17:52:07 +08:00
|
|
|
#include "storage/v2/replication/replication_client.hpp"
|
|
|
|
#include "storage/v2/replication/replication_server.hpp"
|
2023-06-29 17:44:55 +08:00
|
|
|
#include "storage/v2/storage_error.hpp"
|
2023-04-05 00:46:26 +08:00
|
|
|
#include "storage/v2/storage_mode.hpp"
|
2023-06-29 17:44:55 +08:00
|
|
|
#include "storage/v2/vertices_iterable.hpp"
|
|
|
|
#include "utils/event_counter.hpp"
|
|
|
|
#include "utils/event_histogram.hpp"
|
[StorageV2] Implement GC
Summary:
Here are some numbers from the benchmark:
```
(TOOLCHAIN) mtomic@poso:~/memgraph/build_release$ tests/benchmark/storage_v2_gc --num-threads 8
Config: NoGc, Time: 25.9836
Config: OnFinishGc, Time: 49.012
Config: 100msPeriodicGc, Time: 45.9856
Config: 1000msPeriodicGc, Time: 40.3094
```
```
(TOOLCHAIN) mtomic@poso:~/memgraph/build_release$ tests/benchmark/storage_v2_gc --num-threads 7
Config: NoGc, Time: 20.4256
Config: OnFinishGc, Time: 39.6669
Config: 100msPeriodicGc, Time: 30.7956
Config: 1000msPeriodicGc, Time: 35.128
```
It is not that bad if there is a core dedicated to doing garbage collection.
Reviewers: mferencevic, teon.banek
Reviewed By: mferencevic, teon.banek
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D2168
2019-07-09 22:34:23 +08:00
|
|
|
#include "utils/scheduler.hpp"
|
2023-06-29 17:44:55 +08:00
|
|
|
#include "utils/timer.hpp"
|
2020-12-01 23:51:25 +08:00
|
|
|
#include "utils/uuid.hpp"
|
2019-06-26 22:01:51 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
namespace memgraph::metrics {
|
|
|
|
extern const Event SnapshotCreationLatency_us;
|
|
|
|
|
|
|
|
extern const Event ActiveLabelIndices;
|
|
|
|
extern const Event ActiveLabelPropertyIndices;
|
|
|
|
} // namespace memgraph::metrics
|
2020-10-27 17:11:43 +08:00
|
|
|
|
2022-02-22 20:33:45 +08:00
|
|
|
namespace memgraph::storage {
|
2019-06-26 22:01:51 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
struct Transaction;
|
|
|
|
class EdgeAccessor;
|
|
|
|
|
|
|
|
struct IndicesInfo {
|
|
|
|
std::vector<LabelId> label;
|
|
|
|
std::vector<std::pair<LabelId, PropertyId>> label_property;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ConstraintsInfo {
|
|
|
|
std::vector<std::pair<LabelId, PropertyId>> existence;
|
|
|
|
std::vector<std::pair<LabelId, std::set<PropertyId>>> unique;
|
|
|
|
};
|
2019-07-22 22:05:44 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
struct StorageInfo {
|
|
|
|
uint64_t vertex_count;
|
|
|
|
uint64_t edge_count;
|
|
|
|
double average_degree;
|
|
|
|
uint64_t memory_usage;
|
|
|
|
uint64_t disk_usage;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Storage {
|
2023-08-31 23:06:44 +08:00
|
|
|
friend class ReplicationServer;
|
|
|
|
friend class ReplicationClient;
|
|
|
|
|
2019-07-29 20:26:31 +08:00
|
|
|
public:
|
2023-06-29 17:44:55 +08:00
|
|
|
Storage(Config config, StorageMode storage_mode);
|
2019-07-22 22:05:44 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
Storage(const Storage &) = delete;
|
|
|
|
Storage(Storage &&) = delete;
|
|
|
|
Storage &operator=(const Storage &) = delete;
|
|
|
|
Storage &operator=(Storage &&) = delete;
|
|
|
|
|
2023-08-25 17:52:07 +08:00
|
|
|
virtual ~Storage() = default;
|
2023-06-29 17:44:55 +08:00
|
|
|
|
2023-08-02 00:49:11 +08:00
|
|
|
const std::string &id() const { return id_; }
|
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
class Accessor {
|
2019-07-22 22:05:44 +08:00
|
|
|
public:
|
2023-06-29 17:44:55 +08:00
|
|
|
Accessor(Storage *storage, IsolationLevel isolation_level, StorageMode storage_mode);
|
|
|
|
Accessor(const Accessor &) = delete;
|
|
|
|
Accessor &operator=(const Accessor &) = delete;
|
|
|
|
Accessor &operator=(Accessor &&other) = delete;
|
2019-07-22 22:05:44 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
Accessor(Accessor &&other) noexcept;
|
2019-07-22 22:05:44 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual ~Accessor() {}
|
2019-07-22 22:05:44 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual VertexAccessor CreateVertex() = 0;
|
2019-07-22 22:05:44 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual std::optional<VertexAccessor> FindVertex(Gid gid, View view) = 0;
|
2019-07-22 22:05:44 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual VerticesIterable Vertices(View view) = 0;
|
2019-07-22 22:05:44 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual VerticesIterable Vertices(LabelId label, View view) = 0;
|
2019-07-29 20:26:31 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual VerticesIterable Vertices(LabelId label, PropertyId property, View view) = 0;
|
2019-07-29 20:26:31 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual VerticesIterable Vertices(LabelId label, PropertyId property, const PropertyValue &value, View view) = 0;
|
2019-07-29 20:26:31 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual VerticesIterable Vertices(LabelId label, PropertyId property,
|
|
|
|
const std::optional<utils::Bound<PropertyValue>> &lower_bound,
|
|
|
|
const std::optional<utils::Bound<PropertyValue>> &upper_bound, View view) = 0;
|
2019-07-29 20:26:31 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual uint64_t ApproximateVertexCount() const = 0;
|
2019-07-29 20:26:31 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual uint64_t ApproximateVertexCount(LabelId label) const = 0;
|
2019-07-29 20:26:31 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual uint64_t ApproximateVertexCount(LabelId label, PropertyId property) const = 0;
|
2019-07-29 20:26:31 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual uint64_t ApproximateVertexCount(LabelId label, PropertyId property, const PropertyValue &value) const = 0;
|
2019-07-29 20:26:31 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual uint64_t ApproximateVertexCount(LabelId label, PropertyId property,
|
|
|
|
const std::optional<utils::Bound<PropertyValue>> &lower,
|
|
|
|
const std::optional<utils::Bound<PropertyValue>> &upper) const = 0;
|
2019-07-29 20:26:31 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual std::optional<storage::LabelIndexStats> GetIndexStats(const storage::LabelId &label) const = 0;
|
2019-07-29 20:26:31 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual std::optional<storage::LabelPropertyIndexStats> GetIndexStats(
|
|
|
|
const storage::LabelId &label, const storage::PropertyId &property) const = 0;
|
2019-07-29 20:26:31 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual void SetIndexStats(const storage::LabelId &label, const LabelIndexStats &stats) = 0;
|
2019-07-29 20:26:31 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual void SetIndexStats(const storage::LabelId &label, const storage::PropertyId &property,
|
|
|
|
const LabelPropertyIndexStats &stats) = 0;
|
2019-07-29 20:26:31 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual std::vector<std::pair<LabelId, PropertyId>> ClearLabelPropertyIndexStats() = 0;
|
2019-07-29 20:26:31 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual std::vector<LabelId> ClearLabelIndexStats() = 0;
|
2019-07-29 20:26:31 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual std::vector<std::pair<LabelId, PropertyId>> DeleteLabelPropertyIndexStats(
|
|
|
|
std::span<std::string> labels) = 0;
|
2019-09-11 19:22:11 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual std::vector<LabelId> DeleteLabelIndexStats(std::span<std::string> labels) = 0;
|
2019-09-11 19:22:11 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual Result<std::optional<VertexAccessor>> DeleteVertex(VertexAccessor *vertex) = 0;
|
2019-12-09 22:49:28 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual Result<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> DetachDeleteVertex(
|
|
|
|
VertexAccessor *vertex) = 0;
|
[StorageV2] Implement GC
Summary:
Here are some numbers from the benchmark:
```
(TOOLCHAIN) mtomic@poso:~/memgraph/build_release$ tests/benchmark/storage_v2_gc --num-threads 8
Config: NoGc, Time: 25.9836
Config: OnFinishGc, Time: 49.012
Config: 100msPeriodicGc, Time: 45.9856
Config: 1000msPeriodicGc, Time: 40.3094
```
```
(TOOLCHAIN) mtomic@poso:~/memgraph/build_release$ tests/benchmark/storage_v2_gc --num-threads 7
Config: NoGc, Time: 20.4256
Config: OnFinishGc, Time: 39.6669
Config: 100msPeriodicGc, Time: 30.7956
Config: 1000msPeriodicGc, Time: 35.128
```
It is not that bad if there is a core dedicated to doing garbage collection.
Reviewers: mferencevic, teon.banek
Reviewed By: mferencevic, teon.banek
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D2168
2019-07-09 22:34:23 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual void PrefetchInEdges(const VertexAccessor &vertex_acc) = 0;
|
[StorageV2] Implement GC
Summary:
Here are some numbers from the benchmark:
```
(TOOLCHAIN) mtomic@poso:~/memgraph/build_release$ tests/benchmark/storage_v2_gc --num-threads 8
Config: NoGc, Time: 25.9836
Config: OnFinishGc, Time: 49.012
Config: 100msPeriodicGc, Time: 45.9856
Config: 1000msPeriodicGc, Time: 40.3094
```
```
(TOOLCHAIN) mtomic@poso:~/memgraph/build_release$ tests/benchmark/storage_v2_gc --num-threads 7
Config: NoGc, Time: 20.4256
Config: OnFinishGc, Time: 39.6669
Config: 100msPeriodicGc, Time: 30.7956
Config: 1000msPeriodicGc, Time: 35.128
```
It is not that bad if there is a core dedicated to doing garbage collection.
Reviewers: mferencevic, teon.banek
Reviewed By: mferencevic, teon.banek
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D2168
2019-07-09 22:34:23 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual void PrefetchOutEdges(const VertexAccessor &vertex_acc) = 0;
|
2019-07-11 19:27:50 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual Result<EdgeAccessor> CreateEdge(VertexAccessor *from, VertexAccessor *to, EdgeTypeId edge_type) = 0;
|
2019-06-26 22:01:51 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual Result<std::optional<EdgeAccessor>> DeleteEdge(EdgeAccessor *edge) = 0;
|
2019-06-26 22:01:51 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual bool LabelIndexExists(LabelId label) const = 0;
|
2019-06-26 22:01:51 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual bool LabelPropertyIndexExists(LabelId label, PropertyId property) const = 0;
|
2019-11-12 17:31:57 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual IndicesInfo ListAllIndices() const = 0;
|
|
|
|
|
|
|
|
virtual ConstraintsInfo ListAllConstraints() const = 0;
|
2019-07-03 21:32:03 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
// NOLINTNEXTLINE(google-default-arguments)
|
|
|
|
virtual utils::BasicResult<StorageDataManipulationError, void> Commit(
|
|
|
|
std::optional<uint64_t> desired_commit_timestamp = {}) = 0;
|
2019-07-03 21:32:03 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual void Abort() = 0;
|
2019-06-26 22:01:51 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual void FinalizeTransaction() = 0;
|
2021-04-23 20:19:42 +08:00
|
|
|
|
2023-03-27 21:46:00 +08:00
|
|
|
std::optional<uint64_t> GetTransactionId() const;
|
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
void AdvanceCommand();
|
|
|
|
|
|
|
|
const std::string &LabelToName(LabelId label) const { return storage_->LabelToName(label); }
|
2020-10-27 17:11:43 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
const std::string &PropertyToName(PropertyId property) const { return storage_->PropertyToName(property); }
|
2020-10-27 17:11:43 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
const std::string &EdgeTypeToName(EdgeTypeId edge_type) const { return storage_->EdgeTypeToName(edge_type); }
|
|
|
|
|
|
|
|
LabelId NameToLabel(std::string_view name) { return storage_->NameToLabel(name); }
|
|
|
|
|
|
|
|
PropertyId NameToProperty(std::string_view name) { return storage_->NameToProperty(name); }
|
|
|
|
|
|
|
|
EdgeTypeId NameToEdgeType(std::string_view name) { return storage_->NameToEdgeType(name); }
|
|
|
|
|
|
|
|
StorageMode GetCreationStorageMode() const;
|
|
|
|
|
2023-08-02 00:49:11 +08:00
|
|
|
const std::string &id() const { return storage_->id(); }
|
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
protected:
|
2019-06-26 22:01:51 +08:00
|
|
|
Storage *storage_;
|
2019-09-12 18:15:07 +08:00
|
|
|
std::shared_lock<utils::RWLock> storage_guard_;
|
2019-07-11 19:27:50 +08:00
|
|
|
Transaction transaction_;
|
2021-04-23 20:19:42 +08:00
|
|
|
std::optional<uint64_t> commit_timestamp_;
|
2019-07-11 19:27:50 +08:00
|
|
|
bool is_transaction_active_;
|
2019-06-26 22:01:51 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
private:
|
|
|
|
StorageMode creation_storage_mode_;
|
|
|
|
};
|
2019-09-11 19:22:11 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
const std::string &LabelToName(LabelId label) const { return name_id_mapper_->IdToName(label.AsUint()); }
|
2019-08-20 20:59:13 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
const std::string &PropertyToName(PropertyId property) const { return name_id_mapper_->IdToName(property.AsUint()); }
|
2019-09-11 19:22:11 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
const std::string &EdgeTypeToName(EdgeTypeId edge_type) const {
|
|
|
|
return name_id_mapper_->IdToName(edge_type.AsUint());
|
|
|
|
}
|
2019-12-09 22:49:28 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
LabelId NameToLabel(const std::string_view name) const { return LabelId::FromUint(name_id_mapper_->NameToId(name)); }
|
2020-11-01 22:15:06 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
PropertyId NameToProperty(const std::string_view name) const {
|
|
|
|
return PropertyId::FromUint(name_id_mapper_->NameToId(name));
|
|
|
|
}
|
2020-12-03 20:28:23 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
EdgeTypeId NameToEdgeType(const std::string_view name) const {
|
|
|
|
return EdgeTypeId::FromUint(name_id_mapper_->NameToId(name));
|
|
|
|
}
|
2020-11-01 22:15:06 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
void SetStorageMode(StorageMode storage_mode);
|
2020-11-01 22:15:06 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
StorageMode GetStorageMode() const;
|
2020-11-19 21:26:03 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual void FreeMemory(std::unique_lock<utils::RWLock> main_guard) = 0;
|
2023-08-26 20:16:12 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
void FreeMemory() { FreeMemory({}); }
|
2020-12-03 20:28:23 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual std::unique_ptr<Accessor> Access(std::optional<IsolationLevel> override_isolation_level) = 0;
|
|
|
|
std::unique_ptr<Accessor> Access() { return Access(std::optional<IsolationLevel>{}); }
|
2020-12-03 20:28:23 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual utils::BasicResult<StorageIndexDefinitionError, void> CreateIndex(
|
|
|
|
LabelId label, std::optional<uint64_t> desired_commit_timestamp) = 0;
|
2022-06-23 16:22:57 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
utils::BasicResult<StorageIndexDefinitionError, void> CreateIndex(LabelId label) {
|
|
|
|
return CreateIndex(label, std::optional<uint64_t>{});
|
|
|
|
}
|
2020-12-03 20:28:23 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual utils::BasicResult<StorageIndexDefinitionError, void> CreateIndex(
|
|
|
|
LabelId label, PropertyId property, std::optional<uint64_t> desired_commit_timestamp) = 0;
|
2020-10-27 17:11:43 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
utils::BasicResult<StorageIndexDefinitionError, void> CreateIndex(LabelId label, PropertyId property) {
|
|
|
|
return CreateIndex(label, property, std::optional<uint64_t>{});
|
|
|
|
}
|
2021-03-04 19:20:11 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual utils::BasicResult<StorageIndexDefinitionError, void> DropIndex(
|
|
|
|
LabelId label, std::optional<uint64_t> desired_commit_timestamp) = 0;
|
2021-06-14 21:47:57 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
utils::BasicResult<StorageIndexDefinitionError, void> DropIndex(LabelId label) {
|
|
|
|
return DropIndex(label, std::optional<uint64_t>{});
|
|
|
|
}
|
2021-06-30 18:31:30 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual utils::BasicResult<StorageIndexDefinitionError, void> DropIndex(
|
|
|
|
LabelId label, PropertyId property, std::optional<uint64_t> desired_commit_timestamp) = 0;
|
2023-04-05 00:46:26 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
utils::BasicResult<StorageIndexDefinitionError, void> DropIndex(LabelId label, PropertyId property) {
|
|
|
|
return DropIndex(label, property, std::optional<uint64_t>{});
|
|
|
|
}
|
2023-04-05 00:46:26 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
IndicesInfo ListAllIndices() const;
|
2023-04-05 00:46:26 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual utils::BasicResult<StorageExistenceConstraintDefinitionError, void> CreateExistenceConstraint(
|
|
|
|
LabelId label, PropertyId property, std::optional<uint64_t> desired_commit_timestamp) = 0;
|
2021-06-30 18:31:30 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual utils::BasicResult<StorageExistenceConstraintDroppingError, void> DropExistenceConstraint(
|
|
|
|
LabelId label, PropertyId property, std::optional<uint64_t> desired_commit_timestamp) = 0;
|
2019-09-12 18:15:07 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual utils::BasicResult<StorageUniqueConstraintDefinitionError, UniqueConstraints::CreationStatus>
|
|
|
|
CreateUniqueConstraint(LabelId label, const std::set<PropertyId> &properties,
|
|
|
|
std::optional<uint64_t> desired_commit_timestamp) = 0;
|
[StorageV2] Implement GC
Summary:
Here are some numbers from the benchmark:
```
(TOOLCHAIN) mtomic@poso:~/memgraph/build_release$ tests/benchmark/storage_v2_gc --num-threads 8
Config: NoGc, Time: 25.9836
Config: OnFinishGc, Time: 49.012
Config: 100msPeriodicGc, Time: 45.9856
Config: 1000msPeriodicGc, Time: 40.3094
```
```
(TOOLCHAIN) mtomic@poso:~/memgraph/build_release$ tests/benchmark/storage_v2_gc --num-threads 7
Config: NoGc, Time: 20.4256
Config: OnFinishGc, Time: 39.6669
Config: 100msPeriodicGc, Time: 30.7956
Config: 1000msPeriodicGc, Time: 35.128
```
It is not that bad if there is a core dedicated to doing garbage collection.
Reviewers: mferencevic, teon.banek
Reviewed By: mferencevic, teon.banek
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D2168
2019-07-09 22:34:23 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual utils::BasicResult<StorageUniqueConstraintDroppingError, UniqueConstraints::DeletionStatus>
|
|
|
|
DropUniqueConstraint(LabelId label, const std::set<PropertyId> &properties,
|
|
|
|
std::optional<uint64_t> desired_commit_timestamp) = 0;
|
2020-07-25 00:26:36 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
ConstraintsInfo ListAllConstraints() const;
|
2020-07-25 00:26:36 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
enum class SetIsolationLevelError : uint8_t { DisabledForAnalyticalMode };
|
2020-11-25 19:08:26 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
utils::BasicResult<SetIsolationLevelError> SetIsolationLevel(IsolationLevel isolation_level);
|
|
|
|
IsolationLevel GetIsolationLevel() const noexcept;
|
2023-06-22 01:08:58 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual StorageInfo GetInfo() const = 0;
|
2022-07-07 19:30:28 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
virtual Transaction CreateTransaction(IsolationLevel isolation_level, StorageMode storage_mode) = 0;
|
2022-07-07 19:30:28 +08:00
|
|
|
|
2023-08-22 19:29:25 +08:00
|
|
|
virtual void EstablishNewEpoch() = 0;
|
|
|
|
|
2023-08-25 17:52:07 +08:00
|
|
|
virtual auto CreateReplicationClient(std::string name, io::network::Endpoint endpoint,
|
|
|
|
replication::ReplicationMode mode,
|
|
|
|
replication::ReplicationClientConfig const &config)
|
|
|
|
-> std::unique_ptr<ReplicationClient> = 0;
|
|
|
|
|
|
|
|
virtual auto CreateReplicationServer(io::network::Endpoint endpoint,
|
|
|
|
replication::ReplicationServerConfig const &config)
|
|
|
|
-> std::unique_ptr<ReplicationServer> = 0;
|
|
|
|
|
2023-08-31 23:06:44 +08:00
|
|
|
/// REPLICATION
|
|
|
|
bool SetReplicaRole(io::network::Endpoint endpoint, const replication::ReplicationServerConfig &config) {
|
|
|
|
return replication_state_.SetReplicaRole(std::move(endpoint), config, this);
|
|
|
|
}
|
|
|
|
bool SetMainReplicationRole() { return replication_state_.SetMainReplicationRole(this); }
|
|
|
|
|
|
|
|
/// @pre The instance should have a MAIN role
|
|
|
|
/// @pre Timeout can only be set for SYNC replication
|
|
|
|
auto RegisterReplica(std::string name, io::network::Endpoint endpoint,
|
|
|
|
const replication::ReplicationMode replication_mode,
|
|
|
|
const replication::RegistrationMode registration_mode,
|
|
|
|
const replication::ReplicationClientConfig &config) {
|
|
|
|
return replication_state_.RegisterReplica(std::move(name), std::move(endpoint), replication_mode, registration_mode,
|
|
|
|
config, this);
|
|
|
|
}
|
|
|
|
/// @pre The instance should have a MAIN role
|
|
|
|
bool UnregisterReplica(const std::string &name) { return replication_state_.UnregisterReplica(name); }
|
|
|
|
replication::ReplicationRole GetReplicationRole() const { return replication_state_.GetRole(); }
|
|
|
|
auto ReplicasInfo() { return replication_state_.ReplicasInfo(); }
|
|
|
|
std::optional<replication::ReplicaState> GetReplicaState(std::string_view name) {
|
|
|
|
return replication_state_.GetReplicaState(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void RestoreReplicas() { return replication_state_.RestoreReplicas(this); }
|
|
|
|
void RestoreReplicationRole() { return replication_state_.RestoreReplicationRole(this); }
|
|
|
|
|
|
|
|
public:
|
2019-07-22 20:01:24 +08:00
|
|
|
// Main storage lock.
|
|
|
|
// Accessors take a shared lock when starting, so it is possible to block
|
2019-08-20 20:59:13 +08:00
|
|
|
// creation of new accessors by taking a unique lock. This is used when doing
|
|
|
|
// operations on storage that affect the global state, for example index
|
|
|
|
// creation.
|
2019-11-12 17:31:57 +08:00
|
|
|
mutable utils::RWLock main_lock_{utils::RWLock::Priority::WRITE};
|
2019-07-22 20:01:24 +08:00
|
|
|
|
2019-12-09 22:49:28 +08:00
|
|
|
// Even though the edge count is already kept in the `edges_` SkipList, the
|
|
|
|
// list is used only when properties are enabled for edges. Because of that we
|
2023-08-29 19:07:23 +08:00
|
|
|
// keep a separate count of edges that is always updated. This counter is also used
|
|
|
|
// for disk storage.
|
2019-12-09 22:49:28 +08:00
|
|
|
std::atomic<uint64_t> edge_count_{0};
|
2019-06-26 22:01:51 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
std::unique_ptr<NameIdMapper> name_id_mapper_;
|
|
|
|
Config config_;
|
2019-07-25 23:11:45 +08:00
|
|
|
|
2019-06-26 22:01:51 +08:00
|
|
|
// Transaction engine
|
[StorageV2] Implement GC
Summary:
Here are some numbers from the benchmark:
```
(TOOLCHAIN) mtomic@poso:~/memgraph/build_release$ tests/benchmark/storage_v2_gc --num-threads 8
Config: NoGc, Time: 25.9836
Config: OnFinishGc, Time: 49.012
Config: 100msPeriodicGc, Time: 45.9856
Config: 1000msPeriodicGc, Time: 40.3094
```
```
(TOOLCHAIN) mtomic@poso:~/memgraph/build_release$ tests/benchmark/storage_v2_gc --num-threads 7
Config: NoGc, Time: 20.4256
Config: OnFinishGc, Time: 39.6669
Config: 100msPeriodicGc, Time: 30.7956
Config: 1000msPeriodicGc, Time: 35.128
```
It is not that bad if there is a core dedicated to doing garbage collection.
Reviewers: mferencevic, teon.banek
Reviewed By: mferencevic, teon.banek
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D2168
2019-07-09 22:34:23 +08:00
|
|
|
utils::SpinLock engine_lock_;
|
2019-06-26 22:01:51 +08:00
|
|
|
uint64_t timestamp_{kTimestampInitialId};
|
|
|
|
uint64_t transaction_id_{kTransactionInitialId};
|
[StorageV2] Implement GC
Summary:
Here are some numbers from the benchmark:
```
(TOOLCHAIN) mtomic@poso:~/memgraph/build_release$ tests/benchmark/storage_v2_gc --num-threads 8
Config: NoGc, Time: 25.9836
Config: OnFinishGc, Time: 49.012
Config: 100msPeriodicGc, Time: 45.9856
Config: 1000msPeriodicGc, Time: 40.3094
```
```
(TOOLCHAIN) mtomic@poso:~/memgraph/build_release$ tests/benchmark/storage_v2_gc --num-threads 7
Config: NoGc, Time: 20.4256
Config: OnFinishGc, Time: 39.6669
Config: 100msPeriodicGc, Time: 30.7956
Config: 1000msPeriodicGc, Time: 35.128
```
It is not that bad if there is a core dedicated to doing garbage collection.
Reviewers: mferencevic, teon.banek
Reviewed By: mferencevic, teon.banek
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D2168
2019-07-09 22:34:23 +08:00
|
|
|
|
2021-06-14 21:47:57 +08:00
|
|
|
IsolationLevel isolation_level_;
|
2023-04-05 00:46:26 +08:00
|
|
|
StorageMode storage_mode_;
|
[StorageV2] Implement GC
Summary:
Here are some numbers from the benchmark:
```
(TOOLCHAIN) mtomic@poso:~/memgraph/build_release$ tests/benchmark/storage_v2_gc --num-threads 8
Config: NoGc, Time: 25.9836
Config: OnFinishGc, Time: 49.012
Config: 100msPeriodicGc, Time: 45.9856
Config: 1000msPeriodicGc, Time: 40.3094
```
```
(TOOLCHAIN) mtomic@poso:~/memgraph/build_release$ tests/benchmark/storage_v2_gc --num-threads 7
Config: NoGc, Time: 20.4256
Config: OnFinishGc, Time: 39.6669
Config: 100msPeriodicGc, Time: 30.7956
Config: 1000msPeriodicGc, Time: 35.128
```
It is not that bad if there is a core dedicated to doing garbage collection.
Reviewers: mferencevic, teon.banek
Reviewed By: mferencevic, teon.banek
Subscribers: pullbot
Differential Revision: https://phabricator.memgraph.io/D2168
2019-07-09 22:34:23 +08:00
|
|
|
|
2023-06-29 17:44:55 +08:00
|
|
|
Indices indices_;
|
|
|
|
Constraints constraints_;
|
|
|
|
|
|
|
|
std::atomic<uint64_t> vertex_id_{0};
|
|
|
|
std::atomic<uint64_t> edge_id_{0};
|
2023-08-02 00:49:11 +08:00
|
|
|
const std::string id_; //!< High-level assigned ID
|
2023-08-31 23:06:44 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
ReplicationState replication_state_;
|
2019-06-26 22:01:51 +08:00
|
|
|
};
|
|
|
|
|
2022-02-22 20:33:45 +08:00
|
|
|
} // namespace memgraph::storage
|