Skip to content

Commit

Permalink
Handle analytical mode in community_detection during parallel changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidar Samerkhanov committed Oct 23, 2023
1 parent d812a04 commit 323cec8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
10 changes: 10 additions & 0 deletions cpp/mg_utility/data_structures/graph_view.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cstdint>
#include <optional>
#include <vector>

#include "graph_data.hpp"
Expand Down Expand Up @@ -97,9 +98,18 @@ class GraphView {
///
///@param memgraph_id Memgraph's internal ID
///@return TSize
///@throws mg_exception::InvalidIDException if vertex does not exist
///
virtual TSize GetInnerNodeId(std::uint64_t memgraph_id) const = 0;

///
///@brief Get the Inner Node ID from Memgraph ID
///
///@param memgraph_id Memgraph's internal ID
///@return std::optional<TSize>, which is null if vertex does not exist
///
virtual std::optional<TSize> GetInnerNodeIdOpt(std::uint64_t memgraph_id) const = 0;

///
///@brief Get the Memgraph Edge Id from the inner renumbered node ID
///
Expand Down
31 changes: 29 additions & 2 deletions cpp/mg_utility/mg_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,14 @@ class Graph : public GraphView<TSize> {
return std::nullopt;
}

auto from = GetInnerNodeId(memgraph_id_from);
auto to = GetInnerNodeId(memgraph_id_to);
auto fromOpt = GetInnerNodeIdOpt(memgraph_id_from);
auto toOpt = GetInnerNodeIdOpt(memgraph_id_to);
if (!fromOpt || !toOpt) {
return std::nullopt;
}

auto from = *fromOpt;
auto to = *toOpt;

auto id = edges_.size();
inner_to_memgraph_edge_id_.emplace(id, edge_id);
Expand Down Expand Up @@ -314,6 +320,21 @@ class Graph : public GraphView<TSize> {
return memgraph_to_inner_id_.at(memgraph_id);
}

///
/// Returns the GraphView ID from Memgraph's internal ID
///
/// @param node_id Memgraphs's inner ID
///
std::optional<TSize> GetInnerNodeIdOpt(std::uint64_t memgraph_id) const override {
if (memgraph_to_inner_id_.find(memgraph_id) == memgraph_to_inner_id_.end()) {
if (IsTransactional()) {
throw mg_exception::InvalidIDException();
}
return std::nullopt;
}
return memgraph_to_inner_id_.at(memgraph_id);
}

///
/// Returns the Memgraph database ID from graph view
///
Expand Down Expand Up @@ -381,6 +402,10 @@ class Graph : public GraphView<TSize> {
nodes_to_edge_.clear();
}

void SetIsTransactional(bool is_transactional) { is_transactional_ = is_transactional; }

bool IsTransactional() const { return is_transactional_; }

private:
// Constant is used for marking deleted edges.
// If edge id is equal to constant, edge is deleted.
Expand All @@ -402,5 +427,7 @@ class Graph : public GraphView<TSize> {
std::unordered_map<std::uint64_t, TSize> memgraph_to_inner_edge_id_;

std::multimap<std::pair<TSize, TSize>, TSize> nodes_to_edge_;

bool is_transactional_;
};
} // namespace mg_graph
4 changes: 3 additions & 1 deletion cpp/mg_utility/mg_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <memory>
#include <unordered_set>

#include "_mgp.hpp"
#include "mg_graph.hpp"
#include "mgp.hpp"
#include "_mgp.hpp"

namespace mg_graph {

Expand Down Expand Up @@ -119,6 +119,8 @@ std::unique_ptr<mg_graph::Graph<TSize>> GetGraphView(mgp_graph *memgraph_graph,
const char *weight_property = nullptr,
double default_weight = 1.0) {
auto graph = std::make_unique<mg_graph::Graph<TSize>>();
bool isTransactionalStorage = mgp::graph_is_transactional(memgraph_graph);
graph->SetIsTransactional(isTransactionalStorage);

///
/// Mapping Memgraph in-memory vertices into the graph view
Expand Down

0 comments on commit 323cec8

Please sign in to comment.