Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion grpc/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Eq for AttributeValue {}
/// A collection of attributes indexed by their type.
///
/// `Attributes` provides a map-like interface where values are keyed by their
/// TypeId.
/// `TypeId`.
///
/// Equality and ordering of `Attributes` are structural.
/// This means two `Attributes` maps are equal if they contain the same set of
Expand Down
16 changes: 8 additions & 8 deletions grpc/src/client/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ impl Channel {
/// by the user. Valid examples of target names include:
///
/// "foo.googleapis.com:8080"
/// "dns:///foo.googleapis.com:8080"
/// "dns:///foo.googleapis.com"
/// "dns:///10.0.0.213:8080"
/// "dns:///%5B2001:db8:85a3:8d3:1319:8a2e:370:7348%5D:443"
/// "dns://8.8.8.8/foo.googleapis.com:8080"
/// "dns://8.8.8.8/foo.googleapis.com"
/// "zookeeper://zk.example.com:9900/example_service"
/// "<dns:///foo.googleapis.com:8080>"
/// "<dns:///foo.googleapis.com>"
/// "<dns:///10.0.0.213:8080>"
/// "<dns:///%5B2001:db8:85a3:8d3:1319:8a2e:370:7348%5D:443>"
/// "<dns://8.8.8.8/foo.googleapis.com:8080>"
/// "<dns://8.8.8.8/foo.googleapis.com>"
/// "<zookeeper://zk.example.com:9900/example_service>"
///
/// Credentials must implement the [`ChannelCredentials`] trait.
///
Expand Down Expand Up @@ -326,7 +326,7 @@ impl ActiveChannel {
while let Some(w) = wqrx.recv().await {
match w {
WorkQueueItem::ScheduleResolver => {
resolver.work(&mut resolver_channel_controller)
resolver.work(&mut resolver_channel_controller);
}
WorkQueueItem::ResolveNow => resolver.resolve_now(),
WorkQueueItem::ScheduleLbPolicy(data) => {
Expand Down
10 changes: 5 additions & 5 deletions grpc/src/client/interceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,14 +588,14 @@ mod test {
}

/// An Invoke impl that can be controlled via its paired
/// MockInvokerController.
/// `MockInvokerController`.
#[derive(Clone)]
struct MockInvoker {
resp_tx: broadcast::Sender<ResponseStreamItem>,
req_tx: mpsc::Sender<(Bytes, SendOptions)>,
}
/// A controller used to control the behavior of its paired MockInvoker's
/// SendStream and RecvStream.
/// A controller used to control the behavior of its paired `MockInvoker`'s
/// `SendStream` and `RecvStream`.
struct MockInvokerController {
resp_tx: broadcast::Sender<ResponseStreamItem>,
req_rx: mpsc::Receiver<(Bytes, SendOptions)>,
Expand Down Expand Up @@ -884,7 +884,7 @@ mod test {
RecvStreamState::Done(_) => Some(fut.await),
}
}
/// Resolves `self`: either returns the already-Done() result of the
/// Resolves `self`: either returns the `already-Done()` result of the
/// recv operation or awaits the future and returns the result.
async fn resolve(self) -> ResponseStreamItem {
match self {
Expand Down Expand Up @@ -917,7 +917,7 @@ mod test {
Self { data }
}
}
impl<'a> SendMessage for ByteSendMsg<'a> {
impl SendMessage for ByteSendMsg<'_> {
fn encode(&self) -> Result<Box<dyn Buf + Send + Sync>, String> {
Ok(Box::new(self.data.clone()))
}
Expand Down
42 changes: 21 additions & 21 deletions grpc/src/client/load_balancing/child_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ pub struct Child<T> {
work_scheduler: Arc<ChildWorkScheduler>,
}

/// A collection of data sent to a child of the ChildManager.
/// A collection of data sent to a child of the `ChildManager`.
pub struct ChildUpdate<'a, T> {
/// The identifier the ChildManager should use for this child.
/// The identifier the `ChildManager` should use for this child.
pub child_identifier: T,
/// The builder the ChildManager should use to create this child if it does
/// not exist. The child_policy_builder's name is effectively a part of the
/// child_identifier. If two identifiers are identical but have different
/// The builder the `ChildManager` should use to create this child if it does
/// not exist. The `child_policy_builder`'s name is effectively a part of the
/// `child_identifier`. If two identifiers are identical but have different
/// builder names, they are treated as different children.
pub child_policy_builder: Arc<DynLbPolicyBuilder>,
/// The relevant ResolverUpdate and LbConfig to send to this child. If
/// None, then resolver_update will not be called on the child. Should
/// The relevant `ResolverUpdate` and `LbConfig` to send to this child. If
/// None, then `resolver_update` will not be called on the child. Should
/// generally be Some for any new children, otherwise they will not be
/// called.
pub child_update: Option<(ResolverUpdate, Option<&'a DynLbConfig>)>,
Expand All @@ -89,8 +89,8 @@ impl<T> ChildManager<T>
where
T: Debug + PartialEq + Hash + Eq + Send + Sync + 'static,
{
/// Creates a new ChildManager LB policy. shard_update is called whenever a
/// resolver_update operation occurs.
/// Creates a new `ChildManager` LB policy. `shard_update` is called whenever a
/// `resolver_update` operation occurs.
pub fn new(runtime: GrpcRuntime, work_scheduler: Arc<dyn WorkScheduler>) -> Self {
Self {
subchannel_to_child_idx: Default::default(),
Expand Down Expand Up @@ -163,18 +163,18 @@ where
if let Some(state) = channel_controller.picker_update {
self.children[child_idx].state = state;
self.updated = true;
};
}
}

/// Returns true if any child has updated its picker since the last call to
/// child_updated.
/// `child_updated`.
pub fn child_updated(&mut self) -> bool {
mem::take(&mut self.updated)
}

/// Retains only the child policies specified by the iterator.
///
/// If an ID is provided that does not exist in the ChildManager, it will be
/// If an ID is provided that does not exist in the `ChildManager`, it will be
/// ignored.
pub fn retain_children(
&mut self,
Expand All @@ -184,8 +184,8 @@ where
}

/// Resets the children and all state related to tracking them in accordance
/// with the iterator provided. When retain_only is true, any entry in
/// ids_builders that is not in the current set of children will be ignored;
/// with the iterator provided. When `retain_only` is true, any entry in
/// `ids_builders` that is not in the current set of children will be ignored;
/// otherwise a new child will be built for it.
fn reset_children(
&mut self,
Expand Down Expand Up @@ -270,17 +270,17 @@ where
policy,
work_scheduler,
});
};
}
}
// Anything left in old_children will just be Dropped and cleaned up.
}

/// Updates the ChildManager's children.
/// Updates the `ChildManager`'s children.
///
/// `child_updates` is used to determine which children should exist (one
/// for each item), how to construct them if they don't already, and what to
/// send to their `resolver_update` methods, if anything. Any existing
/// children not present in child_updates will be removed.
/// children not present in `child_updates` will be removed.
pub fn update<'a>(
&mut self,
child_updates: impl IntoIterator<Item = ChildUpdate<'a, T>>,
Expand Down Expand Up @@ -360,7 +360,7 @@ where
}
}

/// Forwards the incoming subchannel_update to the child that created the
/// Forwards the incoming `subchannel_update` to the child that created the
/// subchannel being updated.
pub fn subchannel_update(
&mut self,
Expand Down Expand Up @@ -407,7 +407,7 @@ where
}
}

/// Calls exit_idle on all children.
/// Calls `exit_idle` on all children.
pub fn exit_idle(&mut self, channel_controller: &mut dyn ChannelController) {
for child_idx in 0..self.children.len() {
let child = &mut self.children[child_idx];
Expand Down Expand Up @@ -566,7 +566,7 @@ mod test {
endpoints.push(Endpoint {
addresses,
..Default::default()
})
});
}
endpoints
}
Expand Down Expand Up @@ -617,7 +617,7 @@ mod test {
subchannels.push(sc);
}
other => panic!("unexpected event {:?}", other),
};
}
}
subchannels
}
Expand Down
2 changes: 1 addition & 1 deletion grpc/src/client/load_balancing/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
}

#[derive(Debug)]
enum Inner<T: LbPolicyBuilder> {

Check warning on line 57 in grpc/src/client/load_balancing/lazy.rs

View workflow job for this annotation

GitHub Actions / clippy

large size difference between variants
Void,
Pending(Pending<T>),
Built(T::LbPolicy),
Expand Down Expand Up @@ -412,7 +412,7 @@
assert!(rx.try_recv().is_err());
}

/// Implements both LbPolicyBuilder and LbPolicy to send events on a
/// Implements both `LbPolicyBuilder` and `LbPolicy` to send events on a
/// channel.
#[derive(Debug, Clone)]
struct MockPolicy {
Expand Down
52 changes: 26 additions & 26 deletions grpc/src/client/load_balancing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ pub use registry::GLOBAL_LB_REGISTRY;
#[cfg(test)]
pub(crate) mod test_utils;

/// An LB policy factory that produces LbPolicy instances used by the channel
/// An LB policy factory that produces `LbPolicy` instances used by the channel
/// to manage connections and pick connections for RPCs.
pub trait LbPolicyBuilder: Send + Sync + Debug + 'static {
type LbPolicy: LbPolicy;

/// Builds and returns a new LB policy instance.
///
/// Note that build must not fail. Any optional configuration is delivered
/// via the LbPolicy's resolver_update method.
/// via the `LbPolicy`'s `resolver_update` method.
///
/// An LbPolicy instance is assumed to begin in a Connecting state that
/// An `LbPolicy` instance is assumed to begin in a Connecting state that
/// queues RPCs until its first update.
fn build(&self, options: LbPolicyOptions) -> Self::LbPolicy;

Expand Down Expand Up @@ -110,20 +110,20 @@ pub trait LbPolicy: Send + Sync + Debug + 'static {
);

/// Called by the channel in response to a call from the LB policy to the
/// WorkScheduler's request_work method.
/// `WorkScheduler`'s `request_work` method.
fn work(&mut self, data: Option<WorkData>, channel_controller: &mut dyn ChannelController);

/// Called by the channel when an LbPolicy goes idle and the channel
/// Called by the channel when an `LbPolicy` goes idle and the channel
/// wants it to start connecting to subchannels again.
fn exit_idle(&mut self, channel_controller: &mut dyn ChannelController);
}

/// A collection of data configured on the channel that is constructing this
/// LbPolicy.
/// `LbPolicy`.
#[derive(Debug)]
pub struct LbPolicyOptions {
/// A hook into the channel's work scheduler that allows the LbPolicy to
/// request the ability to perform operations on the ChannelController.
/// A hook into the channel's work scheduler that allows the `LbPolicy` to
/// request the ability to perform operations on the `ChannelController`.
pub work_scheduler: Arc<dyn WorkScheduler>,
pub runtime: GrpcRuntime,
}
Expand Down Expand Up @@ -168,8 +168,8 @@ impl dyn WorkDataTrait {
/// associated policy's [`work`](LbPolicy::work) method.
pub type WorkData = Box<dyn WorkDataTrait>;

/// Used to asynchronously request a call into the LbPolicy's work method if
/// the LbPolicy needs to provide an update without waiting for an update
/// Used to asynchronously request a call into the `LbPolicy`'s work method if
/// the `LbPolicy` needs to provide an update without waiting for an update
/// from the channel first.
pub trait WorkScheduler: Send + Sync + Debug {
// Schedules a call into the LbPolicy's work method. If there is already a
Expand All @@ -187,7 +187,7 @@ pub struct ParsedJsonLbConfig {
}

impl ParsedJsonLbConfig {
/// Creates a new ParsedJsonLbConfig from the provided JSON string.
/// Creates a new `ParsedJsonLbConfig` from the provided JSON string.
pub fn new(json: &str) -> Result<Self, String> {
match serde_json::from_str(json) {
Ok(value) => Ok(ParsedJsonLbConfig { value }),
Expand Down Expand Up @@ -232,41 +232,41 @@ pub trait ChannelController: Send + Sync {
}

/// A Picker is responsible for deciding what Subchannel to use for any given
/// request. A Picker is only used once for any RPC. If pick() returns Queue,
/// request. A Picker is only used once for any RPC. If `pick()` returns Queue,
/// the channel will queue the RPC until a new Picker is produced by the
/// LbPolicy, and will call pick() on the new Picker for the request.
/// `LbPolicy`, and will call `pick()` on the new Picker for the request.
///
/// Pickers are always paired with a ConnectivityState which the channel will
/// Pickers are always paired with a `ConnectivityState` which the channel will
/// expose to applications so they can predict what might happens when
/// performing RPCs:
///
/// If the ConnectivityState is Idle, the Picker should ensure connections are
/// initiated by the LbPolicy that produced the Picker, and return a Queue
/// If the `ConnectivityState` is Idle, the Picker should ensure connections are
/// initiated by the `LbPolicy` that produced the Picker, and return a Queue
/// result so the request is attempted the next time a Picker is produced.
///
/// If the ConnectivityState is Connecting, the Picker should return a Queue
/// If the `ConnectivityState` is Connecting, the Picker should return a Queue
/// result and continue to wait for pending connections.
///
/// If the ConnectivityState is Ready, the Picker should return a Ready
/// If the `ConnectivityState` is Ready, the Picker should return a Ready
/// Subchannel.
///
/// If the ConnectivityState is TransientFailure, the Picker should return an
/// If the `ConnectivityState` is `TransientFailure`, the Picker should return an
/// Err with an error that describes why connections are failing.
pub trait Picker: Send + Sync + Debug {
/// Picks a connection to use for the request.
///
/// This function should not block. If the Picker needs to do blocking or
/// time-consuming work to service this request, it should return Queue, and
/// the Pick call will be repeated by the channel when a new Picker is
/// produced by the LbPolicy.
/// produced by the `LbPolicy`.
fn pick(&self, request: &RequestHeaders) -> PickResult;
}

#[derive(Debug)]
pub enum PickResult {
/// Indicates the Subchannel in the Pick should be used for the request.
Pick(Pick),
/// Indicates the LbPolicy is attempting to connect to a server to use for
/// Indicates the `LbPolicy` is attempting to connect to a server to use for
/// the request.
Queue,
/// Indicates that the request should fail with the included error status
Expand Down Expand Up @@ -332,7 +332,7 @@ pub struct LbState {
}

impl PartialEq for LbState {
/// Equality for two LbStates.
/// Equality for two `LbStates`.
///
/// Two `LbState`s are equal if and only if they have the same connectivity
/// state and the same Picker allocation. Even if two Pickers have the same
Expand All @@ -347,7 +347,7 @@ impl PartialEq for LbState {
impl Eq for LbState {}

impl LbState {
/// Returns a generic initial LbState which is Connecting and a picker which
/// Returns a generic initial `LbState` which is Connecting and a picker which
/// queues all picks.
pub fn initial() -> Self {
Self {
Expand Down Expand Up @@ -380,7 +380,7 @@ impl Debug for Pick {
}
}

/// OneSubchannelPicker always returns a single subchannel.
/// `OneSubchannelPicker` always returns a single subchannel.
#[derive(Debug)]
pub(crate) struct OneSubchannelPicker {
sc: Arc<dyn Subchannel>,
Expand All @@ -396,7 +396,7 @@ impl Picker for OneSubchannelPicker {
}
}

/// QueuingPicker always returns Queue. LB policies that are not actively
/// `QueuingPicker` always returns Queue. LB policies that are not actively
/// Connecting should not use this picker.
#[derive(Debug)]
pub(crate) struct QueuingPicker;
Expand Down Expand Up @@ -457,6 +457,6 @@ impl<T: LbPolicy + ?Sized> LbPolicy for Box<T> {
}

fn exit_idle(&mut self, channel_controller: &mut dyn ChannelController) {
(**self).exit_idle(channel_controller)
(**self).exit_idle(channel_controller);
}
}
4 changes: 2 additions & 2 deletions grpc/src/client/load_balancing/pick_first.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl LbPolicyBuilder for PickFirstBuilder {
}

pub(crate) fn reg() {
super::GLOBAL_LB_REGISTRY.add_builder(PickFirstBuilder {})
super::GLOBAL_LB_REGISTRY.add_builder(PickFirstBuilder {});
}

pub struct PickFirstPolicy {
Expand Down Expand Up @@ -928,7 +928,7 @@ mod test {
let res = state.picker.pick(&RequestHeaders::default());
match res {
PickResult::Pick(pick) => {
assert_eq!(pick.subchannel.address().address.to_string(), "addr1")
assert_eq!(pick.subchannel.address().address.to_string(), "addr1");
}
other => panic!("unexpected pick result {:?}", other),
}
Expand Down
Loading
Loading