From 4bcae54aa95c913366de085aaa24aca28a2fa5d0 Mon Sep 17 00:00:00 2001 From: Joan Martinez Date: Sun, 21 Jul 2024 19:01:58 +0200 Subject: [PATCH] fix: use Arc to handle IO --- bindings/wasm/lib.rs | 3 ++- cli/main.rs | 12 +++++++----- core/btree.rs | 2 +- core/lib.rs | 5 +++-- core/pager.rs | 6 +++--- core/vdbe.rs | 4 ++-- core/where_clause.rs | 10 +++++----- perf/latency/limbo/Cargo.toml | 2 +- perf/latency/limbo/src/main.rs | 2 +- simulator/main.rs | 3 ++- sqlite3/src/lib.rs | 5 +++-- 11 files changed, 30 insertions(+), 24 deletions(-) diff --git a/bindings/wasm/lib.rs b/bindings/wasm/lib.rs index 447b869c5..ba56ccdc4 100644 --- a/bindings/wasm/lib.rs +++ b/bindings/wasm/lib.rs @@ -1,5 +1,6 @@ use anyhow::Result; use std::rc::Rc; +use std::sync::Arc; use wasm_bindgen::prelude::*; #[wasm_bindgen] @@ -11,7 +12,7 @@ pub struct Database { impl Database { #[wasm_bindgen(constructor)] pub fn new(_path: &str) -> Database { - let io = Rc::new(IO {}); + let io = Arc::new(IO {}); let page_source = limbo_core::PageSource::from_io(Rc::new(PageIO {})); let inner = limbo_core::Database::open(io, page_source).unwrap(); Database { _inner: inner } diff --git a/cli/main.rs b/cli/main.rs index 9816b43a6..936791b3c 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -5,7 +5,9 @@ use cli_table::{Cell, Table}; use limbo_core::{Database, RowResult, Value}; use opcodes_dictionary::OPCODE_DESCRIPTIONS; use rustyline::{error::ReadlineError, DefaultEditor}; -use std::{path::PathBuf, rc::Rc}; +use std::path::PathBuf; +use std::sync::Arc; + #[derive(ValueEnum, Copy, Clone, Debug, PartialEq, Eq)] enum OutputMode { @@ -35,7 +37,7 @@ fn main() -> anyhow::Result<()> { env_logger::init(); let opts = Opts::parse(); let path = opts.database.to_str().unwrap(); - let io = Rc::new(limbo_core::PlatformIO::new()?); + let io = Arc::new(limbo_core::PlatformIO::new()?); let db = Database::open_file(io.clone(), path)?; let conn = db.connect(); if let Some(sql) = opts.sql { @@ -108,7 +110,7 @@ Note: } fn handle_dot_command( - io: Rc, + io: Arc, conn: &limbo_core::Connection, line: &str, ) -> anyhow::Result<()> { @@ -153,7 +155,7 @@ fn handle_dot_command( } fn display_schema( - io: Rc, + io: Arc, conn: &limbo_core::Connection, table: Option<&str>, ) -> anyhow::Result<()> { @@ -208,7 +210,7 @@ fn display_schema( } fn query( - io: Rc, + io: Arc, conn: &limbo_core::Connection, sql: &str, output_mode: &OutputMode, diff --git a/core/btree.rs b/core/btree.rs index 37e9a8c21..49d313b8f 100644 --- a/core/btree.rs +++ b/core/btree.rs @@ -101,7 +101,7 @@ impl BTreeCursor { BTreeCell::TableLeafCell(TableLeafCell { _rowid, _payload, - first_overflow_page, + first_overflow_page: _, }) => { mem_page.advance(); let record = crate::sqlite3_ondisk::read_record(_payload)?; diff --git a/core/lib.rs b/core/lib.rs index 4049ab8f0..1a40b03c9 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -27,6 +27,7 @@ use schema::Schema; use sqlite3_ondisk::DatabaseHeader; use sqlite3_parser::{ast::Cmd, lexer::sql::Parser}; use std::{cell::RefCell, rc::Rc}; +use std::sync::Arc; #[cfg(feature = "fs")] pub use io::PlatformIO; @@ -42,13 +43,13 @@ pub struct Database { impl Database { #[cfg(feature = "fs")] - pub fn open_file(io: Rc, path: &str) -> Result { + pub fn open_file(io: Arc, path: &str) -> Result { let file = io.open_file(path)?; let storage = storage::PageSource::from_file(file); Self::open(io, storage) } - pub fn open(io: Rc, page_source: PageSource) -> Result { + pub fn open(io: Arc, page_source: PageSource) -> Result { let db_header = Pager::begin_open(&page_source)?; io.run_once()?; let pager = Rc::new(Pager::finish_open( diff --git a/core/pager.rs b/core/pager.rs index c2b29574b..95e2531b0 100644 --- a/core/pager.rs +++ b/core/pager.rs @@ -8,7 +8,7 @@ use std::cell::RefCell; use std::hash::Hash; use std::rc::Rc; use std::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::RwLock; +use std::sync::{Arc, RwLock}; pub struct Page { flags: AtomicUsize, @@ -102,7 +102,7 @@ pub struct Pager { pub page_source: PageSource, page_cache: RefCell>>, buffer_pool: Rc, - pub io: Rc, + pub io: Arc, } impl Pager { @@ -113,7 +113,7 @@ impl Pager { pub fn finish_open( db_header: Rc>, page_source: PageSource, - io: Rc, + io: Arc, ) -> anyhow::Result { let db_header = db_header.borrow(); let page_size = db_header.page_size as usize; diff --git a/core/vdbe.rs b/core/vdbe.rs index 40d56aea5..986220be2 100644 --- a/core/vdbe.rs +++ b/core/vdbe.rs @@ -439,7 +439,7 @@ impl ProgramBuilder { Insn::If { reg: _reg, target_pc, - null_reg, + null_reg: _, } => { assert!(*target_pc < 0); *target_pc = to_offset; @@ -447,7 +447,7 @@ impl ProgramBuilder { Insn::IfNot { reg: _reg, target_pc, - null_reg, + null_reg: _, } => { assert!(*target_pc < 0); *target_pc = to_offset; diff --git a/core/where_clause.rs b/core/where_clause.rs index 225d83246..f6dabcb31 100644 --- a/core/where_clause.rs +++ b/core/where_clause.rs @@ -416,13 +416,13 @@ fn translate_condition_expr( } _ => todo!(), }, - ast::Expr::InList { lhs, not, rhs } => {} + ast::Expr::InList { lhs: _, not: _, rhs: _ } => {} ast::Expr::Like { lhs, not, op, rhs, - escape, + escape: _, } => { let cur_reg = program.alloc_register(); assert!(match rhs.as_ref() { @@ -494,10 +494,10 @@ fn introspect_expression_for_cursors( ast::Expr::Literal(_) => {} ast::Expr::Like { lhs, - not, - op, + not: _, + op: _, rhs, - escape, + escape: _, } => { cursors.extend(introspect_expression_for_cursors(program, select, lhs)?); cursors.extend(introspect_expression_for_cursors(program, select, rhs)?); diff --git a/perf/latency/limbo/Cargo.toml b/perf/latency/limbo/Cargo.toml index b11a40bfc..aab20e518 100644 --- a/perf/latency/limbo/Cargo.toml +++ b/perf/latency/limbo/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" clap = { version = "4.4.2", features = ["derive"] } env_logger = "0.11.0" hdrhistogram = "7.5.2" -limbo_core = { path = "../../../limbo/core" } +limbo_core = { path = "../../../core" } [profile.release] debug = true diff --git a/perf/latency/limbo/src/main.rs b/perf/latency/limbo/src/main.rs index 15c3b3bed..2a10eb1bc 100644 --- a/perf/latency/limbo/src/main.rs +++ b/perf/latency/limbo/src/main.rs @@ -34,7 +34,7 @@ fn main() { let mut rows = stmt.query().unwrap(); let mut count = 0; loop { - let row = rows.next().unwrap(); + let row = rows.next_row().unwrap(); match row { limbo_core::RowResult::Row(_) => { count += 1; diff --git a/simulator/main.rs b/simulator/main.rs index 11fccd67c..f31f4a83d 100644 --- a/simulator/main.rs +++ b/simulator/main.rs @@ -4,6 +4,7 @@ use rand::prelude::*; use rand_chacha::ChaCha8Rng; use std::cell::RefCell; use std::rc::Rc; +use std::sync::Arc; fn main() { let seed = match std::env::var("SEED") { @@ -12,7 +13,7 @@ fn main() { }; println!("Seed: {}", seed); let mut rng = ChaCha8Rng::seed_from_u64(seed); - let io = Rc::new(SimulatorIO::new().unwrap()); + let io = Arc::new(SimulatorIO::new().unwrap()); for _ in 0..100000 { let db = match Database::open_file(io.clone(), "./testing/testing.db") { Ok(db) => db, diff --git a/sqlite3/src/lib.rs b/sqlite3/src/lib.rs index aa0ee6d86..9de12a339 100644 --- a/sqlite3/src/lib.rs +++ b/sqlite3/src/lib.rs @@ -4,7 +4,8 @@ use log::trace; use std::cell::RefCell; use std::ffi; -use std::rc::Rc; + +use std::sync::Arc; macro_rules! stub { () => { @@ -103,7 +104,7 @@ pub unsafe extern "C" fn sqlite3_open( Err(_) => return SQLITE_MISUSE, }; let io = match limbo_core::PlatformIO::new() { - Ok(io) => Rc::new(io), + Ok(io) => Arc::new(io), Err(_) => return SQLITE_MISUSE, }; match limbo_core::Database::open_file(io, filename) {