Move vertex deletion to storage accessor
Reviewers: mtomic, teon.banek Reviewed By: mtomic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2174
This commit is contained in:
parent
6e6dff81e0
commit
26f14443c2
@ -75,6 +75,26 @@ std::optional<VertexAccessor> Storage::Accessor::FindVertex(Gid gid,
|
||||
return VertexAccessor::Create(&*it, transaction_, view);
|
||||
}
|
||||
|
||||
Result<bool> Storage::Accessor::DeleteVertex(VertexAccessor *vertex) {
|
||||
CHECK(vertex->transaction_ == transaction_)
|
||||
<< "VertexAccessor must be from the same transaction as the storage "
|
||||
"accessor when deleting a vertex!";
|
||||
auto vertex_ptr = vertex->vertex_;
|
||||
|
||||
std::lock_guard<utils::SpinLock> guard(vertex_ptr->lock);
|
||||
|
||||
if (!PrepareForWrite(transaction_, vertex_ptr))
|
||||
return Result<bool>{Error::SERIALIZATION_ERROR};
|
||||
|
||||
if (vertex_ptr->deleted) return Result<bool>{false};
|
||||
|
||||
CreateAndLinkDelta(transaction_, vertex_ptr, Delta::RecreateObjectTag());
|
||||
|
||||
vertex_ptr->deleted = true;
|
||||
|
||||
return Result<bool>{true};
|
||||
}
|
||||
|
||||
void Storage::Accessor::AdvanceCommand() { ++transaction_->command_id; }
|
||||
|
||||
void Storage::Accessor::Commit() {
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "utils/skip_list.hpp"
|
||||
|
||||
#include "storage/v2/result.hpp"
|
||||
#include "storage/v2/transaction.hpp"
|
||||
#include "storage/v2/vertex.hpp"
|
||||
#include "storage/v2/vertex_accessor.hpp"
|
||||
@ -39,6 +40,8 @@ class Storage final {
|
||||
|
||||
std::optional<VertexAccessor> FindVertex(Gid gid, View view);
|
||||
|
||||
Result<bool> DeleteVertex(VertexAccessor *vertex);
|
||||
|
||||
void AdvanceCommand();
|
||||
|
||||
void Commit();
|
||||
|
@ -37,21 +37,6 @@ std::optional<VertexAccessor> VertexAccessor::Create(Vertex *vertex,
|
||||
return VertexAccessor{vertex, transaction};
|
||||
}
|
||||
|
||||
Result<bool> VertexAccessor::Delete() {
|
||||
std::lock_guard<utils::SpinLock> guard(vertex_->lock);
|
||||
|
||||
if (!PrepareForWrite(transaction_, vertex_))
|
||||
return Result<bool>{Error::SERIALIZATION_ERROR};
|
||||
|
||||
if (vertex_->deleted) return Result<bool>{false};
|
||||
|
||||
CreateAndLinkDelta(transaction_, vertex_, Delta::RecreateObjectTag());
|
||||
|
||||
vertex_->deleted = true;
|
||||
|
||||
return Result<bool>{true};
|
||||
}
|
||||
|
||||
Result<bool> VertexAccessor::AddLabel(uint64_t label) {
|
||||
std::lock_guard<utils::SpinLock> guard(vertex_->lock);
|
||||
|
||||
|
@ -10,8 +10,12 @@
|
||||
|
||||
namespace storage {
|
||||
|
||||
class Storage;
|
||||
|
||||
class VertexAccessor final {
|
||||
private:
|
||||
friend class Storage;
|
||||
|
||||
VertexAccessor(Vertex *vertex, Transaction *transaction)
|
||||
: vertex_(vertex), transaction_(transaction) {}
|
||||
|
||||
@ -20,8 +24,6 @@ class VertexAccessor final {
|
||||
Transaction *transaction,
|
||||
View view);
|
||||
|
||||
Result<bool> Delete();
|
||||
|
||||
Result<bool> AddLabel(uint64_t label);
|
||||
|
||||
Result<bool> RemoveLabel(uint64_t label);
|
||||
|
@ -28,7 +28,7 @@ TEST(StorageV2, Commit) {
|
||||
auto vertex = acc.FindVertex(gid, storage::View::NEW);
|
||||
ASSERT_TRUE(vertex);
|
||||
|
||||
auto res = vertex->Delete();
|
||||
auto res = acc.DeleteVertex(&*vertex);
|
||||
ASSERT_FALSE(res.IsError());
|
||||
|
||||
acc.Commit();
|
||||
@ -224,7 +224,7 @@ TEST(StorageV2, VertexDeleteCommit) {
|
||||
auto vertex = acc4.FindVertex(gid, storage::View::NEW);
|
||||
ASSERT_TRUE(vertex);
|
||||
|
||||
auto res = vertex->Delete();
|
||||
auto res = acc4.DeleteVertex(&*vertex);
|
||||
ASSERT_TRUE(res.IsReturn());
|
||||
|
||||
acc4.Commit();
|
||||
@ -279,7 +279,7 @@ TEST(StorageV2, VertexDeleteAbort) {
|
||||
auto vertex = acc4.FindVertex(gid, storage::View::NEW);
|
||||
ASSERT_TRUE(vertex);
|
||||
|
||||
auto res = vertex->Delete();
|
||||
auto res = acc4.DeleteVertex(&*vertex);
|
||||
ASSERT_TRUE(res.IsReturn());
|
||||
|
||||
acc4.Abort();
|
||||
@ -305,7 +305,7 @@ TEST(StorageV2, VertexDeleteAbort) {
|
||||
auto vertex = acc6.FindVertex(gid, storage::View::NEW);
|
||||
ASSERT_TRUE(vertex);
|
||||
|
||||
auto res = vertex->Delete();
|
||||
auto res = acc6.DeleteVertex(&*vertex);
|
||||
ASSERT_TRUE(res.IsReturn());
|
||||
|
||||
acc6.Commit();
|
||||
@ -359,13 +359,13 @@ TEST(StorageV2, VertexDeleteSerializationError) {
|
||||
ASSERT_TRUE(vertex);
|
||||
|
||||
{
|
||||
auto res = vertex->Delete();
|
||||
auto res = acc1.DeleteVertex(&*vertex);
|
||||
ASSERT_TRUE(res.IsReturn());
|
||||
ASSERT_TRUE(res.GetReturn());
|
||||
}
|
||||
|
||||
{
|
||||
auto res = vertex->Delete();
|
||||
auto res = acc1.DeleteVertex(&*vertex);
|
||||
ASSERT_TRUE(res.IsReturn());
|
||||
ASSERT_FALSE(res.GetReturn());
|
||||
}
|
||||
@ -375,7 +375,7 @@ TEST(StorageV2, VertexDeleteSerializationError) {
|
||||
{
|
||||
auto vertex = acc2.FindVertex(gid, storage::View::OLD);
|
||||
ASSERT_TRUE(vertex);
|
||||
auto res = vertex->Delete();
|
||||
auto res = acc2.DeleteVertex(&*vertex);
|
||||
ASSERT_TRUE(res.IsError());
|
||||
ASSERT_EQ(res.GetError(), storage::Error::SERIALIZATION_ERROR);
|
||||
}
|
||||
@ -409,7 +409,7 @@ TEST(StorageV2, VertexDeleteSpecialCases) {
|
||||
gid1 = vertex.Gid();
|
||||
ASSERT_FALSE(acc.FindVertex(gid1, storage::View::OLD).has_value());
|
||||
ASSERT_TRUE(acc.FindVertex(gid1, storage::View::NEW).has_value());
|
||||
auto res = vertex.Delete();
|
||||
auto res = acc.DeleteVertex(&vertex);
|
||||
ASSERT_TRUE(res.IsReturn());
|
||||
ASSERT_TRUE(res.GetReturn());
|
||||
acc.Abort();
|
||||
@ -422,7 +422,7 @@ TEST(StorageV2, VertexDeleteSpecialCases) {
|
||||
gid2 = vertex.Gid();
|
||||
ASSERT_FALSE(acc.FindVertex(gid2, storage::View::OLD).has_value());
|
||||
ASSERT_TRUE(acc.FindVertex(gid2, storage::View::NEW).has_value());
|
||||
auto res = vertex.Delete();
|
||||
auto res = acc.DeleteVertex(&vertex);
|
||||
ASSERT_TRUE(res.IsReturn());
|
||||
ASSERT_TRUE(res.GetReturn());
|
||||
acc.Commit();
|
||||
@ -481,7 +481,7 @@ TEST(StorageV2, VertexDeleteLabel) {
|
||||
}
|
||||
|
||||
// Delete the vertex
|
||||
ASSERT_TRUE(vertex->Delete().GetReturn());
|
||||
ASSERT_TRUE(acc.DeleteVertex(&*vertex).GetReturn());
|
||||
|
||||
// Check whether label 5 exists
|
||||
ASSERT_FALSE(vertex->HasLabel(5, storage::View::OLD).GetReturn());
|
||||
@ -551,7 +551,7 @@ TEST(StorageV2, VertexDeleteLabel) {
|
||||
}
|
||||
|
||||
// Delete the vertex
|
||||
ASSERT_TRUE(vertex->Delete().GetReturn());
|
||||
ASSERT_TRUE(acc.DeleteVertex(&*vertex).GetReturn());
|
||||
|
||||
// Check whether label 5 exists
|
||||
ASSERT_TRUE(vertex->HasLabel(5, storage::View::OLD).GetReturn());
|
||||
@ -644,7 +644,7 @@ TEST(StorageV2, VertexDeleteProperty) {
|
||||
}
|
||||
|
||||
// Delete the vertex
|
||||
ASSERT_TRUE(vertex->Delete().GetReturn());
|
||||
ASSERT_TRUE(acc.DeleteVertex(&*vertex).GetReturn());
|
||||
|
||||
// Check whether label 5 exists
|
||||
ASSERT_TRUE(
|
||||
@ -719,7 +719,7 @@ TEST(StorageV2, VertexDeleteProperty) {
|
||||
}
|
||||
|
||||
// Delete the vertex
|
||||
ASSERT_TRUE(vertex->Delete().GetReturn());
|
||||
ASSERT_TRUE(acc.DeleteVertex(&*vertex).GetReturn());
|
||||
|
||||
// Check whether property 5 exists
|
||||
ASSERT_EQ(
|
||||
|
Loading…
Reference in New Issue
Block a user