2019-06-26 22:01:51 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <optional>
|
2019-07-22 20:01:24 +08:00
|
|
|
#include <shared_mutex>
|
2019-06-26 22:01:51 +08:00
|
|
|
|
[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"
|
2019-08-20 20:59:13 +08:00
|
|
|
#include "storage/v2/constraints.hpp"
|
2019-10-01 19:42:27 +08:00
|
|
|
#include "storage/v2/durability.hpp"
|
2019-07-08 21:10:05 +08:00
|
|
|
#include "storage/v2/edge.hpp"
|
|
|
|
#include "storage/v2/edge_accessor.hpp"
|
2019-07-25 23:11:45 +08:00
|
|
|
#include "storage/v2/indices.hpp"
|
2019-07-08 21:10:05 +08:00
|
|
|
#include "storage/v2/mvcc.hpp"
|
2019-07-18 22:17:41 +08:00
|
|
|
#include "storage/v2/name_id_mapper.hpp"
|
2019-07-04 19:06:03 +08:00
|
|
|
#include "storage/v2/result.hpp"
|
2019-06-26 22:01:51 +08:00
|
|
|
#include "storage/v2/transaction.hpp"
|
|
|
|
#include "storage/v2/vertex.hpp"
|
|
|
|
#include "storage/v2/vertex_accessor.hpp"
|
2019-07-22 20:01:24 +08:00
|
|
|
#include "utils/rw_lock.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"
|
|
|
|
#include "utils/skip_list.hpp"
|
2019-07-22 23:05:00 +08:00
|
|
|
#include "utils/synchronized.hpp"
|
2019-06-26 22:01:51 +08:00
|
|
|
|
|
|
|
namespace storage {
|
|
|
|
|
|
|
|
// The storage is based on this paper:
|
|
|
|
// https://db.in.tum.de/~muehlbau/papers/mvcc.pdf
|
|
|
|
// The paper implements a fully serializable storage, in our implementation we
|
|
|
|
// only implement snapshot isolation for transactions.
|
|
|
|
|
2019-07-29 20:26:31 +08:00
|
|
|
/// Iterable for iterating through all vertices of a Storage.
|
|
|
|
///
|
|
|
|
/// An instance of this will be usually be wrapped inside VerticesIterable for
|
|
|
|
/// generic, public use.
|
|
|
|
class AllVerticesIterable final {
|
2019-07-22 22:05:44 +08:00
|
|
|
utils::SkipList<Vertex>::Accessor vertices_accessor_;
|
|
|
|
Transaction *transaction_;
|
|
|
|
View view_;
|
2019-07-25 23:11:45 +08:00
|
|
|
Indices *indices_;
|
2019-09-24 22:48:36 +08:00
|
|
|
Config::Items config_;
|
2019-07-22 22:05:44 +08:00
|
|
|
|
2019-07-29 20:26:31 +08:00
|
|
|
public:
|
2019-07-22 22:05:44 +08:00
|
|
|
class Iterator final {
|
2019-07-29 20:26:31 +08:00
|
|
|
AllVerticesIterable *self_;
|
2019-07-22 22:05:44 +08:00
|
|
|
utils::SkipList<Vertex>::Iterator it_;
|
|
|
|
|
|
|
|
public:
|
2019-07-29 20:26:31 +08:00
|
|
|
Iterator(AllVerticesIterable *self, utils::SkipList<Vertex>::Iterator it);
|
2019-07-22 22:05:44 +08:00
|
|
|
|
|
|
|
VertexAccessor operator*() const;
|
|
|
|
|
|
|
|
Iterator &operator++();
|
|
|
|
|
|
|
|
bool operator==(const Iterator &other) const {
|
|
|
|
return self_ == other.self_ && it_ == other.it_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const Iterator &other) const { return !(*this == other); }
|
|
|
|
};
|
|
|
|
|
2019-07-29 20:26:31 +08:00
|
|
|
AllVerticesIterable(utils::SkipList<Vertex>::Accessor vertices_accessor,
|
2019-10-21 18:22:11 +08:00
|
|
|
Transaction *transaction, View view, Indices *indices,
|
|
|
|
Config::Items config)
|
2019-07-22 22:05:44 +08:00
|
|
|
: vertices_accessor_(std::move(vertices_accessor)),
|
|
|
|
transaction_(transaction),
|
2019-07-25 23:11:45 +08:00
|
|
|
view_(view),
|
2019-10-21 18:22:11 +08:00
|
|
|
indices_(indices),
|
|
|
|
config_(config) {}
|
2019-07-22 22:05:44 +08:00
|
|
|
|
|
|
|
Iterator begin() { return Iterator(this, vertices_accessor_.begin()); }
|
|
|
|
Iterator end() { return Iterator(this, vertices_accessor_.end()); }
|
|
|
|
};
|
|
|
|
|
2019-07-29 20:26:31 +08:00
|
|
|
/// Generic access to different kinds of vertex iterations.
|
|
|
|
///
|
|
|
|
/// This class should be the primary type used by the client code to iterate
|
|
|
|
/// over vertices inside a Storage instance.
|
|
|
|
class VerticesIterable final {
|
|
|
|
enum class Type { ALL, BY_LABEL, BY_LABEL_PROPERTY };
|
|
|
|
|
|
|
|
Type type_;
|
|
|
|
union {
|
|
|
|
AllVerticesIterable all_vertices_;
|
|
|
|
LabelIndex::Iterable vertices_by_label_;
|
|
|
|
LabelPropertyIndex::Iterable vertices_by_label_property_;
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit VerticesIterable(AllVerticesIterable);
|
|
|
|
explicit VerticesIterable(LabelIndex::Iterable);
|
|
|
|
explicit VerticesIterable(LabelPropertyIndex::Iterable);
|
|
|
|
|
|
|
|
VerticesIterable(const VerticesIterable &) = delete;
|
|
|
|
VerticesIterable &operator=(const VerticesIterable &) = delete;
|
|
|
|
|
|
|
|
VerticesIterable(VerticesIterable &&) noexcept;
|
|
|
|
VerticesIterable &operator=(VerticesIterable &&) noexcept;
|
|
|
|
|
|
|
|
~VerticesIterable();
|
|
|
|
|
|
|
|
class Iterator final {
|
|
|
|
Type type_;
|
|
|
|
union {
|
|
|
|
AllVerticesIterable::Iterator all_it_;
|
|
|
|
LabelIndex::Iterable::Iterator by_label_it_;
|
|
|
|
LabelPropertyIndex::Iterable::Iterator by_label_property_it_;
|
|
|
|
};
|
|
|
|
|
|
|
|
void Destroy() noexcept;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit Iterator(AllVerticesIterable::Iterator);
|
|
|
|
explicit Iterator(LabelIndex::Iterable::Iterator);
|
|
|
|
explicit Iterator(LabelPropertyIndex::Iterable::Iterator);
|
|
|
|
|
|
|
|
Iterator(const Iterator &);
|
|
|
|
Iterator &operator=(const Iterator &);
|
|
|
|
|
|
|
|
Iterator(Iterator &&) noexcept;
|
|
|
|
Iterator &operator=(Iterator &&) noexcept;
|
|
|
|
|
|
|
|
~Iterator();
|
|
|
|
|
|
|
|
VertexAccessor operator*() const;
|
|
|
|
|
2019-07-31 17:10:19 +08:00
|
|
|
/// @throw std::bad_alloc raised in
|
|
|
|
/// LabelPropertyIndex::Iterable::Iterator::operator++
|
2019-07-29 20:26:31 +08:00
|
|
|
Iterator &operator++();
|
|
|
|
|
|
|
|
bool operator==(const Iterator &other) const;
|
|
|
|
bool operator!=(const Iterator &other) const { return !(*this == other); }
|
|
|
|
};
|
|
|
|
|
|
|
|
Iterator begin();
|
|
|
|
Iterator end();
|
|
|
|
};
|
|
|
|
|
2019-09-11 19:22:11 +08:00
|
|
|
/// Structure used to return information about existing indices in the storage.
|
|
|
|
struct IndicesInfo {
|
|
|
|
std::vector<LabelId> label;
|
|
|
|
std::vector<std::pair<LabelId, PropertyId>> label_property;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Structure used to return information about existing constraints in the
|
|
|
|
/// storage.
|
|
|
|
struct ConstraintsInfo {
|
|
|
|
std::vector<std::pair<LabelId, PropertyId>> existence;
|
|
|
|
};
|
|
|
|
|
2019-06-26 22:01:51 +08:00
|
|
|
class Storage final {
|
|
|
|
public:
|
2019-07-31 17:10:19 +08:00
|
|
|
/// @throw std::system_error
|
|
|
|
/// @throw std::bad_alloc
|
2019-09-13 17:18:17 +08:00
|
|
|
explicit Storage(Config config = Config());
|
[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
|
|
|
|
|
|
|
~Storage();
|
|
|
|
|
2019-06-26 22:01:51 +08:00
|
|
|
class Accessor final {
|
2019-07-11 19:27:50 +08:00
|
|
|
private:
|
|
|
|
friend class Storage;
|
|
|
|
|
2019-09-12 18:15:07 +08:00
|
|
|
explicit Accessor(Storage *storage);
|
2019-06-26 22:01:51 +08:00
|
|
|
|
2019-07-11 19:27:50 +08:00
|
|
|
public:
|
2019-06-26 22:01:51 +08:00
|
|
|
Accessor(const Accessor &) = delete;
|
|
|
|
Accessor &operator=(const Accessor &) = delete;
|
2019-07-11 19:27:50 +08:00
|
|
|
Accessor &operator=(Accessor &&other) = delete;
|
2019-06-26 22:01:51 +08:00
|
|
|
|
2019-07-11 19:27:50 +08:00
|
|
|
// NOTE: After the accessor is moved, all objects derived from it (accessors
|
|
|
|
// and iterators) are *invalid*. You have to get all derived objects again.
|
2019-07-03 21:32:03 +08:00
|
|
|
Accessor(Accessor &&other) noexcept;
|
2019-06-26 22:01:51 +08:00
|
|
|
|
2019-07-03 21:32:03 +08:00
|
|
|
~Accessor();
|
|
|
|
|
2019-07-31 17:10:19 +08:00
|
|
|
/// @throw std::bad_alloc
|
2019-07-03 21:32:03 +08:00
|
|
|
VertexAccessor CreateVertex();
|
|
|
|
|
|
|
|
std::optional<VertexAccessor> FindVertex(Gid gid, View view);
|
|
|
|
|
2019-07-22 22:05:44 +08:00
|
|
|
VerticesIterable Vertices(View view) {
|
2019-10-21 18:22:11 +08:00
|
|
|
return VerticesIterable(
|
|
|
|
AllVerticesIterable(storage_->vertices_.access(), &transaction_, view,
|
|
|
|
&storage_->indices_, storage_->config_.items));
|
2019-07-22 22:05:44 +08:00
|
|
|
}
|
|
|
|
|
2019-07-29 20:26:31 +08:00
|
|
|
VerticesIterable Vertices(LabelId label, View view);
|
2019-07-25 23:11:45 +08:00
|
|
|
|
2019-07-31 17:10:19 +08:00
|
|
|
/// @throw std::bad_alloc raised in Index::Vertices
|
2019-07-29 20:26:31 +08:00
|
|
|
VerticesIterable Vertices(LabelId label, PropertyId property, View view);
|
2019-07-25 23:11:45 +08:00
|
|
|
|
2019-07-31 17:10:19 +08:00
|
|
|
/// @throw std::bad_alloc raised in Index::Vertices
|
2019-07-29 20:26:31 +08:00
|
|
|
VerticesIterable Vertices(LabelId label, PropertyId property,
|
|
|
|
const PropertyValue &value, View view);
|
2019-07-25 23:11:45 +08:00
|
|
|
|
2019-07-31 17:10:19 +08:00
|
|
|
/// @throw std::bad_alloc raised in Index::Vertices
|
2019-07-29 20:26:31 +08:00
|
|
|
VerticesIterable Vertices(
|
2019-07-25 23:11:45 +08:00
|
|
|
LabelId label, PropertyId property,
|
|
|
|
const std::optional<utils::Bound<PropertyValue>> &lower_bound,
|
|
|
|
const std::optional<utils::Bound<PropertyValue>> &upper_bound,
|
|
|
|
View view);
|
|
|
|
|
2019-08-22 22:49:45 +08:00
|
|
|
/// Return approximate number of all vertices in the database.
|
|
|
|
/// Note that this is always an over-estimate and never an under-estimate.
|
|
|
|
int64_t ApproximateVertexCount() const {
|
|
|
|
return storage_->vertices_.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return approximate number of vertices with the given label.
|
|
|
|
/// Note that this is always an over-estimate and never an under-estimate.
|
|
|
|
int64_t ApproximateVertexCount(LabelId label) const {
|
|
|
|
return storage_->indices_.label_index.ApproximateVertexCount(label);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return approximate number of vertices with the given label and property.
|
|
|
|
/// Note that this is always an over-estimate and never an under-estimate.
|
|
|
|
int64_t ApproximateVertexCount(LabelId label, PropertyId property) const {
|
|
|
|
return storage_->indices_.label_property_index.ApproximateVertexCount(
|
|
|
|
label, property);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return approximate number of vertices with the given label and the given
|
|
|
|
/// value for the given property. Note that this is always an over-estimate
|
|
|
|
/// and never an under-estimate.
|
|
|
|
int64_t ApproximateVertexCount(LabelId label, PropertyId property,
|
|
|
|
const PropertyValue &value) const {
|
|
|
|
return storage_->indices_.label_property_index.ApproximateVertexCount(
|
|
|
|
label, property, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return approximate number of vertices with the given label and value for
|
|
|
|
/// the given property in the range defined by provided upper and lower
|
|
|
|
/// bounds.
|
|
|
|
int64_t ApproximateVertexCount(
|
|
|
|
LabelId label, PropertyId property,
|
|
|
|
const std::optional<utils::Bound<PropertyValue>> &lower,
|
|
|
|
const std::optional<utils::Bound<PropertyValue>> &upper) const {
|
|
|
|
return storage_->indices_.label_property_index.ApproximateVertexCount(
|
|
|
|
label, property, lower, upper);
|
|
|
|
}
|
|
|
|
|
2019-07-31 17:10:19 +08:00
|
|
|
/// @throw std::bad_alloc
|
2019-07-04 19:06:03 +08:00
|
|
|
Result<bool> DeleteVertex(VertexAccessor *vertex);
|
|
|
|
|
2019-07-31 17:10:19 +08:00
|
|
|
/// @throw std::bad_alloc
|
2019-07-08 21:10:05 +08:00
|
|
|
Result<bool> DetachDeleteVertex(VertexAccessor *vertex);
|
|
|
|
|
2019-07-31 17:10:19 +08:00
|
|
|
/// @throw std::bad_alloc
|
2019-07-08 21:10:05 +08:00
|
|
|
Result<EdgeAccessor> CreateEdge(VertexAccessor *from, VertexAccessor *to,
|
2019-07-22 19:35:36 +08:00
|
|
|
EdgeTypeId edge_type);
|
2019-07-08 21:10:05 +08:00
|
|
|
|
2019-07-31 17:10:19 +08:00
|
|
|
/// @throw std::bad_alloc
|
2019-07-08 21:10:05 +08:00
|
|
|
Result<bool> DeleteEdge(EdgeAccessor *edge);
|
|
|
|
|
2019-07-31 20:43:45 +08:00
|
|
|
const std::string &LabelToName(LabelId label) const;
|
|
|
|
const std::string &PropertyToName(PropertyId property) const;
|
|
|
|
const std::string &EdgeTypeToName(EdgeTypeId edge_type) const;
|
2019-07-18 22:17:41 +08:00
|
|
|
|
2019-07-31 17:10:19 +08:00
|
|
|
/// @throw std::bad_alloc if unable to insert a new mapping
|
2019-07-22 19:35:36 +08:00
|
|
|
LabelId NameToLabel(const std::string &name);
|
2019-07-31 17:10:19 +08:00
|
|
|
|
|
|
|
/// @throw std::bad_alloc if unable to insert a new mapping
|
2019-07-22 19:35:36 +08:00
|
|
|
PropertyId NameToProperty(const std::string &name);
|
2019-07-31 17:10:19 +08:00
|
|
|
|
|
|
|
/// @throw std::bad_alloc if unable to insert a new mapping
|
2019-07-22 19:35:36 +08:00
|
|
|
EdgeTypeId NameToEdgeType(const std::string &name);
|
2019-07-18 22:17:41 +08:00
|
|
|
|
2019-07-03 21:32:03 +08:00
|
|
|
void AdvanceCommand();
|
|
|
|
|
2019-08-20 20:59:13 +08:00
|
|
|
/// Commit returns `ExistenceConstraintViolation` if the changes made by
|
|
|
|
/// this transaction violate an existence constraint. In that case the
|
2019-09-09 21:52:09 +08:00
|
|
|
/// transaction is automatically aborted. Otherwise, void is returned.
|
2019-07-31 17:10:19 +08:00
|
|
|
/// @throw std::bad_alloc
|
2019-09-09 21:52:09 +08:00
|
|
|
utils::BasicResult<ExistenceConstraintViolation, void> Commit();
|
2019-07-03 21:32:03 +08:00
|
|
|
|
2019-07-31 17:10:19 +08:00
|
|
|
/// @throw std::bad_alloc
|
2019-07-03 21:32:03 +08:00
|
|
|
void Abort();
|
2019-06-26 22:01:51 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
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_;
|
|
|
|
bool is_transaction_active_;
|
2019-09-24 22:48:36 +08:00
|
|
|
Config::Items config_;
|
2019-06-26 22:01:51 +08:00
|
|
|
};
|
|
|
|
|
2019-09-12 18:15:07 +08:00
|
|
|
Accessor Access() { return Accessor{this}; }
|
2019-06-26 22:01:51 +08:00
|
|
|
|
2019-07-31 20:43:45 +08:00
|
|
|
const std::string &LabelToName(LabelId label) const;
|
|
|
|
const std::string &PropertyToName(PropertyId property) const;
|
|
|
|
const std::string &EdgeTypeToName(EdgeTypeId edge_type) const;
|
|
|
|
|
2019-07-31 17:10:19 +08:00
|
|
|
/// @throw std::bad_alloc if unable to insert a new mapping
|
2019-07-31 20:43:45 +08:00
|
|
|
LabelId NameToLabel(const std::string &name);
|
2019-07-31 17:10:19 +08:00
|
|
|
|
|
|
|
/// @throw std::bad_alloc if unable to insert a new mapping
|
2019-07-31 20:43:45 +08:00
|
|
|
PropertyId NameToProperty(const std::string &name);
|
2019-07-31 17:10:19 +08:00
|
|
|
|
|
|
|
/// @throw std::bad_alloc if unable to insert a new mapping
|
2019-07-31 20:43:45 +08:00
|
|
|
EdgeTypeId NameToEdgeType(const std::string &name);
|
|
|
|
|
2019-09-23 21:29:50 +08:00
|
|
|
/// @throw std::bad_alloc
|
2019-10-29 22:35:57 +08:00
|
|
|
bool CreateIndex(LabelId label);
|
2019-09-23 21:29:50 +08:00
|
|
|
|
2019-07-31 17:10:19 +08:00
|
|
|
/// @throw std::bad_alloc
|
2019-10-29 22:35:57 +08:00
|
|
|
bool CreateIndex(LabelId label, PropertyId property);
|
2019-07-25 23:11:45 +08:00
|
|
|
|
2019-10-29 22:35:57 +08:00
|
|
|
bool DropIndex(LabelId label);
|
2019-09-23 21:29:50 +08:00
|
|
|
|
2019-10-29 22:35:57 +08:00
|
|
|
bool DropIndex(LabelId label, PropertyId property);
|
2019-07-25 23:11:45 +08:00
|
|
|
|
2019-09-23 21:29:50 +08:00
|
|
|
bool LabelIndexExists(LabelId label) const {
|
|
|
|
return indices_.label_index.IndexExists(label);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LabelPropertyIndexExists(LabelId label, PropertyId property) const {
|
2019-07-25 23:11:45 +08:00
|
|
|
return indices_.label_property_index.IndexExists(label, property);
|
|
|
|
}
|
|
|
|
|
2019-09-11 19:22:11 +08:00
|
|
|
IndicesInfo ListAllIndices() const {
|
|
|
|
return {indices_.label_index.ListIndices(),
|
|
|
|
indices_.label_property_index.ListIndices()};
|
|
|
|
}
|
|
|
|
|
2019-08-20 20:59:13 +08:00
|
|
|
/// Creates a unique constraint`. Returns true if the constraint was
|
|
|
|
/// successfuly added, false if it already exists and an
|
|
|
|
/// `ExistenceConstraintViolation` if there is an existing vertex violating
|
|
|
|
/// the constraint.
|
|
|
|
///
|
|
|
|
/// @throw std::bad_alloc
|
|
|
|
/// @throw std::length_error
|
|
|
|
utils::BasicResult<ExistenceConstraintViolation, bool>
|
2019-10-29 22:35:57 +08:00
|
|
|
CreateExistenceConstraint(LabelId label, PropertyId property);
|
2019-08-20 20:59:13 +08:00
|
|
|
|
|
|
|
/// Removes a unique constraint. Returns true if the constraint was removed,
|
|
|
|
/// and false if it doesn't exist.
|
2019-10-29 22:35:57 +08:00
|
|
|
bool DropExistenceConstraint(LabelId label, PropertyId property);
|
2019-08-20 20:59:13 +08:00
|
|
|
|
2019-09-11 19:22:11 +08:00
|
|
|
ConstraintsInfo ListAllConstraints() const {
|
|
|
|
return {ListExistenceConstraints(constraints_)};
|
|
|
|
}
|
|
|
|
|
2019-06-26 22:01:51 +08:00
|
|
|
private:
|
2019-09-12 18:15:07 +08:00
|
|
|
Transaction CreateTransaction();
|
|
|
|
|
2019-07-31 17:10:19 +08:00
|
|
|
/// @throw std::system_error
|
|
|
|
/// @throw std::bad_alloc
|
[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
|
|
|
void CollectGarbage();
|
|
|
|
|
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-07-22 20:01:24 +08:00
|
|
|
utils::RWLock main_lock_{utils::RWLock::Priority::WRITE};
|
|
|
|
|
2019-06-26 22:01:51 +08:00
|
|
|
// Main object storage
|
|
|
|
utils::SkipList<storage::Vertex> vertices_;
|
2019-07-08 21:10:05 +08:00
|
|
|
utils::SkipList<storage::Edge> edges_;
|
2019-06-26 22:01:51 +08:00
|
|
|
std::atomic<uint64_t> vertex_id_{0};
|
2019-07-08 21:10:05 +08:00
|
|
|
std::atomic<uint64_t> edge_id_{0};
|
2019-06-26 22:01:51 +08:00
|
|
|
|
2019-07-22 23:05:00 +08:00
|
|
|
NameIdMapper name_id_mapper_;
|
|
|
|
|
2019-07-25 23:11:45 +08:00
|
|
|
Indices indices_;
|
2019-08-20 20:59:13 +08:00
|
|
|
Constraints constraints_;
|
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
|
|
|
// TODO: This isn't really a commit log, it doesn't even care if a
|
|
|
|
// transaction commited or aborted. We could probably combine this with
|
|
|
|
// `timestamp_` in a sensible unit, something like TransactionClock or
|
|
|
|
// whatever.
|
|
|
|
CommitLog commit_log_;
|
|
|
|
|
2019-07-22 23:05:00 +08:00
|
|
|
utils::Synchronized<std::list<Transaction>, utils::SpinLock>
|
|
|
|
committed_transactions_;
|
[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
|
|
|
|
2019-09-13 17:18:17 +08:00
|
|
|
Config config_;
|
[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::Scheduler gc_runner_;
|
|
|
|
std::mutex gc_lock_;
|
2019-07-22 23:05:00 +08:00
|
|
|
|
|
|
|
// Undo buffers that were unlinked and now are waiting to be freed.
|
|
|
|
utils::Synchronized<std::list<std::pair<uint64_t, std::list<Delta>>>,
|
|
|
|
utils::SpinLock>
|
|
|
|
garbage_undo_buffers_;
|
|
|
|
|
2019-07-25 23:11:45 +08:00
|
|
|
// Vertices that are logically deleted but still have to be removed from
|
|
|
|
// indices before removing them from the main storage.
|
2019-07-22 23:05:00 +08:00
|
|
|
utils::Synchronized<std::list<Gid>, utils::SpinLock> deleted_vertices_;
|
2019-07-25 23:11:45 +08:00
|
|
|
|
|
|
|
// Vertices that are logically deleted and removed from indices and now wait
|
|
|
|
// to be removed from the main storage.
|
|
|
|
std::list<std::pair<uint64_t, Gid>> garbage_vertices_;
|
|
|
|
|
|
|
|
// Edges that are logically deleted and wait to be removed from the main
|
|
|
|
// storage.
|
2019-07-22 23:05:00 +08:00
|
|
|
utils::Synchronized<std::list<Gid>, utils::SpinLock> deleted_edges_;
|
2019-10-01 19:42:27 +08:00
|
|
|
|
|
|
|
Durability durability_;
|
2019-06-26 22:01:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace storage
|