Introduces `replica::rate_limit_exception` - an exceptions that is supposed to be thrown/returned on the replica side when the request is rejected due to the exceeding the per-partition rate limit. Additionally, introduces the `exception_variant` type which allows to transport the new exception over RPC while preserving the type information. This will be useful in later commits, as the coordinator will have to know whether a replica has failed due to rate limit being exceeded or another kind of error. The `exception_variant` currently can only either hold "other exception" (std::monostate) or the aforementioned `rate_limit_exception`, but can be extended in a backwards-compatible way in the future to be able to hold more exceptions that need to be handled in a different way.
41 lines
925 B
C++
41 lines
925 B
C++
/*
|
|
* Copyright 2022-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#include <concepts>
|
|
#include <sstream>
|
|
#include <stdexcept>
|
|
#include <type_traits>
|
|
|
|
#include "replica/exceptions.hh"
|
|
#include "utils/exceptions.hh"
|
|
|
|
|
|
namespace replica {
|
|
|
|
exception_variant try_encode_replica_exception(std::exception_ptr eptr) {
|
|
try {
|
|
std::rethrow_exception(std::move(eptr));
|
|
} catch (rate_limit_exception&) {
|
|
return rate_limit_exception();
|
|
} catch (...) {
|
|
return no_exception{};
|
|
}
|
|
}
|
|
|
|
std::exception_ptr exception_variant::into_exception_ptr() noexcept {
|
|
return std::visit([] <typename Ex> (Ex&& ex) {
|
|
if constexpr (std::is_same_v<Ex, unknown_exception>) {
|
|
return std::make_exception_ptr(std::runtime_error("unknown exception"));
|
|
} else {
|
|
return std::make_exception_ptr(std::move(ex));
|
|
}
|
|
}, std::move(reason));
|
|
}
|
|
|
|
}
|