From 9304791ce55682a4796c7219ecb504a4eab5bd3a Mon Sep 17 00:00:00 2001 From: Piotr Dulikowski Date: Tue, 1 Feb 2022 17:58:40 +0100 Subject: [PATCH] exceptions: add coordinator_exception_container and coordinator_result Adds coordinator_exception_container which is a typedef over exception_container and is meant to hold exceptions returned from the coordinator code path. Currently, it can only hold mutation write timeout exceptions, because only that kind of error will be returned by value as a result of this PR. In the future, more exception types can be added. Adds coordinator_result which is a boost::outcome::result that uses coordinator_exception_container as the error type. --- exceptions/exceptions.hh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/exceptions/exceptions.hh b/exceptions/exceptions.hh index 5cc3c3b437..795e3fecd9 100644 --- a/exceptions/exceptions.hh +++ b/exceptions/exceptions.hh @@ -19,6 +19,9 @@ #include #include #include "bytes.hh" +#include +#include "utils/exception_container.hh" +#include "utils/result.hh" namespace exceptions { @@ -331,4 +334,27 @@ public: { } }; +// 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 +>; + +template +using coordinator_result = bo::result; + }