Skip to content

Commit

Permalink
rpc: switch rpc::type from boost to std
Browse files Browse the repository at this point in the history
rpc has a marker type rpc::type which it uses to communicate with
the user-provided deserializer. It is currently based on boost::type.

In an ideal universe, switching to the similar std::type_identity
would involve only changing the typedef. However, some users
pass boost::type directly, so we can't do that without breaking them.

To preserve compatiblity, have all read() calls pass through a helper
function that checks which variant is available and calls it. The
older one is marked deprecated. With that done, we switch the rpc::type
alias to std::type_identity.
  • Loading branch information
avikivity committed Oct 20, 2024
1 parent 14a59f3 commit 7394b70
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
28 changes: 26 additions & 2 deletions include/seastar/rpc/rpc_impl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <seastar/net/packet-data-source.hh>
#include <seastar/core/print.hh>

#include <boost/type.hpp> // for compatibility

namespace seastar {

namespace rpc {
Expand Down Expand Up @@ -278,17 +280,39 @@ inline snd_buf marshall(Serializer& serializer, size_t head_space, const T&... a
template <typename Serializer, typename Input, typename... T>
std::tuple<T...> do_unmarshall(connection& c, Input& in);

// The protocol to call the serializer is read(serializer, stream, rpc::type<T>).
// However, some users (ahem) used boost::type instead of rpc::type when the two
// types were aliased, preventing us from moving to the newer std::type_identity.
// To preserve compatibility, calls to read() are routed through
// read_via_type_marker(), of which there are two variants, one for
// boost::type (marked as deprecated) and one for std::type_identity.

template <typename T, typename... Args>
requires requires (Args... args, type<T> t) { read(std::forward<Args>(args)..., t); }
auto
read_via_type_marker(Args&&... args) {
return read(std::forward<Args>(args)..., type<T>());
}

template <typename T, typename... Args>
requires requires (Args... args, boost::type<T> t) { read(std::forward<Args>(args)..., t); }
[[deprecated("Use rpc::type<> instead of boost::type<>")]]
auto
read_via_type_marker(Args&&... args) {
return read(std::forward<Args>(args)..., boost::type<T>());
}

template<typename Serializer, typename Input>
struct unmarshal_one {
template<typename T> struct helper {
static T doit(connection& c, Input& in) {
return read(c.serializer<Serializer>(), in, type<T>());
return read_via_type_marker<T>(c.serializer<Serializer>(), in);
}
};
template<typename T> struct helper<optional<T>> {
static optional<T> doit(connection& c, Input& in) {
if (in.size()) {
return optional<T>(read(c.serializer<Serializer>(), in, type<typename remove_optional<T>::type>()));
return optional<T>(read_via_type_marker<typename remove_optional<T>::type>(c.serializer<Serializer>(), in));
} else {
return optional<T>();
}
Expand Down
3 changes: 1 addition & 2 deletions include/seastar/rpc/rpc_types.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <stdexcept>
#include <string>
#include <any>
#include <boost/type.hpp>
#include <seastar/util/std-compat.hh>
#include <seastar/util/variant_utils.hh>
#include <seastar/core/timer.hh>
Expand All @@ -50,7 +49,7 @@ using rpc_clock_type = lowres_clock;

// used to tag a type for serializers
template<typename T>
using type = boost::type<T>;
using type = std::type_identity<T>;

struct stats {
using counter_type = uint64_t;
Expand Down

0 comments on commit 7394b70

Please sign in to comment.