From ebdf7344d8b1e16e06284cef0e2a6727f7b99eb1 Mon Sep 17 00:00:00 2001 From: gvolfing Date: Thu, 2 Mar 2023 11:07:40 +0100 Subject: [PATCH] Make a split_threshold stub --- src/coordinator/shard_map.hpp | 5 ++++- src/query/v2/request_router.hpp | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/coordinator/shard_map.hpp b/src/coordinator/shard_map.hpp index fc408e965..4177c3403 100644 --- a/src/coordinator/shard_map.hpp +++ b/src/coordinator/shard_map.hpp @@ -1,4 +1,4 @@ -// Copyright 2022 Memgraph Ltd. +// 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 @@ -128,6 +128,9 @@ struct LabelSpace { // Maps between the smallest primary key stored in the shard and the shard std::map shards; size_t replication_factor; + // TODO + // Stub value. Should be replaced once the shard-split logic is in place. + int64_t split_threshold{10000}; friend std::ostream &operator<<(std::ostream &in, const LabelSpace &label_space) { using utils::print_helpers::operator<<; diff --git a/src/query/v2/request_router.hpp b/src/query/v2/request_router.hpp index 6e23a494f..2a3c10baf 100644 --- a/src/query/v2/request_router.hpp +++ b/src/query/v2/request_router.hpp @@ -419,15 +419,28 @@ class RequestRouter : public RequestRouterInterface { return shards_map_.GetLabelId(name); } - int64_t GetApproximateVertexCount() const override { return 1; } + int64_t GetApproximateVertexCount() const override { + int64_t vertex_count = 0; + + for (const auto &label_space : shards_map_.label_spaces) { + const auto split_threshold = label_space.second.split_threshold; + const auto shard_count = static_cast(label_space.second.shards.size()); + vertex_count += split_threshold * shard_count; + } + + return vertex_count; + } int64_t GetApproximateVertexCount(storage::v3::LabelId label) const override { const auto &label_space = shards_map_.label_spaces.at(label); - return 1; + return label_space.split_threshold * label_space.shards.size(); } - int64_t GetApproximateVertexCount(storage::v3::LabelId label, storage::v3::PropertyId property) const override { - return 1; + int64_t GetApproximateVertexCount(storage::v3::LabelId label, storage::v3::PropertyId /*property*/) const override { + // TODO + // Once we have reliable metadata to approximate the + // vertex count -based on properties- rework this function. + return GetApproximateVertexCount(label); } private: