From 016a407d01ac8924081a4a34367931439c2e3983 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Sun, 4 Oct 2026 22:25:06 -0500 Subject: [PATCH] Document channel sink behavior and distributed data reads --- .../Akka.DistributedData/DistributedData.cs | 5 +- .../Akka.DistributedData/ReadAggregator.cs | 86 ++++++++++++++++++- src/core/Akka.Streams/Dsl/ChannelSink.cs | 22 +++-- 3 files changed, 101 insertions(+), 12 deletions(-) diff --git a/src/contrib/cluster/Akka.DistributedData/DistributedData.cs b/src/contrib/cluster/Akka.DistributedData/DistributedData.cs index 3e4e3361d22..61bba5d87fc 100644 --- a/src/contrib/cluster/Akka.DistributedData/DistributedData.cs +++ b/src/contrib/cluster/Akka.DistributedData/DistributedData.cs @@ -29,7 +29,8 @@ public class DistributedData : IExtension private readonly ActorSystem _system; /// - /// Returns true if this member is not tagged with the role configured for the replicas. + /// Returns true if the cluster has terminated or this member does not have the configured replica role. + /// When either condition holds as the extension is constructed, its is set to dead letters. /// public bool IsTerminated => Cluster.Cluster.Get(_system).IsTerminated || (!string.IsNullOrEmpty(_settings.Role) && !Cluster.Cluster.Get(_system).SelfRoles.Contains(_settings.Role)); @@ -116,7 +117,7 @@ public static Config DefaultConfig() => /// /// Asynchronously returns list of locally known keys. /// - /// + /// A task that completes with the key identifiers currently stored in the local replicator; deleted keys are omitted. public async Task> GetKeysAsync(CancellationToken cancellation = default (CancellationToken)) { var response = await Replicator.Ask(Dsl.GetKeyIds, cancellation); diff --git a/src/contrib/cluster/Akka.DistributedData/ReadAggregator.cs b/src/contrib/cluster/Akka.DistributedData/ReadAggregator.cs index 952b829f8d5..23fe0012a79 100644 --- a/src/contrib/cluster/Akka.DistributedData/ReadAggregator.cs +++ b/src/contrib/cluster/Akka.DistributedData/ReadAggregator.cs @@ -157,15 +157,32 @@ private Receive WaitRepairAck(DataEnvelope envelope) => msg => }; } + /// + /// Specifies the read consistency level used by a request. + /// See for an overview of the available read consistency levels. + /// public interface IReadConsistency { + /// + /// Gets the maximum time to wait for the requested read consistency level to be reached. + /// TimeSpan Timeout { get; } } + /// + /// Reads a value from the local replica only. This is the default consistency level for + /// . + /// public sealed class ReadLocal : IReadConsistency { + /// + /// Gets the singleton local read consistency level. + /// public static readonly ReadLocal Instance = new(); + /// + /// Gets the timeout for this consistency level, which is always zero because it reads only local state. + /// public TimeSpan Timeout => TimeSpan.Zero; private ReadLocal() { } @@ -179,12 +196,27 @@ private ReadLocal() { } public override int GetHashCode() => nameof(ReadLocal).GetHashCode(); } + /// + /// Reads and merges values from the requested number of replicas in total, including the local replica. + /// See for the read consistency overview. + /// public sealed class ReadFrom : IReadConsistency, IEquatable { + /// + /// Gets the number of replicas whose values are included in the read, counting the local replica. + /// public int N { get; } + /// + /// Gets the maximum time to wait for the requested replica responses. + /// public TimeSpan Timeout { get; } + /// + /// Initializes a read that waits for values from replicas, including the local replica. + /// + /// The number of replicas whose values are included in the read, counting the local replica. + /// The maximum time to wait for the requested replica responses. public ReadFrom(int n, TimeSpan timeout) { N = n; @@ -215,11 +247,29 @@ public override int GetHashCode() public override string ToString() => $"ReadFrom({N}, timeout={Timeout})"; } + /// + /// Reads and merges values from a majority of replicas. The required response count is the larger of the + /// majority count and , capped at the number of replicas selected for the request. + /// See for the read consistency overview. + /// public sealed class ReadMajority : IReadConsistency, IEquatable { + /// + /// Gets the maximum time to wait for the required replica responses. + /// public TimeSpan Timeout { get; } + + /// + /// Gets the minimum response count used in the calculation. The final response count is capped at the + /// number of replicas selected for the request. + /// public int MinCapacity { get; } + /// + /// Initializes a majority read. + /// + /// The maximum time to wait for the required replica responses. + /// The minimum response count used in the calculation; the final response count is capped at the number of replicas selected for the request. public ReadMajority(TimeSpan timeout, int minCapacity = 0) { Timeout = timeout; @@ -254,16 +304,35 @@ public override int GetHashCode() } /// - /// but with the given number of nodes added to the majority count. At most - /// all nodes. Exiting nodes are excluded using `ReadMajorityPlus` because those are typically - /// about to be removed and will not be able to respond. + /// Adjusts the majority response count by . The greater of that adjusted count and + /// is capped at the number of replicas selected for the request. Exiting nodes + /// are excluded from this read, since they may not be able to respond. /// public sealed class ReadMajorityPlus : IReadConsistency, IEquatable { + /// + /// Gets the maximum time to wait for the required replica responses. + /// public TimeSpan Timeout { get; } + + /// + /// Gets the adjustment applied to the majority response count before is applied + /// and the result is capped at the number of replicas selected for the request. + /// public int Additional { get; } + + /// + /// Gets the minimum response count used in the calculation. The final response count is capped at the + /// number of replicas selected for the request. + /// public int MinCapacity { get; } + /// + /// Initializes a majority read with an adjusted response count. + /// + /// The maximum time to wait for the required replica responses. + /// The adjustment to the majority response count. + /// The minimum response count used in the calculation; the final response count is capped at the number of replicas selected for the request. public ReadMajorityPlus(TimeSpan timeout, int additional, int minCapacity = 0) { Timeout = timeout; @@ -302,10 +371,21 @@ public override int GetHashCode() } } + /// + /// Reads and merges values from every replica selected for the request. Exiting nodes are excluded. + /// See for the read consistency overview. + /// public sealed class ReadAll : IReadConsistency, IEquatable { + /// + /// Gets the maximum time to wait for responses from all replicas selected for the request. + /// public TimeSpan Timeout { get; } + /// + /// Initializes a read that waits for responses from all replicas selected for the request. + /// + /// The maximum time to wait for responses from all replicas selected for the request. public ReadAll(TimeSpan timeout) { Timeout = timeout; diff --git a/src/core/Akka.Streams/Dsl/ChannelSink.cs b/src/core/Akka.Streams/Dsl/ChannelSink.cs index 520339a6d8f..5fb38ce5f2b 100644 --- a/src/core/Akka.Streams/Dsl/ChannelSink.cs +++ b/src/core/Akka.Streams/Dsl/ChannelSink.cs @@ -12,6 +12,10 @@ namespace Akka.Streams.Dsl { + /// + /// Provides sinks that write stream elements to instances + /// or expose a bounded channel through a . + /// public static class ChannelSink { /// @@ -38,14 +42,18 @@ public static Sink FromWriter(ChannelWriter writer, bool isOwn /// /// Creates a sink that upon materialization, returns a connected with - /// this materialized graph. It can then be used to consume events incoming from the graph. It will - /// also be completed once upstream completes. + /// this materialized graph. The reader can be used to consume events emitted by the graph. The channel + /// closes after normal upstream completion, once any pending write has finished. If upstream fails, the + /// channel closes with that failure. Buffered elements remain readable; the reader's + /// task completes or faults after no more data is available to read. + /// When the channel is full, waits for space and backpressures + /// upstream. The drop modes can discard an incoming or buffered element according to the selected mode. /// - /// - /// - /// - /// - /// + /// The type of elements written to the channel. + /// The maximum number of elements the bounded channel can store. + /// Indicates that the caller guarantees at most one read operation at a time. + /// The behavior to use when the bounded channel is full. + /// A sink that materializes to a reader for its bounded channel. public static Sink> AsReader(int bufferSize, bool singleReader = false, BoundedChannelFullMode fullMode = BoundedChannelFullMode.Wait) => Sink.FromGraph(new ChannelReaderSink(bufferSize, singleReader, fullMode));