View Source ProcessHub.Service.RequestManager (ProcessHub v0.8.0)
Unified module for distributed operation tracking and execution utilities.
This module provides:
- Operation struct for tracking distributed operations across nodes
- State management (store, get, update, remove from coordinator state)
- GenServer handlers for coordinator callbacks
- Execution utilities (partition check, send response, request factories)
- Tracking utilities (expired?, all_responded?, record_response)
- Request splitting for batching large requests
Summary
Types
Who answers a sub-request: the node, or the node and the nodes that forwarded the request to it.
Functions
Composes sub-requests for each target node.
Factory: Creates a contraction request for topology contraction.
Finalizes an operation by aggregating results and running post-processing.
The fields of a request this node forwards on behalf of the request whose
options are opts: the same transaction and originating node, so the
target answers the coordinator that is waiting, and the forward path
extended by this node, which names the answer and bounds the forwarding.
True when every node a child belongs to already forwarded it, so forwarding it again would only send it back.
The nodes that forwarded the request whose options are opts, in order.
The answers a node gives for the children it forwarded, one
{child_id, {:forwarded, node}} per target.
Answers each awaited operation that now waits only on nodes this node is no
longer connected to. Their children answer :no_response at once, as they
would at the timeout, so a caller can try again while the time it was given
lasts. Called when a node goes down.
Loads the strategies a child-start request resolves against.
Factory: Creates a migration request for topology expansion.
Creates a new Operation struct.
Groups children by target node into a keyword list [{node, [child_data, ...]}, ...].
Records a node's response and checks if operation is complete.
Records the answer of responder to its sub-request.
Converts request struct to keyword options for response routing.
Sends response to coordinator.
Splits large requests into smaller batches for efficient cross-node transmission.
Wraps function execution with partition check.
Types
Who answers a sub-request: the node, or the node and the nodes that forwarded the request to it.
@type t() :: %ProcessHub.Service.RequestManager{ awaiter: {pid(), reference()} | nil, expires_at: integer(), future: ProcessHub.Future.t() | nil, handler: module(), hub_id: ProcessHub.hub_id(), nodes_data: [{node(), [map()]}], options: keyword(), result: struct() | nil, sub_requests: [struct()], transaction_id: reference() }
Functions
@spec cleanup_expired(ProcessHub.Coordinator.State.t()) :: ProcessHub.Coordinator.State.t()
Composes sub-requests for each target node.
contraction_request(hub, children_data, opts \\ [migration_add: true])
View Source@spec contraction_request( ProcessHub.Hub.t(), [{ProcessHub.child_spec(), map()}], keyword() ) :: ProcessHub.Request.Handler.StartChildrenRequest.t()
Factory: Creates a contraction request for topology contraction.
@spec finalize(t(), ProcessHub.Hub.t()) :: struct()
Finalizes an operation by aggregating results and running post-processing.
@spec forward_fields( ProcessHub.Hub.t(), keyword() ) :: map()
The fields of a request this node forwards on behalf of the request whose
options are opts: the same transaction and originating node, so the
target answers the coordinator that is waiting, and the forward path
extended by this node, which names the answer and bounds the forwarding.
True when every node a child belongs to already forwarded it, so forwarding it again would only send it back.
The nodes that forwarded the request whose options are opts, in order.
@spec forwarded_answers(keyword()) :: [{ProcessHub.child_id(), {:forwarded, node()}}]
The answers a node gives for the children it forwarded, one
{child_id, {:forwarded, node}} per target.
@spec get(ProcessHub.Coordinator.State.t(), reference()) :: t() | nil
@spec handle_await( ProcessHub.Coordinator.State.t(), reference(), {pid(), reference()} ) :: {:reply, term(), ProcessHub.Coordinator.State.t()} | {:noreply, ProcessHub.Coordinator.State.t()}
@spec handle_departed(ProcessHub.Coordinator.State.t()) :: ProcessHub.Coordinator.State.t()
Answers each awaited operation that now waits only on nodes this node is no
longer connected to. Their children answer :no_response at once, as they
would at the timeout, so a caller can try again while the time it was given
lasts. Called when a node goes down.
@spec handle_response( ProcessHub.Coordinator.State.t(), reference(), responder(), term() ) :: {:noreply, ProcessHub.Coordinator.State.t()}
@spec handle_timeout( ProcessHub.Coordinator.State.t(), reference(), {pid(), reference()} ) :: {:noreply, ProcessHub.Coordinator.State.t()}
@spec load_strategies(ProcessHub.Hub.t()) :: %{dist: term(), redun: term()}
Loads the strategies a child-start request resolves against.
Propagation reads the synchronization strategy itself, through
ProcessHub.Service.Dispatcher.propagate_event/3.
@spec migration_request( ProcessHub.Hub.t(), node(), [{ProcessHub.child_spec(), map()}], keyword() ) :: ProcessHub.Request.Handler.StartChildrenRequest.t()
Factory: Creates a migration request for topology expansion.
Each child carries migrated_from, the node it is moving away from.
Creates a new Operation struct.
Groups children by target node into a keyword list [{node, [child_data, ...]}, ...].
Records a node's response and checks if operation is complete.
Records the answer of responder to its sub-request.
An answer naming a child as {:forwarded, node} adds a sub-request for that
node's answer to the forward. A forward's answer can arrive before the
answer announcing it; it is kept, and the announcement then finds it.
@spec remove(ProcessHub.Coordinator.State.t(), reference()) :: ProcessHub.Coordinator.State.t()
Converts request struct to keyword options for response routing.
@spec send_response(atom(), keyword(), [{ProcessHub.child_id(), term()}]) :: :ok | :skip
Sends response to coordinator.
Splits large requests into smaller batches for efficient cross-node transmission.
@spec store(ProcessHub.Coordinator.State.t(), t()) :: ProcessHub.Coordinator.State.t()
@spec update(ProcessHub.Coordinator.State.t(), t()) :: ProcessHub.Coordinator.State.t()
@spec with_partition_check(ProcessHub.Hub.t(), (-> term())) :: term() | {:error, :partitioned}
Wraps function execution with partition check.