Skip to content

Commit

Permalink
chore: pin rust version and fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed Jan 18, 2025
1 parent d3a8a9c commit 282bc7f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ jobs:
timeout-minutes: 15

steps:
- run: rustup component add clippy rustfmt

- uses: actions/checkout@v4
- name: Rust Cache
uses: Swatinem/[email protected]
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt, clippy
toolchain: 1.84.0
# - name: Rust Cache
# uses: Swatinem/[email protected]
- name: Check format
run: cargo fmt --all -- --check
- name: Check
Expand Down
4 changes: 2 additions & 2 deletions crates/ott-balancer/src/balancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,12 @@ impl BalancerContext {

pub fn select_monolith(&self, room: &RoomName) -> anyhow::Result<&BalancerMonolith> {
let filtered = self.filter_monoliths();
return self.monolith_selection.select_monolith(room, filtered);
self.monolith_selection.select_monolith(room, filtered)
}

pub fn random_monolith(&self) -> anyhow::Result<&BalancerMonolith> {
let filtered = self.filter_monoliths();
return self.monolith_selection.random_monolith(filtered);
self.monolith_selection.random_monolith(filtered)
}

#[instrument(skip(self, monolith), err, fields(monolith_id = %monolith))]
Expand Down
5 changes: 1 addition & 4 deletions crates/ott-balancer/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,7 @@ pub async fn client_entry<'r>(
Ok(())
}

async fn close<'s, S>(
stream: &mut WebSocketStream<S>,
frame: CloseFrame<'static>,
) -> anyhow::Result<()>
async fn close<S>(stream: &mut WebSocketStream<S>, frame: CloseFrame<'static>) -> anyhow::Result<()>
where
S: AsyncRead + AsyncWrite + Unpin,
{
Expand Down
8 changes: 7 additions & 1 deletion crates/ott-balancer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,25 @@ impl BalancerConfig {
config.region = region.into();
}
// SAFETY: CONFIG is only mutated once, and only from this thread. All other accesses are read-only.
#[allow(static_mut_refs)]
CONFIG_INIT.call_once(|| unsafe { *CONFIG.borrow_mut() = Some(config) });
Ok(())
}

/// Initialize the config with default values.
pub fn init_default() {
// SAFETY: CONFIG is only mutated once, and only from this thread. All other accesses are read-only.
#[allow(static_mut_refs)]
CONFIG_INIT.call_once(|| unsafe { *CONFIG.borrow_mut() = Some(BalancerConfig::default()) });
}

pub fn get() -> &'static Self {
debug_assert!(CONFIG_INIT.is_completed(), "config not initialized");
// SAFETY: get is never called before CONFIG is initialized.
unsafe { CONFIG.as_ref().expect("config not initialized") }
#[allow(static_mut_refs)]
unsafe {
CONFIG.as_ref().expect("config not initialized")
}
}

/// Get a mutable reference to the config. Should only be used for tests and benchmarks.
Expand All @@ -72,6 +77,7 @@ impl BalancerConfig {
pub unsafe fn get_mut() -> &'static mut Self {
debug_assert!(CONFIG_INIT.is_completed(), "config not initialized");
// SAFETY: get_mut is only used for benchmarks
#[allow(static_mut_refs)]
CONFIG.as_mut().expect("config not initialized")
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/ott-balancer/src/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ pub trait MonolithSelection: std::fmt::Debug {
&'a self,
room: &RoomName,
monoliths: Vec<&'a BalancerMonolith>,
) -> anyhow::Result<&BalancerMonolith>;
) -> anyhow::Result<&'a BalancerMonolith>;

fn random_monolith<'a>(
&'a self,
monoliths: Vec<&'a BalancerMonolith>,
) -> anyhow::Result<&BalancerMonolith> {
) -> anyhow::Result<&'a BalancerMonolith> {
let selected = monoliths
.iter()
.choose(&mut rand::thread_rng())
Expand Down Expand Up @@ -72,7 +72,7 @@ impl MonolithSelection for MinRoomsSelector {
&'a self,
_room: &RoomName,
monoliths: Vec<&'a BalancerMonolith>,
) -> anyhow::Result<&BalancerMonolith> {
) -> anyhow::Result<&'a BalancerMonolith> {
fn cmp(x: &BalancerMonolith, y: &BalancerMonolith) -> std::cmp::Ordering {
x.rooms().len().cmp(&y.rooms().len())
}
Expand Down Expand Up @@ -113,7 +113,7 @@ impl MonolithSelection for HashRingSelector {
&'a self,
room: &RoomName,
monoliths: Vec<&'a BalancerMonolith>,
) -> anyhow::Result<&BalancerMonolith> {
) -> anyhow::Result<&'a BalancerMonolith> {
let weight = self.config.weight.max(1);
let mut ring = HashRing::new();
ring.batch_add(
Expand Down Expand Up @@ -154,7 +154,7 @@ impl MonolithSelection for RandomSelector {
&'a self,
_room: &RoomName,
monoliths: Vec<&'a BalancerMonolith>,
) -> anyhow::Result<&BalancerMonolith> {
) -> anyhow::Result<&'a BalancerMonolith> {
self.random_monolith(monoliths)
}
}
Expand Down

0 comments on commit 282bc7f

Please sign in to comment.