Move constraints to common
Summary: Preparing unique constraint code to be implemented in HA. To do so, I'm moving everything to `stograge/common/` folder. I also added a new header, `gid.hpp` which does a `ifdef` include of the correct `gid.hpp` based on the product. Reviewers: ipaljak, mferencevic, vkasljevic, teon.banek Reviewed By: mferencevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2079
This commit is contained in:
parent
e1fdb85a34
commit
4ec3f62f4e
@ -63,14 +63,14 @@ set(mg_single_node_sources
|
||||
query/plan/variable_start_planner.cpp
|
||||
query/repl.cpp
|
||||
query/typed_value.cpp
|
||||
storage/single_node/edge_accessor.cpp
|
||||
storage/common/constraints/record.cpp
|
||||
storage/common/constraints/unique_constraints.cpp
|
||||
storage/common/locking/record_lock.cpp
|
||||
storage/common/types/property_value.cpp
|
||||
storage/common/types/property_value_store.cpp
|
||||
storage/single_node/edge_accessor.cpp
|
||||
storage/single_node/record_accessor.cpp
|
||||
storage/single_node/vertex_accessor.cpp
|
||||
storage/single_node/constraints/record.cpp
|
||||
storage/single_node/constraints/unique_constraints.cpp
|
||||
transactions/single_node/engine.cpp
|
||||
memgraph_init.cpp
|
||||
)
|
||||
|
@ -13,8 +13,8 @@
|
||||
|
||||
#include "database/single_node/exceptions.hpp"
|
||||
#include "database/single_node/graph_db.hpp"
|
||||
#include "storage/common/constraints/exceptions.hpp"
|
||||
#include "storage/common/types/types.hpp"
|
||||
#include "storage/single_node/constraints/exceptions.hpp"
|
||||
#include "storage/single_node/edge_accessor.hpp"
|
||||
#include "storage/single_node/vertex_accessor.hpp"
|
||||
#include "transactions/transaction.hpp"
|
||||
|
@ -2,8 +2,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "storage/common/types/property_value_store.hpp"
|
||||
#include "transactions/single_node/engine.hpp"
|
||||
#include "transactions/engine.hpp"
|
||||
#include "transactions/snapshot.hpp"
|
||||
|
||||
namespace storage::constraints::common {
|
@ -1,8 +1,8 @@
|
||||
#include "storage/single_node/constraints/record.hpp"
|
||||
#include "storage/common/constraints/record.hpp"
|
||||
|
||||
#include "storage/single_node/constraints/exceptions.hpp"
|
||||
#include "storage/single_node/mvcc/version_list.hpp"
|
||||
#include "transactions/single_node/engine.hpp"
|
||||
#include "storage/common/constraints/exceptions.hpp"
|
||||
#include "storage/common/mvcc/exceptions.hpp"
|
||||
#include "transactions/engine.hpp"
|
||||
#include "transactions/transaction.hpp"
|
||||
|
||||
namespace storage::constraints::impl {
|
@ -3,7 +3,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/common/locking/record_lock.hpp"
|
||||
#include "storage/single_node/gid.hpp"
|
||||
#include "storage/gid.hpp"
|
||||
#include "transactions/type.hpp"
|
||||
|
||||
namespace tx {
|
@ -1,8 +1,8 @@
|
||||
#include "storage/single_node/constraints/unique_constraints.hpp"
|
||||
#include "storage/common/constraints/unique_constraints.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "storage/single_node/vertex_accessor.hpp"
|
||||
#include "storage/vertex_accessor.hpp"
|
||||
|
||||
namespace storage::constraints {
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "storage/common/types/property_value.hpp"
|
||||
#include "storage/common/types/types.hpp"
|
||||
#include "storage/single_node/constraints/record.hpp"
|
||||
#include "storage/common/constraints/record.hpp"
|
||||
|
||||
namespace tx {
|
||||
class Snapshot;
|
15
src/storage/common/mvcc/exceptions.hpp
Normal file
15
src/storage/common/mvcc/exceptions.hpp
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "utils/exceptions.hpp"
|
||||
|
||||
namespace mvcc {
|
||||
class SerializationError : public utils::BasicException {
|
||||
static constexpr const char *default_message =
|
||||
"Can't serialize due to concurrent operations.";
|
||||
|
||||
public:
|
||||
using utils::BasicException::BasicException;
|
||||
SerializationError() : BasicException(default_message) {}
|
||||
};
|
||||
|
||||
} // namespace mvcc
|
@ -1,21 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/distributed/gid.hpp"
|
||||
#include "storage/common/locking/record_lock.hpp"
|
||||
#include "storage/common/mvcc/exceptions.hpp"
|
||||
#include "storage/distributed/gid.hpp"
|
||||
#include "transactions/transaction.hpp"
|
||||
#include "utils/exceptions.hpp"
|
||||
|
||||
namespace mvcc {
|
||||
|
||||
class SerializationError : public utils::BasicException {
|
||||
static constexpr const char *default_message =
|
||||
"Can't serialize due to concurrent operations.";
|
||||
|
||||
public:
|
||||
using utils::BasicException::BasicException;
|
||||
SerializationError() : BasicException(default_message) {}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class VersionList {
|
||||
public:
|
||||
|
13
src/storage/gid.hpp
Normal file
13
src/storage/gid.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef MG_SINGLE_NODE
|
||||
#include "storage/single_node/gid.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef MG_SINGLE_NODE_HA
|
||||
#include "storage/single_node_ha/gid.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef MG_DISTRIBUTED
|
||||
#include "storage/distributed/gid.hpp"
|
||||
#endif
|
@ -1,74 +0,0 @@
|
||||
#include "storage/single_node/constraints/existence_constraints.hpp"
|
||||
|
||||
#include "storage/single_node/constraints/common.hpp"
|
||||
|
||||
namespace storage::constraints {
|
||||
bool Contains(const PropertyValueStore &store,
|
||||
const std::vector<storage::Property> &properties) {
|
||||
for (auto property : properties) {
|
||||
if (store.at(property).IsNull()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CheckIfSatisfiesExistenceRule(const Vertex *vertex,
|
||||
const ExistenceRule &rule) {
|
||||
if (!utils::Contains(vertex->labels_, rule.label)) return true;
|
||||
if (!Contains(vertex->properties_, rule.properties)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExistenceConstraints::AddConstraint(const ExistenceRule &rule) {
|
||||
auto found = std::find(constraints_.begin(), constraints_.end(), rule);
|
||||
if (found != constraints_.end()) return false;
|
||||
|
||||
constraints_.push_back(rule);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExistenceConstraints::RemoveConstraint(const ExistenceRule &rule) {
|
||||
auto found = std::find(constraints_.begin(), constraints_.end(), rule);
|
||||
if (found != constraints_.end()) {
|
||||
std::swap(*found, constraints_.back());
|
||||
constraints_.pop_back();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ExistenceConstraints::Exists(const ExistenceRule &rule) const {
|
||||
auto found = std::find(constraints_.begin(), constraints_.end(), rule);
|
||||
return found != constraints_.end();
|
||||
}
|
||||
|
||||
bool ExistenceConstraints::CheckOnAddLabel(const Vertex *vertex,
|
||||
storage::Label label) const {
|
||||
for (auto &constraint : constraints_) {
|
||||
if (constraint.label == label &&
|
||||
!CheckIfSatisfiesExistenceRule(vertex, constraint)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExistenceConstraints::CheckOnRemoveProperty(
|
||||
const Vertex *vertex, storage::Property property) const {
|
||||
for (auto &constraint : constraints_) {
|
||||
if (utils::Contains(constraint.properties, property) &&
|
||||
!CheckIfSatisfiesExistenceRule(vertex, constraint)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::vector<ExistenceRule> &ExistenceConstraints::ListConstraints() const {
|
||||
return constraints_;
|
||||
}
|
||||
} // namespace storage::constraints
|
@ -1,22 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/single_node/gid.hpp"
|
||||
#include "storage/common/locking/record_lock.hpp"
|
||||
#include "storage/common/mvcc/exceptions.hpp"
|
||||
#include "storage/single_node/gid.hpp"
|
||||
#include "transactions/transaction.hpp"
|
||||
#include "utils/cast.hpp"
|
||||
#include "utils/exceptions.hpp"
|
||||
|
||||
namespace mvcc {
|
||||
|
||||
class SerializationError : public utils::BasicException {
|
||||
static constexpr const char *default_message =
|
||||
"Can't serialize due to concurrent operations.";
|
||||
|
||||
public:
|
||||
using utils::BasicException::BasicException;
|
||||
SerializationError() : BasicException(default_message) {}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class VersionList {
|
||||
public:
|
||||
|
@ -4,9 +4,9 @@
|
||||
#include <optional>
|
||||
|
||||
#include "data_structures/concurrent/concurrent_map.hpp"
|
||||
#include "storage/common/constraints/unique_constraints.hpp"
|
||||
#include "storage/common/kvstore/kvstore.hpp"
|
||||
#include "storage/common/types/types.hpp"
|
||||
#include "storage/single_node/constraints/unique_constraints.hpp"
|
||||
#include "storage/single_node/edge.hpp"
|
||||
#include "storage/single_node/indexes/key_index.hpp"
|
||||
#include "storage/single_node/indexes/label_property_index.hpp"
|
||||
|
@ -1,22 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/single_node_ha/gid.hpp"
|
||||
#include "storage/common/locking/record_lock.hpp"
|
||||
#include "storage/common/mvcc/exceptions.hpp"
|
||||
#include "storage/single_node_ha/gid.hpp"
|
||||
#include "transactions/transaction.hpp"
|
||||
#include "utils/cast.hpp"
|
||||
#include "utils/exceptions.hpp"
|
||||
|
||||
namespace mvcc {
|
||||
|
||||
class SerializationError : public utils::BasicException {
|
||||
static constexpr const char *default_message =
|
||||
"Can't serialize due to concurrent operations.";
|
||||
|
||||
public:
|
||||
using utils::BasicException::BasicException;
|
||||
SerializationError() : BasicException(default_message) {}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class VersionList {
|
||||
public:
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "database/single_node/graph_db.hpp"
|
||||
#include "database/single_node/graph_db_accessor.hpp"
|
||||
#include "storage/single_node/constraints/unique_constraints.hpp"
|
||||
#include "storage/common/constraints/unique_constraints.hpp"
|
||||
|
||||
using storage::constraints::ConstraintEntry;
|
||||
using storage::constraints::UniqueConstraints;
|
||||
|
Loading…
Reference in New Issue
Block a user