Merge branch 'project-pineapples' into T1149-MG-split-shard
This commit is contained in:
commit
7a4e2e017c
27
.github/workflows/diff.yaml
vendored
27
.github/workflows/diff.yaml
vendored
@ -271,3 +271,30 @@ jobs:
|
|||||||
source ve3/bin/activate
|
source ve3/bin/activate
|
||||||
cd e2e
|
cd e2e
|
||||||
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../libs/mgclient/lib python runner.py --workloads-root-directory ./distributed_queries
|
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../../libs/mgclient/lib python runner.py --workloads-root-directory ./distributed_queries
|
||||||
|
|
||||||
|
- name: Run query performance tests
|
||||||
|
run: |
|
||||||
|
cd tests/manual
|
||||||
|
./query_performance_runner.py
|
||||||
|
|
||||||
|
- name: Get branch name (merge)
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
shell: bash
|
||||||
|
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Get branch name (pull request)
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
shell: bash
|
||||||
|
run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF} | tr / -)" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Upload macro benchmark results
|
||||||
|
run: |
|
||||||
|
cd tools/bench-graph-client
|
||||||
|
virtualenv -p python3 ve3
|
||||||
|
source ve3/bin/activate
|
||||||
|
pip install -r requirements.txt
|
||||||
|
./main.py --benchmark-name "query_performance" \
|
||||||
|
--benchmark-results-path "../../build/tests/manual/query_performance_benchmark/summary.json" \
|
||||||
|
--github-run-id "${{ github.run_id }}" \
|
||||||
|
--github-run-number "${{ github.run_number }}" \
|
||||||
|
--head-branch-name "${{ env.BRANCH_NAME }}"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -51,7 +51,7 @@ constexpr char kId[] = "ID";
|
|||||||
|
|
||||||
namespace MG_INJECTED_NAMESPACE_NAME {
|
namespace MG_INJECTED_NAMESPACE_NAME {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
using antlropencypher::MemgraphCypher;
|
using antlropencypher::v2::MemgraphCypher;
|
||||||
|
|
||||||
template <typename TVisitor>
|
template <typename TVisitor>
|
||||||
std::optional<std::pair<Expression *, size_t>> VisitMemoryLimit(MemgraphCypher::MemoryLimitContext *memory_limit_ctx,
|
std::optional<std::pair<Expression *, size_t>> VisitMemoryLimit(MemgraphCypher::MemoryLimitContext *memory_limit_ctx,
|
||||||
@ -211,13 +211,13 @@ inline std::string_view ToString(const PulsarConfigKey key) {
|
|||||||
}
|
}
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
using antlropencypher::MemgraphCypher;
|
using antlropencypher::v2::MemgraphCypher;
|
||||||
|
|
||||||
struct ParsingContext {
|
struct ParsingContext {
|
||||||
bool is_query_cached = false;
|
bool is_query_cached = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CypherMainVisitor : public antlropencypher::MemgraphCypherBaseVisitor {
|
class CypherMainVisitor : public antlropencypher::v2::MemgraphCypherBaseVisitor {
|
||||||
public:
|
public:
|
||||||
explicit CypherMainVisitor(ParsingContext context, AstStorage *storage) : context_(context), storage_(storage) {}
|
explicit CypherMainVisitor(ParsingContext context, AstStorage *storage) : context_(context), storage_(storage) {}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -120,7 +120,7 @@ class Shared {
|
|||||||
MG_ASSERT(!consumed_, "Promise filled after it was already consumed!");
|
MG_ASSERT(!consumed_, "Promise filled after it was already consumed!");
|
||||||
MG_ASSERT(!filled_, "Promise filled twice!");
|
MG_ASSERT(!filled_, "Promise filled twice!");
|
||||||
|
|
||||||
item_ = item;
|
item_ = std::move(item);
|
||||||
filled_ = true;
|
filled_ = true;
|
||||||
} // lock released before condition variable notification
|
} // lock released before condition variable notification
|
||||||
|
|
||||||
@ -235,7 +235,7 @@ class Promise {
|
|||||||
// Fill the expected item into the Future.
|
// Fill the expected item into the Future.
|
||||||
void Fill(T item) {
|
void Fill(T item) {
|
||||||
MG_ASSERT(!filled_or_moved_, "Promise::Fill called on a promise that is already filled or moved!");
|
MG_ASSERT(!filled_or_moved_, "Promise::Fill called on a promise that is already filled or moved!");
|
||||||
shared_->Fill(item);
|
shared_->Fill(std::move(item));
|
||||||
filled_or_moved_ = true;
|
filled_or_moved_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -30,10 +30,10 @@ class LocalTransport {
|
|||||||
explicit LocalTransport(std::shared_ptr<LocalTransportHandle> local_transport_handle)
|
explicit LocalTransport(std::shared_ptr<LocalTransportHandle> local_transport_handle)
|
||||||
: local_transport_handle_(std::move(local_transport_handle)) {}
|
: local_transport_handle_(std::move(local_transport_handle)) {}
|
||||||
|
|
||||||
template <Message RequestT, Message ResponseT>
|
template <Message ResponseT, Message RequestT>
|
||||||
ResponseFuture<ResponseT> Request(Address to_address, Address from_address, RequestT request,
|
ResponseFuture<ResponseT> Request(Address to_address, Address from_address, RValueRef<RequestT> request,
|
||||||
std::function<void()> fill_notifier, Duration timeout) {
|
std::function<void()> fill_notifier, Duration timeout) {
|
||||||
return local_transport_handle_->template SubmitRequest<RequestT, ResponseT>(
|
return local_transport_handle_->template SubmitRequest<ResponseT, RequestT>(
|
||||||
to_address, from_address, std::move(request), timeout, fill_notifier);
|
to_address, from_address, std::move(request), timeout, fill_notifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,8 +43,8 @@ class LocalTransport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <Message M>
|
template <Message M>
|
||||||
void Send(Address to_address, Address from_address, RequestId request_id, M &&message) {
|
void Send(Address to_address, Address from_address, RequestId request_id, RValueRef<M> message) {
|
||||||
return local_transport_handle_->template Send<M>(to_address, from_address, request_id, std::forward<M>(message));
|
return local_transport_handle_->template Send<M>(to_address, from_address, request_id, std::move(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
Time Now() const { return local_transport_handle_->Now(); }
|
Time Now() const { return local_transport_handle_->Now(); }
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -104,10 +104,10 @@ class LocalTransportHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <Message M>
|
template <Message M>
|
||||||
void Send(Address to_address, Address from_address, RequestId request_id, M &&message) {
|
void Send(Address to_address, Address from_address, RequestId request_id, RValueRef<M> message) {
|
||||||
auto type_info = TypeInfoFor(message);
|
auto type_info = TypeInfoFor(message);
|
||||||
|
|
||||||
std::any message_any(std::forward<M>(message));
|
std::any message_any(std::move(message));
|
||||||
OpaqueMessage opaque_message{.to_address = to_address,
|
OpaqueMessage opaque_message{.to_address = to_address,
|
||||||
.from_address = from_address,
|
.from_address = from_address,
|
||||||
.request_id = request_id,
|
.request_id = request_id,
|
||||||
@ -138,14 +138,14 @@ class LocalTransportHandle {
|
|||||||
cv_.notify_all();
|
cv_.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <Message RequestT, Message ResponseT>
|
template <Message ResponseT, Message RequestT>
|
||||||
ResponseFuture<ResponseT> SubmitRequest(Address to_address, Address from_address, RequestT &&request,
|
ResponseFuture<ResponseT> SubmitRequest(Address to_address, Address from_address, RValueRef<RequestT> request,
|
||||||
Duration timeout, std::function<void()> fill_notifier) {
|
Duration timeout, std::function<void()> fill_notifier) {
|
||||||
auto [future, promise] = memgraph::io::FuturePromisePairWithNotifications<ResponseResult<ResponseT>>(
|
auto [future, promise] = memgraph::io::FuturePromisePairWithNotifications<ResponseResult<ResponseT>>(
|
||||||
// set null notifier for when the Future::Wait is called
|
// set null notifier for when the Future::Wait is called
|
||||||
nullptr,
|
nullptr,
|
||||||
// set notifier for when Promise::Fill is called
|
// set notifier for when Promise::Fill is called
|
||||||
std::forward<std::function<void()>>(fill_notifier));
|
std::move(fill_notifier));
|
||||||
|
|
||||||
const bool port_matches = to_address.last_known_port == from_address.last_known_port;
|
const bool port_matches = to_address.last_known_port == from_address.last_known_port;
|
||||||
const bool ip_matches = to_address.last_known_ip == from_address.last_known_ip;
|
const bool ip_matches = to_address.last_known_ip == from_address.last_known_ip;
|
||||||
@ -168,7 +168,7 @@ class LocalTransportHandle {
|
|||||||
promises_.emplace(std::move(promise_key), std::move(dop));
|
promises_.emplace(std::move(promise_key), std::move(dop));
|
||||||
} // lock dropped
|
} // lock dropped
|
||||||
|
|
||||||
Send(to_address, from_address, request_id, std::forward<RequestT>(request));
|
Send<RequestT>(to_address, from_address, request_id, std::move(request));
|
||||||
|
|
||||||
return std::move(future);
|
return std::move(future);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -19,6 +19,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <type_traits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <boost/core/demangle.hpp>
|
#include <boost/core/demangle.hpp>
|
||||||
@ -246,7 +247,7 @@ to a CAS operation.
|
|||||||
template <typename WriteOperation, typename ReadOperation, typename ReplicatedState, typename WriteResponseValue,
|
template <typename WriteOperation, typename ReadOperation, typename ReplicatedState, typename WriteResponseValue,
|
||||||
typename ReadResponseValue>
|
typename ReadResponseValue>
|
||||||
concept Rsm = requires(ReplicatedState state, WriteOperation w, ReadOperation r) {
|
concept Rsm = requires(ReplicatedState state, WriteOperation w, ReadOperation r) {
|
||||||
{ state.Read(r) } -> std::same_as<ReadResponseValue>;
|
{ state.Read(std::move(r)) } -> std::same_as<ReadResponseValue>;
|
||||||
{ state.Apply(w) } -> std::same_as<WriteResponseValue>;
|
{ state.Apply(w) } -> std::same_as<WriteResponseValue>;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -402,7 +403,7 @@ class Raft {
|
|||||||
const PendingClientRequest client_request = std::move(leader.pending_client_requests.at(apply_index));
|
const PendingClientRequest client_request = std::move(leader.pending_client_requests.at(apply_index));
|
||||||
leader.pending_client_requests.erase(apply_index);
|
leader.pending_client_requests.erase(apply_index);
|
||||||
|
|
||||||
const WriteResponse<WriteResponseValue> resp{
|
WriteResponse<WriteResponseValue> resp{
|
||||||
.success = true,
|
.success = true,
|
||||||
.write_return = std::move(write_return),
|
.write_return = std::move(write_return),
|
||||||
.raft_index = apply_index,
|
.raft_index = apply_index,
|
||||||
@ -554,7 +555,7 @@ class Raft {
|
|||||||
for (const auto &peer : peers_) {
|
for (const auto &peer : peers_) {
|
||||||
// request_id not necessary to set because it's not a Future-backed Request.
|
// request_id not necessary to set because it's not a Future-backed Request.
|
||||||
static constexpr auto request_id = 0;
|
static constexpr auto request_id = 0;
|
||||||
io_.template Send<VoteRequest>(peer, request_id, request);
|
io_.template Send(peer, request_id, VoteRequest{request});
|
||||||
outstanding_votes.insert(peer);
|
outstanding_votes.insert(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -624,13 +625,12 @@ class Raft {
|
|||||||
MG_ASSERT(std::max(req.term, state_.term) == req.term);
|
MG_ASSERT(std::max(req.term, state_.term) == req.term);
|
||||||
}
|
}
|
||||||
|
|
||||||
const VoteResponse res{
|
io_.Send(from_address, request_id,
|
||||||
|
VoteResponse{
|
||||||
.term = std::max(req.term, state_.term),
|
.term = std::max(req.term, state_.term),
|
||||||
.committed_log_size = state_.committed_log_size,
|
.committed_log_size = state_.committed_log_size,
|
||||||
.vote_granted = new_leader,
|
.vote_granted = new_leader,
|
||||||
};
|
});
|
||||||
|
|
||||||
io_.Send(from_address, request_id, res);
|
|
||||||
|
|
||||||
if (new_leader) {
|
if (new_leader) {
|
||||||
// become a follower
|
// become a follower
|
||||||
@ -718,6 +718,10 @@ class Raft {
|
|||||||
.log_size = state_.log.size(),
|
.log_size = state_.log.size(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static_assert(std::is_trivially_copyable_v<AppendResponse>,
|
||||||
|
"This function copies this message, therefore it is important to be trivially copyable. Otherwise it "
|
||||||
|
"should be moved");
|
||||||
|
|
||||||
if constexpr (std::is_same<ALL, Leader>()) {
|
if constexpr (std::is_same<ALL, Leader>()) {
|
||||||
MG_ASSERT(req.term != state_.term, "Multiple leaders are acting under the term ", req.term);
|
MG_ASSERT(req.term != state_.term, "Multiple leaders are acting under the term ", req.term);
|
||||||
}
|
}
|
||||||
@ -736,7 +740,7 @@ class Raft {
|
|||||||
// become follower of this leader, reply with our log status
|
// become follower of this leader, reply with our log status
|
||||||
state_.term = req.term;
|
state_.term = req.term;
|
||||||
|
|
||||||
io_.Send(from_address, request_id, res);
|
io_.Send(from_address, request_id, AppendResponse{res});
|
||||||
|
|
||||||
Log("becoming Follower of Leader ", from_address.last_known_port, " at term ", req.term);
|
Log("becoming Follower of Leader ", from_address.last_known_port, " at term ", req.term);
|
||||||
return Follower{
|
return Follower{
|
||||||
@ -747,7 +751,7 @@ class Raft {
|
|||||||
|
|
||||||
if (req.term < state_.term) {
|
if (req.term < state_.term) {
|
||||||
// nack this request from an old leader
|
// nack this request from an old leader
|
||||||
io_.Send(from_address, request_id, res);
|
io_.Send(from_address, request_id, AppendResponse{res});
|
||||||
|
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
@ -808,7 +812,7 @@ class Raft {
|
|||||||
|
|
||||||
Log("returning log_size of ", res.log_size);
|
Log("returning log_size of ", res.log_size);
|
||||||
|
|
||||||
io_.Send(from_address, request_id, res);
|
io_.Send(from_address, request_id, AppendResponse{res});
|
||||||
|
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
@ -859,17 +863,17 @@ class Raft {
|
|||||||
auto type_info = TypeInfoFor(req);
|
auto type_info = TypeInfoFor(req);
|
||||||
std::string demangled_name = boost::core::demangle(type_info.get().name());
|
std::string demangled_name = boost::core::demangle(type_info.get().name());
|
||||||
Log("handling ReadOperation<" + demangled_name + ">");
|
Log("handling ReadOperation<" + demangled_name + ">");
|
||||||
ReadOperation read_operation = req.operation;
|
ReadOperation &read_operation = req.operation;
|
||||||
|
|
||||||
ReadResponseValue read_return = replicated_state_.Read(read_operation);
|
ReadResponseValue read_return = replicated_state_.Read(std::move(read_operation));
|
||||||
|
|
||||||
const ReadResponse<ReadResponseValue> resp{
|
ReadResponse<ReadResponseValue> resp{
|
||||||
.success = true,
|
.success = true,
|
||||||
.read_return = std::move(read_return),
|
.read_return = std::move(read_return),
|
||||||
.retry_leader = std::nullopt,
|
.retry_leader = std::nullopt,
|
||||||
};
|
};
|
||||||
|
|
||||||
io_.Send(from_address, request_id, resp);
|
io_.Send(from_address, request_id, std::move(resp));
|
||||||
|
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
@ -878,11 +882,11 @@ class Raft {
|
|||||||
std::optional<Role> Handle(Candidate & /* variable */, ReadRequest<ReadOperation> && /* variable */,
|
std::optional<Role> Handle(Candidate & /* variable */, ReadRequest<ReadOperation> && /* variable */,
|
||||||
RequestId request_id, Address from_address) {
|
RequestId request_id, Address from_address) {
|
||||||
Log("received ReadOperation - not redirecting because no Leader is known");
|
Log("received ReadOperation - not redirecting because no Leader is known");
|
||||||
const ReadResponse<ReadResponseValue> res{
|
ReadResponse<ReadResponseValue> res{
|
||||||
.success = false,
|
.success = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
io_.Send(from_address, request_id, res);
|
io_.Send(from_address, request_id, std::move(res));
|
||||||
|
|
||||||
Cron();
|
Cron();
|
||||||
|
|
||||||
@ -894,12 +898,12 @@ class Raft {
|
|||||||
Address from_address) {
|
Address from_address) {
|
||||||
Log("redirecting client to known Leader with port ", follower.leader_address.last_known_port);
|
Log("redirecting client to known Leader with port ", follower.leader_address.last_known_port);
|
||||||
|
|
||||||
const ReadResponse<ReadResponseValue> res{
|
ReadResponse<ReadResponseValue> res{
|
||||||
.success = false,
|
.success = false,
|
||||||
.retry_leader = follower.leader_address,
|
.retry_leader = follower.leader_address,
|
||||||
};
|
};
|
||||||
|
|
||||||
io_.Send(from_address, request_id, res);
|
io_.Send(from_address, request_id, std::move(res));
|
||||||
|
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
@ -913,12 +917,12 @@ class Raft {
|
|||||||
Address from_address) {
|
Address from_address) {
|
||||||
Log("redirecting client to known Leader with port ", follower.leader_address.last_known_port);
|
Log("redirecting client to known Leader with port ", follower.leader_address.last_known_port);
|
||||||
|
|
||||||
const WriteResponse<WriteResponseValue> res{
|
WriteResponse<WriteResponseValue> res{
|
||||||
.success = false,
|
.success = false,
|
||||||
.retry_leader = follower.leader_address,
|
.retry_leader = follower.leader_address,
|
||||||
};
|
};
|
||||||
|
|
||||||
io_.Send(from_address, request_id, res);
|
io_.Send(from_address, request_id, std::move(res));
|
||||||
|
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
@ -927,11 +931,11 @@ class Raft {
|
|||||||
RequestId request_id, Address from_address) {
|
RequestId request_id, Address from_address) {
|
||||||
Log("received WriteRequest - not redirecting because no Leader is known");
|
Log("received WriteRequest - not redirecting because no Leader is known");
|
||||||
|
|
||||||
const WriteResponse<WriteResponseValue> res{
|
WriteResponse<WriteResponseValue> res{
|
||||||
.success = false,
|
.success = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
io_.Send(from_address, request_id, res);
|
io_.Send(from_address, request_id, std::move(res));
|
||||||
|
|
||||||
Cron();
|
Cron();
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -95,7 +95,7 @@ class RsmClient {
|
|||||||
BasicResult<TimedOut, WriteResponseT> SendWriteRequest(WriteRequestT req) {
|
BasicResult<TimedOut, WriteResponseT> SendWriteRequest(WriteRequestT req) {
|
||||||
Notifier notifier;
|
Notifier notifier;
|
||||||
const ReadinessToken readiness_token{0};
|
const ReadinessToken readiness_token{0};
|
||||||
SendAsyncWriteRequest(req, notifier, readiness_token);
|
SendAsyncWriteRequest(std::move(req), notifier, readiness_token);
|
||||||
auto poll_result = AwaitAsyncWriteRequest(readiness_token);
|
auto poll_result = AwaitAsyncWriteRequest(readiness_token);
|
||||||
while (!poll_result) {
|
while (!poll_result) {
|
||||||
poll_result = AwaitAsyncWriteRequest(readiness_token);
|
poll_result = AwaitAsyncWriteRequest(readiness_token);
|
||||||
@ -106,7 +106,7 @@ class RsmClient {
|
|||||||
BasicResult<TimedOut, ReadResponseT> SendReadRequest(ReadRequestT req) {
|
BasicResult<TimedOut, ReadResponseT> SendReadRequest(ReadRequestT req) {
|
||||||
Notifier notifier;
|
Notifier notifier;
|
||||||
const ReadinessToken readiness_token{0};
|
const ReadinessToken readiness_token{0};
|
||||||
SendAsyncReadRequest(req, notifier, readiness_token);
|
SendAsyncReadRequest(std::move(req), notifier, readiness_token);
|
||||||
auto poll_result = AwaitAsyncReadRequest(readiness_token);
|
auto poll_result = AwaitAsyncReadRequest(readiness_token);
|
||||||
while (!poll_result) {
|
while (!poll_result) {
|
||||||
poll_result = AwaitAsyncReadRequest(readiness_token);
|
poll_result = AwaitAsyncReadRequest(readiness_token);
|
||||||
@ -115,15 +115,15 @@ class RsmClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// AsyncRead methods
|
/// AsyncRead methods
|
||||||
void SendAsyncReadRequest(const ReadRequestT &req, Notifier notifier, ReadinessToken readiness_token) {
|
void SendAsyncReadRequest(ReadRequestT &&req, Notifier notifier, ReadinessToken readiness_token) {
|
||||||
ReadRequest<ReadRequestT> read_req = {.operation = req};
|
ReadRequest<ReadRequestT> read_req = {.operation = req};
|
||||||
|
|
||||||
AsyncRequest<ReadRequestT, ReadResponse<ReadResponseT>> async_request{
|
AsyncRequest<ReadRequestT, ReadResponse<ReadResponseT>> async_request{
|
||||||
.start_time = io_.Now(),
|
.start_time = io_.Now(),
|
||||||
.request = std::move(req),
|
.request = std::move(req),
|
||||||
.notifier = notifier,
|
.notifier = notifier,
|
||||||
.future = io_.template RequestWithNotification<ReadRequest<ReadRequestT>, ReadResponse<ReadResponseT>>(
|
.future = io_.template RequestWithNotification<ReadResponse<ReadResponseT>, ReadRequest<ReadRequestT>>(
|
||||||
leader_, read_req, notifier, readiness_token),
|
leader_, std::move(read_req), notifier, readiness_token),
|
||||||
};
|
};
|
||||||
|
|
||||||
async_reads_.emplace(readiness_token.GetId(), std::move(async_request));
|
async_reads_.emplace(readiness_token.GetId(), std::move(async_request));
|
||||||
@ -134,8 +134,8 @@ class RsmClient {
|
|||||||
|
|
||||||
ReadRequest<ReadRequestT> read_req = {.operation = async_request.request};
|
ReadRequest<ReadRequestT> read_req = {.operation = async_request.request};
|
||||||
|
|
||||||
async_request.future = io_.template RequestWithNotification<ReadRequest<ReadRequestT>, ReadResponse<ReadResponseT>>(
|
async_request.future = io_.template RequestWithNotification<ReadResponse<ReadResponseT>, ReadRequest<ReadRequestT>>(
|
||||||
leader_, read_req, async_request.notifier, readiness_token);
|
leader_, std::move(read_req), async_request.notifier, readiness_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<BasicResult<TimedOut, ReadResponseT>> PollAsyncReadRequest(const ReadinessToken &readiness_token) {
|
std::optional<BasicResult<TimedOut, ReadResponseT>> PollAsyncReadRequest(const ReadinessToken &readiness_token) {
|
||||||
@ -184,15 +184,15 @@ class RsmClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// AsyncWrite methods
|
/// AsyncWrite methods
|
||||||
void SendAsyncWriteRequest(const WriteRequestT &req, Notifier notifier, ReadinessToken readiness_token) {
|
void SendAsyncWriteRequest(WriteRequestT &&req, Notifier notifier, ReadinessToken readiness_token) {
|
||||||
WriteRequest<WriteRequestT> write_req = {.operation = req};
|
WriteRequest<WriteRequestT> write_req = {.operation = req};
|
||||||
|
|
||||||
AsyncRequest<WriteRequestT, WriteResponse<WriteResponseT>> async_request{
|
AsyncRequest<WriteRequestT, WriteResponse<WriteResponseT>> async_request{
|
||||||
.start_time = io_.Now(),
|
.start_time = io_.Now(),
|
||||||
.request = std::move(req),
|
.request = std::move(req),
|
||||||
.notifier = notifier,
|
.notifier = notifier,
|
||||||
.future = io_.template RequestWithNotification<WriteRequest<WriteRequestT>, WriteResponse<WriteResponseT>>(
|
.future = io_.template RequestWithNotification<WriteResponse<WriteResponseT>, WriteRequest<WriteRequestT>>(
|
||||||
leader_, write_req, notifier, readiness_token),
|
leader_, std::move(write_req), notifier, readiness_token),
|
||||||
};
|
};
|
||||||
|
|
||||||
async_writes_.emplace(readiness_token.GetId(), std::move(async_request));
|
async_writes_.emplace(readiness_token.GetId(), std::move(async_request));
|
||||||
@ -204,8 +204,8 @@ class RsmClient {
|
|||||||
WriteRequest<WriteRequestT> write_req = {.operation = async_request.request};
|
WriteRequest<WriteRequestT> write_req = {.operation = async_request.request};
|
||||||
|
|
||||||
async_request.future =
|
async_request.future =
|
||||||
io_.template RequestWithNotification<WriteRequest<WriteRequestT>, WriteResponse<WriteResponseT>>(
|
io_.template RequestWithNotification<WriteResponse<WriteResponseT>, WriteRequest<WriteRequestT>>(
|
||||||
leader_, write_req, async_request.notifier, readiness_token);
|
leader_, std::move(write_req), async_request.notifier, readiness_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<BasicResult<TimedOut, WriteResponseT>> PollAsyncWriteRequest(const ReadinessToken &readiness_token) {
|
std::optional<BasicResult<TimedOut, WriteResponseT>> PollAsyncWriteRequest(const ReadinessToken &readiness_token) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -105,19 +105,19 @@ class SimulatorHandle {
|
|||||||
|
|
||||||
bool ShouldShutDown() const;
|
bool ShouldShutDown() const;
|
||||||
|
|
||||||
template <Message Request, Message Response>
|
template <Message ResponseT, Message RequestT>
|
||||||
ResponseFuture<Response> SubmitRequest(Address to_address, Address from_address, Request &&request, Duration timeout,
|
ResponseFuture<ResponseT> SubmitRequest(Address to_address, Address from_address, RValueRef<RequestT> request,
|
||||||
std::function<bool()> &&maybe_tick_simulator,
|
Duration timeout, std::function<bool()> &&maybe_tick_simulator,
|
||||||
std::function<void()> &&fill_notifier) {
|
std::function<void()> &&fill_notifier) {
|
||||||
auto type_info = TypeInfoFor(request);
|
auto type_info = TypeInfoFor(request);
|
||||||
std::string demangled_name = boost::core::demangle(type_info.get().name());
|
std::string demangled_name = boost::core::demangle(type_info.get().name());
|
||||||
spdlog::trace("simulator sending request {} to {}", demangled_name, to_address);
|
spdlog::trace("simulator sending request {} to {}", demangled_name, to_address);
|
||||||
|
|
||||||
auto [future, promise] = memgraph::io::FuturePromisePairWithNotifications<ResponseResult<Response>>(
|
auto [future, promise] = memgraph::io::FuturePromisePairWithNotifications<ResponseResult<ResponseT>>(
|
||||||
// set notifier for when the Future::Wait is called
|
// set notifier for when the Future::Wait is called
|
||||||
std::forward<std::function<bool()>>(maybe_tick_simulator),
|
std::move(maybe_tick_simulator),
|
||||||
// set notifier for when Promise::Fill is called
|
// set notifier for when Promise::Fill is called
|
||||||
std::forward<std::function<void()>>(fill_notifier));
|
std::move(fill_notifier));
|
||||||
|
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(mu_);
|
std::unique_lock<std::mutex> lock(mu_);
|
||||||
@ -126,7 +126,7 @@ class SimulatorHandle {
|
|||||||
|
|
||||||
const Time deadline = cluster_wide_time_microseconds_ + timeout;
|
const Time deadline = cluster_wide_time_microseconds_ + timeout;
|
||||||
|
|
||||||
std::any message(request);
|
std::any message(std::move(request));
|
||||||
OpaqueMessage om{.to_address = to_address,
|
OpaqueMessage om{.to_address = to_address,
|
||||||
.from_address = from_address,
|
.from_address = from_address,
|
||||||
.request_id = request_id,
|
.request_id = request_id,
|
||||||
@ -194,7 +194,7 @@ class SimulatorHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <Message M>
|
template <Message M>
|
||||||
void Send(Address to_address, Address from_address, RequestId request_id, M message) {
|
void Send(Address to_address, Address from_address, RequestId request_id, RValueRef<M> message) {
|
||||||
spdlog::trace("sending message from {} to {}", from_address.last_known_port, to_address.last_known_port);
|
spdlog::trace("sending message from {} to {}", from_address.last_known_port, to_address.last_known_port);
|
||||||
auto type_info = TypeInfoFor(message);
|
auto type_info = TypeInfoFor(message);
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -33,14 +33,14 @@ class SimulatorTransport {
|
|||||||
SimulatorTransport(std::shared_ptr<SimulatorHandle> simulator_handle, Address address, uint64_t seed)
|
SimulatorTransport(std::shared_ptr<SimulatorHandle> simulator_handle, Address address, uint64_t seed)
|
||||||
: simulator_handle_(simulator_handle), address_(address), rng_(std::mt19937{seed}) {}
|
: simulator_handle_(simulator_handle), address_(address), rng_(std::mt19937{seed}) {}
|
||||||
|
|
||||||
template <Message RequestT, Message ResponseT>
|
template <Message ResponseT, Message RequestT>
|
||||||
ResponseFuture<ResponseT> Request(Address to_address, Address from_address, RequestT request,
|
ResponseFuture<ResponseT> Request(Address to_address, Address from_address, RValueRef<RequestT> request,
|
||||||
std::function<void()> notification, Duration timeout) {
|
std::function<void()> notification, Duration timeout) {
|
||||||
std::function<bool()> tick_simulator = [handle_copy = simulator_handle_] {
|
std::function<bool()> tick_simulator = [handle_copy = simulator_handle_] {
|
||||||
return handle_copy->MaybeTickSimulator();
|
return handle_copy->MaybeTickSimulator();
|
||||||
};
|
};
|
||||||
|
|
||||||
return simulator_handle_->template SubmitRequest<RequestT, ResponseT>(
|
return simulator_handle_->template SubmitRequest<ResponseT, RequestT>(
|
||||||
to_address, from_address, std::move(request), timeout, std::move(tick_simulator), std::move(notification));
|
to_address, from_address, std::move(request), timeout, std::move(tick_simulator), std::move(notification));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,8 +50,8 @@ class SimulatorTransport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <Message M>
|
template <Message M>
|
||||||
void Send(Address to_address, Address from_address, uint64_t request_id, M message) {
|
void Send(Address to_address, Address from_address, uint64_t request_id, RValueRef<M> message) {
|
||||||
return simulator_handle_->template Send<M>(to_address, from_address, request_id, message);
|
return simulator_handle_->template Send<M>(to_address, from_address, request_id, std::move(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
Time Now() const { return simulator_handle_->Now(); }
|
Time Now() const { return simulator_handle_->Now(); }
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -22,6 +22,7 @@
|
|||||||
#include "io/message_histogram_collector.hpp"
|
#include "io/message_histogram_collector.hpp"
|
||||||
#include "io/notifier.hpp"
|
#include "io/notifier.hpp"
|
||||||
#include "io/time.hpp"
|
#include "io/time.hpp"
|
||||||
|
#include "utils/concepts.hpp"
|
||||||
#include "utils/result.hpp"
|
#include "utils/result.hpp"
|
||||||
|
|
||||||
namespace memgraph::io {
|
namespace memgraph::io {
|
||||||
@ -32,7 +33,15 @@ using memgraph::utils::BasicResult;
|
|||||||
// reasonable constraints around message types over time,
|
// reasonable constraints around message types over time,
|
||||||
// as we adapt things to use Thrift-generated message types.
|
// as we adapt things to use Thrift-generated message types.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
concept Message = std::same_as<T, std::decay_t<T>>;
|
concept Message = std::movable<T> && std::copyable<T>;
|
||||||
|
|
||||||
|
template <utils::Object T>
|
||||||
|
struct RValueRefEnforcer {
|
||||||
|
using Type = T &&;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using RValueRef = typename RValueRefEnforcer<T>::Type;
|
||||||
|
|
||||||
using RequestId = uint64_t;
|
using RequestId = uint64_t;
|
||||||
|
|
||||||
@ -82,43 +91,43 @@ class Io {
|
|||||||
Duration GetDefaultTimeout() { return default_timeout_; }
|
Duration GetDefaultTimeout() { return default_timeout_; }
|
||||||
|
|
||||||
/// Issue a request with an explicit timeout in microseconds provided. This tends to be used by clients.
|
/// Issue a request with an explicit timeout in microseconds provided. This tends to be used by clients.
|
||||||
template <Message RequestT, Message ResponseT>
|
template <Message ResponseT, Message RequestT>
|
||||||
ResponseFuture<ResponseT> RequestWithTimeout(Address address, RequestT request, Duration timeout) {
|
ResponseFuture<ResponseT> RequestWithTimeout(Address address, RValueRef<RequestT> request, Duration timeout) {
|
||||||
const Address from_address = address_;
|
const Address from_address = address_;
|
||||||
std::function<void()> fill_notifier = nullptr;
|
std::function<void()> fill_notifier = nullptr;
|
||||||
return implementation_.template Request<RequestT, ResponseT>(address, from_address, request, fill_notifier,
|
return implementation_.template Request<ResponseT, RequestT>(address, from_address, std::move(request),
|
||||||
timeout);
|
fill_notifier, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Issue a request that times out after the default timeout. This tends
|
/// Issue a request that times out after the default timeout. This tends
|
||||||
/// to be used by clients.
|
/// to be used by clients.
|
||||||
template <Message RequestT, Message ResponseT>
|
template <Message ResponseT, Message RequestT>
|
||||||
ResponseFuture<ResponseT> Request(Address to_address, RequestT request) {
|
ResponseFuture<ResponseT> Request(Address to_address, RValueRef<RequestT> request) {
|
||||||
const Duration timeout = default_timeout_;
|
const Duration timeout = default_timeout_;
|
||||||
const Address from_address = address_;
|
const Address from_address = address_;
|
||||||
std::function<void()> fill_notifier = nullptr;
|
std::function<void()> fill_notifier = nullptr;
|
||||||
return implementation_.template Request<RequestT, ResponseT>(to_address, from_address, std::move(request),
|
return implementation_.template Request<ResponseT, RequestT>(to_address, from_address, std::move(request),
|
||||||
fill_notifier, timeout);
|
fill_notifier, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Issue a request that will notify a Notifier when it is filled or times out.
|
/// Issue a request that will notify a Notifier when it is filled or times out.
|
||||||
template <Message RequestT, Message ResponseT>
|
template <Message ResponseT, Message RequestT>
|
||||||
ResponseFuture<ResponseT> RequestWithNotification(Address to_address, RequestT request, Notifier notifier,
|
ResponseFuture<ResponseT> RequestWithNotification(Address to_address, RValueRef<RequestT> request, Notifier notifier,
|
||||||
ReadinessToken readiness_token) {
|
ReadinessToken readiness_token) {
|
||||||
const Duration timeout = default_timeout_;
|
const Duration timeout = default_timeout_;
|
||||||
const Address from_address = address_;
|
const Address from_address = address_;
|
||||||
std::function<void()> fill_notifier = [notifier, readiness_token]() { notifier.Notify(readiness_token); };
|
std::function<void()> fill_notifier = [notifier, readiness_token]() { notifier.Notify(readiness_token); };
|
||||||
return implementation_.template Request<RequestT, ResponseT>(to_address, from_address, std::move(request),
|
return implementation_.template Request<ResponseT, RequestT>(to_address, from_address, std::move(request),
|
||||||
fill_notifier, timeout);
|
fill_notifier, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Issue a request that will notify a Notifier when it is filled or times out.
|
/// Issue a request that will notify a Notifier when it is filled or times out.
|
||||||
template <Message RequestT, Message ResponseT>
|
template <Message ResponseT, Message RequestT>
|
||||||
ResponseFuture<ResponseT> RequestWithNotificationAndTimeout(Address to_address, RequestT request, Notifier notifier,
|
ResponseFuture<ResponseT> RequestWithNotificationAndTimeout(Address to_address, RequestT &&request, Notifier notifier,
|
||||||
ReadinessToken readiness_token, Duration timeout) {
|
ReadinessToken readiness_token, Duration timeout) {
|
||||||
const Address from_address = address_;
|
const Address from_address = address_;
|
||||||
std::function<void()> fill_notifier = [notifier, readiness_token]() { notifier.Notify(readiness_token); };
|
std::function<void()> fill_notifier = [notifier, readiness_token]() { notifier.Notify(readiness_token); };
|
||||||
return implementation_.template Request<RequestT, ResponseT>(to_address, from_address, std::move(request),
|
return implementation_.template Request<ResponseT>(to_address, from_address, std::forward<RequestT>(request),
|
||||||
fill_notifier, timeout);
|
fill_notifier, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,9 +150,9 @@ class Io {
|
|||||||
/// responses are not necessarily expected, and for servers to respond to requests.
|
/// responses are not necessarily expected, and for servers to respond to requests.
|
||||||
/// If you need reliable delivery, this must be built on-top. TCP is not enough for most use cases.
|
/// If you need reliable delivery, this must be built on-top. TCP is not enough for most use cases.
|
||||||
template <Message M>
|
template <Message M>
|
||||||
void Send(Address to_address, RequestId request_id, M message) {
|
void Send(Address to_address, RequestId request_id, M &&message) {
|
||||||
Address from_address = address_;
|
Address from_address = address_;
|
||||||
return implementation_.template Send<M>(to_address, from_address, request_id, std::move(message));
|
return implementation_.template Send<M>(to_address, from_address, request_id, std::forward<M>(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The current system time. This time source should be preferred over any other,
|
/// The current system time. This time source should be preferred over any other,
|
||||||
|
@ -23,7 +23,7 @@ add_custom_command(
|
|||||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${opencypher_generated}
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${opencypher_generated}
|
||||||
COMMAND
|
COMMAND
|
||||||
java -jar ${CMAKE_SOURCE_DIR}/libs/antlr-4.10.1-complete.jar
|
java -jar ${CMAKE_SOURCE_DIR}/libs/antlr-4.10.1-complete.jar
|
||||||
-Dlanguage=Cpp -visitor -package antlropencypher
|
-Dlanguage=Cpp -visitor -package antlropencypher::v2
|
||||||
-o ${opencypher_generated}
|
-o ${opencypher_generated}
|
||||||
${opencypher_lexer_grammar} ${opencypher_parser_grammar}
|
${opencypher_lexer_grammar} ${opencypher_parser_grammar}
|
||||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
|
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -14,10 +14,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "antlr4-runtime.h"
|
#include "antlr4-runtime.h"
|
||||||
#include "utils/exceptions.hpp"
|
|
||||||
#include "parser/opencypher/generated/MemgraphCypher.h"
|
#include "parser/opencypher/generated/MemgraphCypher.h"
|
||||||
#include "parser/opencypher/generated/MemgraphCypherLexer.h"
|
#include "parser/opencypher/generated/MemgraphCypherLexer.h"
|
||||||
#include "utils/concepts.hpp"
|
#include "utils/concepts.hpp"
|
||||||
|
#include "utils/exceptions.hpp"
|
||||||
|
|
||||||
namespace memgraph::frontend::opencypher {
|
namespace memgraph::frontend::opencypher {
|
||||||
|
|
||||||
@ -32,9 +32,7 @@ class SyntaxException : public utils::BasicException {
|
|||||||
* This thing must me a class since parser.cypher() returns pointer and there is
|
* This thing must me a class since parser.cypher() returns pointer and there is
|
||||||
* no way for us to get ownership over the object.
|
* no way for us to get ownership over the object.
|
||||||
*/
|
*/
|
||||||
enum class ParserOpTag : uint8_t {
|
enum class ParserOpTag : uint8_t { CYPHER, EXPRESSION };
|
||||||
CYPHER, EXPRESSION
|
|
||||||
};
|
|
||||||
|
|
||||||
template <ParserOpTag Tag = ParserOpTag::CYPHER>
|
template <ParserOpTag Tag = ParserOpTag::CYPHER>
|
||||||
class Parser {
|
class Parser {
|
||||||
@ -48,8 +46,7 @@ class Parser {
|
|||||||
parser_.addErrorListener(&error_listener_);
|
parser_.addErrorListener(&error_listener_);
|
||||||
if constexpr (Tag == ParserOpTag::CYPHER) {
|
if constexpr (Tag == ParserOpTag::CYPHER) {
|
||||||
tree_ = parser_.cypher();
|
tree_ = parser_.cypher();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
tree_ = parser_.expression();
|
tree_ = parser_.expression();
|
||||||
}
|
}
|
||||||
if (parser_.getNumberOfSyntaxErrors()) {
|
if (parser_.getNumberOfSyntaxErrors()) {
|
||||||
@ -75,11 +72,11 @@ class Parser {
|
|||||||
FirstMessageErrorListener error_listener_;
|
FirstMessageErrorListener error_listener_;
|
||||||
std::string query_;
|
std::string query_;
|
||||||
antlr4::ANTLRInputStream input_{query_};
|
antlr4::ANTLRInputStream input_{query_};
|
||||||
antlropencypher::MemgraphCypherLexer lexer_{&input_};
|
antlropencypher::v2::MemgraphCypherLexer lexer_{&input_};
|
||||||
antlr4::CommonTokenStream tokens_{&lexer_};
|
antlr4::CommonTokenStream tokens_{&lexer_};
|
||||||
|
|
||||||
// generate ast
|
// generate ast
|
||||||
antlropencypher::MemgraphCypher parser_{&tokens_};
|
antlropencypher::v2::MemgraphCypher parser_{&tokens_};
|
||||||
antlr4::tree::ParseTree *tree_ = nullptr;
|
antlr4::tree::ParseTree *tree_ = nullptr;
|
||||||
};
|
};
|
||||||
} // namespace memgraph::frontend::opencypher
|
} // namespace memgraph::frontend::opencypher
|
||||||
|
@ -48,18 +48,20 @@ add_dependencies(mg-query generate_lcp_query)
|
|||||||
target_include_directories(mg-query PUBLIC ${CMAKE_SOURCE_DIR}/include)
|
target_include_directories(mg-query PUBLIC ${CMAKE_SOURCE_DIR}/include)
|
||||||
target_link_libraries(mg-query dl cppitertools Boost::headers)
|
target_link_libraries(mg-query dl cppitertools Boost::headers)
|
||||||
target_link_libraries(mg-query mg-integrations-pulsar mg-integrations-kafka mg-storage-v2 mg-license mg-utils mg-kvstore mg-memory)
|
target_link_libraries(mg-query mg-integrations-pulsar mg-integrations-kafka mg-storage-v2 mg-license mg-utils mg-kvstore mg-memory)
|
||||||
|
|
||||||
if(NOT "${MG_PYTHON_PATH}" STREQUAL "")
|
if(NOT "${MG_PYTHON_PATH}" STREQUAL "")
|
||||||
set(Python3_ROOT_DIR "${MG_PYTHON_PATH}")
|
set(Python3_ROOT_DIR "${MG_PYTHON_PATH}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if("${MG_PYTHON_VERSION}" STREQUAL "")
|
if("${MG_PYTHON_VERSION}" STREQUAL "")
|
||||||
find_package(Python3 3.5 REQUIRED COMPONENTS Development)
|
find_package(Python3 3.5 REQUIRED COMPONENTS Development)
|
||||||
else()
|
else()
|
||||||
find_package(Python3 "${MG_PYTHON_VERSION}" EXACT REQUIRED COMPONENTS Development)
|
find_package(Python3 "${MG_PYTHON_VERSION}" EXACT REQUIRED COMPONENTS Development)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(mg-query Python3::Python)
|
target_link_libraries(mg-query Python3::Python)
|
||||||
|
|
||||||
# Generate Antlr openCypher parser
|
# Generate Antlr openCypher parser
|
||||||
|
|
||||||
set(opencypher_frontend ${CMAKE_CURRENT_SOURCE_DIR}/frontend/opencypher)
|
set(opencypher_frontend ${CMAKE_CURRENT_SOURCE_DIR}/frontend/opencypher)
|
||||||
set(opencypher_generated ${opencypher_frontend}/generated)
|
set(opencypher_generated ${opencypher_frontend}/generated)
|
||||||
set(opencypher_lexer_grammar ${opencypher_frontend}/grammar/MemgraphCypherLexer.g4)
|
set(opencypher_lexer_grammar ${opencypher_frontend}/grammar/MemgraphCypherLexer.g4)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -14,9 +14,9 @@
|
|||||||
#include "query/v2/request_router.hpp"
|
#include "query/v2/request_router.hpp"
|
||||||
|
|
||||||
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
|
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
DEFINE_HIDDEN_bool(query_cost_planner, true, "Use the cost-estimating query planner.");
|
DEFINE_HIDDEN_bool(query_v2_cost_planner, true, "Use the cost-estimating query planner.");
|
||||||
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
|
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
DEFINE_VALIDATED_int32(query_plan_cache_ttl, 60, "Time to live for cached query plans, in seconds.",
|
DEFINE_VALIDATED_int32(query_v2_plan_cache_ttl, 60, "Time to live for cached query plans, in seconds.",
|
||||||
FLAG_IN_RANGE(0, std::numeric_limits<int32_t>::max()));
|
FLAG_IN_RANGE(0, std::numeric_limits<int32_t>::max()));
|
||||||
|
|
||||||
namespace memgraph::query::v2 {
|
namespace memgraph::query::v2 {
|
||||||
@ -123,7 +123,7 @@ std::unique_ptr<LogicalPlan> MakeLogicalPlan(AstStorage ast_storage, CypherQuery
|
|||||||
auto vertex_counts = plan::MakeVertexCountCache(request_router);
|
auto vertex_counts = plan::MakeVertexCountCache(request_router);
|
||||||
auto symbol_table = expr::MakeSymbolTable(query, predefined_identifiers);
|
auto symbol_table = expr::MakeSymbolTable(query, predefined_identifiers);
|
||||||
auto planning_context = plan::MakePlanningContext(&ast_storage, &symbol_table, query, &vertex_counts);
|
auto planning_context = plan::MakePlanningContext(&ast_storage, &symbol_table, query, &vertex_counts);
|
||||||
auto [root, cost] = plan::MakeLogicalPlan(&planning_context, parameters, FLAGS_query_cost_planner);
|
auto [root, cost] = plan::MakeLogicalPlan(&planning_context, parameters, FLAGS_query_v2_cost_planner);
|
||||||
return std::make_unique<SingleNodeLogicalPlan>(std::move(root), cost, std::move(ast_storage),
|
return std::make_unique<SingleNodeLogicalPlan>(std::move(root), cost, std::move(ast_storage),
|
||||||
std::move(symbol_table));
|
std::move(symbol_table));
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -22,9 +22,9 @@
|
|||||||
#include "utils/timer.hpp"
|
#include "utils/timer.hpp"
|
||||||
|
|
||||||
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
|
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
DECLARE_bool(query_cost_planner);
|
DECLARE_bool(query_v2_cost_planner);
|
||||||
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
|
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
DECLARE_int32(query_plan_cache_ttl);
|
DECLARE_int32(query_v2_plan_cache_ttl);
|
||||||
|
|
||||||
namespace memgraph::query::v2 {
|
namespace memgraph::query::v2 {
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ class CachedPlan {
|
|||||||
|
|
||||||
bool IsExpired() const {
|
bool IsExpired() const {
|
||||||
// NOLINTNEXTLINE (modernize-use-nullptr)
|
// NOLINTNEXTLINE (modernize-use-nullptr)
|
||||||
return cache_timer_.Elapsed() > std::chrono::seconds(FLAGS_query_plan_cache_ttl);
|
return cache_timer_.Elapsed() > std::chrono::seconds(FLAGS_query_v2_plan_cache_ttl);
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -3087,25 +3087,18 @@ class DistributedExpandCursor : public Cursor {
|
|||||||
MG_ASSERT(direction != EdgeAtom::Direction::BOTH);
|
MG_ASSERT(direction != EdgeAtom::Direction::BOTH);
|
||||||
const auto &edge = frame[self_.common_.edge_symbol].ValueEdge();
|
const auto &edge = frame[self_.common_.edge_symbol].ValueEdge();
|
||||||
static constexpr auto get_dst_vertex = [](const EdgeAccessor &edge,
|
static constexpr auto get_dst_vertex = [](const EdgeAccessor &edge,
|
||||||
const EdgeAtom::Direction direction) -> msgs::VertexId {
|
const EdgeAtom::Direction direction) -> accessors::VertexAccessor {
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case EdgeAtom::Direction::IN:
|
case EdgeAtom::Direction::IN:
|
||||||
return edge.From().Id();
|
return edge.From();
|
||||||
case EdgeAtom::Direction::OUT:
|
case EdgeAtom::Direction::OUT:
|
||||||
return edge.To().Id();
|
return edge.To();
|
||||||
case EdgeAtom::Direction::BOTH:
|
case EdgeAtom::Direction::BOTH:
|
||||||
throw std::runtime_error("EdgeDirection Both not implemented");
|
throw std::runtime_error("EdgeDirection Both not implemented");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
msgs::GetPropertiesRequest request;
|
frame[self_.common_.node_symbol] = get_dst_vertex(edge, direction);
|
||||||
// to not fetch any properties of the edges
|
|
||||||
request.vertex_ids.push_back(get_dst_vertex(edge, direction));
|
|
||||||
auto result_rows = context.request_router->GetProperties(std::move(request));
|
|
||||||
MG_ASSERT(result_rows.size() == 1);
|
|
||||||
auto &result_row = result_rows.front();
|
|
||||||
frame[self_.common_.node_symbol] =
|
|
||||||
accessors::VertexAccessor(msgs::Vertex{result_row.vertex}, result_row.props, context.request_router);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InitEdges(Frame &frame, ExecutionContext &context) {
|
bool InitEdges(Frame &frame, ExecutionContext &context) {
|
||||||
@ -3129,6 +3122,8 @@ class DistributedExpandCursor : public Cursor {
|
|||||||
// to not fetch any properties of the edges
|
// to not fetch any properties of the edges
|
||||||
request.edge_properties.emplace();
|
request.edge_properties.emplace();
|
||||||
request.src_vertices.push_back(vertex.Id());
|
request.src_vertices.push_back(vertex.Id());
|
||||||
|
request.edge_properties.emplace();
|
||||||
|
request.src_vertex_properties.emplace();
|
||||||
auto result_rows = std::invoke([&context, &request]() mutable {
|
auto result_rows = std::invoke([&context, &request]() mutable {
|
||||||
SCOPED_REQUEST_WAIT_PROFILE;
|
SCOPED_REQUEST_WAIT_PROFILE;
|
||||||
return context.request_router->ExpandOne(std::move(request));
|
return context.request_router->ExpandOne(std::move(request));
|
||||||
@ -3271,6 +3266,7 @@ class DistributedExpandCursor : public Cursor {
|
|||||||
[](const storage::v3::EdgeTypeId edge_type_id) { return msgs::EdgeType{edge_type_id}; });
|
[](const storage::v3::EdgeTypeId edge_type_id) { return msgs::EdgeType{edge_type_id}; });
|
||||||
// to not fetch any properties of the edges
|
// to not fetch any properties of the edges
|
||||||
request.edge_properties.emplace();
|
request.edge_properties.emplace();
|
||||||
|
request.src_vertex_properties.emplace();
|
||||||
for (const auto &frame : own_multi_frame_->GetValidFramesReader()) {
|
for (const auto &frame : own_multi_frame_->GetValidFramesReader()) {
|
||||||
const auto &vertex_value = frame[self_.input_symbol_];
|
const auto &vertex_value = frame[self_.input_symbol_];
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -13,7 +13,8 @@
|
|||||||
|
|
||||||
#include "utils/flag_validation.hpp"
|
#include "utils/flag_validation.hpp"
|
||||||
|
|
||||||
DEFINE_VALIDATED_HIDDEN_int64(query_vertex_count_to_expand_existing, 10,
|
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
DEFINE_VALIDATED_HIDDEN_int64(query_v2_vertex_count_to_expand_existing, 10,
|
||||||
"Maximum count of indexed vertices which provoke "
|
"Maximum count of indexed vertices which provoke "
|
||||||
"indexed lookup and then expand to existing, instead of "
|
"indexed lookup and then expand to existing, instead of "
|
||||||
"a regular expand. Default is 10, to turn off use -1.",
|
"a regular expand. Default is 10, to turn off use -1.",
|
||||||
|
@ -30,7 +30,8 @@
|
|||||||
#include "query/v2/plan/preprocess.hpp"
|
#include "query/v2/plan/preprocess.hpp"
|
||||||
#include "storage/v3/id_types.hpp"
|
#include "storage/v3/id_types.hpp"
|
||||||
|
|
||||||
DECLARE_int64(query_vertex_count_to_expand_existing);
|
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
DECLARE_int64(query_v2_vertex_count_to_expand_existing);
|
||||||
|
|
||||||
namespace memgraph::query::v2::plan {
|
namespace memgraph::query::v2::plan {
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ class IndexLookupRewriter final : public HierarchicalLogicalOperatorVisitor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
ScanAll dst_scan(expand.input(), expand.common_.node_symbol, expand.view_);
|
ScanAll dst_scan(expand.input(), expand.common_.node_symbol, expand.view_);
|
||||||
auto indexed_scan = GenScanByIndex(dst_scan, FLAGS_query_vertex_count_to_expand_existing);
|
auto indexed_scan = GenScanByIndex(dst_scan, FLAGS_query_v2_vertex_count_to_expand_existing);
|
||||||
if (indexed_scan) {
|
if (indexed_scan) {
|
||||||
expand.set_input(std::move(indexed_scan));
|
expand.set_input(std::move(indexed_scan));
|
||||||
expand.common_.existing_node = true;
|
expand.common_.existing_node = true;
|
||||||
@ -129,7 +130,7 @@ class IndexLookupRewriter final : public HierarchicalLogicalOperatorVisitor {
|
|||||||
// unconditionally creating an indexed scan.
|
// unconditionally creating an indexed scan.
|
||||||
indexed_scan = GenScanByIndex(dst_scan);
|
indexed_scan = GenScanByIndex(dst_scan);
|
||||||
} else {
|
} else {
|
||||||
indexed_scan = GenScanByIndex(dst_scan, FLAGS_query_vertex_count_to_expand_existing);
|
indexed_scan = GenScanByIndex(dst_scan, FLAGS_query_v2_vertex_count_to_expand_existing);
|
||||||
}
|
}
|
||||||
if (indexed_scan) {
|
if (indexed_scan) {
|
||||||
expand.set_input(std::move(indexed_scan));
|
expand.set_input(std::move(indexed_scan));
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -17,7 +17,8 @@
|
|||||||
#include "utils/flag_validation.hpp"
|
#include "utils/flag_validation.hpp"
|
||||||
#include "utils/logging.hpp"
|
#include "utils/logging.hpp"
|
||||||
|
|
||||||
DEFINE_VALIDATED_HIDDEN_uint64(query_max_plans, 1000U, "Maximum number of generated plans for a query.",
|
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
DEFINE_VALIDATED_HIDDEN_uint64(query_v2_max_plans, 1000U, "Maximum number of generated plans for a query.",
|
||||||
FLAG_IN_RANGE(1, std::numeric_limits<std::uint64_t>::max()));
|
FLAG_IN_RANGE(1, std::numeric_limits<std::uint64_t>::max()));
|
||||||
|
|
||||||
namespace memgraph::query::v2::plan::impl {
|
namespace memgraph::query::v2::plan::impl {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
#include "query/v2/plan/rule_based_planner.hpp"
|
#include "query/v2/plan/rule_based_planner.hpp"
|
||||||
|
|
||||||
DECLARE_uint64(query_max_plans);
|
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
DECLARE_uint64(query_v2_max_plans);
|
||||||
|
|
||||||
namespace memgraph::query::v2::plan {
|
namespace memgraph::query::v2::plan {
|
||||||
|
|
||||||
@ -310,7 +311,7 @@ class VariableStartPlanner {
|
|||||||
for (const auto &query_part : query_parts) {
|
for (const auto &query_part : query_parts) {
|
||||||
alternative_query_parts.emplace_back(impl::VaryQueryPartMatching(query_part, symbol_table));
|
alternative_query_parts.emplace_back(impl::VaryQueryPartMatching(query_part, symbol_table));
|
||||||
}
|
}
|
||||||
return iter::slice(MakeCartesianProduct(std::move(alternative_query_parts)), 0UL, FLAGS_query_max_plans);
|
return iter::slice(MakeCartesianProduct(std::move(alternative_query_parts)), 0UL, FLAGS_query_v2_max_plans);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -323,8 +323,8 @@ class RequestRouter : public RequestRouterInterface {
|
|||||||
io::ReadinessToken readiness_token{i};
|
io::ReadinessToken readiness_token{i};
|
||||||
auto &storage_client = GetStorageClientForShard(request.shard);
|
auto &storage_client = GetStorageClientForShard(request.shard);
|
||||||
msgs::WriteRequests req = request.request;
|
msgs::WriteRequests req = request.request;
|
||||||
storage_client.SendAsyncWriteRequest(req, notifier_, readiness_token);
|
storage_client.SendAsyncWriteRequest(std::move(req), notifier_, readiness_token);
|
||||||
running_requests.emplace(readiness_token.GetId(), request);
|
running_requests.emplace(readiness_token.GetId(), std::move(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
// drive requests to completion
|
// drive requests to completion
|
||||||
@ -339,7 +339,8 @@ class RequestRouter : public RequestRouterInterface {
|
|||||||
// must be fetched again with an ExpandOne(Edges.dst)
|
// must be fetched again with an ExpandOne(Edges.dst)
|
||||||
|
|
||||||
// create requests
|
// create requests
|
||||||
std::vector<ShardRequestState<msgs::ExpandOneRequest>> requests_to_be_sent = RequestsForExpandOne(request);
|
std::vector<ShardRequestState<msgs::ExpandOneRequest>> requests_to_be_sent =
|
||||||
|
RequestsForExpandOne(std::move(request));
|
||||||
|
|
||||||
// begin all requests in parallel
|
// begin all requests in parallel
|
||||||
RunningRequests<msgs::ExpandOneRequest> running_requests = {};
|
RunningRequests<msgs::ExpandOneRequest> running_requests = {};
|
||||||
@ -349,8 +350,8 @@ class RequestRouter : public RequestRouterInterface {
|
|||||||
io::ReadinessToken readiness_token{i};
|
io::ReadinessToken readiness_token{i};
|
||||||
auto &storage_client = GetStorageClientForShard(request.shard);
|
auto &storage_client = GetStorageClientForShard(request.shard);
|
||||||
msgs::ReadRequests req = request.request;
|
msgs::ReadRequests req = request.request;
|
||||||
storage_client.SendAsyncReadRequest(req, notifier_, readiness_token);
|
storage_client.SendAsyncReadRequest(std::move(req), notifier_, readiness_token);
|
||||||
running_requests.emplace(readiness_token.GetId(), request);
|
running_requests.emplace(readiness_token.GetId(), std::move(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
// drive requests to completion
|
// drive requests to completion
|
||||||
@ -386,8 +387,8 @@ class RequestRouter : public RequestRouterInterface {
|
|||||||
io::ReadinessToken readiness_token{i};
|
io::ReadinessToken readiness_token{i};
|
||||||
auto &storage_client = GetStorageClientForShard(request.shard);
|
auto &storage_client = GetStorageClientForShard(request.shard);
|
||||||
msgs::ReadRequests req = request.request;
|
msgs::ReadRequests req = request.request;
|
||||||
storage_client.SendAsyncReadRequest(req, notifier_, readiness_token);
|
storage_client.SendAsyncReadRequest(std::move(req), notifier_, readiness_token);
|
||||||
running_requests.emplace(readiness_token.GetId(), request);
|
running_requests.emplace(readiness_token.GetId(), std::move(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
// drive requests to completion
|
// drive requests to completion
|
||||||
@ -503,6 +504,7 @@ class RequestRouter : public RequestRouterInterface {
|
|||||||
|
|
||||||
msgs::ScanVerticesRequest request;
|
msgs::ScanVerticesRequest request;
|
||||||
request.transaction_id = transaction_id_;
|
request.transaction_id = transaction_id_;
|
||||||
|
request.props_to_return.emplace();
|
||||||
request.start_id.second = storage::conversions::ConvertValueVector(key);
|
request.start_id.second = storage::conversions::ConvertValueVector(key);
|
||||||
|
|
||||||
ShardRequestState<msgs::ScanVerticesRequest> shard_request_state{
|
ShardRequestState<msgs::ScanVerticesRequest> shard_request_state{
|
||||||
@ -517,7 +519,7 @@ class RequestRouter : public RequestRouterInterface {
|
|||||||
return requests;
|
return requests;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ShardRequestState<msgs::ExpandOneRequest>> RequestsForExpandOne(const msgs::ExpandOneRequest &request) {
|
std::vector<ShardRequestState<msgs::ExpandOneRequest>> RequestsForExpandOne(msgs::ExpandOneRequest &&request) {
|
||||||
std::map<ShardMetadata, msgs::ExpandOneRequest> per_shard_request_table;
|
std::map<ShardMetadata, msgs::ExpandOneRequest> per_shard_request_table;
|
||||||
msgs::ExpandOneRequest top_level_rqst_template = request;
|
msgs::ExpandOneRequest top_level_rqst_template = request;
|
||||||
top_level_rqst_template.transaction_id = transaction_id_;
|
top_level_rqst_template.transaction_id = transaction_id_;
|
||||||
@ -529,7 +531,7 @@ class RequestRouter : public RequestRouterInterface {
|
|||||||
if (!per_shard_request_table.contains(shard)) {
|
if (!per_shard_request_table.contains(shard)) {
|
||||||
per_shard_request_table.insert(std::pair(shard, top_level_rqst_template));
|
per_shard_request_table.insert(std::pair(shard, top_level_rqst_template));
|
||||||
}
|
}
|
||||||
per_shard_request_table[shard].src_vertices.push_back(vertex);
|
per_shard_request_table[shard].src_vertices.push_back(std::move(vertex));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ShardRequestState<msgs::ExpandOneRequest>> requests = {};
|
std::vector<ShardRequestState<msgs::ExpandOneRequest>> requests = {};
|
||||||
@ -726,10 +728,10 @@ class RequestRouter : public RequestRouterInterface {
|
|||||||
coordinator::CoordinatorWriteRequests requests{coordinator::AllocateEdgeIdBatchRequest{.batch_size = 1000000}};
|
coordinator::CoordinatorWriteRequests requests{coordinator::AllocateEdgeIdBatchRequest{.batch_size = 1000000}};
|
||||||
|
|
||||||
io::rsm::WriteRequest<coordinator::CoordinatorWriteRequests> ww;
|
io::rsm::WriteRequest<coordinator::CoordinatorWriteRequests> ww;
|
||||||
ww.operation = requests;
|
ww.operation = std::move(requests);
|
||||||
auto resp =
|
auto resp = io_.template Request<io::rsm::WriteResponse<coordinator::CoordinatorWriteResponses>,
|
||||||
io_.template Request<io::rsm::WriteRequest<coordinator::CoordinatorWriteRequests>,
|
io::rsm::WriteRequest<coordinator::CoordinatorWriteRequests>>(coordinator_address,
|
||||||
io::rsm::WriteResponse<coordinator::CoordinatorWriteResponses>>(coordinator_address, ww)
|
std::move(ww))
|
||||||
.Wait();
|
.Wait();
|
||||||
if (resp.HasValue()) {
|
if (resp.HasValue()) {
|
||||||
const auto alloc_edge_id_reps =
|
const auto alloc_edge_id_reps =
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -35,7 +35,7 @@ msgs::Value ConstructValueVertex(const VertexAccessor &acc, View view) {
|
|||||||
memgraph::msgs::Label value_label{.id = prim_label};
|
memgraph::msgs::Label value_label{.id = prim_label};
|
||||||
|
|
||||||
auto prim_key = conversions::ConvertValueVector(acc.PrimaryKey(view).GetValue());
|
auto prim_key = conversions::ConvertValueVector(acc.PrimaryKey(view).GetValue());
|
||||||
memgraph::msgs::VertexId vertex_id = std::make_pair(value_label, prim_key);
|
memgraph::msgs::VertexId vertex_id = std::make_pair(value_label, std::move(prim_key));
|
||||||
|
|
||||||
// Get the labels
|
// Get the labels
|
||||||
auto vertex_labels = acc.Labels(view).GetValue();
|
auto vertex_labels = acc.Labels(view).GetValue();
|
||||||
@ -45,7 +45,7 @@ msgs::Value ConstructValueVertex(const VertexAccessor &acc, View view) {
|
|||||||
std::transform(vertex_labels.begin(), vertex_labels.end(), std::back_inserter(value_labels),
|
std::transform(vertex_labels.begin(), vertex_labels.end(), std::back_inserter(value_labels),
|
||||||
[](const auto &label) { return msgs::Label{.id = label}; });
|
[](const auto &label) { return msgs::Label{.id = label}; });
|
||||||
|
|
||||||
return msgs::Value({.id = vertex_id, .labels = value_labels});
|
return msgs::Value({.id = std::move(vertex_id), .labels = std::move(value_labels)});
|
||||||
}
|
}
|
||||||
|
|
||||||
msgs::Value ConstructValueEdge(const EdgeAccessor &acc, View view) {
|
msgs::Value ConstructValueEdge(const EdgeAccessor &acc, View view) {
|
||||||
|
@ -46,7 +46,6 @@ struct VertexIdCmpr {
|
|||||||
std::optional<std::map<PropertyId, Value>> PrimaryKeysFromAccessor(const VertexAccessor &acc, View view,
|
std::optional<std::map<PropertyId, Value>> PrimaryKeysFromAccessor(const VertexAccessor &acc, View view,
|
||||||
const Schemas::Schema &schema) {
|
const Schemas::Schema &schema) {
|
||||||
std::map<PropertyId, Value> ret;
|
std::map<PropertyId, Value> ret;
|
||||||
auto props = acc.Properties(view);
|
|
||||||
auto maybe_pk = acc.PrimaryKey(view);
|
auto maybe_pk = acc.PrimaryKey(view);
|
||||||
if (maybe_pk.HasError()) {
|
if (maybe_pk.HasError()) {
|
||||||
spdlog::debug("Encountered an error while trying to get vertex primary key.");
|
spdlog::debug("Encountered an error while trying to get vertex primary key.");
|
||||||
@ -58,7 +57,7 @@ std::optional<std::map<PropertyId, Value>> PrimaryKeysFromAccessor(const VertexA
|
|||||||
ret.emplace(schema.second[i].property_id, FromPropertyValueToValue(std::move(pk[i])));
|
ret.emplace(schema.second[i].property_id, FromPropertyValueToValue(std::move(pk[i])));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return {std::move(ret)};
|
||||||
}
|
}
|
||||||
|
|
||||||
ShardResult<std::vector<msgs::Label>> FillUpSourceVertexSecondaryLabels(const std::optional<VertexAccessor> &v_acc,
|
ShardResult<std::vector<msgs::Label>> FillUpSourceVertexSecondaryLabels(const std::optional<VertexAccessor> &v_acc,
|
||||||
@ -99,7 +98,7 @@ ShardResult<std::map<PropertyId, Value>> FillUpSourceVertexProperties(const std:
|
|||||||
}
|
}
|
||||||
auto pks = PrimaryKeysFromAccessor(*v_acc, view, schema);
|
auto pks = PrimaryKeysFromAccessor(*v_acc, view, schema);
|
||||||
if (pks) {
|
if (pks) {
|
||||||
src_vertex_properties.merge(*pks);
|
src_vertex_properties.merge(std::move(*pks));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (req.src_vertex_properties.value().empty()) {
|
} else if (req.src_vertex_properties.value().empty()) {
|
||||||
@ -384,13 +383,10 @@ bool FilterOnEdge(DbAccessor &dba, const storage::v3::VertexAccessor &v_acc, con
|
|||||||
}
|
}
|
||||||
|
|
||||||
ShardResult<msgs::ExpandOneResultRow> GetExpandOneResult(
|
ShardResult<msgs::ExpandOneResultRow> GetExpandOneResult(
|
||||||
Shard::Accessor &acc, msgs::VertexId src_vertex, const msgs::ExpandOneRequest &req,
|
VertexAccessor v_acc, msgs::VertexId src_vertex, const msgs::ExpandOneRequest &req,
|
||||||
const EdgeUniquenessFunction &maybe_filter_based_on_edge_uniqueness, const EdgeFiller &edge_filler,
|
const EdgeUniquenessFunction &maybe_filter_based_on_edge_uniqueness, const EdgeFiller &edge_filler,
|
||||||
const Schemas::Schema &schema) {
|
const Schemas::Schema &schema) {
|
||||||
/// Fill up source vertex
|
/// Fill up source vertex
|
||||||
const auto primary_key = ConvertPropertyVector(src_vertex.second);
|
|
||||||
auto v_acc = acc.FindVertex(primary_key, View::NEW);
|
|
||||||
|
|
||||||
msgs::Vertex source_vertex = {.id = src_vertex};
|
msgs::Vertex source_vertex = {.id = src_vertex};
|
||||||
auto maybe_secondary_labels = FillUpSourceVertexSecondaryLabels(v_acc, req);
|
auto maybe_secondary_labels = FillUpSourceVertexSecondaryLabels(v_acc, req);
|
||||||
if (maybe_secondary_labels.HasError()) {
|
if (maybe_secondary_labels.HasError()) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -233,7 +233,7 @@ ShardResult<std::map<PropertyId, Value>> CollectAllPropertiesImpl(const TAccesso
|
|||||||
[](std::pair<const PropertyId, PropertyValue> &pair) {
|
[](std::pair<const PropertyId, PropertyValue> &pair) {
|
||||||
return std::make_pair(pair.first, conversions::FromPropertyValueToValue(std::move(pair.second)));
|
return std::make_pair(pair.first, conversions::FromPropertyValueToValue(std::move(pair.second)));
|
||||||
});
|
});
|
||||||
return ret;
|
return {std::move(ret)};
|
||||||
}
|
}
|
||||||
} // namespace impl
|
} // namespace impl
|
||||||
|
|
||||||
@ -247,7 +247,7 @@ EdgeUniquenessFunction InitializeEdgeUniquenessFunction(bool only_unique_neighbo
|
|||||||
EdgeFiller InitializeEdgeFillerFunction(const msgs::ExpandOneRequest &req);
|
EdgeFiller InitializeEdgeFillerFunction(const msgs::ExpandOneRequest &req);
|
||||||
|
|
||||||
ShardResult<msgs::ExpandOneResultRow> GetExpandOneResult(
|
ShardResult<msgs::ExpandOneResultRow> GetExpandOneResult(
|
||||||
Shard::Accessor &acc, msgs::VertexId src_vertex, const msgs::ExpandOneRequest &req,
|
VertexAccessor v_acc, msgs::VertexId src_vertex, const msgs::ExpandOneRequest &req,
|
||||||
const EdgeUniquenessFunction &maybe_filter_based_on_edge_uniqueness, const EdgeFiller &edge_filler,
|
const EdgeUniquenessFunction &maybe_filter_based_on_edge_uniqueness, const EdgeFiller &edge_filler,
|
||||||
const Schemas::Schema &schema);
|
const Schemas::Schema &schema);
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -250,8 +250,8 @@ class ShardManager {
|
|||||||
|
|
||||||
spdlog::info("SM sending heartbeat to coordinator {}", coordinator_leader_.ToString());
|
spdlog::info("SM sending heartbeat to coordinator {}", coordinator_leader_.ToString());
|
||||||
heartbeat_res_.emplace(std::move(
|
heartbeat_res_.emplace(std::move(
|
||||||
io_.template Request<WriteRequest<CoordinatorWriteRequests>, WriteResponse<CoordinatorWriteResponses>>(
|
io_.template Request<WriteResponse<CoordinatorWriteResponses>, WriteRequest<CoordinatorWriteRequests>>(
|
||||||
coordinator_leader_, ww)));
|
coordinator_leader_, std::move(ww))));
|
||||||
spdlog::info("SM sent heartbeat");
|
spdlog::info("SM sent heartbeat");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,7 +472,8 @@ msgs::ReadResponses ShardRsm::HandleRead(msgs::ExpandOneRequest &&req) {
|
|||||||
if (req.order_by_edges.empty()) {
|
if (req.order_by_edges.empty()) {
|
||||||
const auto *schema = shard_->GetSchema(shard_->PrimaryLabel());
|
const auto *schema = shard_->GetSchema(shard_->PrimaryLabel());
|
||||||
MG_ASSERT(schema);
|
MG_ASSERT(schema);
|
||||||
return GetExpandOneResult(acc, src_vertex, req, maybe_filter_based_on_edge_uniqueness, edge_filler, *schema);
|
return GetExpandOneResult(src_vertex_acc, std::move(src_vertex), req, maybe_filter_based_on_edge_uniqueness,
|
||||||
|
edge_filler, *schema);
|
||||||
}
|
}
|
||||||
auto [in_edge_accessors, out_edge_accessors] = GetEdgesFromVertex(src_vertex_acc, req.direction);
|
auto [in_edge_accessors, out_edge_accessors] = GetEdgesFromVertex(src_vertex_acc, req.direction);
|
||||||
const auto in_ordered_edges = OrderByEdges(dba, in_edge_accessors, req.order_by_edges, src_vertex_acc);
|
const auto in_ordered_edges = OrderByEdges(dba, in_edge_accessors, req.order_by_edges, src_vertex_acc);
|
||||||
@ -487,12 +488,13 @@ msgs::ReadResponses ShardRsm::HandleRead(msgs::ExpandOneRequest &&req) {
|
|||||||
[](const auto &edge_element) { return edge_element.object_acc; });
|
[](const auto &edge_element) { return edge_element.object_acc; });
|
||||||
const auto *schema = shard_->GetSchema(shard_->PrimaryLabel());
|
const auto *schema = shard_->GetSchema(shard_->PrimaryLabel());
|
||||||
MG_ASSERT(schema);
|
MG_ASSERT(schema);
|
||||||
return GetExpandOneResult(src_vertex_acc, src_vertex, req, in_edge_ordered_accessors, out_edge_ordered_accessors,
|
return GetExpandOneResult(src_vertex_acc, std::move(src_vertex), req, std::move(in_edge_ordered_accessors),
|
||||||
maybe_filter_based_on_edge_uniqueness, edge_filler, *schema);
|
std::move(out_edge_ordered_accessors), maybe_filter_based_on_edge_uniqueness,
|
||||||
|
edge_filler, *schema);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (maybe_result.HasError()) {
|
if (maybe_result.HasError()) {
|
||||||
shard_error.emplace(CreateErrorResponse(primary_key.GetError(), req.transaction_id, "getting primary key"));
|
shard_error.emplace(CreateErrorResponse(maybe_result.GetError(), req.transaction_id, "getting expand result"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,12 +583,12 @@ msgs::ReadResponses ShardRsm::HandleRead(msgs::GetPropertiesRequest &&req) {
|
|||||||
if (maybe_id.HasError()) {
|
if (maybe_id.HasError()) {
|
||||||
return {maybe_id.GetError()};
|
return {maybe_id.GetError()};
|
||||||
}
|
}
|
||||||
const auto &id = maybe_id.GetValue();
|
auto &vertex_id = maybe_id.GetValue();
|
||||||
std::optional<msgs::EdgeId> e_id;
|
std::optional<msgs::EdgeId> e_id;
|
||||||
if (e_acc) {
|
if (e_acc) {
|
||||||
e_id = msgs::EdgeId{e_acc->Gid().AsUint()};
|
e_id = msgs::EdgeId{e_acc->Gid().AsUint()};
|
||||||
}
|
}
|
||||||
msgs::VertexId v_id{msgs::Label{id.primary_label}, ConvertValueVector(id.primary_key)};
|
msgs::VertexId v_id{msgs::Label{vertex_id.primary_label}, ConvertValueVector(std::move(vertex_id.primary_key))};
|
||||||
auto maybe_props = collect_props(v_acc, e_acc);
|
auto maybe_props = collect_props(v_acc, e_acc);
|
||||||
if (maybe_props.HasError()) {
|
if (maybe_props.HasError()) {
|
||||||
return {maybe_props.GetError()};
|
return {maybe_props.GetError()};
|
||||||
|
@ -57,7 +57,7 @@ class ShardRsm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
|
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
|
||||||
msgs::ReadResponses Read(msgs::ReadRequests requests) {
|
msgs::ReadResponses Read(msgs::ReadRequests &&requests) {
|
||||||
return std::visit([&](auto &&request) mutable { return HandleRead(std::forward<decltype(request)>(request)); },
|
return std::visit([&](auto &&request) mutable { return HandleRead(std::forward<decltype(request)>(request)); },
|
||||||
std::move(requests));
|
std::move(requests));
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -100,7 +100,7 @@ class Queue {
|
|||||||
|
|
||||||
inner_->submitted++;
|
inner_->submitted++;
|
||||||
|
|
||||||
inner_->queue.emplace_back(std::forward<Message>(message));
|
inner_->queue.emplace_back(std::move(message));
|
||||||
} // lock dropped before notifying condition variable
|
} // lock dropped before notifying condition variable
|
||||||
|
|
||||||
inner_->cv.notify_all();
|
inner_->cv.notify_all();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -126,6 +126,17 @@ inline std::vector<Value> ConvertValueVector(const std::vector<v3::PropertyValue
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::vector<Value> ConvertValueVector(std::vector<v3::PropertyValue> &&vec) {
|
||||||
|
std::vector<Value> ret;
|
||||||
|
ret.reserve(vec.size());
|
||||||
|
|
||||||
|
for (auto &&elem : vec) {
|
||||||
|
ret.push_back(FromPropertyValueToValue(std::move(elem)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
inline msgs::VertexId ToMsgsVertexId(const v3::VertexId &vertex_id) {
|
inline msgs::VertexId ToMsgsVertexId(const v3::VertexId &vertex_id) {
|
||||||
return {msgs::Label{vertex_id.primary_label}, ConvertValueVector(vertex_id.primary_key)};
|
return {msgs::Label{vertex_id.primary_label}, ConvertValueVector(vertex_id.primary_key)};
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -12,6 +12,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <concepts>
|
#include <concepts>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace memgraph::utils {
|
namespace memgraph::utils {
|
||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
@ -34,4 +35,7 @@ template <typename T>
|
|||||||
concept Dereferenceable = requires(T t) {
|
concept Dereferenceable = requires(T t) {
|
||||||
{ *t } -> CanReference;
|
{ *t } -> CanReference;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
concept Object = std::is_object_v<T>;
|
||||||
} // namespace memgraph::utils
|
} // namespace memgraph::utils
|
||||||
|
@ -36,7 +36,9 @@ def test_awesome_memgraph_functions(connection):
|
|||||||
assert len(results) == 1
|
assert len(results) == 1
|
||||||
assert results[0][0] == 5
|
assert results[0][0] == 5
|
||||||
|
|
||||||
results = execute_and_fetch_all(cursor, "MATCH (n) WITH COLLECT(n.property) as nn RETURN ALL(i IN nn WHERE i > 0)")
|
results = execute_and_fetch_all(
|
||||||
|
cursor, "UNWIND [2, 1, 3] AS value WITH COLLECT(value) as nn RETURN ALL(i IN nn WHERE i > 0)"
|
||||||
|
)
|
||||||
assert len(results) == 1
|
assert len(results) == 1
|
||||||
assert results[0][0] == True
|
assert results[0][0] == True
|
||||||
|
|
||||||
|
@ -9,11 +9,13 @@
|
|||||||
# by the Apache License, Version 2.0, included in the file
|
# by the Apache License, Version 2.0, included in the file
|
||||||
# licenses/APL.txt.
|
# licenses/APL.txt.
|
||||||
|
|
||||||
import typing
|
|
||||||
import mgclient
|
|
||||||
import sys
|
import sys
|
||||||
import pytest
|
|
||||||
import time
|
import time
|
||||||
|
import typing
|
||||||
|
|
||||||
|
import mgclient
|
||||||
|
import pytest
|
||||||
|
|
||||||
from common import *
|
from common import *
|
||||||
|
|
||||||
|
|
||||||
@ -30,8 +32,7 @@ def test_distinct(connection):
|
|||||||
assert len(results) == 2
|
assert len(results) == 2
|
||||||
for i, n in enumerate(results):
|
for i, n in enumerate(results):
|
||||||
n_props = n[0].properties
|
n_props = n[0].properties
|
||||||
assert len(n_props) == 1
|
assert len(n_props) == 0
|
||||||
assert n_props["property"] == i
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -13,7 +13,12 @@ import sys
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from common import connection, execute_and_fetch_all, has_n_result_row, wait_for_shard_manager_to_initialize
|
from common import (
|
||||||
|
connection,
|
||||||
|
execute_and_fetch_all,
|
||||||
|
has_n_result_row,
|
||||||
|
wait_for_shard_manager_to_initialize,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_sequenced_expand_one(connection):
|
def test_sequenced_expand_one(connection):
|
||||||
@ -22,15 +27,21 @@ def test_sequenced_expand_one(connection):
|
|||||||
|
|
||||||
for i in range(1, 4):
|
for i in range(1, 4):
|
||||||
assert has_n_result_row(cursor, f"CREATE (:label {{property:{i}}})", 0), f"Failed creating node"
|
assert has_n_result_row(cursor, f"CREATE (:label {{property:{i}}})", 0), f"Failed creating node"
|
||||||
assert has_n_result_row(cursor, "MATCH (n {property:1}), (m {property:2}) CREATE (n)-[:TO]->(m)", 0)
|
assert has_n_result_row(cursor, "MATCH (n:label {property:1}), (m:label {property:2}) CREATE (n)-[:TO]->(m)", 0)
|
||||||
assert has_n_result_row(cursor, "MATCH (n {property:2}), (m {property:3}) CREATE (n)-[:TO]->(m)", 0)
|
assert has_n_result_row(cursor, "MATCH (n:label {property:2}), (m:label {property:3}) CREATE (n)-[:TO]->(m)", 0)
|
||||||
|
|
||||||
results = execute_and_fetch_all(cursor, "MATCH (n)-[:TO]->(m)-[:TO]->(l) RETURN n,m,l")
|
results = execute_and_fetch_all(cursor, "MATCH (n)-[:TO]->(m)-[:TO]->(l) RETURN n,m,l")
|
||||||
assert len(results) == 1
|
assert len(results) == 1
|
||||||
n, m, l = results[0]
|
n, m, l = results[0]
|
||||||
assert n.properties["property"] == 1
|
assert (
|
||||||
assert m.properties["property"] == 2
|
len(n.properties) == 0
|
||||||
assert l.properties["property"] == 3
|
), "we don't return any properties of the node received from expansion and the bolt layer doesn't serialize the primary key of vertices"
|
||||||
|
assert (
|
||||||
|
len(m.properties) == 0
|
||||||
|
), "we don't return any properties of the node received from expansion and the bolt layer doesn't serialize the primary key of vertices"
|
||||||
|
assert (
|
||||||
|
len(l.properties) == 0
|
||||||
|
), "we don't return any properties of the node received from expansion and the bolt layer doesn't serialize the primary key of vertices"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -9,11 +9,13 @@
|
|||||||
# by the Apache License, Version 2.0, included in the file
|
# by the Apache License, Version 2.0, included in the file
|
||||||
# licenses/APL.txt.
|
# licenses/APL.txt.
|
||||||
|
|
||||||
import typing
|
|
||||||
import mgclient
|
|
||||||
import sys
|
import sys
|
||||||
import pytest
|
|
||||||
import time
|
import time
|
||||||
|
import typing
|
||||||
|
|
||||||
|
import mgclient
|
||||||
|
import pytest
|
||||||
|
|
||||||
from common import *
|
from common import *
|
||||||
|
|
||||||
|
|
||||||
@ -35,13 +37,13 @@ def test_vertex_creation_and_scanall(connection):
|
|||||||
assert len(results) == 9
|
assert len(results) == 9
|
||||||
for (n, r, m) in results:
|
for (n, r, m) in results:
|
||||||
n_props = n.properties
|
n_props = n.properties
|
||||||
assert len(n_props) == 1, "n is not expected to have properties, update the test!"
|
assert len(n_props) == 0, "n is not expected to have properties, update the test!"
|
||||||
assert len(n.labels) == 0, "n is not expected to have labels, update the test!"
|
assert len(n.labels) == 0, "n is not expected to have labels, update the test!"
|
||||||
|
|
||||||
assert r.type == "TO"
|
assert r.type == "TO"
|
||||||
|
|
||||||
m_props = m.properties
|
m_props = m.properties
|
||||||
assert m_props["property"] <= 3 and m_props["property"] >= 0, "Wrong key"
|
assert len(m_props) == 0, "n is not expected to have properties, update the test!"
|
||||||
assert len(m.labels) == 0, "m is not expected to have labels, update the test!"
|
assert len(m.labels) == 0, "m is not expected to have labels, update the test!"
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,11 +9,13 @@
|
|||||||
# by the Apache License, Version 2.0, included in the file
|
# by the Apache License, Version 2.0, included in the file
|
||||||
# licenses/APL.txt.
|
# licenses/APL.txt.
|
||||||
|
|
||||||
import typing
|
|
||||||
import mgclient
|
|
||||||
import sys
|
import sys
|
||||||
import pytest
|
|
||||||
import time
|
import time
|
||||||
|
import typing
|
||||||
|
|
||||||
|
import mgclient
|
||||||
|
import pytest
|
||||||
|
|
||||||
from common import *
|
from common import *
|
||||||
|
|
||||||
|
|
||||||
@ -21,23 +23,23 @@ def test_order_by_and_limit(connection):
|
|||||||
wait_for_shard_manager_to_initialize()
|
wait_for_shard_manager_to_initialize()
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
assert has_n_result_row(cursor, "CREATE (n :label {property:1})", 0)
|
results = execute_and_fetch_all(
|
||||||
assert has_n_result_row(cursor, "CREATE (n :label {property:2})", 0)
|
cursor,
|
||||||
assert has_n_result_row(cursor, "CREATE (n :label {property:3})", 0)
|
"UNWIND [{property:1}, {property:3}, {property:2}] AS map RETURN map ORDER BY map.property DESC",
|
||||||
assert has_n_result_row(cursor, "CREATE (n :label {property:4})", 0)
|
)
|
||||||
|
assert len(results) == 3
|
||||||
results = execute_and_fetch_all(cursor, "MATCH (n) RETURN n ORDER BY n.property DESC")
|
i = 3
|
||||||
assert len(results) == 4
|
for map in results:
|
||||||
i = 4
|
assert len(map) == 1
|
||||||
for n in results:
|
assert map[0]["property"] == i
|
||||||
n_props = n[0].properties
|
|
||||||
assert len(n_props) == 1
|
|
||||||
assert n_props["property"] == i
|
|
||||||
i = i - 1
|
i = i - 1
|
||||||
|
|
||||||
result = execute_and_fetch_all(cursor, "MATCH (n) RETURN n ORDER BY n.property LIMIT 1")
|
result = execute_and_fetch_all(
|
||||||
|
cursor,
|
||||||
|
"UNWIND [{property:1}, {property:3}, {property:2}] AS map RETURN map ORDER BY map.property LIMIT 1",
|
||||||
|
)
|
||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
assert result[0][0].properties["property"] == 1
|
assert result[0][0]["property"] == 1
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -9,6 +9,7 @@ function(add_manual_test test_cpp)
|
|||||||
get_filename_component(exec_name ${test_cpp} NAME_WE)
|
get_filename_component(exec_name ${test_cpp} NAME_WE)
|
||||||
set(target_name ${test_prefix}${exec_name})
|
set(target_name ${test_prefix}${exec_name})
|
||||||
add_executable(${target_name} ${test_cpp} ${ARGN})
|
add_executable(${target_name} ${test_cpp} ${ARGN})
|
||||||
|
|
||||||
# OUTPUT_NAME sets the real name of a target when it is built and can be
|
# OUTPUT_NAME sets the real name of a target when it is built and can be
|
||||||
# used to help create two targets of the same name even though CMake
|
# used to help create two targets of the same name even though CMake
|
||||||
# requires unique logical target names
|
# requires unique logical target names
|
||||||
@ -37,12 +38,14 @@ target_link_libraries(${test_prefix}query_hash mg-query)
|
|||||||
|
|
||||||
add_manual_test(query_planner.cpp interactive/planning.cpp)
|
add_manual_test(query_planner.cpp interactive/planning.cpp)
|
||||||
target_link_libraries(${test_prefix}query_planner mg-query)
|
target_link_libraries(${test_prefix}query_planner mg-query)
|
||||||
|
|
||||||
if(READLINE_FOUND)
|
if(READLINE_FOUND)
|
||||||
target_link_libraries(${test_prefix}query_planner readline)
|
target_link_libraries(${test_prefix}query_planner readline)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_manual_test(query_execution_dummy.cpp)
|
add_manual_test(query_execution_dummy.cpp)
|
||||||
target_link_libraries(${test_prefix}query_execution_dummy mg-query)
|
target_link_libraries(${test_prefix}query_execution_dummy mg-query)
|
||||||
|
|
||||||
if(READLINE_FOUND)
|
if(READLINE_FOUND)
|
||||||
target_link_libraries(${test_prefix}query_execution_dummy readline)
|
target_link_libraries(${test_prefix}query_execution_dummy readline)
|
||||||
endif()
|
endif()
|
||||||
@ -61,3 +64,6 @@ target_link_libraries(${test_prefix}ssl_client mg-communication)
|
|||||||
|
|
||||||
add_manual_test(ssl_server.cpp)
|
add_manual_test(ssl_server.cpp)
|
||||||
target_link_libraries(${test_prefix}ssl_server mg-communication)
|
target_link_libraries(${test_prefix}ssl_server mg-communication)
|
||||||
|
|
||||||
|
add_manual_test(query_performance.cpp)
|
||||||
|
target_link_libraries(${test_prefix}query_performance mg-communication mg-utils mg-io mg-io-simulator mg-coordinator mg-query-v2 mg-storage-v3 mg-query mg-storage-v2)
|
||||||
|
352
tests/manual/query_performance.cpp
Normal file
352
tests/manual/query_performance.cpp
Normal file
@ -0,0 +1,352 @@
|
|||||||
|
// Copyright 2023 Memgraph Ltd.
|
||||||
|
//
|
||||||
|
// Use of this software is governed by the Business Source License
|
||||||
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
// License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
//
|
||||||
|
// As of the Change Date specified in that file, in accordance with
|
||||||
|
// the Business Source License, use of this software will be governed
|
||||||
|
// by the Apache License, Version 2.0, included in the file
|
||||||
|
// licenses/APL.txt.
|
||||||
|
|
||||||
|
// This binary is meant to easily compare the performance of:
|
||||||
|
// - Memgraph v2
|
||||||
|
// - Memgraph v3
|
||||||
|
// - Memgraph v3 with MultiFrame
|
||||||
|
// This binary measures three things which provides a high level and easily understandable metric about the performance
|
||||||
|
// difference between the different versions:
|
||||||
|
// 1. Read time: how much time does it take to read the files:
|
||||||
|
// 2. Init time: how much time does it take to run the init queries, including the index creation. For details please
|
||||||
|
// check RunV2.
|
||||||
|
// 3. Benchmark time: how much time does it take to run the benchmark queries.
|
||||||
|
// To quickly compare performance of the different versions just change the query or queries in the benchmark queries
|
||||||
|
// file you can see the different by running this executable. This way we don't have keep multiple binaries of Memgraph
|
||||||
|
// v2 and Memgraph v3 with/without MultiFrame, start Memgraph and connect to it with mgconsole and other hassles. As
|
||||||
|
// everything is run in this binary, it makes easier to generate perf reports/flamegraphs from the query execution of
|
||||||
|
// different Memgraph versions compared to using the full blown version of Memgraph.
|
||||||
|
//
|
||||||
|
// A few important notes:
|
||||||
|
// - All the input files are mandated to have an empty line at the end of the file as the reading logic expect that.
|
||||||
|
// - tests/mgbench/dataset_creator_unwind.py is recommended to generate the dataset because it generates queries with
|
||||||
|
// UNWIND that makes the import faster in Memgraph v3, thus we can compare the performance on non trivial datasets
|
||||||
|
// also. To make it possible to use the generated dataset, you have to move the generated index queries into a
|
||||||
|
// separate file that can be supplied as index queries file for this binary when using Memgraph v2. The reason for
|
||||||
|
// this is Memgraph v3 cannot handle indices yet, thus it crashes.
|
||||||
|
// - Check the command line flags and their description defined in this file.
|
||||||
|
// - Also check out the --default-multi-frame-size command line flag if you want to play with that.
|
||||||
|
// - The log level is manually set to warning in the main function to avoid the overwhelming log messages from Memgraph
|
||||||
|
// v3. Apart from ease of use, the huge amount of looging can degrade the actual performance.
|
||||||
|
//
|
||||||
|
// Example usage with Memgraph v2:
|
||||||
|
// ./query_performance
|
||||||
|
// --index-queries-file indices.cypher
|
||||||
|
// --init-queries-file dataset.cypher
|
||||||
|
// --benchmark-queries-files expand.cypher,match.cypyher
|
||||||
|
// --use-v3=false
|
||||||
|
//
|
||||||
|
// Example usage with Memgraph v3 without MultiFrame:
|
||||||
|
// ./query_performance
|
||||||
|
// --split-file split_file
|
||||||
|
// --init-queries-file dataset.cypher
|
||||||
|
// --benchmark-queries-files expand.cypher,match.cypyher
|
||||||
|
// --use-v3=true
|
||||||
|
// --use-multi-frame=false
|
||||||
|
//
|
||||||
|
// Example usage with Memgraph v3 with MultiFrame:
|
||||||
|
// ./query_performance
|
||||||
|
// --split-file split_file
|
||||||
|
// --init-queries-file dataset.cypher
|
||||||
|
// --benchmark-queries-files expand.cypher,match.cypyher
|
||||||
|
// --use-v3=true
|
||||||
|
// --use-multi-frame=true
|
||||||
|
//
|
||||||
|
// The examples are using only the necessary flags, however specifying all of them is not a problem, so if you specify
|
||||||
|
// --index-queries-file for Memgraph v3, then it will be safely ignored just as --split-file for Memgraph v2.
|
||||||
|
//
|
||||||
|
// To generate flamegraph you can use the following command:
|
||||||
|
// flamegraph --cmd "record -F 997 --call-graph fp -g" --root -o flamegraph.svg -- ./query_performance <flags>
|
||||||
|
// Using the default option (dwarf) for --call-graph when calling perf might result in too long runtine of flamegraph
|
||||||
|
// because of address resolution. See https://github.com/flamegraph-rs/flamegraph/issues/74.
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <istream>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
#include <fmt/core.h>
|
||||||
|
#include <gflags/gflags.h>
|
||||||
|
#include <spdlog/cfg/env.h>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <json/json.hpp>
|
||||||
|
|
||||||
|
// v3 includes
|
||||||
|
#include "io/address.hpp"
|
||||||
|
#include "io/local_transport/local_system.hpp"
|
||||||
|
#include "io/message_histogram_collector.hpp"
|
||||||
|
#include "machine_manager/machine_manager.hpp"
|
||||||
|
#include "query/discard_value_stream.hpp"
|
||||||
|
#include "query/v2/discard_value_stream.hpp"
|
||||||
|
#include "query/v2/interpreter.hpp"
|
||||||
|
#include "query/v2/request_router.hpp"
|
||||||
|
|
||||||
|
// v2 includes
|
||||||
|
#include "query/interpreter.hpp"
|
||||||
|
#include "storage/v2/storage.hpp"
|
||||||
|
|
||||||
|
// common includes
|
||||||
|
#include "utils/string.hpp"
|
||||||
|
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
DEFINE_string(index_queries_file, "",
|
||||||
|
"Path to the file which contains the queries to create indices. Used only for v2. Must contain an empty "
|
||||||
|
"line at the end of the file after the queries.");
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
DEFINE_string(split_file, "",
|
||||||
|
"Path to the split file which contains the predefined labels, properties, edge types and shard-ranges. "
|
||||||
|
"Used only for v3. Must contain an empty line at the end of the file.");
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
DEFINE_string(init_queries_file, "",
|
||||||
|
"Path to the file that is used to insert the initial dataset, one query per line. Must contain an empty "
|
||||||
|
"line at the end of the file after the queries.");
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
DEFINE_string(benchmark_queries_files, "",
|
||||||
|
"Comma separated paths to the files that contain the queries that we want to compare, one query per "
|
||||||
|
"line. Must contain an empty line at the end of each file after the queries.");
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
DEFINE_bool(use_v3, true, "If set to true, then Memgraph v3 will be used, otherwise Memgraph v2 will be used.");
|
||||||
|
|
||||||
|
DEFINE_string(export_json_results, "", "If not empty, then the results will be exported as a json file.");
|
||||||
|
|
||||||
|
DEFINE_string(data_directory, "mg_data", "Path to directory to use as storage directory for Memgraph v2.");
|
||||||
|
|
||||||
|
namespace memgraph::tests::manual {
|
||||||
|
|
||||||
|
template <typename TInterpreterContext>
|
||||||
|
struct DependantTypes {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct DependantTypes<query::InterpreterContext> {
|
||||||
|
using Interpreter = query::Interpreter;
|
||||||
|
using DiscardValueResultStream = query::DiscardValueResultStream;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct DependantTypes<query::v2::InterpreterContext> {
|
||||||
|
using Interpreter = query::v2::Interpreter;
|
||||||
|
using DiscardValueResultStream = query::v2::DiscardValueResultStream;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename TRep, typename TPeriod>
|
||||||
|
void PutResult(nlohmann::json &json, const std::string_view name, std::chrono::duration<TRep, TPeriod> duration) {
|
||||||
|
json[name] = std::chrono::duration_cast<std::chrono::microseconds>(duration).count();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename TInterpreterContext>
|
||||||
|
using Interpreter = typename DependantTypes<TInterpreterContext>::Interpreter;
|
||||||
|
|
||||||
|
template <typename TInterpreterContext>
|
||||||
|
using DiscardValueResultStream = typename DependantTypes<TInterpreterContext>::DiscardValueResultStream;
|
||||||
|
|
||||||
|
template <typename TInterpreterContext>
|
||||||
|
void RunQueries(TInterpreterContext &interpreter_context, const std::vector<std::string> &queries) {
|
||||||
|
Interpreter<TInterpreterContext> interpreter{&interpreter_context};
|
||||||
|
DiscardValueResultStream<TInterpreterContext> stream;
|
||||||
|
|
||||||
|
for (const auto &query : queries) {
|
||||||
|
auto result = interpreter.Prepare(query, {}, nullptr);
|
||||||
|
interpreter.Pull(&stream, std::nullopt, result.qid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename TInterpreterContext>
|
||||||
|
void RunInitQueries(TInterpreterContext &interpreter_context, const std::vector<std::string> &init_queries) {
|
||||||
|
RunQueries(interpreter_context, init_queries);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename TInterpreterContext>
|
||||||
|
void RunBenchmarkQueries(TInterpreterContext &interpreter_context, const std::vector<std::string> &benchmark_queries) {
|
||||||
|
RunQueries(interpreter_context, benchmark_queries);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> ReadQueries(const std::string &file_name) {
|
||||||
|
std::vector<std::string> queries{};
|
||||||
|
std::string buffer;
|
||||||
|
|
||||||
|
std::ifstream file{file_name, std::ios::in};
|
||||||
|
MG_ASSERT(file.good(), "Cannot open queries file to read: {}", file_name);
|
||||||
|
while (file.good()) {
|
||||||
|
std::getline(file, buffer);
|
||||||
|
if (buffer.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Trim the trailing `;`
|
||||||
|
queries.push_back(buffer.substr(0, buffer.size() - 1));
|
||||||
|
}
|
||||||
|
return queries;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, std::vector<std::string>> ReadBenchmarkQueries(const std::string benchmark_queries_files) {
|
||||||
|
auto benchmark_files = utils::Split(benchmark_queries_files, ",");
|
||||||
|
std::map<std::string, std::vector<std::string>> result;
|
||||||
|
for (const auto &benchmark_file : benchmark_files) {
|
||||||
|
const auto path = std::filesystem::path(benchmark_file);
|
||||||
|
result.emplace(path.stem().string(), ReadQueries(benchmark_file));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RunV2() {
|
||||||
|
spdlog::critical("Running V2");
|
||||||
|
const auto run_start = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
const auto index_queries = ReadQueries(FLAGS_index_queries_file);
|
||||||
|
const auto init_queries = ReadQueries(FLAGS_init_queries_file);
|
||||||
|
const auto benchmarks = ReadBenchmarkQueries(FLAGS_benchmark_queries_files);
|
||||||
|
|
||||||
|
storage::Storage storage{
|
||||||
|
storage::Config{.durability{.storage_directory = FLAGS_data_directory,
|
||||||
|
.snapshot_wal_mode = storage::Config::Durability::SnapshotWalMode::DISABLED}}};
|
||||||
|
|
||||||
|
memgraph::query::InterpreterContext interpreter_context{
|
||||||
|
&storage,
|
||||||
|
{.query = {.allow_load_csv = false},
|
||||||
|
.execution_timeout_sec = 0,
|
||||||
|
.replication_replica_check_frequency = std::chrono::seconds(0),
|
||||||
|
.default_kafka_bootstrap_servers = "",
|
||||||
|
.default_pulsar_service_url = "",
|
||||||
|
.stream_transaction_conflict_retries = 0,
|
||||||
|
.stream_transaction_retry_interval = std::chrono::milliseconds(0)},
|
||||||
|
FLAGS_data_directory};
|
||||||
|
|
||||||
|
const auto init_start = std::chrono::high_resolution_clock::now();
|
||||||
|
RunInitQueries(interpreter_context, index_queries);
|
||||||
|
RunInitQueries(interpreter_context, init_queries);
|
||||||
|
const auto benchmark_start = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
spdlog::critical("Read: {}ms", std::chrono::duration_cast<std::chrono::milliseconds>(init_start - run_start).count());
|
||||||
|
spdlog::critical("Init: {}ms",
|
||||||
|
std::chrono::duration_cast<std::chrono::milliseconds>(benchmark_start - init_start).count());
|
||||||
|
|
||||||
|
std::map<std::string, std::chrono::nanoseconds> benchmark_results;
|
||||||
|
for (const auto &[name, queries] : benchmarks) {
|
||||||
|
const auto current_start = std::chrono::high_resolution_clock::now();
|
||||||
|
RunBenchmarkQueries(interpreter_context, queries);
|
||||||
|
const auto current_stop = std::chrono::high_resolution_clock::now();
|
||||||
|
const auto elapsed = current_stop - current_start;
|
||||||
|
spdlog::critical("Benchmark {}: {}ms", name,
|
||||||
|
std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count());
|
||||||
|
benchmark_results.emplace(name, elapsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto benchmark_end = std::chrono::high_resolution_clock::now();
|
||||||
|
spdlog::critical("Benchmark: {}ms",
|
||||||
|
std::chrono::duration_cast<std::chrono::milliseconds>(benchmark_end - benchmark_start).count());
|
||||||
|
|
||||||
|
if (!FLAGS_export_json_results.empty()) {
|
||||||
|
nlohmann::json results;
|
||||||
|
PutResult(results, "init", benchmark_start - init_start);
|
||||||
|
nlohmann::json benchmark_results_json;
|
||||||
|
for (const auto &[name, duration] : benchmark_results) {
|
||||||
|
PutResult(benchmark_results_json, name, duration);
|
||||||
|
}
|
||||||
|
results["benchmarks"] = std::move(benchmark_results_json);
|
||||||
|
std::ofstream results_file{FLAGS_export_json_results};
|
||||||
|
results_file << results.dump();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RunV3() {
|
||||||
|
spdlog::critical("Running V3");
|
||||||
|
const auto run_start = std::chrono::high_resolution_clock::now();
|
||||||
|
std::ifstream sm_file{FLAGS_split_file, std::ios::in};
|
||||||
|
MG_ASSERT(sm_file.good(), "Cannot open split file to read: {}", FLAGS_split_file);
|
||||||
|
auto sm = memgraph::coordinator::ShardMap::Parse(sm_file);
|
||||||
|
|
||||||
|
const auto init_queries = ReadQueries(FLAGS_init_queries_file);
|
||||||
|
const auto benchmarks = ReadBenchmarkQueries(FLAGS_benchmark_queries_files);
|
||||||
|
|
||||||
|
io::local_transport::LocalSystem ls;
|
||||||
|
|
||||||
|
auto unique_local_addr_query = io::Address::UniqueLocalAddress();
|
||||||
|
auto io = ls.Register(unique_local_addr_query);
|
||||||
|
|
||||||
|
memgraph::machine_manager::MachineConfig config{
|
||||||
|
.coordinator_addresses = std::vector<memgraph::io::Address>{unique_local_addr_query},
|
||||||
|
.is_storage = true,
|
||||||
|
.is_coordinator = true,
|
||||||
|
.listen_ip = unique_local_addr_query.last_known_ip,
|
||||||
|
.listen_port = unique_local_addr_query.last_known_port,
|
||||||
|
.shard_worker_threads = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
memgraph::coordinator::Coordinator coordinator{sm};
|
||||||
|
|
||||||
|
memgraph::machine_manager::MachineManager<memgraph::io::local_transport::LocalTransport> mm{io, config, coordinator};
|
||||||
|
std::jthread mm_thread([&mm] { mm.Run(); });
|
||||||
|
|
||||||
|
auto rr_factory = std::make_unique<memgraph::query::v2::LocalRequestRouterFactory>(io);
|
||||||
|
|
||||||
|
query::v2::InterpreterContext interpreter_context{(memgraph::storage::v3::Shard *)(nullptr),
|
||||||
|
{.execution_timeout_sec = 0},
|
||||||
|
"data",
|
||||||
|
std::move(rr_factory),
|
||||||
|
mm.CoordinatorAddress()};
|
||||||
|
|
||||||
|
// without this it fails sometimes because the CreateVertices request might reach the shard worker faster than the
|
||||||
|
// ShardToInitialize
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(150));
|
||||||
|
|
||||||
|
const auto init_start = std::chrono::high_resolution_clock::now();
|
||||||
|
RunInitQueries(interpreter_context, init_queries);
|
||||||
|
const auto benchmark_start = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
spdlog::critical("Read: {}ms", std::chrono::duration_cast<std::chrono::milliseconds>(init_start - run_start).count());
|
||||||
|
spdlog::critical("Init: {}ms",
|
||||||
|
std::chrono::duration_cast<std::chrono::milliseconds>(benchmark_start - init_start).count());
|
||||||
|
|
||||||
|
std::map<std::string, std::chrono::nanoseconds> benchmark_results;
|
||||||
|
for (const auto &[name, queries] : benchmarks) {
|
||||||
|
const auto current_start = std::chrono::high_resolution_clock::now();
|
||||||
|
RunBenchmarkQueries(interpreter_context, queries);
|
||||||
|
const auto current_stop = std::chrono::high_resolution_clock::now();
|
||||||
|
const auto elapsed = current_stop - current_start;
|
||||||
|
spdlog::critical("Benchmark {}: {}ms", name,
|
||||||
|
std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count());
|
||||||
|
benchmark_results.emplace(name, elapsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto benchmark_end = std::chrono::high_resolution_clock::now();
|
||||||
|
spdlog::critical("Benchmark: {}ms",
|
||||||
|
std::chrono::duration_cast<std::chrono::milliseconds>(benchmark_end - benchmark_start).count());
|
||||||
|
|
||||||
|
ls.ShutDown();
|
||||||
|
auto latency_histograms = nlohmann::json::parse(fmt::format("{}", io.ResponseLatencies()));
|
||||||
|
spdlog::warn(latency_histograms.dump(4));
|
||||||
|
|
||||||
|
if (!FLAGS_export_json_results.empty()) {
|
||||||
|
nlohmann::json results;
|
||||||
|
PutResult(results, "init", benchmark_start - init_start);
|
||||||
|
nlohmann::json benchmark_results_json;
|
||||||
|
for (const auto &[name, duration] : benchmark_results) {
|
||||||
|
PutResult(benchmark_results_json, name, duration);
|
||||||
|
}
|
||||||
|
results["benchmarks"] = std::move(benchmark_results_json);
|
||||||
|
results["latencies"] = std::move(latency_histograms);
|
||||||
|
std::ofstream results_file{FLAGS_export_json_results};
|
||||||
|
results_file << results.dump();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace memgraph::tests::manual
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
spdlog::set_level(spdlog::level::warn);
|
||||||
|
spdlog::cfg::load_env_levels();
|
||||||
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||||
|
if (FLAGS_use_v3) {
|
||||||
|
memgraph::tests::manual::RunV3();
|
||||||
|
} else {
|
||||||
|
memgraph::tests::manual::RunV2();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
116
tests/manual/query_performance_runner.py
Executable file
116
tests/manual/query_performance_runner.py
Executable file
@ -0,0 +1,116 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# Copyright 2023 Memgraph Ltd.
|
||||||
|
#
|
||||||
|
# Use of this software is governed by the Business Source License
|
||||||
|
# included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
|
# License, and you may not use this file except in compliance with the Business Source License.
|
||||||
|
#
|
||||||
|
# As of the Change Date specified in that file, in accordance with
|
||||||
|
# the Business Source License, use of this software will be governed
|
||||||
|
# by the Apache License, Version 2.0, included in the file
|
||||||
|
# licenses/APL.txt.
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import io
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import tarfile
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
PROJECT_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, "..", ".."))
|
||||||
|
BUILD_DIR = os.path.join(PROJECT_DIR, "build")
|
||||||
|
BINARY_DIR = os.path.join(BUILD_DIR, "tests/manual")
|
||||||
|
DEFAULT_BENCHMARK_DIR = os.path.join(BINARY_DIR, "query_performance_benchmark")
|
||||||
|
DATA_URL = (
|
||||||
|
"https://s3.eu-west-1.amazonaws.com/deps.memgraph.io/dataset/query_performance/query_performance_benchmark.tar.gz"
|
||||||
|
)
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||||
|
parser.add_argument(
|
||||||
|
"--binary",
|
||||||
|
type=str,
|
||||||
|
default=os.path.join(BINARY_DIR, "query_performance"),
|
||||||
|
help="Path to the binary to use for the benchmark.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--data-dir",
|
||||||
|
type=str,
|
||||||
|
default=tempfile.TemporaryDirectory().name,
|
||||||
|
help="Path to directory that can be used as a data directory for ",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--summary-path",
|
||||||
|
type=str,
|
||||||
|
default=os.path.join(DEFAULT_BENCHMARK_DIR, "summary.json"),
|
||||||
|
help="Path to which file write the summary.",
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument("--init-queries-file", type=str, default=os.path.join(DEFAULT_BENCHMARK_DIR, "dataset.cypher"))
|
||||||
|
parser.add_argument("--index-queries-file", type=str, default=os.path.join(DEFAULT_BENCHMARK_DIR, "indices.cypher"))
|
||||||
|
parser.add_argument("--split-file", type=str, default=os.path.join(DEFAULT_BENCHMARK_DIR, "split_file"))
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--benchmark-queries-files",
|
||||||
|
type=str,
|
||||||
|
default=",".join(
|
||||||
|
[os.path.join(DEFAULT_BENCHMARK_DIR, file_name) for file_name in ["expand.cypher", "match_files.cypher"]]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
v2_results_path = os.path.join(DEFAULT_BENCHMARK_DIR, "v2_results.json")
|
||||||
|
v3_results_path = os.path.join(DEFAULT_BENCHMARK_DIR, "v3_results.json")
|
||||||
|
|
||||||
|
|
||||||
|
if os.path.exists(DEFAULT_BENCHMARK_DIR):
|
||||||
|
print(f"Using cachced data from {DEFAULT_BENCHMARK_DIR}")
|
||||||
|
else:
|
||||||
|
print(f"Downloading benchmark data to {DEFAULT_BENCHMARK_DIR}")
|
||||||
|
r = requests.get(DATA_URL)
|
||||||
|
assert r.ok, "Cannot download data"
|
||||||
|
file_like_object = io.BytesIO(r.content)
|
||||||
|
tar = tarfile.open(fileobj=file_like_object)
|
||||||
|
tar.extractall(os.path.dirname(DEFAULT_BENCHMARK_DIR))
|
||||||
|
|
||||||
|
subprocess.run(
|
||||||
|
[
|
||||||
|
args.binary,
|
||||||
|
f"--split-file={args.split_file}",
|
||||||
|
f"--index-queries-file={args.index_queries_file}",
|
||||||
|
f"--init-queries-file={args.init_queries_file}",
|
||||||
|
f"--benchmark-queries-files={args.benchmark_queries_files}",
|
||||||
|
"--use-v3=false",
|
||||||
|
"--use-multi-frame=true",
|
||||||
|
f"--export-json-results={v2_results_path}",
|
||||||
|
f"--data-directory={args.data_dir}",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
subprocess.run(
|
||||||
|
[
|
||||||
|
args.binary,
|
||||||
|
f"--split-file={args.split_file}",
|
||||||
|
f"--index-queries-file={args.index_queries_file}",
|
||||||
|
f"--init-queries-file={args.init_queries_file}",
|
||||||
|
f"--benchmark-queries-files={args.benchmark_queries_files}",
|
||||||
|
"--use-v3=true",
|
||||||
|
"--use-multi-frame=true",
|
||||||
|
f"--export-json-results={v3_results_path}",
|
||||||
|
f"--data-directory={args.data_dir}",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
v2_results_file = open(v2_results_path)
|
||||||
|
v2_results = json.load(v2_results_file)
|
||||||
|
v3_results_file = open(v3_results_path)
|
||||||
|
v3_results = json.load(v3_results_file)
|
||||||
|
|
||||||
|
with open(args.summary_path, "w") as summary:
|
||||||
|
json.dump({"v2": v2_results, "v3": v3_results}, summary)
|
@ -51,10 +51,22 @@ import helpers
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--number_of_identities", type=int, default=10)
|
parser.add_argument(
|
||||||
parser.add_argument("--number_of_files", type=int, default=10)
|
"--number_of_identities",
|
||||||
parser.add_argument("--percentage_of_permissions", type=float, default=1.0)
|
type=int,
|
||||||
parser.add_argument("--filename", default="dataset.cypher")
|
default=10,
|
||||||
|
help="Determines how many :Identity nodes will the dataset contain.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--number_of_files", type=int, default=10, help="Determines how many :File nodes will the dataset contain."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--percentage_of_permissions",
|
||||||
|
type=float,
|
||||||
|
default=1.0,
|
||||||
|
help="Determines approximately what percentage of the all possible identity-permission-file connections will be created.",
|
||||||
|
)
|
||||||
|
parser.add_argument("--filename", default="dataset.cypher", help="The name of the output file.")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -51,10 +51,22 @@ import helpers
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--number_of_identities", type=int, default=10)
|
parser.add_argument(
|
||||||
parser.add_argument("--number_of_files", type=int, default=10)
|
"--number_of_identities",
|
||||||
parser.add_argument("--percentage_of_permissions", type=float, default=1.0)
|
type=int,
|
||||||
parser.add_argument("--filename", default="dataset.cypher")
|
default=10,
|
||||||
|
help="Determines how many :Identity nodes will the dataset contain.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--number_of_files", type=int, default=10, help="Determines how many :File nodes will the dataset contain."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--percentage_of_permissions",
|
||||||
|
type=float,
|
||||||
|
default=1.0,
|
||||||
|
help="Determines approximately what percentage of the all possible identity-permission-file connections will be created.",
|
||||||
|
)
|
||||||
|
parser.add_argument("--filename", default="dataset.cypher", help="The name of the output file.")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -55,7 +55,7 @@ void run_server(Io<SimulatorTransport> io) {
|
|||||||
highest_seen = std::max(highest_seen, req.proposal);
|
highest_seen = std::max(highest_seen, req.proposal);
|
||||||
auto srv_res = CounterResponse{highest_seen};
|
auto srv_res = CounterResponse{highest_seen};
|
||||||
|
|
||||||
io.Send(request_envelope.from_address, request_envelope.request_id, srv_res);
|
io.Send(request_envelope.from_address, request_envelope.request_id, std::move(srv_res));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ std::pair<SimulatorStats, LatencyHistogramSummaries> RunWorkload(SimulatorConfig
|
|||||||
CounterRequest cli_req;
|
CounterRequest cli_req;
|
||||||
cli_req.proposal = i;
|
cli_req.proposal = i;
|
||||||
spdlog::info("[CLIENT] calling Request");
|
spdlog::info("[CLIENT] calling Request");
|
||||||
auto res_f = cli_io.Request<CounterRequest, CounterResponse>(srv_addr, cli_req);
|
auto res_f = cli_io.Request<CounterResponse, CounterRequest>(srv_addr, std::move(cli_req));
|
||||||
spdlog::info("[CLIENT] calling Wait");
|
spdlog::info("[CLIENT] calling Wait");
|
||||||
auto res_rez = std::move(res_f).Wait();
|
auto res_rez = std::move(res_f).Wait();
|
||||||
spdlog::info("[CLIENT] Wait returned");
|
spdlog::info("[CLIENT] Wait returned");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -44,7 +44,7 @@ void run_server(Io<SimulatorTransport> io) {
|
|||||||
for (auto index = start_index; index < start_index + req.count; ++index) {
|
for (auto index = start_index; index < start_index + req.count; ++index) {
|
||||||
response.vertices.push_back({std::string("Vertex_") + std::to_string(index)});
|
response.vertices.push_back({std::string("Vertex_") + std::to_string(index)});
|
||||||
}
|
}
|
||||||
io.Send(request_envelope.from_address, request_envelope.request_id, response);
|
io.Send(request_envelope.from_address, request_envelope.request_id, std::move(response));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ int main() {
|
|||||||
|
|
||||||
auto req = ScanVerticesRequest{2, std::nullopt};
|
auto req = ScanVerticesRequest{2, std::nullopt};
|
||||||
|
|
||||||
auto res_f = cli_io.Request<ScanVerticesRequest, VerticesResponse>(srv_addr, req);
|
auto res_f = cli_io.Request<VerticesResponse, ScanVerticesRequest>(srv_addr, std::move(req));
|
||||||
auto res_rez = std::move(res_f).Wait();
|
auto res_rez = std::move(res_f).Wait();
|
||||||
simulator.ShutDown();
|
simulator.ShutDown();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2022 Memgraph Ltd.
|
// Copyright 2023 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -48,7 +48,7 @@ void RunServer(Io<LocalTransport> io) {
|
|||||||
highest_seen = std::max(highest_seen, req.proposal);
|
highest_seen = std::max(highest_seen, req.proposal);
|
||||||
auto srv_res = CounterResponse{highest_seen};
|
auto srv_res = CounterResponse{highest_seen};
|
||||||
|
|
||||||
io.Send(request_envelope.from_address, request_envelope.request_id, srv_res);
|
io.Send(request_envelope.from_address, request_envelope.request_id, std::move(srv_res));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ TEST(LocalTransport, BasicRequest) {
|
|||||||
auto value = 1; // i;
|
auto value = 1; // i;
|
||||||
cli_req.proposal = value;
|
cli_req.proposal = value;
|
||||||
spdlog::info("[CLIENT] sending request");
|
spdlog::info("[CLIENT] sending request");
|
||||||
auto res_f = cli_io.Request<CounterRequest, CounterResponse>(srv_addr, cli_req);
|
auto res_f = cli_io.Request<CounterResponse, CounterRequest>(srv_addr, std::move(cli_req));
|
||||||
spdlog::info("[CLIENT] waiting on future");
|
spdlog::info("[CLIENT] waiting on future");
|
||||||
|
|
||||||
auto res_rez = std::move(res_f).Wait();
|
auto res_rez = std::move(res_f).Wait();
|
||||||
|
Loading…
Reference in New Issue
Block a user