diff options
-rw-r--r-- | Cargo.lock | 35 | ||||
-rw-r--r-- | Cargo.toml | 6 | ||||
-rw-r--r-- | ext/kv/lib.rs | 7 | ||||
-rw-r--r-- | ext/kv/sqlite.rs | 54 | ||||
-rw-r--r-- | tests/unit/kv_test.ts | 2 |
5 files changed, 78 insertions, 26 deletions
diff --git a/Cargo.lock b/Cargo.lock index 7f7b51fd0..8a7899b8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1998,9 +1998,9 @@ dependencies = [ [[package]] name = "denokv_proto" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98a79f7e98bfd3c148ce782c27c1494e77c3c94ab87c9e7e86e901cbc1643449" +checksum = "bd644ad038e7b6e8453463e96c278ba378e8bdc9f557959d511ac830ea0ec969" dependencies = [ "anyhow", "async-trait", @@ -2015,9 +2015,9 @@ dependencies = [ [[package]] name = "denokv_remote" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "518e181eb14f1a3b8fc423e48de431048249780fb0815d81e8139faf347c3269" +checksum = "23cfa4786f9c609711aab89ce173232ceda0617167881e58fd5e0b78868a6932" dependencies = [ "anyhow", "async-stream", @@ -2040,9 +2040,9 @@ dependencies = [ [[package]] name = "denokv_sqlite" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90af93f2ab8eec43fea9f8931fa99d38e73fa0af60aba0fae79de3fb87a0ed06" +checksum = "f36c1c54cda2de93d0f4ded0392d0b6917bcd9b1d13c056dd7c309668aa43e17" dependencies = [ "anyhow", "async-stream", @@ -2058,7 +2058,9 @@ dependencies = [ "serde_json", "thiserror", "tokio", + "tokio-stream", "uuid", + "v8_valueserializer", ] [[package]] @@ -7305,6 +7307,21 @@ dependencies = [ ] [[package]] +name = "v8_valueserializer" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97599c400fc79925922b58303e98fcb8fa88f573379a08ddb652e72cbd2e70f6" +dependencies = [ + "bitflags 2.5.0", + "encoding_rs", + "indexmap", + "num-bigint", + "serde", + "thiserror", + "wtf8", +] + +[[package]] name = "value-trait" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -7819,6 +7836,12 @@ dependencies = [ ] [[package]] +name = "wtf8" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c01ae8492c38f52376efd3a17d0994b6bcf3df1e39c0226d458b7d81670b2a06" + +[[package]] name = "wyz" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml index b3b96c85f..6723c54e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,10 +55,10 @@ deno_terminal = "0.1.1" napi_sym = { version = "0.83.0", path = "./cli/napi/sym" } test_util = { package = "test_server", path = "./tests/util/server" } -denokv_proto = "0.5.0" -denokv_remote = "0.5.0" +denokv_proto = "0.7.0" +denokv_remote = "0.7.0" # denokv_sqlite brings in bundled sqlite if we don't disable the default features -denokv_sqlite = { default-features = false, version = "0.5.0" } +denokv_sqlite = { default-features = false, version = "0.7.0" } # exts deno_broadcast_channel = { version = "0.147.0", path = "./ext/broadcast_channel" } diff --git a/ext/kv/lib.rs b/ext/kv/lib.rs index 285614389..8a57d610d 100644 --- a/ext/kv/lib.rs +++ b/ext/kv/lib.rs @@ -534,7 +534,12 @@ fn mutation_from_v8( let kind = match (value.1.as_str(), value.2) { ("set", Some(value)) => MutationKind::Set(value.try_into()?), ("delete", None) => MutationKind::Delete, - ("sum", Some(value)) => MutationKind::Sum(value.try_into()?), + ("sum", Some(value)) => MutationKind::Sum { + value: value.try_into()?, + min_v8: vec![], + max_v8: vec![], + clamp: false, + }, ("min", Some(value)) => MutationKind::Min(value.try_into()?), ("max", Some(value)) => MutationKind::Max(value.try_into()?), ("setSuffixVersionstampedKey", Some(value)) => { diff --git a/ext/kv/sqlite.rs b/ext/kv/sqlite.rs index d42f8988e..a8a7fbace 100644 --- a/ext/kv/sqlite.rs +++ b/ext/kv/sqlite.rs @@ -8,6 +8,7 @@ use std::marker::PhantomData; use std::path::Path; use std::path::PathBuf; use std::rc::Rc; +use std::sync::Arc; use std::sync::Mutex; use std::sync::OnceLock; @@ -18,8 +19,8 @@ use deno_core::unsync::spawn_blocking; use deno_core::OpState; use deno_node::PathClean; pub use denokv_sqlite::SqliteBackendError; +use denokv_sqlite::SqliteConfig; use denokv_sqlite::SqliteNotifier; -use rand::RngCore; use rand::SeedableRng; use rusqlite::OpenFlags; @@ -84,32 +85,40 @@ impl<P: SqliteDbHandlerPermissions> DatabaseHandler for SqliteDbHandler<P> { let path = path.clone(); let default_storage_dir = self.default_storage_dir.clone(); - let (conn, notifier_key) = spawn_blocking(move || { + type ConnGen = + Arc<dyn Fn() -> rusqlite::Result<rusqlite::Connection> + Send + Sync>; + let (conn_gen, notifier_key): (ConnGen, _) = spawn_blocking(move || { denokv_sqlite::sqlite_retry_loop(|| { let (conn, notifier_key) = match (path.as_deref(), &default_storage_dir) { - (Some(":memory:"), _) | (None, None) => { - (rusqlite::Connection::open_in_memory()?, None) - } + (Some(":memory:"), _) | (None, None) => ( + Arc::new(rusqlite::Connection::open_in_memory) as ConnGen, + None, + ), (Some(path), _) => { let flags = OpenFlags::default().difference(OpenFlags::SQLITE_OPEN_URI); let resolved_path = canonicalize_path(&PathBuf::from(path)) .map_err(anyhow::Error::from)?; + let path = path.to_string(); ( - rusqlite::Connection::open_with_flags(path, flags)?, + Arc::new(move || { + rusqlite::Connection::open_with_flags(&path, flags) + }) as ConnGen, Some(resolved_path), ) } (None, Some(path)) => { std::fs::create_dir_all(path).map_err(anyhow::Error::from)?; let path = path.join("kv.sqlite3"); - (rusqlite::Connection::open(path.clone())?, Some(path)) + let path2 = path.clone(); + ( + Arc::new(move || rusqlite::Connection::open(&path2)) as ConnGen, + Some(path), + ) } }; - conn.pragma_update(None, "journal_mode", "wal")?; - Ok::<_, SqliteBackendError>((conn, notifier_key)) }) }) @@ -128,13 +137,28 @@ impl<P: SqliteDbHandlerPermissions> DatabaseHandler for SqliteDbHandler<P> { SqliteNotifier::default() }; - let versionstamp_rng: Box<dyn RngCore + Send> = - match &self.versionstamp_rng_seed { - Some(seed) => Box::new(rand::rngs::StdRng::seed_from_u64(*seed)), - None => Box::new(rand::rngs::StdRng::from_entropy()), - }; + let versionstamp_rng_seed = self.versionstamp_rng_seed; + + let config = SqliteConfig { + batch_timeout: None, + num_workers: 1, + }; - denokv_sqlite::Sqlite::new(conn, notifier, versionstamp_rng) + denokv_sqlite::Sqlite::new( + move || { + let conn = conn_gen()?; + conn.pragma_update(None, "journal_mode", "wal")?; + Ok(( + conn, + match versionstamp_rng_seed { + Some(seed) => Box::new(rand::rngs::StdRng::seed_from_u64(seed)), + None => Box::new(rand::rngs::StdRng::from_entropy()), + }, + )) + }, + notifier, + config, + ) } } diff --git a/tests/unit/kv_test.ts b/tests/unit/kv_test.ts index 42914cccd..c39e0d0fc 100644 --- a/tests/unit/kv_test.ts +++ b/tests/unit/kv_test.ts @@ -472,7 +472,7 @@ dbTest("atomic mutation type=sum wrong type in mutation", async (db) => { .commit(); }, TypeError, - "Failed to perform 'sum' mutation on a non-U64 operand", + "Cannot sum KvU64 with Number", ); }); |