From 7c211e8e506e7562b2e562b17fb7f92a0c2d1065 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Mon, 19 Sep 2022 15:41:32 +0300 Subject: [PATCH] token_metadata: Hide token_metadata_impl copy constructor Copying of token_metadata_impl is heavy operation and it's performed internally with the help of the dedicated clone_async() method. This method, in turn, doesn't copy the whole object in its copy-ctor, but rather default-initializes it and carries the remaining fields later. Having said that, the standart copy-ctor is better to be made private and, for the sake of being more explicit, marked as shallow-copy-ctor Signed-off-by: Pavel Emelyanov --- locator/token_metadata.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/locator/token_metadata.cc b/locator/token_metadata.cc index 6a4380ddf4..210a814c97 100644 --- a/locator/token_metadata.cc +++ b/locator/token_metadata.cc @@ -74,9 +74,13 @@ private: void sort_tokens(); + struct shallow_copy {}; + token_metadata_impl(shallow_copy, const token_metadata_impl& o) noexcept + {} + public: token_metadata_impl() noexcept {}; - token_metadata_impl(const token_metadata_impl&) = default; + token_metadata_impl(const token_metadata_impl&) = delete; // it's too huge for direct copy, use clone_async() token_metadata_impl(token_metadata_impl&&) noexcept = default; const std::vector& sorted_tokens() const; future<> update_normal_tokens(std::unordered_set tokens, inet_address endpoint); @@ -358,7 +362,7 @@ future token_metadata_impl::clone_async() const noexcept { } future token_metadata_impl::clone_only_token_map(bool clone_sorted_tokens) const noexcept { - return do_with(token_metadata_impl(), [this, clone_sorted_tokens] (token_metadata_impl& ret) { + return do_with(token_metadata_impl(shallow_copy{}, *this), [this, clone_sorted_tokens] (token_metadata_impl& ret) { ret._token_to_endpoint_map.reserve(_token_to_endpoint_map.size()); return do_for_each(_token_to_endpoint_map, [&ret] (const auto& p) { ret._token_to_endpoint_map.emplace(p);