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

Allow one way partitionings #187

Merged
merged 2 commits into from
Oct 9, 2024
Merged

Allow one way partitionings #187

merged 2 commits into from
Oct 9, 2024

Conversation

andersmusikkahs
Copy link
Contributor

This is an attempt to solve #167 .

Copy link
Contributor

@mcches mcches left a comment

Choose a reason for hiding this comment

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

Thanks for picking up this issue!

src/sim.rs Outdated Show resolved Hide resolved
src/sim.rs Outdated Show resolved Hide resolved
src/top.rs Outdated Show resolved Hide resolved
src/top.rs Outdated
@@ -332,14 +368,20 @@ impl Link {
let delay = self.delay(global_config.latency(), rand);
DeliveryStatus::DeliverAfter(self.now + delay)
}
State::ExplicitPartitionAToB if src.ip() > dst.ip() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit tricky to reason about as written. I assume this delivers in the non-partitioned link direction. Consider adding a comment on these branches.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. I'll see if I can make it clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried to make it clearer.

src/top.rs Outdated
@@ -155,7 +155,15 @@ enum State {
Healthy,

/// The link was explicitly partitioned.
ExplicitPartition,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This implementation strategy was chosen because it was the easiest to implement.

The disadvantage is that making oneway partitionings a specific type of link status means that it can't easily be combined with 'Hold' or 'RandPartition'. For my particular use case this is fine. I'm unsure of how common the need to combine 'Hold' or 'RandPartition' with one-way partitioning is.

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't seen a need for this yet, but one idea to achieve this is to model a link with two direction states and allow setting either one. This also might make the A,B -> src,dst stuff cleaner. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would be a lot cleaner if the 'links'-map in the 'Topology'-struct didn't deduplicate links. I.e, if the network topology between any two nodes 'a' and 'b' was described by two links, 'a'->'b' and 'b'->'a', instead of having one multidirectional link.

However, that feels like a rather big change, and it might also have other downsides.

We could just split 'state' in struct 'Link' into 'state_a_to_b' and 'state_b_to_a'. I worry that the tricky A,B->src,dst stuff would basically remain the same though?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree we should hold off on a larger refactor. We've been discussing a larger restructuring of the network to support different ip versions and a more realistic lo for some time now. We can tackle that then.

This idea doesn't avoid complexity around the directions, but it does make it really clear what is happening in each direction. I think its worth doing that as part of this change.

struct Link {
    a_b: State,
    b_a: State,
}

Copy link
Contributor Author

@andersmusikkahs andersmusikkahs Oct 3, 2024

Choose a reason for hiding this comment

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

I implemented your suggestion, as I understood it, and I think it was a big improvement. Thanks for the idea!

src/sim.rs Outdated Show resolved Hide resolved
src/sim.rs Outdated Show resolved Hide resolved
src/top.rs Outdated
@@ -332,14 +368,20 @@ impl Link {
let delay = self.delay(global_config.latency(), rand);
DeliveryStatus::DeliverAfter(self.now + delay)
}
State::ExplicitPartitionAToB if src.ip() > dst.ip() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. I'll see if I can make it clearer.

Copy link
Contributor

@mcches mcches left a comment

Choose a reason for hiding this comment

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

This is coming together nicely. I left a few comments, please let me know what you think.

src/sim.rs Outdated Show resolved Hide resolved
src/top.rs Outdated
@@ -155,7 +155,15 @@ enum State {
Healthy,

/// The link was explicitly partitioned.
ExplicitPartition,
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't seen a need for this yet, but one idea to achieve this is to model a link with two direction states and allow setting either one. This also might make the A,B -> src,dst stuff cleaner. wdyt?

src/top.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@mcches mcches left a comment

Choose a reason for hiding this comment

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

Mainly just one minor comment about arg names. Looks like you also have a couple clippy violations: https://github.com/tokio-rs/turmoil/actions/runs/11164962511/job/31053944943?pr=187

src/top.rs Outdated Show resolved Hide resolved
@@ -251,10 +259,38 @@ impl Topology {
self.links[&Pair::new(a, b)].explicit_partition();
}

pub(crate) fn partition_oneway(&mut self, a: IpAddr, b: IpAddr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the best way to define this is from: IpAddr, to: IpAddr and then the a to b sorting is entirely internal. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's obviously much better!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have implemented your suggestion (I hope :-) ).

src/top.rs Outdated Show resolved Hide resolved
src/sim.rs Show resolved Hide resolved
src/sim.rs Show resolved Hide resolved
@mcches
Copy link
Contributor

mcches commented Oct 8, 2024

Looks like this needs a rebase and was hoping we could get from and to on the pub facing Apis for this.

@andersmusikkahs
Copy link
Contributor Author

Looks like this needs a rebase and was hoping we could get from and to on the pub facing Apis for this.

I rebased, squashed into a single commiit, and renamed the parameter 'a' and 'b' to 'from' and 'to'.

Copy link
Contributor

@mcches mcches left a comment

Choose a reason for hiding this comment

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

I pulled your changes and everything looks good. Thanks for the contribution!

src/sim.rs Outdated Show resolved Hide resolved
minor doc update
@mcches mcches merged commit 9a3da11 into tokio-rs:main Oct 9, 2024
3 checks passed
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