diff --git a/src/storage/v3/transaction.hpp b/src/storage/v3/transaction.hpp index e0ed59290..6b208877a 100644 --- a/src/storage/v3/transaction.hpp +++ b/src/storage/v3/transaction.hpp @@ -31,12 +31,12 @@ struct CommitInfo { }; struct Transaction { - Transaction(coordinator::Hlc start_timestamp, CommitInfo commit_info, uint64_t command_id, - const std::list &deltas, bool must_abort, bool is_aborted, IsolationLevel isolation_level) + Transaction(coordinator::Hlc start_timestamp, CommitInfo new_commit_info, uint64_t command_id, bool must_abort, + bool is_aborted, IsolationLevel isolation_level) : start_timestamp{start_timestamp}, - commit_info{std::make_unique(commit_info)}, + commit_info{std::make_unique(new_commit_info)}, command_id(command_id), - deltas(CopyDeltas(deltas)), + deltas(CopyDeltas(commit_info.get())), must_abort(must_abort), is_aborted(is_aborted), isolation_level(isolation_level){}; @@ -64,10 +64,50 @@ struct Transaction { ~Transaction() {} - std::list CopyDeltas(const std::list &deltas) const { return std::list{}; } + std::list CopyDeltas(CommitInfo *commit_info) const { + std::list copied_deltas; + for (const auto &delta : deltas) { + switch (delta.action) { + case Delta::Action::DELETE_OBJECT: + copied_deltas.emplace_back(Delta::DeleteObjectTag{}, commit_info, command_id); + break; + case Delta::Action::RECREATE_OBJECT: + copied_deltas.emplace_back(Delta::RecreateObjectTag{}, commit_info, command_id); + break; + case Delta::Action::ADD_LABEL: + copied_deltas.emplace_back(Delta::AddLabelTag{}, delta.label, commit_info, command_id); + break; + case Delta::Action::REMOVE_LABEL: + copied_deltas.emplace_back(Delta::RemoveLabelTag{}, delta.label, commit_info, 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, 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, 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, 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, command_id); + break; + case Delta::Action::SET_PROPERTY: + copied_deltas.emplace_back(Delta::SetPropertyTag{}, delta.property.key, delta.property.value, commit_info, + command_id); + break; + } + } + return copied_deltas; + } + // This does not solve the whole problem of copying deltas Transaction Clone() const { - return {start_timestamp, *commit_info, command_id, deltas, must_abort, is_aborted, isolation_level}; + return {start_timestamp, *commit_info, command_id, must_abort, is_aborted, isolation_level}; } coordinator::Hlc start_timestamp;