7#include <rdma/fabric.h>
25 requireCapability(info, FI_REMOTE_WRITE,
"Interface is missing required remote write capability");
43 auto proto =
selectIngressProtocol(mxlRegions.dataLayout(), mxlRegions.regions(), mxlRegions.maxSyncBatchSize());
44 auto targetInfo = std::make_unique<TargetInfo>(
45 pep.id(), pep.localAddress(), *provider, proto->registerMemory(domain), proto->bounceBufferInfo());
51 :
RCTarget(std::move(pep), std::move(proto), std::move(domain), options)
56 return {std::make_unique<MakeUniqueEnabler>(std::move(pep), std::move(proto), std::move(domain), options), std::move(targetInfo)};
60 :
_pep(std::move(pep))
79 if (
auto state = std::get_if<Connected>(&
_state); state !=
nullptr)
81 MXL_INFO(
"Shutting down the connection.");
84 auto const deadline = std::chrono::steady_clock::now() +
ShutdownTimeout;
87 auto const remaining = deadline - std::chrono::steady_clock::now();
88 if (remaining <= std::chrono::steady_clock::duration::zero())
90 MXL_WARN(
"Did not receive a shutdown event within {} ms.",
95 auto const event = state->ep.eventQueue()->readBlocking(remaining);
96 if (event && (event->isShutdown() || event->isError()))
106 template<QueueReadMode queueReadMode>
109 auto result = std::optional<Target::ReadResult>{std::nullopt};
121 if (event && event->isConnReq())
124 MXL_INFO(
"Accept connection from: {}", remoteAddr.toString());
130 endpoint.bind(cq, FI_RECV);
137 MXL_DEBUG(
"Accepted the connection waiting for connected event notification.");
149 result = std::make_optional<Target::Interrupted>();
162 if (event && event->isConnected())
164 MXL_INFO(
"Received connected event notification, now connected.");
167 auto connected =
Connected{.ep = std::move(state.ep)};
170 _proto->start(connected.ep);
181 result = std::make_optional<Target::Interrupted>();
197 result =
_proto->read(state.ep, *completion);
200 if (event && event.value().isShutdown())
202 MXL_INFO(
"Remote endpoint has shutdown the connection.");
204 "Failed to shut down the endpoint after the remote endpoint closed it");
205 return Draining{.ep = std::move(state.ep)};
208 return Connected{.ep = std::move(state.ep)};
214 result = std::make_optional<Target::Interrupted>();
215 return Connected{.ep = std::move(state.ep)};
237 result =
_proto->read(state.
ep, *completion);
243 MXL_WARN(
"Failed to read a completion after the connection was shut down: {}", ex.
what());
252 MXL_INFO(
"Transitioning to listening to new connection.");
259 while (
auto event =
_pep.eventQueue()->read())
261 if (event->isConnReq())
263 MXL_INFO(
"Reject connection request from {} that arrived while connected.",
static std::shared_ptr< CompletionQueue > open(std::shared_ptr< Domain > domain, Attributes const &attr=Attributes::defaults())
Create a new completion queue in the specified domain.
static std::shared_ptr< Domain > open(std::shared_ptr< Fabric > fabric)
Open a new domain associated with the specified fabric.
static Endpoint create(std::shared_ptr< Domain > domain, FabricInfoView info)
Allocates (active) new endpoint.
std::shared_ptr< CompletionQueue > completionQueue() const
Get the associated completion queue.
static std::shared_ptr< EventQueue > open(std::shared_ptr< Fabric >, Attributes const &attr=Attributes::defaults())
Create a new event queue associated with the specified fabric.
static Exception invalidArgument(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_ARG exception.
char const * what() const noexcept override
Implements std::exception, returns a descriptive string about the error.
static Exception invalidState(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_STATE exception.
static FabricAddress fromSource(FabricInfoView info) noexcept
Build a FabricAddress from the source address of info.
static FabricAddress fromDestination(FabricInfoView info) noexcept
Build a FabricAddress from the destination address of info.
An internal exception type that extends.
bool isInterrupted() const noexcept
Non-owning view of a FabricInfo. Returned when iterating over a FabricInfoList.
static std::shared_ptr< Fabric > open(FabricInfoView info)
Open a fabric object based on the provided FabricInfoView.
static MxlRegions forWriter(mxlFlowWriter)
RAII Wrapper around a libfabric passive endpoint (fid_pep).
static PassiveEndpoint create(std::shared_ptr< Fabric > fabric)
Allocate a new PassiveEndpoint associated with the given Fabric.
RCTarget(PassiveEndpoint pep, std::unique_ptr< IngressProtocol > proto, std::shared_ptr< Domain > domain, TargetSetupOptions options)
Construct a new RCTarget associated with the given domain and passive endpoint.
std::optional< Target::ReadResult > readNext(std::chrono::steady_clock::duration timeout)
Internal method to drive progress based on the current state.
virtual std::optional< Target::ReadResult > read()
Determine if new data can be consumed.
static PassiveEndpoint makeListener(std::shared_ptr< Fabric > const &fabric)
State drain(Draining state, std::optional< Target::ReadResult > &result)
Read the completions that are left after the Initiator closed the connection.
std::shared_ptr< Domain > _domain
std::unique_ptr< IngressProtocol > _proto
TargetSetupOptions _setupOptions
static std::pair< std::unique_ptr< RCTarget >, std::unique_ptr< TargetInfo > > setup(mxlFabricsTargetConfig const &config, FabricInfoView info, TargetSetupOptions const &options={})
Set up a fresh RCTarget and its associated TargetInfo based on the given configuration.
std::variant< WaitForConnectionRequest, WaitForConnection, Connected, Draining, Closed > State
The internal state of the RCTarget.
virtual std::optional< Target::ReadResult > readBlocking(std::chrono::steady_clock::duration timeout) final
Determine if new data can be consumed.
static constexpr auto ShutdownTimeout
Upper bound for waiting on the local shutdown event in shutdown().
virtual void shutdown() final
Shut down the target gracefully. Initiates a graceful shutdown of the target and blocks until the shu...
void rejectPendingConnectionRequests()
Reject all connection requests that are queued on the passive endpoint.
struct mxlFabricsTargetConfig_t mxlFabricsTargetConfig
std::optional< Event > readEventQueue(EventQueue &eq, std::chrono::steady_clock::duration timeout)
Helper to read an event queue with blocking or non-blocking behaviour.
std::pair< std::optional< Completion >, std::optional< Event > > readEndpointQueues(Endpoint &ep, std::chrono::steady_clock::duration timeout)
Helper to read both completion and event queues of an endpoint with blocking or non-blocking behaviou...
std::optional< Provider > providerFromString(std::string const &s) noexcept
Parse a provider name string, and return the enum value.
void catchAndLogFabricError(F &&fun, std::string_view msg)
std::unique_ptr< IngressProtocol > selectIngressProtocol(DataLayout const &layout, std::vector< Region > regions, std::uint32_t maxSyncBatchSize)
Select an appropriate ingress protocol based on the data layout.
void requireCapability(FabricInfoView info, std::uint64_t cap, std::string_view message)
std::size_t count(uuids::uuid id) const noexcept
Returns the number of writers registered for flow id 'id'.
static constexpr std::size_t DEFAULT_SIZE
The completion-queue depth used when no explicit depth is requested.
static Attributes defaults()
Returns the a CompletionQueueAttr with all of its attributes set to reasonable defaults.
static Attributes defaults()
Creates a configuration with all values set to reasonable defaults.
The wait for connection request state.
The wait for connection state.
Provider-independent tuning options for target setup.