-
Notifications
You must be signed in to change notification settings - Fork 160
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
Refactor: gate tokio rt with feature tokio-rt #1207
Refactor: gate tokio rt with feature tokio-rt #1207
Conversation
d0ae564
to
91b8a0a
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.
Reviewable status: 0 of 15 files reviewed, 1 unresolved discussion
openraft/src/raft/mod.rs
line 171 at r1 (raw file):
(Node , , $crate::impls::BasicNode ), (Entry , , $crate::impls::Entry<Self> ), (SnapshotData , , std::io::Cursor<Vec<u8>> ),
Use the full path here so that users won't need to manually import it when using this default 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.
Reviewed 15 of 15 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @SteveLauC)
openraft/src/metrics/wait.rs
line 69 at r1 (raw file):
futures::select_biased! { _ = delay.fuse() => { tracing::debug!( "id={} timeout wait {:} latest: {}", latest.id, msg.to_string(), latest );
You might want to correct indentation here.
openraft/src/network/snapshot_transport.rs
line 5 at r1 (raw file):
use std::future::Future; #[cfg(feature = "tokio-rt")]
Instead of many markers, you could group all relevant imports in a private mod tokio_deps
or so and then use tokio_imports::*
, so you'll only need two cfg
markers.
Similarly, the tokio_deps
module could also contain relevant impl
s from below, since they can be anywhere in the crate.
openraft/src/raft/mod.rs
line 33 at r1 (raw file):
use std::time::Duration; use async_lock::Mutex;
I'd suggest to move this to the AsyncRuntime
, alongside other sync primitives we already have 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.
Reviewable status: 13 of 15 files reviewed, 3 unresolved discussions (waiting on @drmingdrmer and @schreter)
openraft/src/metrics/wait.rs
line 69 at r1 (raw file):
Previously, schreter wrote…
You might want to correct indentation here.
Thanks for catching it! Done:)
openraft/src/network/snapshot_transport.rs
line 5 at r1 (raw file):
Previously, schreter wrote…
Instead of many markers, you could group all relevant imports in a private
mod tokio_deps
or so and thenuse tokio_imports::*
, so you'll only need twocfg
markers.Similarly, the
tokio_deps
module could also contain relevantimpl
s from below, since they can be anywhere in the crate.
It seems that if we move the implementation to this private module, then we don't need to use tokio_imports::*
as the things that need tokio are already in the module.
Done.
openraft/src/raft/mod.rs
line 33 at r1 (raw file):
Emm, previously @drmingdrmer said:
It's alright to mock a
Mutex
instead of requiring user to implement it.
Perhaps we could discuss a bit before adding it:)
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.
Reviewed 10 of 15 files at r1, 1 of 2 files at r2, all commit messages.
Reviewable status: 14 of 15 files reviewed, 5 unresolved discussions (waiting on @schreter and @SteveLauC)
openraft/src/engine/log_id_list.rs
line 305 at r2 (raw file):
pub(crate) fn key_log_ids(&self) -> &[LogId<C::NodeId>] { &self.key_log_ids }
Why does this method requires tokio-rs
?
Code quote:
#[cfg(feature = "tokio-rt")]
pub(crate) fn key_log_ids(&self) -> &[LogId<C::NodeId>] {
&self.key_log_ids
}
openraft/src/raft/mod.rs
line 33 at r1 (raw file):
Previously, SteveLauC (SteveLauC) wrote…
Emm, previously @drmingdrmer said:
It's alright to mock a
Mutex
instead of requiring user to implement it.Perhaps we could discuss a bit before adding it:)
Let's discuss here:
openraft/src/raft/mod.rs
line 171 at r1 (raw file):
Previously, SteveLauC (SteveLauC) wrote…
Use the full path here so that users won't need to manually import it when using this default value.
Great!
openraft/src/type_config/async_runtime/mod.rs
line 12 at r2 (raw file):
#[cfg(feature = "tokio-rt")] pub use tokio_runtime::TokioRuntime; }
The impls
module is specifically designed for use with Tokio. It would be more appropriately named tokio_impls
. Additionally, the relevant attribute should be applied to this module to clarify its purpose.
Code quote:
pub(crate) mod impls {
#[cfg(feature = "tokio-rt")]
mod tokio_runtime;
#[cfg(feature = "tokio-rt")]
pub use tokio_runtime::TokioRuntime;
}
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.
Reviewable status: 14 of 15 files reviewed, 3 unresolved discussions (waiting on @drmingdrmer and @schreter)
openraft/src/engine/log_id_list.rs
line 305 at r2 (raw file):
Previously, drmingdrmer (张炎泼) wrote…
Why does this method requires
tokio-rs
?
Sorry for being unclear, the attribute should be:
#[cfg_attr(not(feature = "tokio-rt"), allow(dead_code))]
as this method will only be used under feature tokio-rt.
openraft/src/type_config/async_runtime/mod.rs
line 12 at r2 (raw file):
Previously, drmingdrmer (张炎泼) wrote…
The
impls
module is specifically designed for use with Tokio. It would be more appropriately namedtokio_impls
. Additionally, the relevant attribute should be applied to this module to clarify its purpose.
Done.
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.
Reviewed 1 of 2 files at r2, 5 of 5 files at r3, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @schreter)
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.
Reviewed 2 of 2 files at r2, 5 of 5 files at r3, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @drmingdrmer and @SteveLauC)
openraft/src/engine/log_id_list.rs
line 305 at r2 (raw file):
Previously, SteveLauC (SteveLauC) wrote…
Sorry for being unclear, the attribute should be:
#[cfg_attr(not(feature = "tokio-rt"), allow(dead_code))]
as this method will only be used under feature tokio-rt.
I think it would make sense to make this method simply pub
, since it's used in many tests. Tests with other runtimes might want to request the log IDs as well.
openraft/src/network/snapshot_transport.rs
line 5 at r1 (raw file):
Previously, SteveLauC (SteveLauC) wrote…
It seems that if we move the implementation to this private module, then we don't need to
use tokio_imports::*
as the things that need tokio are already in the module.Done.
I didn't check the large move, but I assume it's just a move. If not, please mark code needing extra review.
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.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @drmingdrmer and @schreter)
openraft/src/engine/log_id_list.rs
line 305 at r2 (raw file):
Previously, schreter wrote…
I think it would make sense to make this method simply
pub
, since it's used in many tests. Tests with other runtimes might want to request the log IDs as well.
I think we can do this in the future when the support for other runtimes is added as we are currently not sure how to test a new async runtime
openraft/src/network/snapshot_transport.rs
line 5 at r1 (raw file):
Previously, schreter wrote…
I didn't check the large move, but I assume it's just a move. If not, please mark code needing extra review.
It is just a move, please see this commit.
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.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @drmingdrmer)
openraft/src/engine/log_id_list.rs
line 305 at r2 (raw file):
Previously, SteveLauC (SteveLauC) wrote…
I think we can do this in the future when the support for other runtimes is added as we are currently not sure how to test a new async runtime
Of course, you can keep it as-is. Just most likely it will be needed sooner or later. But, not sure.
60ceeb8
to
6368d5f
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.
Reviewed 9 of 9 files at r4, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @SteveLauC)
openraft/src/raft/mod.rs
line 46 at r4 (raw file):
#[cfg(feature = "tokio-rt")] use crate::async_runtime::mutex::Mutex;
Mutex is defined by async-runtime thus it does no need tokio-rs
feature enabled. no?
Code quote:
#[cfg(feature = "tokio-rt")]
use crate::async_runtime::mutex::Mutex;
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.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @drmingdrmer)
openraft/src/engine/log_id_list.rs
line 305 at r2 (raw file):
Previously, schreter wrote…
Of course, you can keep it as-is. Just most likely it will be needed sooner or later. But, not sure.
Done.
openraft/src/raft/mod.rs
line 46 at r4 (raw file):
Previously, drmingdrmer (张炎泼) wrote…
Mutex is defined by async-runtime thus it does no need
tokio-rs
feature enabled. no?
It is currently only used under the feature tokio-rt
, do I need to change it to:
#[cfg_attr(not(feature = "tokio-rt"), allow(unused_imports))]
to make it more clear?
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.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @SteveLauC)
openraft/src/raft/mod.rs
line 46 at r4 (raw file):
Previously, SteveLauC (SteveLauC) wrote…
It is currently only used under the feature
tokio-rt
, do I need to change it to:#[cfg_attr(not(feature = "tokio-rt"), allow(unused_imports))]
to make it more clear?
If it is not required by this file but only by a function,
you can just move this use
to the function install_snapshot
.
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.
Reviewable status: 15 of 16 files reviewed, 2 unresolved discussions (waiting on @drmingdrmer)
openraft/src/raft/mod.rs
line 46 at r4 (raw file):
Previously, drmingdrmer (张炎泼) wrote…
If it is not required by this file but only by a function,
you can just move thisuse
to the functioninstall_snapshot
.
That's a style I really love, extremely helpful when you are in a big bowl of cfg
soup, done!
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.
Reviewed 1 of 1 files at r5, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @SteveLauC)
Let me squash the commits:) Hi @schreter, do you want to take another look at this PR before I do that? |
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.
Reviewed 8 of 9 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @SteveLauC)
adeee32
to
c895163
Compare
Commits squashed |
Well, I cannot reproduce that test failure locally:> |
These tests are run with I'll have a look on the logs to see what's going wrong: |
Thanks for showing me that parameter! I just tried 17 times with that option, but I didn't reproduce the failure that occurred in CI, instead, I got this one: failures:
t11_add_learner::check_learner_after_leader_transferred
test result: FAILED. 39 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 13.68sj Though this test's log was mixed with previous tests' log so I cannot provide it 😞 |
It appears that these failures are not related to this PR. I will investigate to determine the cause. |
The failure should be fixed in: |
Merged and there should not be such issue any more 🤔 |
c895163
to
2777e81
Compare
Rebased. |
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.
Reviewed 3 of 3 files at r7, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @SteveLauC)
What does this PR do
Gates the tokio runtime with a new feature
tokio-rt
, and makes it a default feature.tokio_select!()
withfutures::select_biased!()
tokio-rt
feature.About the
declare_raft_types!
macroI haven't done anything to this because I haven't found a good way to update it, currently, with the
default
(tokio-rt
) feature off, using this macro without providing a runtime would result in a compile error:Checklist
This change is