Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit af93298

Browse files
authored
remove useless patches (#742)
1 parent 1beda6e commit af93298

File tree

16 files changed

+284
-257
lines changed

16 files changed

+284
-257
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[workspace]
22

3+
resolver = "2"
34
members = [
45
"bottomless",
56
"bottomless-cli",
@@ -33,12 +34,8 @@ publish-jobs = ["homebrew"]
3334
# Whether cargo-dist should create a Github Release or use an existing draft
3435
create-release = false
3536

36-
# TODO(lucio): Remove this once tonic has released a new version with fixes
3737
[patch.crates-io]
38-
tonic = { git = "https://github.com/hyperium/tonic" }
39-
tonic-build = { git = "https://github.com/hyperium/tonic" }
40-
console-api = { git = "https://github.com/tokio-rs/console", branch = "lucio/tonic-fix" }
41-
libsql = { git = "https://github.com/libsql/libsql.git", rev = "61b4f5b" }
38+
sqlite3-parser = { git = "https://github.com/LucioFranco/lemon-rs" }
4239

4340
# The profile that 'cargo dist' will build with
4441
[profile.dist]

bottomless/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,9 @@ pub mod static_init {
583583
INIT.call_once(|| {
584584
crate::bottomless_init();
585585
let orig_methods = unsafe { libsql_wal_methods_find(std::ptr::null()) };
586-
if orig_methods.is_null() {}
586+
if orig_methods.is_null() {
587+
panic!("failed to locate default WAL methods")
588+
}
587589
let methods = crate::bottomless_methods(orig_methods);
588590
let rc = unsafe { libsql_wal_methods_register(methods) };
589591
if rc != crate::ffi::SQLITE_OK {

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
22
profile = "default"
3-
channel = "1.70.0"
3+
channel = "1.73.0"

sqld/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ hyper-rustls = { git = "https://github.com/rustls/hyper-rustls.git", rev = "163b
7070
rustls-pemfile = "1.0.3"
7171
rustls = "0.21.7"
7272
async-stream = "0.3.5"
73-
libsql = { version = "0.1", optional = true }
73+
libsql = { git = "https://github.com/tursodatabase/libsql.git", rev = "bea8863", optional = true }
7474

7575
[dev-dependencies]
7676
proptest = "1.0.0"

sqld/src/auth.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ impl Auth {
7979
}
8080

8181
let Some(auth_header) = auth_header else {
82-
return Err(AuthError::HttpAuthHeaderMissing)
82+
return Err(AuthError::HttpAuthHeaderMissing);
8383
};
8484

8585
match parse_http_auth_header(auth_header)? {
8686
HttpAuthHeader::Basic(actual_value) => {
8787
let Some(expected_value) = self.http_basic.as_ref() else {
88-
return Err(AuthError::BasicNotAllowed)
88+
return Err(AuthError::BasicNotAllowed);
8989
};
9090
// NOTE: this naive comparison may leak information about the `expected_value`
9191
// using a timing attack
@@ -133,7 +133,7 @@ impl Auth {
133133
}
134134

135135
let Some(jwt) = jwt else {
136-
return Err(AuthError::JwtMissing)
136+
return Err(AuthError::JwtMissing);
137137
};
138138

139139
self.validate_jwt(jwt, disable_namespaces)
@@ -145,7 +145,7 @@ impl Auth {
145145
disable_namespaces: bool,
146146
) -> Result<Authenticated, AuthError> {
147147
let Some(jwt_key) = self.jwt_key.as_ref() else {
148-
return Err(AuthError::JwtNotAllowed)
148+
return Err(AuthError::JwtNotAllowed);
149149
};
150150
validate_jwt(jwt_key, jwt, disable_namespaces)
151151
}
@@ -250,11 +250,11 @@ fn parse_http_auth_header(
250250
header: &hyper::header::HeaderValue,
251251
) -> Result<HttpAuthHeader, AuthError> {
252252
let Ok(header) = header.to_str() else {
253-
return Err(AuthError::HttpAuthHeaderInvalid)
253+
return Err(AuthError::HttpAuthHeaderInvalid);
254254
};
255255

256256
let Some((scheme, param)) = header.split_once(' ') else {
257-
return Err(AuthError::HttpAuthHeaderInvalid)
257+
return Err(AuthError::HttpAuthHeaderInvalid);
258258
};
259259

260260
if scheme.eq_ignore_ascii_case("basic") {

sqld/src/connection/dump/exporter.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ impl<W: Write> DumpState<W> {
2424
let mut stmt = txn.prepare(stmt)?;
2525
let mut rows = stmt.query(())?;
2626
while let Some(row) = rows.next()? {
27-
let ValueRef::Text(table) = row.get_ref(0)? else { bail!("invalid schema table") };
28-
let ValueRef::Text(ty) = row.get_ref(1)? else { bail!("invalid schema table") };
29-
let ValueRef::Text(sql) = row.get_ref(2)? else { bail!("invalid schema table") };
27+
let ValueRef::Text(table) = row.get_ref(0)? else {
28+
bail!("invalid schema table")
29+
};
30+
let ValueRef::Text(ty) = row.get_ref(1)? else {
31+
bail!("invalid schema table")
32+
};
33+
let ValueRef::Text(sql) = row.get_ref(2)? else {
34+
bail!("invalid schema table")
35+
};
3036

3137
if table == b"sqlite_sequence" {
3238
writeln!(self.writer, "DELETE FROM sqlite_sequence;")?;
@@ -120,10 +126,14 @@ impl<W: Write> DumpState<W> {
120126
let col_count = stmt.column_count();
121127
let mut rows = stmt.query(())?;
122128
while let Some(row) = rows.next()? {
123-
let ValueRef::Text(sql) = row.get_ref(0)? else { bail!("the first row in a table dump query should be of type text") };
129+
let ValueRef::Text(sql) = row.get_ref(0)? else {
130+
bail!("the first row in a table dump query should be of type text")
131+
};
124132
self.writer.write_all(sql)?;
125133
for i in 1..col_count {
126-
let ValueRef::Text(s) = row.get_ref(i)? else { bail!("row {i} in table dump query should be of type text") };
134+
let ValueRef::Text(s) = row.get_ref(i)? else {
135+
bail!("row {i} in table dump query should be of type text")
136+
};
127137
let s = std::str::from_utf8(s)?;
128138
write!(self.writer, ",{s}")?;
129139
}
@@ -258,7 +268,7 @@ impl Display for Quoted<'_> {
258268
let s = &self.0;
259269
let Some(first) = s.chars().next() else {
260270
write!(f, "{s}")?;
261-
return Ok(())
271+
return Ok(());
262272
};
263273
if !first.is_alphabetic() && first != '_' {
264274
write!(f, r#""{s}""#)?;

sqld/src/hrana/cursor.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ async fn run_cursor<C: Connection>(
7878
open_rx: oneshot::Receiver<OpenReq<C>>,
7979
entry_tx: mpsc::Sender<Result<SizedEntry>>,
8080
) {
81-
let Ok(open_req) = open_rx.await else {
82-
return
83-
};
81+
let Ok(open_req) = open_rx.await else { return };
8482

8583
let result_builder = CursorResultBuilder {
8684
entry_tx: entry_tx.clone(),

sqld/src/hrana/http/stream.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ pub async fn acquire<'srv, D: Connection>(
142142
}
143143
};
144144

145-
let Handle::Available(mut stream) = mem::replace(handle.unwrap(), Handle::Acquired) else {
145+
let Handle::Available(mut stream) = mem::replace(handle.unwrap(), Handle::Acquired)
146+
else {
146147
unreachable!()
147148
};
148149

@@ -235,8 +236,10 @@ impl<'srv, D> Drop for Guard<'srv, D> {
235236

236237
let mut state = self.server.stream_state.lock();
237238
let Some(handle) = state.handles.remove(&stream_id) else {
238-
panic!("Dropped a Guard for stream {stream_id}, \
239-
but Server does not contain a handle to it");
239+
panic!(
240+
"Dropped a Guard for stream {stream_id}, \
241+
but Server does not contain a handle to it"
242+
);
240243
};
241244
if !matches!(handle, Handle::Acquired) {
242245
panic!(

sqld/src/hrana/ws/handshake.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ fn negotiate_subproto(
153153
.map(|s| s.as_str())
154154
.collect::<Vec<_>>()
155155
.join(" ");
156-
return Err(format!("Only these WebSocket subprotocols are supported: {}", supported))
156+
return Err(format!(
157+
"Only these WebSocket subprotocols are supported: {}",
158+
supported
159+
));
157160
};
158161

159162
tracing::debug!(

sqld/src/hrana/ws/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ pub(super) async fn handle_request<F: MakeNamespace>(
379379
while entries.len() < max_count && total_size < max_total_size {
380380
let Some(sized_entry) = cursor_hnd.fetch().await? else {
381381
done = true;
382-
break
382+
break;
383383
};
384384
entries.push(sized_entry.entry);
385385
total_size += sized_entry.size;

sqld/src/namespace/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,9 @@ async fn run_storage_monitor(db_path: PathBuf, stats: Weak<Stats>) -> anyhow::Re
991991
let db_path: Arc<Path> = db_path.into();
992992
loop {
993993
let db_path = db_path.clone();
994-
let Some(stats) = stats.upgrade() else { return Ok(()) };
994+
let Some(stats) = stats.upgrade() else {
995+
return Ok(());
996+
};
995997
let _ = tokio::task::spawn_blocking(move || {
996998
// because closing the last connection interferes with opening a new one, we lazily
997999
// initialize a connection here, and keep it alive for the entirety of the program. If we

sqld/src/replication/primary/logger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ impl ReplicationLogger {
940940
let mut frames_iter = log_file.rev_frames_iter()?;
941941
let Some(last_frame_res) = frames_iter.next() else {
942942
// the log file is empty, nothing to compact
943-
return Ok(false)
943+
return Ok(false);
944944
};
945945
last_frame_res?
946946
};

sqld/src/replication/replica/replicator.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ impl Replicator {
107107

108108
let (snd, rcv) = oneshot::channel();
109109
let handle = BLOCKING_RT.spawn_blocking({
110-
let db_path = db_path;
111110
move || -> anyhow::Result<()> {
112111
let ctx = InjectorHookCtx::new(receiver, pre_commit, post_commit);
113112
let mut injector = FrameInjector::new(&db_path, ctx)?;

sqld/src/replication/snapshot.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,19 @@ pub struct SnapshotFile {
5656
fn parse_snapshot_name(name: &str) -> Option<(Uuid, u64, u64)> {
5757
static SNAPSHOT_FILE_MATCHER: Lazy<Regex> = Lazy::new(|| {
5858
Regex::new(
59-
r#"(?x)
59+
r"(?x)
6060
# match database id
6161
(\w{8}-\w{4}-\w{4}-\w{4}-\w{12})-
6262
# match start frame_no
6363
(\d*)-
6464
# match end frame_no
65-
(\d*).snap"#,
65+
(\d*).snap",
6666
)
6767
.unwrap()
6868
});
69-
let Some(captures) = SNAPSHOT_FILE_MATCHER.captures(name) else { return None};
69+
let Some(captures) = SNAPSHOT_FILE_MATCHER.captures(name) else {
70+
return None;
71+
};
7072
let db_id = captures.get(1).unwrap();
7173
let start_index: u64 = captures.get(2).unwrap().as_str().parse().unwrap();
7274
let end_index: u64 = captures.get(3).unwrap().as_str().parse().unwrap();
@@ -82,10 +84,16 @@ fn snapshot_list(db_path: &Path) -> anyhow::Result<impl Iterator<Item = String>>
8284
let mut entries = std::fs::read_dir(snapshot_dir_path(db_path))?;
8385
Ok(std::iter::from_fn(move || {
8486
for entry in entries.by_ref() {
85-
let Ok(entry) = entry else { continue; };
87+
let Ok(entry) = entry else {
88+
continue;
89+
};
8690
let path = entry.path();
87-
let Some(name) = path.file_name() else {continue;};
88-
let Some(name_str) = name.to_str() else { continue;};
91+
let Some(name) = path.file_name() else {
92+
continue;
93+
};
94+
let Some(name_str) = name.to_str() else {
95+
continue;
96+
};
8997

9098
return Some(name_str.to_string());
9199
}
@@ -100,7 +108,9 @@ pub fn find_snapshot_file(
100108
) -> anyhow::Result<Option<SnapshotFile>> {
101109
let snapshot_dir_path = snapshot_dir_path(db_path);
102110
for name in snapshot_list(db_path)? {
103-
let Some((_, start_frame_no, end_frame_no)) = parse_snapshot_name(&name) else { continue; };
111+
let Some((_, start_frame_no, end_frame_no)) = parse_snapshot_name(&name) else {
112+
continue;
113+
};
104114
// we're looking for the frame right after the last applied frame on the replica
105115
if (start_frame_no..=end_frame_no).contains(&frame_no) {
106116
let snapshot_path = snapshot_dir_path.join(&name);

sqld/tests/cluster.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod test {
66
77
use super::common;
88

9-
use libsql::{hrana::HranaError, Database, Value};
9+
use libsql::{Database, Value};
1010
use serde_json::json;
1111
use sqld::config::{AdminApiConfig, RpcClientConfig, RpcServerConfig, UserApiConfig};
1212
use tempfile::tempdir;
@@ -215,9 +215,13 @@ mod test {
215215
)?;
216216
let conn = db.connect()?;
217217

218-
let Err(e) = conn.execute("create table test (x)", ()).await else { panic!() };
219-
let libsql::Error::Hrana(HranaError::Api(msg)) = e else { panic!() };
220-
assert_eq!(msg, "{\"error\":\"Namespace `foo` doesn't exist\"}");
218+
let Err(e) = conn.execute("create table test (x)", ()).await else {
219+
panic!()
220+
};
221+
assert_eq!(
222+
e.to_string(),
223+
"Hrana: `api error: `{\"error\":\"Namespace `foo` doesn't exist\"}``"
224+
);
221225

222226
let client = Client::new();
223227
let resp = client

0 commit comments

Comments
 (0)