mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 18:18:03 +00:00
fix: use Arc to handle IO
This commit is contained in:
parent
28a078726a
commit
4bcae54aa9
11 changed files with 30 additions and 24 deletions
|
@ -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 }
|
||||
|
|
12
cli/main.rs
12
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<dyn limbo_core::IO>,
|
||||
io: Arc<dyn limbo_core::IO>,
|
||||
conn: &limbo_core::Connection,
|
||||
line: &str,
|
||||
) -> anyhow::Result<()> {
|
||||
|
@ -153,7 +155,7 @@ fn handle_dot_command(
|
|||
}
|
||||
|
||||
fn display_schema(
|
||||
io: Rc<dyn limbo_core::IO>,
|
||||
io: Arc<dyn limbo_core::IO>,
|
||||
conn: &limbo_core::Connection,
|
||||
table: Option<&str>,
|
||||
) -> anyhow::Result<()> {
|
||||
|
@ -208,7 +210,7 @@ fn display_schema(
|
|||
}
|
||||
|
||||
fn query(
|
||||
io: Rc<dyn limbo_core::IO>,
|
||||
io: Arc<dyn limbo_core::IO>,
|
||||
conn: &limbo_core::Connection,
|
||||
sql: &str,
|
||||
output_mode: &OutputMode,
|
||||
|
|
|
@ -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)?;
|
||||
|
|
|
@ -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<dyn crate::io::IO>, path: &str) -> Result<Database> {
|
||||
pub fn open_file(io: Arc<dyn crate::io::IO>, path: &str) -> Result<Database> {
|
||||
let file = io.open_file(path)?;
|
||||
let storage = storage::PageSource::from_file(file);
|
||||
Self::open(io, storage)
|
||||
}
|
||||
|
||||
pub fn open(io: Rc<dyn crate::io::IO>, page_source: PageSource) -> Result<Database> {
|
||||
pub fn open(io: Arc<dyn crate::io::IO>, page_source: PageSource) -> Result<Database> {
|
||||
let db_header = Pager::begin_open(&page_source)?;
|
||||
io.run_once()?;
|
||||
let pager = Rc::new(Pager::finish_open(
|
||||
|
|
|
@ -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<PageCache<usize, Rc<Page>>>,
|
||||
buffer_pool: Rc<BufferPool>,
|
||||
pub io: Rc<dyn crate::io::IO>,
|
||||
pub io: Arc<dyn crate::io::IO>,
|
||||
}
|
||||
|
||||
impl Pager {
|
||||
|
@ -113,7 +113,7 @@ impl Pager {
|
|||
pub fn finish_open(
|
||||
db_header: Rc<RefCell<DatabaseHeader>>,
|
||||
page_source: PageSource,
|
||||
io: Rc<dyn crate::io::IO>,
|
||||
io: Arc<dyn crate::io::IO>,
|
||||
) -> anyhow::Result<Self> {
|
||||
let db_header = db_header.borrow();
|
||||
let page_size = db_header.page_size as usize;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)?);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue