Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions components/supervision_dispatch/docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@ Registry client
Returns a point-in-time snapshot of all fully joined, non-evicting
peers.

.. cpp:function:: void evict_fenced(hpx::id_type const& peer_locality, std::uint64_t generation) const

Removes a joined peer whose local supervision state was fenced by
failure detection, keeping the terminal state as a tombstone so the
peer stays fenced until it is joined again. ``generation`` is the
``peer_snapshot::generation`` of the entry to remove; the call is a
no-op if that entry is gone, or the peer's state is no longer
terminal. Fire-and-forget. If a lifecycle event of the peer is being
mirrored, or was mirrored, while the call checks the terminal state,
it does not remove anything; the failure-detection loop calls it again
on its next sweep.

.. cpp:function:: hpx::future<bool> register_name()
.. cpp:function:: bool register_name(hpx::launch::sync_policy, hpx::error_code& ec = hpx::throws)
.. cpp:function:: hpx::future<hpx::id_type> unregister_name() const
Expand Down Expand Up @@ -368,6 +380,7 @@ unit tests for this module deterministic:
.. cpp:function:: void hpx::supervision::testing::suspend_heartbeat_for_testing()
.. cpp:function:: bool hpx::supervision::testing::failure_detection_sweep_in_flight_for_testing()
.. cpp:function:: void hpx::supervision::testing::stop_background_loops()
.. cpp:function:: void hpx::supervision::testing::set_evict_fenced_hook_for_testing(hpx::function<void()> hook)

See the :ref:`API reference <modules_supervision_dispatch_api>` of this
module for more details, and :ref:`modules_supervision` for the underlying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <hpx/supervision_dispatch/export_definitions.hpp>
#include <hpx/supervision_dispatch/testing.hpp>

#include <cstddef>
#include <cstdint>
#include <iosfwd>
#include <map>
Expand Down Expand Up @@ -158,6 +159,25 @@ namespace hpx::supervision::server {
/// that failure detection fenced. The terminal state is left in place
/// as a tombstone (see cleanup_peer()), so the peer stays fenced.
///
/// Ordering with the peer's lifecycle notifications: the terminal
/// check and the removal are validated against the entry's
/// lifecycle mirroring (see peer_entry::mirror_sequence), so exactly
/// one of the following holds for every notification the entry's
/// lifecycle observer receives:
/// - its mirrored state is visible to the terminal check, so a peer
/// that came back with a newer, non-terminal epoch is not
/// evicted;
/// - it was in flight or finished between the terminal check and
/// the removal, in which case this call backs off without
/// evicting anything (the next failure-detection sweep calls it
/// again if the state is still terminal by then);
/// - it arrived after the removal, in which case it is not mirrored
/// at all, so the tombstone stays in place and the peer has to
/// join again to be monitored, as after any other eviction.
///
/// No lock is held while the local supervision state is queried or
/// while the observers are unregistered on the peer's locality.
///
/// \param peer_locality The peer locality to remove.
/// \param generation The peer_snapshot::generation of the entry to
/// remove. If \p peer_locality has since been evicted, or left
Expand All @@ -184,8 +204,13 @@ namespace hpx::supervision::server {
std::tuple<hpx::id_type, std::uint64_t, bool> reserve_ownership(
hpx::id_type const& peer_locality);

// `generation` is the peer_entry::generation of the entry the
// observers are registered for: the lifecycle callback only mirrors
// notifications while that very entry is still in peers_ (see
// peer_entry::mirror_sequence).
std::pair<hpx::id_type, hpx::id_type> register_observers(
hpx::id_type const& peer_locality, std::uint64_t join_epoch);
hpx::id_type const& peer_locality, std::uint64_t join_epoch,
std::uint64_t generation);

// Evicts a peer that has reached a terminal lifecycle event: erases its
// entry from peers_, unregisters its lifecycle_observer and
Expand Down Expand Up @@ -291,6 +316,22 @@ namespace hpx::supervision::server {
/// peer locality.
std::uint64_t generation = 0;

/// The number of lifecycle notifications the observer installed
/// by register_observers() is mirroring onto peer_locality's
/// local supervision state right now. Incremented before the
/// callback touches that state and decremented once it is done,
/// both under mtx_.
std::size_t mirrors_in_flight = 0;

/// The number of lifecycle notifications mirrored for this entry
/// so far, incremented under mtx_ once the mirrored state has
/// been published. evict_fenced() reads it before its terminal
/// check and only removes the entry if nothing was in flight then,
/// nothing is in flight at the removal, and the count has not
/// changed in between, so a newer lifecycle transition cannot slip
/// in between the check and the removal unnoticed.
std::uint64_t mirror_sequence = 0;

/// The preserve_terminal_state argument evict_peer() was called
/// with when it set evict_pending above, remembered so that
/// join()'s deferred cleanup_peer() call (once the join in progress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
/// \page hpx::supervision::testing::suspend_heartbeat_for_testing
/// \page hpx::supervision::testing::failure_detection_sweep_in_flight_for_testing
/// \page hpx::supervision::testing::stop_background_loops
/// \page hpx::supervision::testing::set_evict_fenced_hook_for_testing
/// \headerfile hpx/supervision_dispatch.hpp

#pragma once

#include <hpx/config.hpp>
#include <hpx/modules/functional.hpp>
#include <hpx/modules/naming_base.hpp>
#include <hpx/modules/timing.hpp>

Expand Down Expand Up @@ -94,4 +96,16 @@ namespace hpx::supervision::testing {
/// examples/tests that need to simulate this exact scenario
/// deterministically.
HPX_SUPERVISION_DISPATCH_EXPORT void stop_background_loops();

/// Installs \p hook to be called by registry::evict_fenced() on this
/// locality after it found the peer's local supervision state terminal
/// and before it removes the peer's registry entry, i.e. in the window in
/// which a newer lifecycle transition of the peer has to be detected (see
/// registry::evict_fenced()). Pass an empty function to remove the hook.
/// Not part of the public dispatch API - exists only so tests can force a
/// lifecycle transition into that window deterministically.
///
/// \param hook The function to call, with no lock held.
HPX_SUPERVISION_DISPATCH_EXPORT void set_evict_fenced_hook_for_testing(
hpx::function<void()> hook);
} // namespace hpx::supervision::testing
Loading
Loading