From bbfef04e843289aae70b5aa060a925e8ee5b1b6f Mon Sep 17 00:00:00 2001 From: DenisBiryukov91 <155981813+DenisBiryukov91@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:48:25 +0100 Subject: [PATCH] support for default recovery option without last sample miss detection (#373) --- examples/zenohc/z_advanced_sub.cxx | 7 ++- include/zenoh/api/ext/session_ext.hxx | 62 +++++++++++++++++++-------- zenoh-c | 2 +- 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/examples/zenohc/z_advanced_sub.cxx b/examples/zenohc/z_advanced_sub.cxx index 11a5a14a..723e1f23 100644 --- a/examples/zenohc/z_advanced_sub.cxx +++ b/examples/zenohc/z_advanced_sub.cxx @@ -48,9 +48,12 @@ int _main(int argc, char **argv) { ext::SessionExt::AdvancedSubscriberOptions opts; opts.history.emplace().detect_late_publishers = true; opts.history->detect_late_publishers = true; - opts.recovery.emplace(); // enable recovery based on received heartbeats from ext::AdvancedPublisher + // enable recovery based on received heartbeats from ext::AdvancedPublisher + opts.recovery.emplace().last_sample_miss_detection = + ext::SessionExt::AdvancedSubscriberOptions::RecoveryOptions::Heartbeat{}; // alternatively recovery can be triggered based on missed sample detection via periodic queries: - // opts.recovery.emplace().periodic_queries_period_ms = 1000; + // opts.recovery.emplace().last_sample_miss_detection = + // ext::SessionExt::AdvancedSubscriberOptions::RecoveryOptions::PeriodicQueriesOptions{1000}; opts.subscriber_detection = true; auto data_handler = [](const Sample &sample) { diff --git a/include/zenoh/api/ext/session_ext.hxx b/include/zenoh/api/ext/session_ext.hxx index ac406241..0bd2d2bb 100644 --- a/include/zenoh/api/ext/session_ext.hxx +++ b/include/zenoh/api/ext/session_ext.hxx @@ -286,12 +286,14 @@ class SessionExt { /// @brief Create default option settings. static CacheOptions create_default() { return {}; } }; - // @brief Settings allowing matching Subscribers to detect lost samples and optionally ask for retransimission. + + /// @brief Settings allowing matching Subscribers to detect lost samples and optionally ask for retransimission. struct SampleMissDetectionOptions { - // The period of publisher heartbeats in ms, which can be used by ``AdvancedSubscriber`` for missed sample - // detection (if heartbeat-based recovery is enabled). If this value is unset, the subscribers will only be - // notified about missed samples if they opt to send periodic queries. + /// The period of publisher heartbeats in ms, which can be used by ``AdvancedSubscriber`` for missed sample + /// detection (if heartbeat-based recovery is enabled). + /// Otherwise, missed samples will be retransmitted based on Advanced Subscriber queries. std::optional heartbeat_period_ms = {}; + /// @brief Create default option settings. static SampleMissDetectionOptions create_default() { return {}; } }; @@ -392,14 +394,32 @@ class SessionExt { struct RecoveryOptions { /// @name Fields - /// @brief Period for queries for not yet received Samples. - /// - /// These queries allow to retrieve the last Sample(s) if the last Sample(s) is/are lost. - /// So it is useful for sporadic publications but useless for periodic publications - /// with a period smaller or equal to this period. - /// If unset, the subscriber will be instead notified about missed samples through ``AdvancedPublisher`` - /// heartbeats (if enabled on publisher side). - std::optional periodic_queries_period_ms = {}; + /// @brief Option tag for Heartbeat-based last sample detection. + struct Heartbeat {}; + + /// @brief Settings for periodic queries-based last sample detection. + struct PeriodicQueriesOptions { + /// @name Fields + + /// @brief Period for queries for not yet received Samples. + /// + /// These queries allow to retrieve the last Sample(s) if the last Sample(s) is/are lost. + /// So it is useful for sporadic publications but useless for periodic publications + /// with a period smaller or equal to this period. + uint64_t period_ms = 1000; + + /// @name Methods + + /// @brief Create default option settings. + static PeriodicQueriesOptions create_default() { return {}; }; + }; + + /// @brief Setting for detecting last sample(s) miss. + /// Note that it does not affect intermediate sample miss detection/retrieval (which is performed + /// automatically as long as recovery is enabled). If this option is disabled, subscriber will be unable to + /// detect/request retransmission of missed sample until it receives a more recent one from the same + /// publisher. + std::optional> last_sample_miss_detection = {}; /// @name Methods @@ -443,12 +463,18 @@ class SessionExt { } if (this->recovery.has_value()) { opts.recovery.is_enabled = true; - if (this->recovery->periodic_queries_period_ms.has_value()) { - // treat 0 as very small delay - opts.recovery.periodic_queries_period_ms = - std::max(1, this->recovery->periodic_queries_period_ms.value()); - } else { - opts.recovery.periodic_queries_period_ms = 0; + if (this->recovery->last_sample_miss_detection.has_value()) { + opts.recovery.last_sample_miss_detection.is_enabled = true; + if (std::holds_alternative( + this->recovery->last_sample_miss_detection.value())) { + opts.recovery.last_sample_miss_detection.periodic_queries_period_ms = 0; + } else { + // treat 0 as very small delay + opts.recovery.last_sample_miss_detection.periodic_queries_period_ms = + std::max(1, std::get( + this->recovery->last_sample_miss_detection.value()) + .period_ms); + } } } opts.query_timeout_ms = this->query_timeout_ms; diff --git a/zenoh-c b/zenoh-c index 67b5dceb..328736fe 160000 --- a/zenoh-c +++ b/zenoh-c @@ -1 +1 @@ -Subproject commit 67b5dceb010fbf2323d8e0b6595710cadd6e8ddd +Subproject commit 328736fe9bb9b654b1d9f47eecfc6d52f0d7d587