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

chore: pin rust version and fix lints #1823

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ 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
rustflags: -D warnings --cfg tokio_unstable
- name: Check format
run: cargo fmt --all -- --check
- name: Check
run: cargo check --verbose --all-targets --all-features
run: cargo check --all-targets --all-features
- name: Clippy
run: cargo clippy --workspace --no-deps --all-features --all-targets -- -D warnings
- name: Validate documentation
run: cargo doc --workspace --no-deps --all-features
- name: Run tests
run: cargo test --verbose
run: cargo test
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
Loading