1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

chore: update denokv_* crates (#23949)

Co-authored-by: losfair <zhy20000919@hotmail.com>
This commit is contained in:
Bartek Iwańczuk 2024-05-23 15:35:16 +01:00 committed by GitHub
parent aeafb7b39e
commit 0b8deca08b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 78 additions and 26 deletions

35
Cargo.lock generated
View file

@ -1998,9 +1998,9 @@ dependencies = [
[[package]] [[package]]
name = "denokv_proto" name = "denokv_proto"
version = "0.5.0" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98a79f7e98bfd3c148ce782c27c1494e77c3c94ab87c9e7e86e901cbc1643449" checksum = "bd644ad038e7b6e8453463e96c278ba378e8bdc9f557959d511ac830ea0ec969"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@ -2015,9 +2015,9 @@ dependencies = [
[[package]] [[package]]
name = "denokv_remote" name = "denokv_remote"
version = "0.5.0" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "518e181eb14f1a3b8fc423e48de431048249780fb0815d81e8139faf347c3269" checksum = "23cfa4786f9c609711aab89ce173232ceda0617167881e58fd5e0b78868a6932"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-stream", "async-stream",
@ -2040,9 +2040,9 @@ dependencies = [
[[package]] [[package]]
name = "denokv_sqlite" name = "denokv_sqlite"
version = "0.5.0" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90af93f2ab8eec43fea9f8931fa99d38e73fa0af60aba0fae79de3fb87a0ed06" checksum = "f36c1c54cda2de93d0f4ded0392d0b6917bcd9b1d13c056dd7c309668aa43e17"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-stream", "async-stream",
@ -2058,7 +2058,9 @@ dependencies = [
"serde_json", "serde_json",
"thiserror", "thiserror",
"tokio", "tokio",
"tokio-stream",
"uuid", "uuid",
"v8_valueserializer",
] ]
[[package]] [[package]]
@ -7304,6 +7306,21 @@ dependencies = [
"which 5.0.0", "which 5.0.0",
] ]
[[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]] [[package]]
name = "value-trait" name = "value-trait"
version = "0.8.1" version = "0.8.1"
@ -7818,6 +7835,12 @@ dependencies = [
"toml", "toml",
] ]
[[package]]
name = "wtf8"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c01ae8492c38f52376efd3a17d0994b6bcf3df1e39c0226d458b7d81670b2a06"
[[package]] [[package]]
name = "wyz" name = "wyz"
version = "0.5.1" version = "0.5.1"

View file

@ -55,10 +55,10 @@ deno_terminal = "0.1.1"
napi_sym = { version = "0.83.0", path = "./cli/napi/sym" } napi_sym = { version = "0.83.0", path = "./cli/napi/sym" }
test_util = { package = "test_server", path = "./tests/util/server" } test_util = { package = "test_server", path = "./tests/util/server" }
denokv_proto = "0.5.0" denokv_proto = "0.7.0"
denokv_remote = "0.5.0" denokv_remote = "0.7.0"
# denokv_sqlite brings in bundled sqlite if we don't disable the default features # 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 # exts
deno_broadcast_channel = { version = "0.147.0", path = "./ext/broadcast_channel" } deno_broadcast_channel = { version = "0.147.0", path = "./ext/broadcast_channel" }

View file

@ -534,7 +534,12 @@ fn mutation_from_v8(
let kind = match (value.1.as_str(), value.2) { let kind = match (value.1.as_str(), value.2) {
("set", Some(value)) => MutationKind::Set(value.try_into()?), ("set", Some(value)) => MutationKind::Set(value.try_into()?),
("delete", None) => MutationKind::Delete, ("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()?), ("min", Some(value)) => MutationKind::Min(value.try_into()?),
("max", Some(value)) => MutationKind::Max(value.try_into()?), ("max", Some(value)) => MutationKind::Max(value.try_into()?),
("setSuffixVersionstampedKey", Some(value)) => { ("setSuffixVersionstampedKey", Some(value)) => {

View file

@ -8,6 +8,7 @@ use std::marker::PhantomData;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc;
use std::sync::Mutex; use std::sync::Mutex;
use std::sync::OnceLock; use std::sync::OnceLock;
@ -18,8 +19,8 @@ use deno_core::unsync::spawn_blocking;
use deno_core::OpState; use deno_core::OpState;
use deno_node::PathClean; use deno_node::PathClean;
pub use denokv_sqlite::SqliteBackendError; pub use denokv_sqlite::SqliteBackendError;
use denokv_sqlite::SqliteConfig;
use denokv_sqlite::SqliteNotifier; use denokv_sqlite::SqliteNotifier;
use rand::RngCore;
use rand::SeedableRng; use rand::SeedableRng;
use rusqlite::OpenFlags; use rusqlite::OpenFlags;
@ -84,32 +85,40 @@ impl<P: SqliteDbHandlerPermissions> DatabaseHandler for SqliteDbHandler<P> {
let path = path.clone(); let path = path.clone();
let default_storage_dir = self.default_storage_dir.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(|| { denokv_sqlite::sqlite_retry_loop(|| {
let (conn, notifier_key) = match (path.as_deref(), &default_storage_dir) let (conn, notifier_key) = match (path.as_deref(), &default_storage_dir)
{ {
(Some(":memory:"), _) | (None, None) => { (Some(":memory:"), _) | (None, None) => (
(rusqlite::Connection::open_in_memory()?, None) Arc::new(rusqlite::Connection::open_in_memory) as ConnGen,
} None,
),
(Some(path), _) => { (Some(path), _) => {
let flags = let flags =
OpenFlags::default().difference(OpenFlags::SQLITE_OPEN_URI); OpenFlags::default().difference(OpenFlags::SQLITE_OPEN_URI);
let resolved_path = canonicalize_path(&PathBuf::from(path)) let resolved_path = canonicalize_path(&PathBuf::from(path))
.map_err(anyhow::Error::from)?; .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), Some(resolved_path),
) )
} }
(None, Some(path)) => { (None, Some(path)) => {
std::fs::create_dir_all(path).map_err(anyhow::Error::from)?; std::fs::create_dir_all(path).map_err(anyhow::Error::from)?;
let path = path.join("kv.sqlite3"); 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)) Ok::<_, SqliteBackendError>((conn, notifier_key))
}) })
}) })
@ -128,13 +137,28 @@ impl<P: SqliteDbHandlerPermissions> DatabaseHandler for SqliteDbHandler<P> {
SqliteNotifier::default() SqliteNotifier::default()
}; };
let versionstamp_rng: Box<dyn RngCore + Send> = let versionstamp_rng_seed = self.versionstamp_rng_seed;
match &self.versionstamp_rng_seed {
Some(seed) => Box::new(rand::rngs::StdRng::seed_from_u64(*seed)), let config = SqliteConfig {
None => Box::new(rand::rngs::StdRng::from_entropy()), 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,
)
} }
} }

View file

@ -472,7 +472,7 @@ dbTest("atomic mutation type=sum wrong type in mutation", async (db) => {
.commit(); .commit();
}, },
TypeError, TypeError,
"Failed to perform 'sum' mutation on a non-U64 operand", "Cannot sum KvU64 with Number",
); );
}); });