cross-tree: split coordinator_result from exceptions.hh

Recently, coordinator_result was introduced as an alternative for
exceptions. It was placed in the main "exceptions/exceptions.hh" header,
which virtually every single source file in Scylla includes.
But unfortunately, it brings in some heavy header files and templates,
leading to a lot of wasted build time - ClangBuildAnalyzer measured that
we include exceptions.hh in 323 source files, taking almost two seconds
each on average.

In this patch, we split the coordinator_result feature into a separate
header file, "exceptions/coordinator_result", and only the few places
which need it include the header file. Unfortunately, some of these
few places are themselves header, so the new header file ends up being
included in 100 source files - but 100 is still much less than 323 and
perhaps we can reduce this number 100 later.

After this patch, the total Scylla object-file size is reduced by 6.5%
(the object size is a proxy for build time, which I didn't directly
measure). ClangBuildAnalyzer reports that now each of the 323 includes
of exceptions.hh only takes 80ms, coordinator_result.hh is only included
100 times, and virtually all the cost to include it comes from Boost's
result.hh (400ms per inclusion).

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
Message-Id: <20220228204323.1427012-1-nyh@scylladb.com>
This commit is contained in:
Nadav Har'El
2022-02-28 22:43:23 +02:00
committed by Botond Dénes
parent 2dba0670ad
commit fa7a302130
12 changed files with 53 additions and 28 deletions

View File

@@ -16,6 +16,7 @@
#include "log.hh"
#include "service_permit.hh"
#include "exceptions/exceptions.hh"
#include "exceptions/coordinator_result.hh"
namespace cql_transport::messages {
class result_message;

View File

@@ -12,6 +12,7 @@
*/
#include <set>
#include <seastar/core/print.hh>
#include "index_prop_defs.hh"
#include "index/secondary_index.hh"
#include "exceptions/exceptions.hh"

View File

@@ -22,6 +22,7 @@
#include "cql3/restrictions/statement_restrictions.hh"
#include "cql3/statements/statement_type.hh"
#include "exceptions/exceptions.hh"
#include "exceptions/coordinator_result.hh"
#include <seastar/core/shared_ptr.hh>

View File

@@ -11,6 +11,7 @@
* SPDX-License-Identifier: (AGPL-3.0-or-later and Apache-2.0)
*/
#include <seastar/core/print.hh>
#include "cql3/statements/property_definitions.hh"
#include "exceptions/exceptions.hh"

View File

@@ -20,6 +20,7 @@
#include "transport/messages/result_message.hh"
#include "index/secondary_index_manager.hh"
#include "exceptions/exceptions.hh"
#include "exceptions/coordinator_result.hh"
namespace service {
class client_state;

View File

@@ -0,0 +1,43 @@
/*
* Copyright (C) 2022-present ScyllaDB
*/
/*
* SPDX-License-Identifier: (AGPL-3.0-or-later and Apache-2.0)
*/
#pragma once
#include "exceptions.hh"
#include <boost/outcome/result.hpp>
#include "utils/exception_container.hh"
#include "utils/result.hh"
namespace exceptions {
// Allows to pass a coordinator exception as a value. With coordinator_result,
// it is possible to handle exceptions and inspect their type/value without
// resorting to costly rethrows. On the other hand, using them is more
// cumbersome than just using exceptions and exception futures.
//
// Not all exceptions are passed in this way, therefore the container
// does not allow all types of coordinator exceptions. On the other hand,
// an exception being listed here does not mean it is _always_ passed
// in an exception_container - it can be thrown in a regular fashion
// as well.
//
// It is advised to use this mechanism mainly for exceptions which can
// happen frequently, e.g. signalling timeouts, overloads or rate limits.
using coordinator_exception_container = utils::exception_container<
mutation_write_timeout_exception,
read_timeout_exception,
read_failure_exception
>;
template<typename T = void>
using coordinator_result = bo::result<T,
coordinator_exception_container,
utils::exception_container_throw_policy
>;
}

View File

@@ -18,9 +18,6 @@
#include <stdexcept>
#include <seastar/core/sstring.hh>
#include "bytes.hh"
#include <boost/outcome/result.hpp>
#include "utils/exception_container.hh"
#include "utils/result.hh"
namespace exceptions {
@@ -295,29 +292,4 @@ public:
function_execution_exception(sstring func_name_, sstring detail, sstring ks_name_, std::vector<sstring> args_) noexcept;
};
// Allows to pass a coordinator exception as a value. With coordinator_result,
// it is possible to handle exceptions and inspect their type/value without
// resorting to costly rethrows. On the other hand, using them is more
// cumbersome than just using exceptions and exception futures.
//
// Not all exceptions are passed in this way, therefore the container
// does not allow all types of coordinator exceptions. On the other hand,
// an exception being listed here does not mean it is _always_ passed
// in an exception_container - it can be thrown in a regular fashion
// as well.
//
// It is advised to use this mechanism mainly for exceptions which can
// happen frequently, e.g. signalling timeouts, overloads or rate limits.
using coordinator_exception_container = utils::exception_container<
mutation_write_timeout_exception,
read_timeout_exception,
read_failure_exception
>;
template<typename T = void>
using coordinator_result = bo::result<T,
coordinator_exception_container,
utils::exception_container_throw_policy
>;
}

View File

@@ -19,6 +19,7 @@
#include "service/query_state.hh"
#include "utils/result.hh"
#include "exceptions/exceptions.hh"
#include "exceptions/coordinator_result.hh"
namespace service {

View File

@@ -46,6 +46,7 @@
#include <seastar/core/circular_buffer.hh>
#include "query_ranges_to_vnodes.hh"
#include "exceptions/exceptions.hh"
#include "exceptions/coordinator_result.hh"
class reconcilable_result;
class frozen_mutation_and_schema;

View File

@@ -19,6 +19,7 @@
#include "transport/messages/result_message_base.hh"
#include "transport/event.hh"
#include "exceptions/exceptions.hh"
#include "exceptions/coordinator_result.hh"
#include <seastar/core/shared_ptr.hh>
#include <seastar/core/sstring.hh>

View File

@@ -30,6 +30,7 @@
#include "cql3/query_options.hh"
#include "transport/messages/result_message.hh"
#include "utils/chunked_vector.hh"
#include "exceptions/coordinator_result.hh"
namespace cql3 {

View File

@@ -13,6 +13,7 @@
#pragma once
#include <seastar/core/print.hh>
#include "exceptions/exceptions.hh"
namespace utils {