Skip to content

Commit

Permalink
Merge 98d6248 into sapling-pr-archive-shadaj
Browse files Browse the repository at this point in the history
  • Loading branch information
shadaj authored Nov 8, 2024
2 parents 1300355 + 98d6248 commit d56476e
Show file tree
Hide file tree
Showing 50 changed files with 8,997 additions and 5,075 deletions.
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions datastores/gossip_kv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "Apache-2.0"
publish = false

[dependencies]
clap = { version = "4.5.4", features = ["derive"] }
clap = { version = "4.5.4", features = ["derive", "env"] }
config = "0.14.0"
governor = "0.7.0"
hostname = "0.4.0"
Expand Down Expand Up @@ -42,4 +42,4 @@ path = "cli/main.rs"

[lib]
name = "gossip_kv"
path = "kv/lib.rs"
path = "kv/lib.rs"
5 changes: 4 additions & 1 deletion datastores/gossip_kv/server/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ struct Opts {
/// The duration (in seconds) between gossip rounds.
#[clap(short, long, default_value = "5", value_parser = clap_duration_from_secs)]
gossip_frequency: Duration,

#[clap(env = "GOSSIP_MEMBER_SUFFIX_LEN", default_value = "4")]
member_suffix_len: usize,
}

/// Parse duration from float string for clap args.
Expand Down Expand Up @@ -133,7 +136,7 @@ async fn main() {
let gossip_protocol_address =
SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), opts.gossip_port);

let member_data = MemberDataBuilder::new(member_name().clone())
let member_data = MemberDataBuilder::new(member_name(opts.member_suffix_len).clone())
.add_protocol(Protocol::new("gossip".into(), gossip_protocol_address))
.add_protocol(Protocol::new("client".into(), client_protocol_address))
.build();
Expand Down
49 changes: 23 additions & 26 deletions datastores/gossip_kv/server/membership.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
use std::sync::OnceLock;

use gossip_kv::membership::MemberId;
// use rand::distributions::Distribution;
// use rand::{Rng};
use rand::distributions::Distribution;
use rand::{thread_rng, Rng};

// /// This is a simple distribution that generates a random lower-case alphanumeric
// struct LowercaseAlphanumeric;
//
// impl Distribution<char> for LowercaseAlphanumeric {
// fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> char {
// let choices = b"abcdefghijklmnopqrstuvwxyz0123456789";
// choices[rng.gen_range(0..choices.len())] as char
// }
// }
/// This is a simple distribution that generates a random lower-case alphanumeric
struct LowercaseAlphanumeric;

impl Distribution<char> for LowercaseAlphanumeric {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> char {
let choices = b"abcdefghijklmnopqrstuvwxyz0123456789";
choices[rng.gen_range(0..choices.len())] as char
}
}

/// Gets a name for the current process.
pub fn member_name() -> &'static MemberId {
pub fn member_name(random_suffix_len: usize) -> &'static MemberId {
static MEMBER_NAME: OnceLock<MemberId> = OnceLock::new();
MEMBER_NAME.get_or_init(|| {
// Generate a lower-case alphanumeric suffix of length 4

// TODO: Random suffixes are good, but make benchmarking a pain. For now, we'll just use
// the hostname as-is.

// let suffix: String = thread_rng()
// .sample_iter(&LowercaseAlphanumeric)
// .take(4)
// .map(char::from)
// .collect();

// Retrieve hostname
hostname::get().unwrap().to_str().unwrap().to_string()
let hostname = hostname::get().unwrap().to_str().unwrap().to_string();

// format!("{}-{}", hostname, suffix)
if random_suffix_len > 0 {
let suffix: String = thread_rng()
.sample_iter(&LowercaseAlphanumeric)
.take(4)
.map(char::from)
.collect();
format!("{}-{}", hostname, suffix)
} else {
hostname
}
})
}
4 changes: 2 additions & 2 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion

const lightCodeTheme = require('prism-react-renderer/themes/github');
const darkCodeTheme = require('prism-react-renderer/themes/dracula');
const lightCodeTheme = require('prism-react-renderer').themes.github;
const darkCodeTheme = require('prism-react-renderer').themes.dracula;

const math = require('remark-math');
const katex = require('rehype-katex');
Expand Down
Loading

0 comments on commit d56476e

Please sign in to comment.