From 90bcdc4e2ba3f95741b3e7f7ec2ac227dcff1286 Mon Sep 17 00:00:00 2001
From: jbajic <jure.bajic@memgraph.com>
Date: Fri, 3 Feb 2023 13:42:28 +0100
Subject: [PATCH] Rename uuid to id

---
 src/storage/v3/delta.hpp              | 22 +++++------
 src/storage/v3/mvcc.hpp               |  4 +-
 src/storage/v3/transaction.hpp        | 18 ++++-----
 tests/unit/storage_v3_shard_split.cpp | 57 +++++++++++++--------------
 4 files changed, 49 insertions(+), 52 deletions(-)

diff --git a/src/storage/v3/delta.hpp b/src/storage/v3/delta.hpp
index 7b8916f6d..b8bea789d 100644
--- a/src/storage/v3/delta.hpp
+++ b/src/storage/v3/delta.hpp
@@ -29,7 +29,7 @@ struct Edge;
 struct Delta;
 struct CommitInfo;
 
-inline uint64_t GetNextDeltaUUID() noexcept {
+inline uint64_t GetNextDeltaId() noexcept {
   static utils::Synchronized<uint64_t, utils::SpinLock> delta_id{0};
   return delta_id.WithLock([](auto &id) { return id++; });
 }
@@ -166,21 +166,21 @@ struct Delta {
   struct RemoveOutEdgeTag {};
 
   Delta(DeleteObjectTag /*unused*/, CommitInfo *commit_info, uint64_t delta_id, uint64_t command_id)
-      : action(Action::DELETE_OBJECT), uuid(delta_id), commit_info(commit_info), command_id(command_id) {}
+      : action(Action::DELETE_OBJECT), id(delta_id), commit_info(commit_info), command_id(command_id) {}
 
   Delta(RecreateObjectTag /*unused*/, CommitInfo *commit_info, uint64_t delta_id, uint64_t command_id)
-      : action(Action::RECREATE_OBJECT), uuid(delta_id), commit_info(commit_info), command_id(command_id) {}
+      : action(Action::RECREATE_OBJECT), id(delta_id), commit_info(commit_info), command_id(command_id) {}
 
   Delta(AddLabelTag /*unused*/, LabelId label, CommitInfo *commit_info, uint64_t delta_id, uint64_t command_id)
-      : action(Action::ADD_LABEL), uuid(delta_id), commit_info(commit_info), command_id(command_id), label(label) {}
+      : action(Action::ADD_LABEL), id(delta_id), commit_info(commit_info), command_id(command_id), label(label) {}
 
   Delta(RemoveLabelTag /*unused*/, LabelId label, CommitInfo *commit_info, uint64_t delta_id, uint64_t command_id)
-      : action(Action::REMOVE_LABEL), uuid(delta_id), commit_info(commit_info), command_id(command_id), label(label) {}
+      : action(Action::REMOVE_LABEL), id(delta_id), commit_info(commit_info), command_id(command_id), label(label) {}
 
   Delta(SetPropertyTag /*unused*/, PropertyId key, const PropertyValue &value, CommitInfo *commit_info,
         uint64_t delta_id, uint64_t command_id)
       : action(Action::SET_PROPERTY),
-        uuid(delta_id),
+        id(delta_id),
         commit_info(commit_info),
         command_id(command_id),
         property({key, value}) {}
@@ -188,7 +188,7 @@ struct Delta {
   Delta(AddInEdgeTag /*unused*/, EdgeTypeId edge_type, VertexId vertex_id, EdgeRef edge, CommitInfo *commit_info,
         uint64_t delta_id, uint64_t command_id)
       : action(Action::ADD_IN_EDGE),
-        uuid(delta_id),
+        id(delta_id),
         commit_info(commit_info),
         command_id(command_id),
         vertex_edge({edge_type, std::move(vertex_id), edge}) {}
@@ -196,7 +196,7 @@ struct Delta {
   Delta(AddOutEdgeTag /*unused*/, EdgeTypeId edge_type, VertexId vertex_id, EdgeRef edge, CommitInfo *commit_info,
         uint64_t delta_id, uint64_t command_id)
       : action(Action::ADD_OUT_EDGE),
-        uuid(delta_id),
+        id(delta_id),
         commit_info(commit_info),
         command_id(command_id),
         vertex_edge({edge_type, std::move(vertex_id), edge}) {}
@@ -204,7 +204,7 @@ struct Delta {
   Delta(RemoveInEdgeTag /*unused*/, EdgeTypeId edge_type, VertexId vertex_id, EdgeRef edge, CommitInfo *commit_info,
         uint64_t delta_id, uint64_t command_id)
       : action(Action::REMOVE_IN_EDGE),
-        uuid(delta_id),
+        id(delta_id),
         commit_info(commit_info),
         command_id(command_id),
         vertex_edge({edge_type, std::move(vertex_id), edge}) {}
@@ -212,7 +212,7 @@ struct Delta {
   Delta(RemoveOutEdgeTag /*unused*/, EdgeTypeId edge_type, VertexId vertex_id, EdgeRef edge, CommitInfo *commit_info,
         uint64_t delta_id, uint64_t command_id)
       : action(Action::REMOVE_OUT_EDGE),
-        uuid(delta_id),
+        id(delta_id),
         commit_info(commit_info),
         command_id(command_id),
         vertex_edge({edge_type, std::move(vertex_id), edge}) {}
@@ -242,7 +242,7 @@ struct Delta {
   }
 
   Action action;
-  uint64_t uuid;
+  uint64_t id;
   // TODO: optimize with in-place copy
   CommitInfo *commit_info;
   uint64_t command_id;
diff --git a/src/storage/v3/mvcc.hpp b/src/storage/v3/mvcc.hpp
index f4e4cb81e..797339f8b 100644
--- a/src/storage/v3/mvcc.hpp
+++ b/src/storage/v3/mvcc.hpp
@@ -108,7 +108,7 @@ inline bool PrepareForWrite(Transaction *transaction, TObj *object) {
 /// a `DELETE_OBJECT` delta).
 /// @throw std::bad_alloc
 inline Delta *CreateDeleteObjectDelta(Transaction *transaction) {
-  return &transaction->deltas.emplace_back(Delta::DeleteObjectTag(), transaction->commit_info.get(), GetNextDeltaUUID(),
+  return &transaction->deltas.emplace_back(Delta::DeleteObjectTag(), transaction->commit_info.get(), GetNextDeltaId(),
                                            transaction->command_id);
 }
 
@@ -119,7 +119,7 @@ template <typename TObj, class... Args>
 requires utils::SameAsAnyOf<TObj, Edge, Vertex>
 inline void CreateAndLinkDelta(Transaction *transaction, TObj *object, Args &&...args) {
   auto delta = &transaction->deltas.emplace_back(std::forward<Args>(args)..., transaction->commit_info.get(),
-                                                 GetNextDeltaUUID(), transaction->command_id);
+                                                 GetNextDeltaId(), transaction->command_id);
   auto *delta_holder = GetDeltaHolder(object);
 
   // The operations are written in such order so that both `next` and `prev`
diff --git a/src/storage/v3/transaction.hpp b/src/storage/v3/transaction.hpp
index 66269e935..8cb4225ee 100644
--- a/src/storage/v3/transaction.hpp
+++ b/src/storage/v3/transaction.hpp
@@ -69,37 +69,37 @@ struct Transaction {
     for (const auto &delta : deltas) {
       switch (delta.action) {
         case Delta::Action::DELETE_OBJECT:
-          copied_deltas.emplace_back(Delta::DeleteObjectTag{}, commit_info, delta.uuid, command_id);
+          copied_deltas.emplace_back(Delta::DeleteObjectTag{}, commit_info, delta.id, command_id);
           break;
         case Delta::Action::RECREATE_OBJECT:
-          copied_deltas.emplace_back(Delta::RecreateObjectTag{}, commit_info, delta.uuid, command_id);
+          copied_deltas.emplace_back(Delta::RecreateObjectTag{}, commit_info, delta.id, command_id);
           break;
         case Delta::Action::ADD_LABEL:
-          copied_deltas.emplace_back(Delta::AddLabelTag{}, delta.label, commit_info, delta.uuid, command_id);
+          copied_deltas.emplace_back(Delta::AddLabelTag{}, delta.label, commit_info, delta.id, command_id);
           break;
         case Delta::Action::REMOVE_LABEL:
-          copied_deltas.emplace_back(Delta::RemoveLabelTag{}, delta.label, commit_info, delta.uuid, command_id);
+          copied_deltas.emplace_back(Delta::RemoveLabelTag{}, delta.label, commit_info, delta.id, command_id);
           break;
         case Delta::Action::ADD_IN_EDGE:
           copied_deltas.emplace_back(Delta::AddInEdgeTag{}, delta.vertex_edge.edge_type, delta.vertex_edge.vertex_id,
-                                     delta.vertex_edge.edge, commit_info, delta.uuid, command_id);
+                                     delta.vertex_edge.edge, commit_info, delta.id, command_id);
           break;
         case Delta::Action::ADD_OUT_EDGE:
           copied_deltas.emplace_back(Delta::AddOutEdgeTag{}, delta.vertex_edge.edge_type, delta.vertex_edge.vertex_id,
-                                     delta.vertex_edge.edge, commit_info, delta.uuid, command_id);
+                                     delta.vertex_edge.edge, commit_info, delta.id, command_id);
           break;
         case Delta::Action::REMOVE_IN_EDGE:
           copied_deltas.emplace_back(Delta::RemoveInEdgeTag{}, delta.vertex_edge.edge_type, delta.vertex_edge.vertex_id,
-                                     delta.vertex_edge.edge, commit_info, delta.uuid, command_id);
+                                     delta.vertex_edge.edge, commit_info, delta.id, command_id);
           break;
         case Delta::Action::REMOVE_OUT_EDGE:
           copied_deltas.emplace_back(Delta::RemoveOutEdgeTag{}, delta.vertex_edge.edge_type,
-                                     delta.vertex_edge.vertex_id, delta.vertex_edge.edge, commit_info, delta.uuid,
+                                     delta.vertex_edge.vertex_id, delta.vertex_edge.edge, commit_info, delta.id,
                                      command_id);
           break;
         case Delta::Action::SET_PROPERTY:
           copied_deltas.emplace_back(Delta::SetPropertyTag{}, delta.property.key, delta.property.value, commit_info,
-                                     delta.uuid, command_id);
+                                     delta.id, command_id);
           break;
       }
     }
diff --git a/tests/unit/storage_v3_shard_split.cpp b/tests/unit/storage_v3_shard_split.cpp
index 22e849d23..69a69e52e 100644
--- a/tests/unit/storage_v3_shard_split.cpp
+++ b/tests/unit/storage_v3_shard_split.cpp
@@ -85,8 +85,7 @@ void AssertEqVertexContainer(const VertexContainer &actual, const VertexContaine
     // This asserts delta chain
     while (expected_delta != nullptr) {
       EXPECT_EQ(actual_delta->action, expected_delta->action);
-      EXPECT_EQ(actual_delta->uuid, expected_delta->uuid);
-      EXPECT_NE(&actual_delta, &expected_delta) << "Deltas must be different objects!";
+      EXPECT_EQ(actual_delta->id, expected_delta->id);
 
       switch (expected_delta->action) {
         case Delta::Action::ADD_LABEL:
@@ -119,8 +118,7 @@ void AssertEqVertexContainer(const VertexContainer &actual, const VertexContaine
         case PreviousPtr::Type::DELTA: {
           ASSERT_EQ(actual_prev.type, PreviousPtr::Type::DELTA) << "Expected type is delta!";
           EXPECT_EQ(actual_prev.delta->action, expected_prev.delta->action);
-          EXPECT_EQ(actual_prev.delta->uuid, expected_prev.delta->uuid);
-          EXPECT_NE(actual_prev.delta, expected_prev.delta) << "Prev deltas must be different objects!";
+          EXPECT_EQ(actual_prev.delta->id, expected_prev.delta->id);
           break;
         }
         case v3::PreviousPtr::Type::EDGE: {
@@ -151,7 +149,7 @@ void AssertEqDeltaLists(const std::list<Delta> &actual, const std::list<Delta> &
   auto expected_it = expected.begin();
   while (actual_it != actual.end()) {
     EXPECT_EQ(actual_it->action, expected_it->action);
-    EXPECT_EQ(actual_it->uuid, expected_it->uuid);
+    EXPECT_EQ(actual_it->id, expected_it->id);
     EXPECT_NE(&*actual_it, &*expected_it) << "Deltas must be different objects!";
   }
 }
@@ -384,34 +382,33 @@ TEST_F(ShardSplitTest, TestBasicSplitWithLabelPropertyIndex) {
   EXPECT_EQ(splitted_data.label_property_indices.size(), 1);
 }
 
-// TEST_F(ShardSplitTest, TestBigSplit) {
-//   int pk{0};
-//   for (int64_t i{0}; i < 10'000; ++i) {
-//     auto acc = storage.Access(GetNextHlc());
-//     EXPECT_FALSE(
-//         acc.CreateVertexAndValidate({secondary_label}, {PropertyValue(pk++)}, {{secondary_property,
-//         PropertyValue(i)}})
-//             .HasError());
-//     EXPECT_FALSE(acc.CreateVertexAndValidate({}, {PropertyValue(pk++)}, {}).HasError());
+TEST_F(ShardSplitTest, TestBigSplit) {
+  int pk{0};
+  for (int64_t i{0}; i < 10'000; ++i) {
+    auto acc = storage.Access(GetNextHlc());
+    EXPECT_FALSE(
+        acc.CreateVertexAndValidate({secondary_label}, {PropertyValue(pk++)}, {{secondary_property, PropertyValue(i)}})
+            .HasError());
+    EXPECT_FALSE(acc.CreateVertexAndValidate({}, {PropertyValue(pk++)}, {}).HasError());
 
-//     EXPECT_FALSE(acc.CreateEdge(VertexId{primary_label, PrimaryKey{PropertyValue(pk - 2)}},
-//                                 VertexId{primary_label, PrimaryKey{PropertyValue(pk - 1)}}, edge_type_id,
-//                                 Gid::FromUint(pk))
-//                      .HasError());
-//     acc.Commit(GetNextHlc());
-//   }
-//   storage.CreateIndex(secondary_label, secondary_property);
+    EXPECT_FALSE(acc.CreateEdge(VertexId{primary_label, PrimaryKey{PropertyValue(pk - 2)}},
+                                VertexId{primary_label, PrimaryKey{PropertyValue(pk - 1)}}, edge_type_id,
+                                Gid::FromUint(pk))
+                     .HasError());
+    acc.Commit(GetNextHlc());
+  }
+  storage.CreateIndex(secondary_label, secondary_property);
 
-//   const auto split_value = pk / 2;
-//   auto splitted_data = storage.PerformSplit({PropertyValue(split_value)}, 2);
+  const auto split_value = pk / 2;
+  auto splitted_data = storage.PerformSplit({PropertyValue(split_value)}, 2);
 
-//   EXPECT_EQ(splitted_data.vertices.size(), 100000);
-//   EXPECT_EQ(splitted_data.edges->size(), 50000);
-//   EXPECT_EQ(splitted_data.transactions.size(), 50000);
-//   EXPECT_EQ(splitted_data.label_indices.size(), 0);
-//   EXPECT_EQ(splitted_data.label_property_indices.size(), 1);
+  // EXPECT_EQ(splitted_data.vertices.size(), 100000);
+  // EXPECT_EQ(splitted_data.edges->size(), 50000);
+  // EXPECT_EQ(splitted_data.transactions.size(), 50000);
+  // EXPECT_EQ(splitted_data.label_indices.size(), 0);
+  // EXPECT_EQ(splitted_data.label_property_indices.size(), 1);
 
-//   AssertSplittedShard(std::move(splitted_data), split_value);
-// }
+  AssertSplittedShard(std::move(splitted_data), split_value);
+}
 
 }  // namespace memgraph::storage::v3::tests