From 96175cccf76f5c821eef613969d998c50ed47c23 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Thu, 6 Mar 2025 09:06:51 +0200 Subject: [PATCH] cli: Add `--experimental-mvcc` option to enable MVCC --- bindings/go/rs_src/lib.rs | 2 +- bindings/java/rs_src/limbo_db.rs | 2 +- bindings/python/src/lib.rs | 2 +- bindings/rust/src/lib.rs | 4 ++-- bindings/wasm/lib.rs | 2 +- cli/app.rs | 6 ++++-- cli/input.rs | 2 ++ core/benches/benchmark.rs | 2 +- core/lib.rs | 5 +++-- core/storage/btree.rs | 2 +- simulator/main.rs | 8 ++++++-- simulator/runner/env.rs | 2 +- sqlite3/src/lib.rs | 2 +- tests/integration/common.rs | 4 ++-- 14 files changed, 27 insertions(+), 18 deletions(-) diff --git a/bindings/go/rs_src/lib.rs b/bindings/go/rs_src/lib.rs index b2240a16b..297b5a7ce 100644 --- a/bindings/go/rs_src/lib.rs +++ b/bindings/go/rs_src/lib.rs @@ -25,7 +25,7 @@ pub unsafe extern "C" fn db_open(path: *const c_char) -> *mut c_void { p if p.contains(":memory:") => Arc::new(limbo_core::MemoryIO::new()), _ => Arc::new(limbo_core::PlatformIO::new().expect("Failed to create IO")), }; - let db = Database::open_file(io.clone(), path); + let db = Database::open_file(io.clone(), path, false); match db { Ok(db) => { let conn = db.connect().unwrap(); diff --git a/bindings/java/rs_src/limbo_db.rs b/bindings/java/rs_src/limbo_db.rs index ef33bf6e2..189ed090b 100644 --- a/bindings/java/rs_src/limbo_db.rs +++ b/bindings/java/rs_src/limbo_db.rs @@ -67,7 +67,7 @@ pub extern "system" fn Java_tech_turso_core_LimboDB_openUtf8<'local>( } }; - let db = match Database::open_file(io.clone(), &path) { + let db = match Database::open_file(io.clone(), &path, false) { Ok(db) => db, Err(e) => { set_err_msg_and_throw_exception(&mut env, obj, LIMBO_ETC, e.to_string()); diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index fa9045ef7..f6c505ba9 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -277,7 +277,7 @@ pub fn connect(path: &str) -> Result { io: Arc, path: &str, ) -> std::result::Result, PyErr> { - limbo_core::Database::open_file(io, path).map_err(|e| { + limbo_core::Database::open_file(io, path, false).map_err(|e| { PyErr::new::(format!("Failed to open database: {:?}", e)) }) } diff --git a/bindings/rust/src/lib.rs b/bindings/rust/src/lib.rs index d99e7bbb6..b65624d10 100644 --- a/bindings/rust/src/lib.rs +++ b/bindings/rust/src/lib.rs @@ -42,12 +42,12 @@ impl Builder { match self.path.as_str() { ":memory:" => { let io: Arc = Arc::new(limbo_core::MemoryIO::new()); - let db = limbo_core::Database::open_file(io, self.path.as_str())?; + let db = limbo_core::Database::open_file(io, self.path.as_str(), false)?; Ok(Database { inner: db }) } path => { let io: Arc = Arc::new(limbo_core::PlatformIO::new()?); - let db = limbo_core::Database::open_file(io, path)?; + let db = limbo_core::Database::open_file(io, path, false)?; Ok(Database { inner: db }) } } diff --git a/bindings/wasm/lib.rs b/bindings/wasm/lib.rs index 6627b6fac..88827e79e 100644 --- a/bindings/wasm/lib.rs +++ b/bindings/wasm/lib.rs @@ -32,7 +32,7 @@ impl Database { let wal_path = format!("{}-wal", path); let wal_shared = WalFileShared::open_shared(&io, wal_path.as_str(), page_size).unwrap(); - let db = limbo_core::Database::open(io, page_io, wal_shared).unwrap(); + let db = limbo_core::Database::open(io, page_io, wal_shared, false).unwrap(); let conn = db.connect().unwrap(); Database { db, conn } } diff --git a/cli/app.rs b/cli/app.rs index 4d1470adf..999dd935d 100644 --- a/cli/app.rs +++ b/cli/app.rs @@ -51,6 +51,8 @@ pub struct Opts { \t'io-uring' when built for Linux with feature 'io_uring'\n" )] pub io: Io, + #[clap(long, help = "Enable experimental MVCC feature")] + pub experimental_mvcc: bool, } #[derive(Debug, Clone)] @@ -210,7 +212,7 @@ impl<'a> Limbo<'a> { _path => get_io(DbLocation::Path, opts.io)?, } }; - let db = Database::open_file(io.clone(), &db_file)?; + let db = Database::open_file(io.clone(), &db_file, opts.experimental_mvcc)?; let conn = db.connect().unwrap(); let h = LimboHelper::new(conn.clone(), io.clone()); rl.set_helper(Some(h)); @@ -412,7 +414,7 @@ impl<'a> Limbo<'a> { } }; self.io = Arc::clone(&io); - let db = Database::open_file(self.io.clone(), path)?; + let db = Database::open_file(self.io.clone(), path, self.opts.experimental_mvcc)?; self.conn = db.connect().unwrap(); self.opts.db_file = path.to_string(); Ok(()) diff --git a/cli/input.rs b/cli/input.rs index f1c1fd3f6..459b9ac2a 100644 --- a/cli/input.rs +++ b/cli/input.rs @@ -65,6 +65,7 @@ pub struct Settings { pub echo: bool, pub is_stdout: bool, pub io: Io, + pub experimental_mvcc: bool, } impl From<&Opts> for Settings { @@ -80,6 +81,7 @@ impl From<&Opts> for Settings { .as_ref() .map_or(":memory:".to_string(), |p| p.to_string_lossy().to_string()), io: opts.io, + experimental_mvcc: opts.experimental_mvcc, } } } diff --git a/core/benches/benchmark.rs b/core/benches/benchmark.rs index 57deca54e..93c071bcb 100644 --- a/core/benches/benchmark.rs +++ b/core/benches/benchmark.rs @@ -18,7 +18,7 @@ fn bench(criterion: &mut Criterion) { #[allow(clippy::arc_with_non_send_sync)] let io = Arc::new(PlatformIO::new().unwrap()); - let db = Database::open_file(io.clone(), "../testing/testing.db").unwrap(); + let db = Database::open_file(io.clone(), "../testing/testing.db", false).unwrap(); let limbo_conn = db.connect().unwrap(); let queries = [ diff --git a/core/lib.rs b/core/lib.rs index 67674e544..08c4d6edf 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -101,7 +101,7 @@ unsafe impl Sync for Database {} impl Database { #[cfg(feature = "fs")] - pub fn open_file(io: Arc, path: &str) -> Result> { + pub fn open_file(io: Arc, path: &str, enable_mvcc: bool) -> Result> { use storage::wal::WalFileShared; let file = io.open_file(path, OpenFlags::Create, true)?; @@ -112,7 +112,7 @@ impl Database { io.run_once()?; let page_size = db_header.lock().unwrap().page_size; let wal_shared = WalFileShared::open_shared(&io, wal_path.as_str(), page_size)?; - Self::open(io, page_io, wal_shared) + Self::open(io, page_io, wal_shared, enable_mvcc) } #[allow(clippy::arc_with_non_send_sync)] @@ -120,6 +120,7 @@ impl Database { io: Arc, page_io: Arc, shared_wal: Arc>, + enable_mvcc: bool, ) -> Result> { let db_header = Pager::begin_open(page_io.clone())?; io.run_once()?; diff --git a/core/storage/btree.rs b/core/storage/btree.rs index 924a6eb2c..2fa4fb65d 100644 --- a/core/storage/btree.rs +++ b/core/storage/btree.rs @@ -2811,7 +2811,7 @@ mod tests { .unwrap(); } let io: Arc = Arc::new(PlatformIO::new().unwrap()); - let db = Database::open_file(io.clone(), path.to_str().unwrap()).unwrap(); + let db = Database::open_file(io.clone(), path.to_str().unwrap(), false).unwrap(); db } diff --git a/simulator/main.rs b/simulator/main.rs index a2f07d95e..d28c2b017 100644 --- a/simulator/main.rs +++ b/simulator/main.rs @@ -308,8 +308,12 @@ fn doublecheck( ) { { let mut env_ = env.lock().unwrap(); - env_.db = - Database::open_file(env_.io.clone(), paths.doublecheck_db.to_str().unwrap()).unwrap(); + env_.db = Database::open_file( + env_.io.clone(), + paths.doublecheck_db.to_str().unwrap(), + false, + ) + .unwrap(); } // Run the simulation again diff --git a/simulator/runner/env.rs b/simulator/runner/env.rs index 1b7240b9b..a9409ad7e 100644 --- a/simulator/runner/env.rs +++ b/simulator/runner/env.rs @@ -87,7 +87,7 @@ impl SimulatorEnv { std::fs::remove_file(db_path).unwrap(); } - let db = match Database::open_file(io.clone(), db_path.to_str().unwrap()) { + let db = match Database::open_file(io.clone(), db_path.to_str().unwrap(), false) { Ok(db) => db, Err(e) => { panic!("error opening simulator test file {:?}: {:?}", db_path, e); diff --git a/sqlite3/src/lib.rs b/sqlite3/src/lib.rs index 43d1ff0fc..c1cab5eb0 100644 --- a/sqlite3/src/lib.rs +++ b/sqlite3/src/lib.rs @@ -116,7 +116,7 @@ pub unsafe extern "C" fn sqlite3_open( Err(_) => return SQLITE_MISUSE, }, }; - match limbo_core::Database::open_file(io, filename) { + match limbo_core::Database::open_file(io, filename, false) { Ok(db) => { let conn = db.connect().unwrap(); *db_out = Box::leak(Box::new(sqlite3::new(db, conn))); diff --git a/tests/integration/common.rs b/tests/integration/common.rs index 1831abbd0..0f0d550b9 100644 --- a/tests/integration/common.rs +++ b/tests/integration/common.rs @@ -42,7 +42,7 @@ impl TempDatabase { pub fn connect_limbo(&self) -> Rc { log::debug!("conneting to limbo"); - let db = Database::open_file(self.io.clone(), self.path.to_str().unwrap()).unwrap(); + let db = Database::open_file(self.io.clone(), self.path.to_str().unwrap(), false).unwrap(); let conn = db.connect().unwrap(); log::debug!("connected to limbo"); @@ -51,7 +51,7 @@ impl TempDatabase { pub fn limbo_database(&self) -> Arc { log::debug!("conneting to limbo"); - Database::open_file(self.io.clone(), self.path.to_str().unwrap()).unwrap() + Database::open_file(self.io.clone(), self.path.to_str().unwrap(), false).unwrap() } }