Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine payload update and setting healthy status. #107

Merged
merged 14 commits into from
Apr 10, 2024
Merged

Conversation

partim
Copy link
Member

@partim partim commented Mar 27, 2024

This PR revises how updates are dispatched. Instead of having separate status and payload updates, these are now merged into one with a payload update implying a status change to healthy. This should avoid the potential for strange races between setting the status back to healthy and updating the data.

A resulting limitation is that if a unit wants to change from stalled to healthy it has to submit a payload update, but in practice this health status change is pretty much always triggered by a new payload update becoming available, so this should be fine.

This is a breaking change.

@partim partim requested a review from ximon18 March 27, 2024 10:30
Copy link
Member

@ximon18 ximon18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some nits.

@@ -162,44 +158,23 @@ impl Gate {
}
}

/// Updates the data set of the unit.
/// Updates the unit.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this one line summary confusing & misleading. What does it mean to "update" a unit? Units produce updates, they are not themselves updated by this function, right? Rather the downstreams are updated by the unit. If renaming this why not rename it to send_update() which more clearly says what it does.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The units themselves now keep their state (to facilitate late arriving new links), so in my mental model, they are indeed updated by this method and just happen to also produce events sent to connected links when being updated.

src/comms.rs Outdated
@@ -286,7 +261,7 @@ impl GateAgent {
#[derive(Debug, Default)]
pub struct GateMetrics {
/// The current unit status.
status: AtomicCell<UnitStatus>,
status: AtomicCell<UnitHealth>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the field also be renamed to 'health' instead of 'status'? Especially as health is a subfield of UnitStatus.

src/comms.rs Show resolved Hide resolved
src/comms.rs Outdated Show resolved Hide resolved
///
/// This may be `None` if the unit status indicates that there hasn’t
/// been an update yet.
fn to_update(&self) -> Option<UnitUpdate> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misread this thinking because of the to in the name that it would take Self (I guess I was wrongly thinking of into because they are similar). It's more like a mapping getter - what would you think about as_update() as a name instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard naming convention for converting methods is that into_ takes Self, to_ takes a &Self, and as_ takes a &Self but returns a &T, so, to_update is the right name following that convention.

src/units/combine.rs Outdated Show resolved Hide resolved
u2.status(Healthy).await;
assert_eq!(t.recv().await, Err(Healthy));
assert_eq!(t.recv().await, Ok(testrig::update(&[1])));
// Set one unit to healthy, check that we get an update.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Set one unit to healthy, check that we get an update.
// Set one unit to healthy by sending an update, which should be received by the target.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rephrased it in a slightly different way.

u1.send_stalled().await;
assert_eq!(t.recv_payload().await.unwrap(), testrig::update(&[2]));

// Now stall the second one, too, and watch us stall.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Now stall the second one, too, and watch us stall.
// Now stall the second one too, and watch us stall.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to get into a grammar discussion, but I have learned way back that there always is a comma before a too.

component: Component,
target: Source,
mut notify: NotifySender
) -> Result<(), ExitError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this code ever break out of the loop or return anything?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn’t. This never returns. Maybe it should, but perhaps that is a separate PR?

src/targets/rtr.rs Show resolved Hide resolved
@partim partim merged commit a6df70e into main Apr 10, 2024
9 checks passed
@partim partim deleted the revised-unit-status branch April 10, 2024 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants