diff --git a/runtime-light/tl/tl-types.cpp b/runtime-light/tl/tl-types.cpp index 62bcf38e1f..27dfca168c 100644 --- a/runtime-light/tl/tl-types.cpp +++ b/runtime-light/tl/tl-types.cpp @@ -193,6 +193,80 @@ bool rpcInvokeReqExtra::fetch(tl::fetcher& tlf, const tl::mask& flags) noexcept return ok; } +void rpcInvokeReqExtra::store(tl::storer& tls, const tl::mask& flags) const noexcept { // NOLINT(readability-function-cognitive-complexity) + if (static_cast(flags.value & WAIT_BINLOG_POS_FLAG)) { + opt_wait_binlog_pos.has_value() ? (*opt_wait_binlog_pos).store(tls) : tl::i64{}.store(tls); + } + if (static_cast(flags.value & STRING_FORWARD_KEYS_FLAG)) { + opt_string_forward_keys.has_value() ? (*opt_string_forward_keys).store(tls) : tl::vector{}.store(tls); + } + if (static_cast(flags.value & INT_FORWARD_KEYS_FLAG)) { + opt_int_forward_keys.has_value() ? (*opt_int_forward_keys).store(tls) : tl::vector{}.store(tls); + } + if (static_cast(flags.value & STRING_FORWARD_FLAG)) { + opt_string_forward.has_value() ? (*opt_string_forward).store(tls) : tl::string{}.store(tls); + } + if (static_cast(flags.value & INT_FORWARD_FLAG)) { + opt_int_forward.has_value() ? (*opt_int_forward).store(tls) : tl::i64{}.store(tls); + } + if (static_cast(flags.value & CUSTOM_TIMEOUT_MS_FLAG)) { + opt_custom_timeout_ms.has_value() ? (*opt_custom_timeout_ms).store(tls) : tl::i32{}.store(tls); + } + if (static_cast(flags.value & SUPPORTED_COMPRESSION_VERSION_FLAG)) { + opt_supported_compression_version.has_value() ? (*opt_supported_compression_version).store(tls) : tl::i32{}.store(tls); + } + if (static_cast(flags.value & RANDOM_DELAY_FLAG)) { + opt_random_delay.has_value() ? (*opt_random_delay).store(tls) : tl::f64{}.store(tls); + } + if (static_cast(flags.value & PERSISTENT_QUERY_FLAG)) { + opt_persistent_query.has_value() ? (*opt_persistent_query).store(tls) : tl::exactlyOnce::PersistentRequest{}.store(tls); + } + if (static_cast(flags.value & TRACE_CONTEXT_FLAG)) { + opt_trace_context.has_value() ? (*opt_trace_context).store(tls) : tl::tracing::traceContext{}.store(tls); + } + if (static_cast(flags.value & EXECUTION_CONTEXT_FLAG)) { + opt_execution_context.has_value() ? (*opt_execution_context).store(tls) : tl::string{}.store(tls); + } +} + +size_t rpcInvokeReqExtra::footprint(const tl::mask& flags) const noexcept { // NOLINT(readability-function-cognitive-complexity) + size_t footprint{}; + if (static_cast(flags.value & WAIT_BINLOG_POS_FLAG)) { + footprint += opt_wait_binlog_pos.has_value() ? (*opt_wait_binlog_pos).footprint() : tl::i64{}.footprint(); + } + if (static_cast(flags.value & STRING_FORWARD_KEYS_FLAG)) { + footprint += opt_string_forward_keys.has_value() ? (*opt_string_forward_keys).footprint() : tl::vector{}.footprint(); + } + if (static_cast(flags.value & INT_FORWARD_KEYS_FLAG)) { + footprint += opt_int_forward_keys.has_value() ? (*opt_int_forward_keys).footprint() : tl::vector{}.footprint(); + } + if (static_cast(flags.value & STRING_FORWARD_FLAG)) { + footprint += opt_string_forward.has_value() ? (*opt_string_forward).footprint() : tl::string{}.footprint(); + } + if (static_cast(flags.value & INT_FORWARD_FLAG)) { + footprint += opt_int_forward.has_value() ? (*opt_int_forward).footprint() : tl::i64{}.footprint(); + } + if (static_cast(flags.value & CUSTOM_TIMEOUT_MS_FLAG)) { + footprint += opt_custom_timeout_ms.has_value() ? (*opt_custom_timeout_ms).footprint() : tl::i32{}.footprint(); + } + if (static_cast(flags.value & SUPPORTED_COMPRESSION_VERSION_FLAG)) { + footprint += opt_supported_compression_version.has_value() ? (*opt_supported_compression_version).footprint() : tl::i32{}.footprint(); + } + if (static_cast(flags.value & RANDOM_DELAY_FLAG)) { + footprint += opt_random_delay.has_value() ? (*opt_random_delay).footprint() : tl::f64{}.footprint(); + } + if (static_cast(flags.value & PERSISTENT_QUERY_FLAG)) { + footprint += opt_persistent_query.has_value() ? (*opt_persistent_query).footprint() : tl::exactlyOnce::PersistentRequest{}.footprint(); + } + if (static_cast(flags.value & TRACE_CONTEXT_FLAG)) { + footprint += opt_trace_context.has_value() ? (*opt_trace_context).footprint() : tl::tracing::traceContext{}.footprint(); + } + if (static_cast(flags.value & EXECUTION_CONTEXT_FLAG)) { + footprint += opt_execution_context.has_value() ? (*opt_execution_context).footprint() : tl::string{}.footprint(); + } + return footprint; +} + tl::mask rpcInvokeReqExtra::get_flags() const noexcept { tl::mask flags{.value = static_cast(return_binlog_pos)}; diff --git a/runtime-light/tl/tl-types.h b/runtime-light/tl/tl-types.h index 53f5a56ae1..63b4d42a29 100644 --- a/runtime-light/tl/tl-types.h +++ b/runtime-light/tl/tl-types.h @@ -1090,6 +1090,14 @@ struct uuid final { bool fetch(tl::fetcher& tlf) noexcept { return lo.fetch(tlf) && hi.fetch(tlf); } + + void store(tl::storer& tls) const noexcept { + lo.store(tls), hi.store(tls); + } + + constexpr size_t footprint() const noexcept { + return lo.footprint() + hi.footprint(); + } }; struct prepareRequest final { @@ -1098,6 +1106,14 @@ struct prepareRequest final { bool fetch(tl::fetcher& tlf) noexcept { return persistent_query_uuid.fetch(tlf); } + + void store(tl::storer& tls) const noexcept { + persistent_query_uuid.store(tls); + } + + constexpr size_t footprint() const noexcept { + return persistent_query_uuid.footprint(); + } }; struct commitRequest final { @@ -1107,6 +1123,14 @@ struct commitRequest final { bool fetch(tl::fetcher& tlf) noexcept { return persistent_query_uuid.fetch(tlf) && persistent_slot_uuid.fetch(tlf); } + + void store(tl::storer& tls) const noexcept { + persistent_query_uuid.store(tls), persistent_slot_uuid.store(tls); + } + + constexpr size_t footprint() const noexcept { + return persistent_query_uuid.footprint() + persistent_slot_uuid.footprint(); + } }; class PersistentRequest final { @@ -1131,6 +1155,24 @@ class PersistentRequest final { } return false; } + + void store(tl::storer& tls) const noexcept { + std::visit( + [&tls](const auto& request) noexcept { + using request_t = std::remove_cvref_t; + if constexpr (std::same_as) { + tl::magic{.value = PREPARE_REQUEST_MAGIC}.store(tls); + } else if constexpr (std::same_as) { + tl::magic{.value = COMMIT_REQUEST_MAGIC}.store(tls); + } + request.store(tls); + }, + request); + } + + constexpr size_t footprint() const noexcept { + return std::visit([](const auto& request) noexcept { return tl::magic{}.footprint() + request.footprint(); }, request); + } }; } // namespace exactlyOnce @@ -1143,6 +1185,14 @@ struct traceID final { bool fetch(tl::fetcher& tlf) noexcept { return lo.fetch(tlf) && hi.fetch(tlf); } + + void store(tl::storer& tls) const noexcept { + lo.store(tls), hi.store(tls); + } + + constexpr size_t footprint() const noexcept { + return lo.footprint() + hi.footprint(); + } }; class traceContext final { @@ -1195,6 +1245,28 @@ class traceContext final { return ok; } + void store(tl::storer& tls) const noexcept { + get_flags().store(tls); + trace_id.store(tls); + if (opt_parent_id.has_value()) { + opt_parent_id->store(tls); + } + if (opt_source_id.has_value()) { + opt_source_id->store(tls); + } + } + + constexpr size_t footprint() const noexcept { + size_t footprint{tl::mask{}.footprint() + trace_id.footprint()}; + if (opt_parent_id.has_value()) { + footprint += opt_parent_id->footprint(); + } + if (opt_source_id.has_value()) { + footprint += opt_source_id->footprint(); + } + return footprint; + } + tl::mask get_flags() const noexcept { tl::mask flags{.value = static_cast(reserved_status_0)}; flags.value |= static_cast(reserved_status_1) << 1; @@ -1254,6 +1326,8 @@ class rpcInvokeReqExtra final { bool return_view_number{}; bool fetch(tl::fetcher& tlf, const tl::mask& flags) noexcept; + void store(tl::storer& tls, const tl::mask& flags) const noexcept; + size_t footprint(const tl::mask& flags) const noexcept; tl::mask get_flags() const noexcept; }; @@ -1333,6 +1407,42 @@ struct rpcReqError final { } }; +template +struct rpcDestActorFlags final { + tl::i64 actor_id{}; + tl::mask flags{}; + tl::rpcInvokeReqExtra extra{}; + T query{}; + + void store(tl::storer& tls) const noexcept + requires tl::serializable + { + actor_id.store(tls), flags.store(tls), extra.store(tls, flags), query.store(tls); + } + + constexpr size_t footprint() const noexcept + requires tl::footprintable + { + return actor_id.footprint() + flags.footprint() + extra.footprint(flags) + query.footprint(); + } +}; + +template +class RpcDestActorFlags final { + static constexpr tl::magic MAGIC{.value = TL_RPC_DEST_ACTOR_FLAGS}; + +public: + tl::rpcDestActorFlags inner{}; + + void store(tl::storer& tls) const noexcept { + MAGIC.store(tls), inner.store(tls); + } + + constexpr size_t footprint() const noexcept { + return MAGIC.footprint() + inner.footprint(); + } +}; + struct k2RpcResponseError final { tl::i32 error_code{}; tl::string error{};