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

Feature: Add random number generator to AsyncRuntime #995

Merged
merged 1 commit into from
Jan 19, 2024

Conversation

schreter
Copy link
Collaborator

@schreter schreter commented Jan 19, 2024

Up to now, the rand crate was used directly to generate random numbers for openraft. However, this has some drawback when integrating with other async runtimes.

Expose the random number generator via AsyncRuntime abstraction and implement it by default via rand::thread_rng().


This change is Reviewable

Up to now, the `rand` crate was used directly to generate random numbers
for `openraft`. However, this has some drawback when integrating with
other async runtimes.

Expose the random number generator via `AsyncRuntime` abstraction and
implement it by default via `rand::thread_rng()`.
Copy link
Collaborator Author

@schreter schreter left a comment

Choose a reason for hiding this comment

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

+reviewer:@drmingdrmer

This completes #943

Reviewable status: 0 of 4 files reviewed, all discussions resolved (waiting on @drmingdrmer)


openraft/src/config/config.rs line 251 at r1 (raw file):

impl Config {
    /// Generate a new random election timeout within the configured min & max.
    pub fn new_rand_election_timeout<RT: AsyncRuntime>(&self) -> u64 {

Instead of generalizing the types Config and EngineConfig I decided to just generalize respective methods to make the change minimal.

Copy link
Member

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @schreter)


openraft/src/config/config.rs line 251 at r1 (raw file):

Previously, schreter wrote…

Instead of generalizing the types Config and EngineConfig I decided to just generalize respective methods to make the change minimal.

Looks good enough :)

@drmingdrmer drmingdrmer merged commit 49e8adf into databendlabs:main Jan 19, 2024
28 checks passed
@schreter schreter deleted the thread_rng_in_runtime branch February 10, 2024 12:51
@drmingdrmer drmingdrmer mentioned this pull request Mar 9, 2024
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