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>
44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
/*
|
|
* 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
|
|
>;
|
|
|
|
}
|