GraphDbAccessor - validity assertion added to all functions
Reviewers: teon.banek, buda Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D571
This commit is contained in:
parent
e8a465e4b5
commit
a00ac885ad
@ -19,6 +19,7 @@ GraphDbAccessor::~GraphDbAccessor() {
|
|||||||
const std::string &GraphDbAccessor::name() const { return db_.name_; }
|
const std::string &GraphDbAccessor::name() const { return db_.name_; }
|
||||||
|
|
||||||
void GraphDbAccessor::advance_command() {
|
void GraphDbAccessor::advance_command() {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
transaction_->engine_.Advance(transaction_->id_);
|
transaction_->engine_.Advance(transaction_->id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,10 +38,13 @@ void GraphDbAccessor::abort() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool GraphDbAccessor::should_abort() const {
|
bool GraphDbAccessor::should_abort() const {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
return transaction_->should_abort();
|
return transaction_->should_abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexAccessor GraphDbAccessor::insert_vertex() {
|
VertexAccessor GraphDbAccessor::insert_vertex() {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
|
|
||||||
// create a vertex
|
// create a vertex
|
||||||
auto vertex_vlist = new mvcc::VersionList<Vertex>(*transaction_);
|
auto vertex_vlist = new mvcc::VersionList<Vertex>(*transaction_);
|
||||||
|
|
||||||
@ -52,6 +56,7 @@ VertexAccessor GraphDbAccessor::insert_vertex() {
|
|||||||
void GraphDbAccessor::update_label_indices(
|
void GraphDbAccessor::update_label_indices(
|
||||||
const GraphDbTypes::Label &label, const VertexAccessor &vertex_accessor,
|
const GraphDbTypes::Label &label, const VertexAccessor &vertex_accessor,
|
||||||
const Vertex *const vertex) {
|
const Vertex *const vertex) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
this->db_.labels_index_.Update(label, vertex_accessor.vlist_, vertex);
|
this->db_.labels_index_.Update(label, vertex_accessor.vlist_, vertex);
|
||||||
this->db_.label_property_index_.UpdateOnLabel(label, vertex_accessor.vlist_,
|
this->db_.label_property_index_.UpdateOnLabel(label, vertex_accessor.vlist_,
|
||||||
vertex);
|
vertex);
|
||||||
@ -60,22 +65,26 @@ void GraphDbAccessor::update_label_indices(
|
|||||||
void GraphDbAccessor::update_property_index(
|
void GraphDbAccessor::update_property_index(
|
||||||
const GraphDbTypes::Property &property,
|
const GraphDbTypes::Property &property,
|
||||||
const RecordAccessor<Vertex> &record_accessor, const Vertex *const vertex) {
|
const RecordAccessor<Vertex> &record_accessor, const Vertex *const vertex) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
this->db_.label_property_index_.UpdateOnProperty(
|
this->db_.label_property_index_.UpdateOnProperty(
|
||||||
property, record_accessor.vlist_, vertex);
|
property, record_accessor.vlist_, vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t GraphDbAccessor::vertices_count() const {
|
int64_t GraphDbAccessor::vertices_count() const {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
return db_.vertices_.access().size();
|
return db_.vertices_.access().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t GraphDbAccessor::vertices_count(
|
int64_t GraphDbAccessor::vertices_count(
|
||||||
const GraphDbTypes::Label &label) const {
|
const GraphDbTypes::Label &label) const {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
return db_.labels_index_.Count(label);
|
return db_.labels_index_.Count(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t GraphDbAccessor::vertices_count(
|
int64_t GraphDbAccessor::vertices_count(
|
||||||
const GraphDbTypes::Label &label,
|
const GraphDbTypes::Label &label,
|
||||||
const GraphDbTypes::Property &property) const {
|
const GraphDbTypes::Property &property) const {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
const LabelPropertyIndex::Key key(label, property);
|
const LabelPropertyIndex::Key key(label, property);
|
||||||
debug_assert(db_.label_property_index_.IndexExists(key),
|
debug_assert(db_.label_property_index_.IndexExists(key),
|
||||||
"Index doesn't exist.");
|
"Index doesn't exist.");
|
||||||
@ -85,6 +94,7 @@ int64_t GraphDbAccessor::vertices_count(
|
|||||||
int64_t GraphDbAccessor::vertices_count(const GraphDbTypes::Label &label,
|
int64_t GraphDbAccessor::vertices_count(const GraphDbTypes::Label &label,
|
||||||
const GraphDbTypes::Property &property,
|
const GraphDbTypes::Property &property,
|
||||||
const PropertyValue &value) const {
|
const PropertyValue &value) const {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
const LabelPropertyIndex::Key key(label, property);
|
const LabelPropertyIndex::Key key(label, property);
|
||||||
debug_assert(db_.label_property_index_.IndexExists(key),
|
debug_assert(db_.label_property_index_.IndexExists(key),
|
||||||
"Index doesn't exist.");
|
"Index doesn't exist.");
|
||||||
@ -96,6 +106,7 @@ int64_t GraphDbAccessor::vertices_count(
|
|||||||
const std::experimental::optional<utils::Bound<PropertyValue>> lower,
|
const std::experimental::optional<utils::Bound<PropertyValue>> lower,
|
||||||
const std::experimental::optional<utils::Bound<PropertyValue>> upper)
|
const std::experimental::optional<utils::Bound<PropertyValue>> upper)
|
||||||
const {
|
const {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
const LabelPropertyIndex::Key key(label, property);
|
const LabelPropertyIndex::Key key(label, property);
|
||||||
debug_assert(db_.label_property_index_.IndexExists(key),
|
debug_assert(db_.label_property_index_.IndexExists(key),
|
||||||
"Index doesn't exist.");
|
"Index doesn't exist.");
|
||||||
@ -134,6 +145,7 @@ int64_t GraphDbAccessor::vertices_count(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool GraphDbAccessor::remove_vertex(VertexAccessor &vertex_accessor) {
|
bool GraphDbAccessor::remove_vertex(VertexAccessor &vertex_accessor) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
vertex_accessor.SwitchNew();
|
vertex_accessor.SwitchNew();
|
||||||
// it's possible the vertex was removed already in this transaction
|
// it's possible the vertex was removed already in this transaction
|
||||||
// due to it getting matched multiple times by some patterns
|
// due to it getting matched multiple times by some patterns
|
||||||
@ -147,6 +159,7 @@ bool GraphDbAccessor::remove_vertex(VertexAccessor &vertex_accessor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GraphDbAccessor::detach_remove_vertex(VertexAccessor &vertex_accessor) {
|
void GraphDbAccessor::detach_remove_vertex(VertexAccessor &vertex_accessor) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
vertex_accessor.SwitchNew();
|
vertex_accessor.SwitchNew();
|
||||||
for (auto edge_accessor : vertex_accessor.in()) remove_edge(edge_accessor);
|
for (auto edge_accessor : vertex_accessor.in()) remove_edge(edge_accessor);
|
||||||
vertex_accessor.SwitchNew();
|
vertex_accessor.SwitchNew();
|
||||||
@ -158,6 +171,7 @@ void GraphDbAccessor::detach_remove_vertex(VertexAccessor &vertex_accessor) {
|
|||||||
EdgeAccessor GraphDbAccessor::insert_edge(VertexAccessor &from,
|
EdgeAccessor GraphDbAccessor::insert_edge(VertexAccessor &from,
|
||||||
VertexAccessor &to,
|
VertexAccessor &to,
|
||||||
GraphDbTypes::EdgeType edge_type) {
|
GraphDbTypes::EdgeType edge_type) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
// create an edge
|
// create an edge
|
||||||
auto edge_vlist = new mvcc::VersionList<Edge>(*transaction_, *from.vlist_,
|
auto edge_vlist = new mvcc::VersionList<Edge>(*transaction_, *from.vlist_,
|
||||||
*to.vlist_, edge_type);
|
*to.vlist_, edge_type);
|
||||||
@ -186,15 +200,18 @@ EdgeAccessor GraphDbAccessor::insert_edge(VertexAccessor &from,
|
|||||||
void GraphDbAccessor::update_edge_type_index(
|
void GraphDbAccessor::update_edge_type_index(
|
||||||
const GraphDbTypes::EdgeType &edge_type, const EdgeAccessor &edge_accessor,
|
const GraphDbTypes::EdgeType &edge_type, const EdgeAccessor &edge_accessor,
|
||||||
const Edge *const edge) {
|
const Edge *const edge) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
this->db_.edge_types_index_.Update(edge_type, edge_accessor.vlist_, edge);
|
this->db_.edge_types_index_.Update(edge_type, edge_accessor.vlist_, edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t GraphDbAccessor::edges_count() const {
|
int64_t GraphDbAccessor::edges_count() const {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
return db_.edges_.access().size();
|
return db_.edges_.access().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t GraphDbAccessor::edges_count(
|
int64_t GraphDbAccessor::edges_count(
|
||||||
const GraphDbTypes::EdgeType &edge_type) const {
|
const GraphDbTypes::EdgeType &edge_type) const {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
return db_.edge_types_index_.Count(edge_type);
|
return db_.edge_types_index_.Count(edge_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,6 +228,7 @@ void swap_out_edge(std::vector<mvcc::VersionList<Edge> *> &edges,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GraphDbAccessor::remove_edge(EdgeAccessor &edge_accessor) {
|
void GraphDbAccessor::remove_edge(EdgeAccessor &edge_accessor) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
// it's possible the edge was removed already in this transaction
|
// it's possible the edge was removed already in this transaction
|
||||||
// due to it getting matched multiple times by some patterns
|
// due to it getting matched multiple times by some patterns
|
||||||
// we can only delete it once, so check if it's already deleted
|
// we can only delete it once, so check if it's already deleted
|
||||||
@ -222,30 +240,36 @@ void GraphDbAccessor::remove_edge(EdgeAccessor &edge_accessor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GraphDbTypes::Label GraphDbAccessor::label(const std::string &label_name) {
|
GraphDbTypes::Label GraphDbAccessor::label(const std::string &label_name) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
return &(*db_.labels_.access().insert(label_name).first);
|
return &(*db_.labels_.access().insert(label_name).first);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &GraphDbAccessor::label_name(
|
const std::string &GraphDbAccessor::label_name(
|
||||||
const GraphDbTypes::Label label) const {
|
const GraphDbTypes::Label label) const {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
return *label;
|
return *label;
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphDbTypes::EdgeType GraphDbAccessor::edge_type(
|
GraphDbTypes::EdgeType GraphDbAccessor::edge_type(
|
||||||
const std::string &edge_type_name) {
|
const std::string &edge_type_name) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
return &(*db_.edge_types_.access().insert(edge_type_name).first);
|
return &(*db_.edge_types_.access().insert(edge_type_name).first);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &GraphDbAccessor::edge_type_name(
|
const std::string &GraphDbAccessor::edge_type_name(
|
||||||
const GraphDbTypes::EdgeType edge_type) const {
|
const GraphDbTypes::EdgeType edge_type) const {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
return *edge_type;
|
return *edge_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphDbTypes::Property GraphDbAccessor::property(
|
GraphDbTypes::Property GraphDbAccessor::property(
|
||||||
const std::string &property_name) {
|
const std::string &property_name) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
return &(*db_.properties_.access().insert(property_name).first);
|
return &(*db_.properties_.access().insert(property_name).first);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &GraphDbAccessor::property_name(
|
const std::string &GraphDbAccessor::property_name(
|
||||||
const GraphDbTypes::Property property) const {
|
const GraphDbTypes::Property property) const {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
return *property;
|
return *property;
|
||||||
}
|
}
|
||||||
|
@ -99,6 +99,7 @@ class GraphDbAccessor {
|
|||||||
* ignored).
|
* ignored).
|
||||||
*/
|
*/
|
||||||
auto vertices(bool current_state) {
|
auto vertices(bool current_state) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
// wrap version lists into accessors, which will look for visible versions
|
// wrap version lists into accessors, which will look for visible versions
|
||||||
auto accessors =
|
auto accessors =
|
||||||
iter::imap([this](auto vlist) { return VertexAccessor(*vlist, *this); },
|
iter::imap([this](auto vlist) { return VertexAccessor(*vlist, *this); },
|
||||||
@ -127,6 +128,7 @@ class GraphDbAccessor {
|
|||||||
* @return iterable collection
|
* @return iterable collection
|
||||||
*/
|
*/
|
||||||
auto vertices(const GraphDbTypes::Label &label, bool current_state) {
|
auto vertices(const GraphDbTypes::Label &label, bool current_state) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
return iter::imap(
|
return iter::imap(
|
||||||
[this, current_state](auto vlist) {
|
[this, current_state](auto vlist) {
|
||||||
return VertexAccessor(*vlist, *this);
|
return VertexAccessor(*vlist, *this);
|
||||||
@ -147,6 +149,7 @@ class GraphDbAccessor {
|
|||||||
*/
|
*/
|
||||||
auto vertices(const GraphDbTypes::Label &label,
|
auto vertices(const GraphDbTypes::Label &label,
|
||||||
const GraphDbTypes::Property &property, bool current_state) {
|
const GraphDbTypes::Property &property, bool current_state) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
debug_assert(db_.label_property_index_.IndexExists(
|
debug_assert(db_.label_property_index_.IndexExists(
|
||||||
LabelPropertyIndex::Key(label, property)),
|
LabelPropertyIndex::Key(label, property)),
|
||||||
"Label+property index doesn't exist.");
|
"Label+property index doesn't exist.");
|
||||||
@ -173,6 +176,7 @@ class GraphDbAccessor {
|
|||||||
auto vertices(const GraphDbTypes::Label &label,
|
auto vertices(const GraphDbTypes::Label &label,
|
||||||
const GraphDbTypes::Property &property,
|
const GraphDbTypes::Property &property,
|
||||||
const PropertyValue &value, bool current_state) {
|
const PropertyValue &value, bool current_state) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
debug_assert(db_.label_property_index_.IndexExists(
|
debug_assert(db_.label_property_index_.IndexExists(
|
||||||
LabelPropertyIndex::Key(label, property)),
|
LabelPropertyIndex::Key(label, property)),
|
||||||
"Label+property index doesn't exist.");
|
"Label+property index doesn't exist.");
|
||||||
@ -217,6 +221,7 @@ class GraphDbAccessor {
|
|||||||
const std::experimental::optional<utils::Bound<PropertyValue>> lower,
|
const std::experimental::optional<utils::Bound<PropertyValue>> lower,
|
||||||
const std::experimental::optional<utils::Bound<PropertyValue>> upper,
|
const std::experimental::optional<utils::Bound<PropertyValue>> upper,
|
||||||
bool current_state) {
|
bool current_state) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
debug_assert(db_.label_property_index_.IndexExists(
|
debug_assert(db_.label_property_index_.IndexExists(
|
||||||
LabelPropertyIndex::Key(label, property)),
|
LabelPropertyIndex::Key(label, property)),
|
||||||
"Label+property index doesn't exist.");
|
"Label+property index doesn't exist.");
|
||||||
@ -255,6 +260,8 @@ class GraphDbAccessor {
|
|||||||
* ignored).
|
* ignored).
|
||||||
*/
|
*/
|
||||||
auto edges(bool current_state) {
|
auto edges(bool current_state) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
|
|
||||||
// wrap version lists into accessors, which will look for visible versions
|
// wrap version lists into accessors, which will look for visible versions
|
||||||
auto accessors =
|
auto accessors =
|
||||||
iter::imap([this](auto vlist) { return EdgeAccessor(*vlist, *this); },
|
iter::imap([this](auto vlist) { return EdgeAccessor(*vlist, *this); },
|
||||||
@ -283,6 +290,7 @@ class GraphDbAccessor {
|
|||||||
* @return iterable collection
|
* @return iterable collection
|
||||||
*/
|
*/
|
||||||
auto edges(const GraphDbTypes::EdgeType &edge_type, bool current_state) {
|
auto edges(const GraphDbTypes::EdgeType &edge_type, bool current_state) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
return iter::imap([this, current_state](
|
return iter::imap([this, current_state](
|
||||||
auto vlist) { return EdgeAccessor(*vlist, *this); },
|
auto vlist) { return EdgeAccessor(*vlist, *this); },
|
||||||
db_.edge_types_index_.GetVlists(edge_type, *transaction_,
|
db_.edge_types_index_.GetVlists(edge_type, *transaction_,
|
||||||
@ -306,6 +314,8 @@ class GraphDbAccessor {
|
|||||||
*/
|
*/
|
||||||
void BuildIndex(const GraphDbTypes::Label &label,
|
void BuildIndex(const GraphDbTypes::Label &label,
|
||||||
const GraphDbTypes::Property &property) {
|
const GraphDbTypes::Property &property) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
|
|
||||||
const LabelPropertyIndex::Key key(label, property);
|
const LabelPropertyIndex::Key key(label, property);
|
||||||
if (db_.label_property_index_.CreateIndex(key) == false) {
|
if (db_.label_property_index_.CreateIndex(key) == false) {
|
||||||
throw IndexExistsException(
|
throw IndexExistsException(
|
||||||
@ -352,6 +362,7 @@ class GraphDbAccessor {
|
|||||||
*/
|
*/
|
||||||
bool LabelPropertyIndexExists(const GraphDbTypes::Label &label,
|
bool LabelPropertyIndexExists(const GraphDbTypes::Label &label,
|
||||||
const GraphDbTypes::Property &property) const {
|
const GraphDbTypes::Property &property) const {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
return db_.label_property_index_.IndexExists(
|
return db_.label_property_index_.IndexExists(
|
||||||
LabelPropertyIndex::Key(label, property));
|
LabelPropertyIndex::Key(label, property));
|
||||||
}
|
}
|
||||||
@ -360,6 +371,7 @@ class GraphDbAccessor {
|
|||||||
* @brief - Returns vector of keys of label-property indices.
|
* @brief - Returns vector of keys of label-property indices.
|
||||||
*/
|
*/
|
||||||
std::vector<LabelPropertyIndex::Key> GetIndicesKeys() {
|
std::vector<LabelPropertyIndex::Key> GetIndicesKeys() {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
return db_.label_property_index_.GetIndicesKeys();
|
return db_.label_property_index_.GetIndicesKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,6 +515,7 @@ class GraphDbAccessor {
|
|||||||
*/
|
*/
|
||||||
template <typename TRecord>
|
template <typename TRecord>
|
||||||
bool Reconstruct(RecordAccessor<TRecord> &accessor) {
|
bool Reconstruct(RecordAccessor<TRecord> &accessor) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
accessor.vlist_->find_set_old_new(*transaction_, accessor.old_,
|
accessor.vlist_->find_set_old_new(*transaction_, accessor.old_,
|
||||||
accessor.new_);
|
accessor.new_);
|
||||||
accessor.current_ = accessor.old_ ? accessor.old_ : accessor.new_;
|
accessor.current_ = accessor.old_ ? accessor.old_ : accessor.new_;
|
||||||
@ -525,6 +538,7 @@ class GraphDbAccessor {
|
|||||||
*/
|
*/
|
||||||
template <typename TRecord>
|
template <typename TRecord>
|
||||||
void update(RecordAccessor<TRecord> &accessor) {
|
void update(RecordAccessor<TRecord> &accessor) {
|
||||||
|
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||||
// can't update a deleted record if:
|
// can't update a deleted record if:
|
||||||
// - we only have old_ and it hasn't been deleted
|
// - we only have old_ and it hasn't been deleted
|
||||||
// - we have new_ and it hasn't been deleted
|
// - we have new_ and it hasn't been deleted
|
||||||
|
Loading…
Reference in New Issue
Block a user