Skip to content

Commit

Permalink
Merge pull request #9 from Horusiath/update-yrs-v0.19
Browse files Browse the repository at this point in the history
updated yrs dependencies to v0.19
  • Loading branch information
Horusiath authored Jul 9, 2024
2 parents c3a3c87 + c120af8 commit 204aabd
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 112 deletions.
4 changes: 2 additions & 2 deletions yrs-kvstore/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yrs-kvstore"
version = "0.2.0"
version = "0.3.0"
description = "Generic persistence layer over Yrs documents"
license = "MIT"
authors = ["Bartosz Sypytkowski <[email protected]>"]
Expand All @@ -13,7 +13,7 @@ readme = "./README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
yrs = "0.17"
yrs = "0.19"
thiserror = "1.0"
smallvec = { version = "1.10", features=["write","union","const_generics","const_new"] }

Expand Down
4 changes: 1 addition & 3 deletions yrs-kvstore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ where
let start = Key::from_const([V1, KEYSPACE_OID]);
let end = Key::from_const([V1, KEYSPACE_DOC]);
let cursor = self.iter_range(&start, &end)?;
Ok(DocsNameIter { cursor, start, end })
Ok(DocsNameIter { cursor })
}

/// Returns an iterator over all metadata entries stored for a given document.
Expand Down Expand Up @@ -488,8 +488,6 @@ where
E: KVEntry,
{
cursor: I,
start: Key<2>,
end: Key<2>,
}

impl<I, E> Iterator for DocsNameIter<I, E>
Expand Down
8 changes: 4 additions & 4 deletions yrs-lmdb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yrs-lmdb"
version = "0.2.0"
version = "0.3.0"
description = "Persistence layer over Yrs documents for LMDB backend"
license = "MIT"
authors = ["Bartosz Sypytkowski <[email protected]>"]
Expand All @@ -13,13 +13,13 @@ readme = "./README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
yrs-kvstore = {version = "0.2", path = "../yrs-kvstore"}
yrs-kvstore = { version = "0.3", path = "../yrs-kvstore" }
lmdb-rs = { version = "0.7" }

[dev-dependencies]
yrs = "0.17"
yrs = "0.19"
criterion = "0.5"
rand = "0.7"
tempdir = "0.3"

[[bench]]
name = "benches"
Expand Down
11 changes: 6 additions & 5 deletions yrs-lmdb/benches/benches.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::sync::Arc;

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use lib0::decoding::{Cursor, Read};
use lmdb_rs::core::DbCreate;
use lmdb_rs::Environment;
use rand::thread_rng;
use std::sync::Arc;
use yrs::encoding::read::{Cursor, Read};
use yrs::{uuid_v4, Doc, Text, Transact};

use yrs_kvstore::DocOps;
use yrs_lmdb::LmdbStore;

Expand All @@ -27,7 +28,7 @@ fn insert_doc(c: &mut Criterion) {
&(doc, env, handle),
|b, (doc, env, handle)| {
b.iter(|| {
let name = uuid_v4(&mut thread_rng()).to_string();
let name = uuid_v4().to_string();
let txn = env.new_transaction().unwrap();
let db = LmdbStore::from(txn.bind(&handle));
db.insert_doc(&name, &doc.transact()).unwrap();
Expand All @@ -54,7 +55,7 @@ fn updates(c: &mut Criterion) {
b.iter(|| {
let env = env.clone();
let handle = handle.clone();
let name = uuid_v4(&mut thread_rng()).to_string();
let name = uuid_v4().to_string();
let _sub = doc.observe_update_v1(move |_, e| {
let db_txn = env.new_transaction().unwrap();
let db = LmdbStore::from(db_txn.bind(&handle));
Expand Down
67 changes: 23 additions & 44 deletions yrs-lmdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
use lmdb_rs::core::{CursorIterator, MdbResult};
use lmdb_rs::{CursorKeyRangeIter, Database, MdbError, ReadonlyTransaction};
use std::ops::Deref;

pub use yrs_kvstore as store;
use yrs_kvstore::error::Error;
use yrs_kvstore::keys::Key;
use yrs_kvstore::{DocOps, KVEntry, KVStore};
Expand Down Expand Up @@ -257,35 +259,12 @@ mod test {
use crate::{DocOps, LmdbStore};
use lmdb_rs::core::DbCreate;
use lmdb_rs::Environment;
use std::path::Path;
use std::sync::Arc;
use tempdir::TempDir;
use yrs::{Doc, GetString, ReadTxn, Text, Transact};

struct Cleaner(&'static str);

impl Cleaner {
fn new(dir: &'static str) -> Self {
Self::cleanup(dir);
Cleaner(dir)
}

fn dir(&self) -> &str {
self.0
}

fn cleanup(dir: &str) {
if let Err(_) = std::fs::remove_dir_all(dir) {
// if dir doesn't exists, ignore
}
}
}

impl Drop for Cleaner {
fn drop(&mut self) {
Self::cleanup(self.dir());
}
}

fn init_env(dir: &str) -> Environment {
fn init_env<P: AsRef<Path>>(dir: P) -> Environment {
let env = Environment::new()
.autocreate_dir(true)
.max_dbs(4)
Expand All @@ -296,8 +275,8 @@ mod test {

#[test]
fn create_get_remove() {
let cleaner = Cleaner::new("lmdb-create_get_remove");
let env = init_env(cleaner.dir());
let dir = TempDir::new("lmdb-create_get_remove").unwrap();
let env = init_env(&dir);
let h = env.create_db("yrs", DbCreate).unwrap();

// insert document
Expand Down Expand Up @@ -350,8 +329,8 @@ mod test {
}
#[test]
fn multi_insert() {
let cleaner = Cleaner::new("lmdb-multi_insert");
let env = init_env(cleaner.dir());
let dir = TempDir::new("lmdb-multi_insert").unwrap();
let env = init_env(&dir);
let h = env.create_db("yrs", DbCreate).unwrap();

// insert document twice
Expand Down Expand Up @@ -390,8 +369,8 @@ mod test {
#[test]
fn incremental_updates() {
const DOC_NAME: &str = "doc";
let cleaner = Cleaner::new("lmdb-incremental_updates");
let env = init_env(cleaner.dir());
let dir = TempDir::new("lmdb-incremental_updates").unwrap();
let env = init_env(&dir);
let h = env.create_db("yrs", DbCreate).unwrap();
let env = Arc::new(env);
let h = Arc::new(h);
Expand Down Expand Up @@ -444,8 +423,8 @@ mod test {
#[test]
fn state_vector_updates_only() {
const DOC_NAME: &str = "doc";
let cleaner = Cleaner::new("lmdb-state_vector_updates_only");
let env = init_env(cleaner.dir());
let dir = TempDir::new("lmdb-state_vector_updates_only").unwrap();
let env = init_env(&dir);
let h = env.create_db("yrs", DbCreate).unwrap();
let env = Arc::new(env);
let h = Arc::new(h);
Expand Down Expand Up @@ -481,8 +460,8 @@ mod test {
#[test]
fn state_diff_from_updates() {
const DOC_NAME: &str = "doc";
let cleaner = Cleaner::new("lmdb-state_diff_from_updates");
let env = init_env(cleaner.dir());
let dir = TempDir::new("lmdb-state_diff_from_updates").unwrap();
let env = init_env(&dir);
let h = env.create_db("yrs", DbCreate).unwrap();
let env = Arc::new(env);
let h = Arc::new(h);
Expand Down Expand Up @@ -518,8 +497,8 @@ mod test {
#[test]
fn state_diff_from_doc() {
const DOC_NAME: &str = "doc";
let cleaner = Cleaner::new("lmdb-state_diff_from_doc");
let env = init_env(cleaner.dir());
let dir = TempDir::new("lmdb-state_diff_from_doc").unwrap();
let env = init_env(&dir);
let h = env.create_db("yrs", DbCreate).unwrap();

let (sv, expected) = {
Expand Down Expand Up @@ -549,8 +528,8 @@ mod test {
#[test]
fn doc_meta() {
const DOC_NAME: &str = "doc";
let cleaner = Cleaner::new("lmdb-doc_meta");
let env = init_env(cleaner.dir());
let dir = TempDir::new("lmdb-doc_meta").unwrap();
let env = init_env(&dir);
let h = env.create_db("yrs", DbCreate).unwrap();

let db_txn = env.new_transaction().unwrap();
Expand Down Expand Up @@ -580,8 +559,8 @@ mod test {

#[test]
fn doc_meta_iter() {
let cleaner = Cleaner::new("lmdb-doc_meta_iter");
let env = init_env(cleaner.dir());
let dir = TempDir::new("lmdb-doc_meta_iter").unwrap();
let env = init_env(&dir);
let h = env.create_db("yrs", DbCreate).unwrap();
let db_txn = env.new_transaction().unwrap();
let db = LmdbStore::from(db_txn.bind(&h));
Expand All @@ -599,8 +578,8 @@ mod test {

#[test]
fn doc_iter() {
let cleaner = Cleaner::new("lmdb-doc_iter");
let env = init_env(cleaner.dir());
let dir = TempDir::new("lmdb-doc_iter").unwrap();
let env = init_env(&dir);
let h = env.create_db("yrs", DbCreate).unwrap();
let env = Arc::new(env);
let h = Arc::new(h);
Expand Down
10 changes: 5 additions & 5 deletions yrs-rocksdb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yrs-rocksdb"
version = "0.2.0"
version = "0.3.0"
description = "Persistence layer over Yrs documents for RocksDB backend"
license = "MIT"
authors = ["Bartosz Sypytkowski <[email protected]>"]
Expand All @@ -13,13 +13,13 @@ readme = "./README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
yrs-kvstore = {version = "0.2", path = "../yrs-kvstore"}
rocksdb = { version = "0.21" }
yrs-kvstore = { version = "0.3", path = "../yrs-kvstore" }
rocksdb = { version = "0.22" }

[dev-dependencies]
yrs = "0.17"
yrs = "0.19"
criterion = "0.5"
rand = "0.7"
tempdir = "0.3"

[[bench]]
name = "benches"
Expand Down
11 changes: 6 additions & 5 deletions yrs-rocksdb/benches/benches.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::sync::Arc;

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use lib0::decoding::{Cursor, Read};
use rand::thread_rng;
use rocksdb::TransactionDB;
use std::sync::Arc;
use yrs::encoding::read::{Cursor, Read};
use yrs::{uuid_v4, Doc, Text, Transact};

use yrs_kvstore::DocOps;
use yrs_rocksdb::RocksDBStore;

Expand All @@ -25,7 +26,7 @@ fn insert_doc(c: &mut Criterion) {
&(doc, db),
|b, (doc, db)| {
b.iter(|| {
let name = uuid_v4(&mut thread_rng()).to_string();
let name = uuid_v4().to_string();
let db_txn = RocksDBStore::from(db.transaction());
db_txn.insert_doc(&name, &doc.transact()).unwrap();
db_txn.commit().unwrap();
Expand All @@ -49,7 +50,7 @@ fn updates(c: &mut Criterion) {
|b, (doc, text, ops, db)| {
b.iter(|| {
let db = db.clone();
let name = uuid_v4(&mut thread_rng()).to_string();
let name = uuid_v4().to_string();
let _sub = doc.observe_update_v1(move |_, e| {
let db_txn = RocksDBStore::from(db.transaction());
db_txn.push_update(&name, &e.update).unwrap();
Expand Down
Loading

0 comments on commit 204aabd

Please sign in to comment.