Skip to content

Commit 59fb620

Browse files
authored
chore: Bump to Rust 2024 edition (#76)
* Bump to Rust 2024 * argo +nightly fmt * changelog
1 parent eb00703 commit 59fb620

File tree

29 files changed

+183
-133
lines changed

29 files changed

+183
-133
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ All notable changes to this project will be documented in this file.
1616

1717
- Improve tracing for running queries on Trino, adding spans for the request to Trino and parsing ([#71]).
1818
- Improve performance by using [`serde_json::value::RawValue`](https://docs.rs/serde_json/latest/serde_json/value/struct.RawValue.html) for the `data` and `columns` attributes to avoid unneeded deserialization and serialization of them ([#73]).
19+
- Bumped to Rust 2024 edition ([#76]).
1920

2021
[#70]: https://github.com/stackabletech/trino-lb/pull/70
2122
[#71]: https://github.com/stackabletech/trino-lb/pull/71
2223
[#73]: https://github.com/stackabletech/trino-lb/pull/73
2324
[#74]: https://github.com/stackabletech/trino-lb/pull/74
25+
[#76]: https://github.com/stackabletech/trino-lb/pull/76
2426

2527
## [0.4.1] - 2025-03-03
2628

Cargo.lock

Lines changed: 14 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ resolver = "2"
1111
version = "0.4.1"
1212
authors = ["Stackable GmbH <[email protected]>"]
1313
license = "Apache-2.0"
14-
edition = "2021"
14+
edition = "2024"
1515
repository = "https://github.com/stackabletech/trino-lb"
1616

1717
[workspace.dependencies]

trino-lb-bench/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{sync::Arc, time::Duration};
33
use args::Args;
44
use clap::Parser;
55
use indicatif::{MultiProgress, ProgressBar};
6-
use prusto::{auth::Auth, ClientBuilder, Row};
6+
use prusto::{ClientBuilder, Row, auth::Auth};
77
use tokio::time;
88

99
mod args;

trino-lb-core/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use serde::Deserialize;
1010
use snafu::{ResultExt, Snafu};
1111
use url::Url;
1212

13-
use crate::{trino_query_plan::QueryPlanEstimation, TrinoClusterName};
13+
use crate::{TrinoClusterName, trino_query_plan::QueryPlanEstimation};
1414

1515
#[derive(Snafu, Debug)]
1616
pub enum Error {

trino-lb-core/src/sanitization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ impl Sanitize for http::HeaderMap {
1515
#[cfg(test)]
1616
mod tests {
1717
use http::{
18-
header::{CONTENT_LENGTH, HOST},
1918
HeaderMap, HeaderValue,
19+
header::{CONTENT_LENGTH, HOST},
2020
};
2121

2222
use super::*;

trino-lb-core/src/trino_api.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use snafu::{ResultExt, Snafu};
1010
use tracing::instrument;
1111
use url::Url;
1212

13-
use crate::{trino_query::QueuedQuery, TrinoQueryId};
13+
use crate::{TrinoQueryId, trino_query::QueuedQuery};
1414

1515
#[derive(Snafu, Debug)]
1616
pub enum Error {
@@ -23,10 +23,14 @@ pub enum Error {
2323
#[snafu(display("Failed to parse nextUri Trino send us"))]
2424
ParseNextUriFromTrino { source: url::ParseError },
2525

26-
#[snafu(display("Failed to determine the elapsed time of a queued query. Are all system clocks of trino-lb instances in sync?"))]
26+
#[snafu(display(
27+
"Failed to determine the elapsed time of a queued query. Are all system clocks of trino-lb instances in sync?"
28+
))]
2729
DetermineElapsedTime { source: SystemTimeError },
2830

29-
#[snafu(display("The queued time {queued_time:?} is too big to be send to trino, as the trino API only accepts an 64bit number for queued_time_millis"))]
31+
#[snafu(display(
32+
"The queued time {queued_time:?} is too big to be send to trino, as the trino API only accepts an 64bit number for queued_time_millis"
33+
))]
3034
ElapsedTimeTooBig {
3135
source: TryFromIntError,
3236
queued_time: Duration,

trino-lb-core/src/trino_query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
66
use tracing::instrument;
77
use url::Url;
88

9-
use crate::{sanitization::Sanitize, TrinoClusterName, TrinoLbQueryId, TrinoQueryId};
9+
use crate::{TrinoClusterName, TrinoLbQueryId, TrinoQueryId, sanitization::Sanitize};
1010

1111
pub const QUEUED_QUERY_ID_PREFIX: &str = "trino_lb_";
1212

trino-lb-persistence/src/in_memory.rs

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use snafu::{OptionExt, ResultExt, Snafu};
99
use tokio::sync::RwLock;
1010
use tracing::{error, info, instrument};
1111
use trino_lb_core::{
12+
TrinoClusterName, TrinoLbQueryId, TrinoQueryId,
1213
trino_cluster::ClusterState,
1314
trino_query::{QueuedQuery, TrinoQuery},
14-
TrinoClusterName, TrinoLbQueryId, TrinoQueryId,
1515
};
1616

1717
use crate::Persistence;
@@ -35,7 +35,9 @@ pub enum Error {
3535
#[snafu(display("Failed to determined elapsed time since last queryCountFetcher update"))]
3636
DetermineElapsedTimeSinceLastUpdate { source: SystemTimeError },
3737

38-
#[snafu(display("Failed to store determined elapsed time since last queryCountFetcher update as millis in a u64"))]
38+
#[snafu(display(
39+
"Failed to store determined elapsed time since last queryCountFetcher update as millis in a u64"
40+
))]
3941
ConvertElapsedTimeSinceLastUpdateToMillis { source: TryFromIntError },
4042
}
4143

@@ -115,37 +117,40 @@ impl Persistence for InMemoryPersistence {
115117
) -> Result<bool, super::Error> {
116118
let current_counts = self.cluster_query_counts.read().await;
117119

118-
if let Some(count) = current_counts.get(cluster_name) {
119-
let mut current = count.load(Ordering::SeqCst);
120-
loop {
121-
if current + 1 > max_allowed_count {
122-
return Ok(false);
123-
}
120+
match current_counts.get(cluster_name) {
121+
Some(count) => {
122+
let mut current = count.load(Ordering::SeqCst);
123+
loop {
124+
if current + 1 > max_allowed_count {
125+
return Ok(false);
126+
}
124127

125-
match count.compare_exchange_weak(
126-
current,
127-
current + 1,
128-
Ordering::SeqCst,
129-
// [`Ordering::Relaxed`] should be sufficient here, but better safe than sorry
130-
Ordering::SeqCst,
131-
) {
132-
Ok(_) => {
133-
return Ok(true);
128+
match count.compare_exchange_weak(
129+
current,
130+
current + 1,
131+
Ordering::SeqCst,
132+
// [`Ordering::Relaxed`] should be sufficient here, but better safe than sorry
133+
Ordering::SeqCst,
134+
) {
135+
Ok(_) => {
136+
return Ok(true);
137+
}
138+
Err(x) => current = x,
134139
}
135-
Err(x) => current = x,
136140
}
137141
}
138-
} else {
139-
// We need to drop `current_counts` here to release the read lock it holds :)
140-
// Otherwise the [`RwLock::write`] call will block forever.
141-
drop(current_counts);
142+
_ => {
143+
// We need to drop `current_counts` here to release the read lock it holds :)
144+
// Otherwise the [`RwLock::write`] call will block forever.
145+
drop(current_counts);
142146

143-
self.cluster_query_counts
144-
.write()
145-
.await
146-
.insert(cluster_name.clone(), AtomicU64::new(1));
147+
self.cluster_query_counts
148+
.write()
149+
.await
150+
.insert(cluster_name.clone(), AtomicU64::new(1));
147151

148-
Ok(true)
152+
Ok(true)
153+
}
149154
}
150155
}
151156

@@ -154,16 +159,21 @@ impl Persistence for InMemoryPersistence {
154159
&self,
155160
cluster_name: &TrinoClusterName,
156161
) -> Result<(), super::Error> {
157-
if let Some(count) = self.cluster_query_counts.read().await.get(cluster_name) {
158-
if count.fetch_sub(1, Ordering::SeqCst) == 0 {
162+
match self.cluster_query_counts.read().await.get(cluster_name) {
163+
Some(count) => {
164+
if count.fetch_sub(1, Ordering::SeqCst) == 0 {
165+
error!(
166+
cluster_name,
167+
"Persistence was asked to decrement the number of queries for the given cluster, but it would result in a negative amount of queries. Setting it to 0 instead."
168+
);
169+
count.store(0, Ordering::SeqCst);
170+
}
171+
}
172+
_ => {
159173
error!(
160-
cluster_name,
161-
"Persistence was asked to decrement the number of queries for the given cluster, but it would result in a negative amount of queries. Setting it to 0 instead."
162-
);
163-
count.store(0, Ordering::SeqCst);
174+
"Persistence was asked to decrement the number of queries, but no query count for this cluster was not known. This should not happen."
175+
)
164176
}
165-
} else {
166-
error!("Persistence was asked to decrement the number of queries, but no query count for this cluster was not known. This should not happen.")
167177
}
168178

169179
Ok(())
@@ -176,15 +186,18 @@ impl Persistence for InMemoryPersistence {
176186
count: u64,
177187
) -> Result<(), super::Error> {
178188
let current_counts = self.cluster_query_counts.read().await;
179-
if let Some(current_count) = current_counts.get(cluster_name) {
180-
current_count.store(count, Ordering::SeqCst);
181-
} else {
182-
drop(current_counts);
183-
184-
self.cluster_query_counts
185-
.write()
186-
.await
187-
.insert(cluster_name.clone(), AtomicU64::from(count));
189+
match current_counts.get(cluster_name) {
190+
Some(current_count) => {
191+
current_count.store(count, Ordering::SeqCst);
192+
}
193+
_ => {
194+
drop(current_counts);
195+
196+
self.cluster_query_counts
197+
.write()
198+
.await
199+
.insert(cluster_name.clone(), AtomicU64::from(count));
200+
}
188201
}
189202

190203
Ok(())

trino-lb-persistence/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use std::{fmt::Debug, time::SystemTime};
33
use enum_dispatch::enum_dispatch;
44
use snafu::Snafu;
55
use trino_lb_core::{
6+
TrinoClusterName, TrinoLbQueryId, TrinoQueryId,
67
trino_cluster::ClusterState,
78
trino_query::{QueuedQuery, TrinoQuery},
8-
TrinoClusterName, TrinoLbQueryId, TrinoQueryId,
99
};
1010

1111
pub mod in_memory;

0 commit comments

Comments
 (0)