-
Notifications
You must be signed in to change notification settings - Fork 0
riir 🦀🦀🦀 [CPP-405] #15
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
Conversation
483918e to
68d7808
Compare
src/client.rs
Outdated
| if fields.len() < 2 || fields[0] != group || fields[1] != name { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this to a function it appears to be used similarly in write_setting_inner. Is this an anticipated mode? If so what settings is this behavior accounting for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it is, unfortunately there is no sequence/session associated with messages like fileio. So if two write requests are made at the same time, we register two MsgSettingsWriteResp callbacks. So you might have callback A triggered when the response intended for B comes in. So the check is to make sure that it's the response for the proper message.
But its not 100% foolproof, like if you made two write requests for the same setting, you'd have no way to figure out which one was intended for which, at least as far as I can tell. This is why all the pub functions take &mut self even though we could get away with &self, so we can make sure only one action is performed at a time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And r.e. the refactor, was able to factor out the check, looks a little cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great work. It is a shame you did not show the change diff in your hackathon presentation seems worthy of recognition.
I wonder if this would be worth setting up with the headless runner for a day or two.
Yeah I think that's a good idea. One thing is afaik the headless running won't actually call any of this api except for the first |
Yeah that would make sense to me. I could see an integration test suite of sorts that could run various test portfolios like this. Outside of manually validating I think running the headless runner may be sufficient for now until we do implement something like this. |
59a4851 to
d92dbf8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome - I learnt some cool Rust techniques.
I wasn't super familiar with this library before this change, so apologies if some of my comments/questions aren't strictly related to this change.
| fn try_from(msg: MsgSettingsReadResp) -> Result<Self, Self::Error> { | ||
| let fields = split_multipart(&msg.setting); | ||
| match fields.as_slice() { | ||
| [group, name] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a valid response? The SBP spec says it should always be group/name/value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell this is the response when the setting isn't found - https://github.com/swift-nav/libsettings/blob/6469986c2b0d1f3081d09c7cd1ad71d438d14eeb/src/setting_sbp_cb.c#L213
| fn try_from(msg: MsgSettingsReadByIndexResp) -> Result<Self, Self::Error> { | ||
| let fields = split_multipart(&msg.setting); | ||
| match fields.as_slice() { | ||
| [group, name, value, fmt_type] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checking - according to the spec fmt_type is optional, but with the way this is implemented I guess this means optional in that it won't necessarily be included in the response but the delimiting null characters will still be there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah as far as I can tell it's still there, we just get an empty string
| }); | ||
| let (settings, errors) = (Mutex::new(Vec::new()), Mutex::new(Vec::new())); | ||
| let idx = AtomicU16::new(0); | ||
| thread::scope(|scope| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice! 🦀
| sbp::to_writer(&mut wtr, &msg).map_err(Into::into) | ||
| }) | ||
| .unwrap(); | ||
| assert!(now.elapsed().as_millis() >= 100); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a sleep here or something to make sure that 100ms has actually elapsed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert!(now.elapsed().as_millis() >= 100); should be checking that. It's not super obvious but scope(...) will block in place until all the threads spawned inside the closure have joined. So, client.read_setting_ctx(group, name, ctx); should block for 100ms and then scope will end, and the assert is checked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh right, sorry, that makes total sense - I totally misunderstood the intention of this test.
| let ctx = ctx.clone(); | ||
| scope.spawn(move |_| loop { | ||
| let idx = idx.fetch_add(1, Ordering::SeqCst); | ||
| match this.read_by_index(idx, done_rx, &ctx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I understanding correctly here that this means that the workers will likely read past the last index? I guess there's not a nice way around it with this approach given that there doesn't appear to be a way to query for the length of settings up front. I'm assuming that all the settings registry implementations should be able to handle this? 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is how the python version works as well, a way to get the length upfront would be very nice indeed
| @@ -1,52 +0,0 @@ | |||
| #ifndef LIBSETTINGS_WRAPPER_H | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think you should also be able to delete the submodule now? 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using the settings.yaml in the root of the repo unfortunately. We could ditch the idea of a default settings.yaml, and move it into the swift-toolbox repo, could be nice
src/client.rs
Outdated
| WriteSettingError::Timeout => write!(f, "request wasn't replied in time"), | ||
| WriteSettingError::Unknown => { | ||
| write!(f, "unknown settings write response") | ||
| [group, name, value] | [group, name, value, ..] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would there be more than group, name, value out of interest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point I don't that should happen, I'll try out removing it
3cefd3d to
15df718
Compare
Had a really hard time debugging the various settings issues. After spending so much time looking at the c code, I realized it wasn't actually that much to re-implement everything natively
Pros:
Cons:
Overall seems to behave much better, I was able to bump the workers back up to 10 like the python version and haven't seen any problems yet
Using it here - swift-nav/swift-toolbox#249