diff --git a/Cargo.lock b/Cargo.lock index 18fa4fb..f3308a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,17 +17,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" -[[package]] -name = "ahash" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - [[package]] name = "ahash" version = "0.8.11" @@ -116,18 +105,6 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "bumpalo" version = "3.16.0" @@ -136,24 +113,25 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytecheck" -version = "0.6.12" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23cdc57ce23ac53c931e88a43d06d070a6fd142f2617be5855eb75efc9beb1c2" +checksum = "50c8f430744b23b54ad15161fcbc22d82a29b73eacbe425fea23ec822600bc6f" dependencies = [ "bytecheck_derive", "ptr_meta", + "rancor", "simdutf8", ] [[package]] name = "bytecheck_derive" -version = "0.6.12" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3db406d29fbcd95542e92559bed4d8ad92636d1ca8b3b72ede10b4bcc010e659" +checksum = "523363cbe1df49b68215efdf500b103ac3b0fb4836aed6d15689a076eadb8fff" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -378,12 +356,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "getrandom" version = "0.2.15" @@ -413,18 +385,15 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -dependencies = [ - "ahash 0.7.8", -] +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "hashbrown" -version = "0.14.5" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" [[package]] name = "hermit-abi" @@ -448,7 +417,7 @@ version = "0.11.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "232929e1d75fe899576a3d5c7416ad0d88dbfbb3c3d6aa00873a7408a50ddb88" dependencies = [ - "ahash 0.8.11", + "ahash", "indexmap", "is-terminal", "itoa", @@ -563,7 +532,6 @@ dependencies = [ name = "mmap-sync" version = "2.0.1" dependencies = [ - "bytecheck", "criterion", "libc", "memmap2", @@ -575,6 +543,26 @@ dependencies = [ "wyhash", ] +[[package]] +name = "munge" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64142d38c84badf60abf06ff9bd80ad2174306a5b11bd4706535090a30a419df" +dependencies = [ + "munge_macro", +] + +[[package]] +name = "munge_macro" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bb5c1d8184f13f7d0ccbeeca0def2f9a181bce2624302793005f5ca8aa62e5e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "nix" version = "0.26.4" @@ -767,22 +755,22 @@ dependencies = [ [[package]] name = "ptr_meta" -version = "0.1.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" +checksum = "fe9e76f66d3f9606f44e45598d155cb13ecf09f4a28199e48daf8c8fc937ea90" dependencies = [ "ptr_meta_derive", ] [[package]] name = "ptr_meta_derive" -version = "0.1.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" +checksum = "ca414edb151b4c8d125c12566ab0d74dc9cdba36fb80eb7b848c15f495fd32d1" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -810,10 +798,13 @@ dependencies = [ ] [[package]] -name = "radium" -version = "0.7.0" +name = "rancor" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +checksum = "caf5f7161924b9d1cea0e4cabc97c372cea92b5f927fc13c6bca67157a0ad947" +dependencies = [ + "ptr_meta", +] [[package]] name = "rand" @@ -914,9 +905,9 @@ checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "rend" -version = "0.4.2" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71fe3824f5629716b1589be05dacd749f6aa084c87e00e016714a8cdfccc997c" +checksum = "a35e8a6bf28cd121053a66aa2e6a2e3eaffad4a60012179f0e864aa5ffeff215" dependencies = [ "bytecheck", ] @@ -932,31 +923,32 @@ dependencies = [ [[package]] name = "rkyv" -version = "0.7.45" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9008cd6385b9e161d8229e1f6549dd23c3d022f132a2ea37ac3a10ac4935779b" +checksum = "b11a153aec4a6ab60795f8ebe2923c597b16b05bb1504377451e705ef1a45323" dependencies = [ - "bitvec", "bytecheck", "bytes", - "hashbrown 0.12.3", + "hashbrown 0.15.2", + "indexmap", + "munge", "ptr_meta", + "rancor", "rend", "rkyv_derive", - "seahash", "tinyvec", "uuid", ] [[package]] name = "rkyv_derive" -version = "0.7.45" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "503d1d27590a2b0a3a4ca4c94755aa2875657196ecbf401a42eff41d7de532c0" +checksum = "beb382a4d9f53bd5c0be86b10d8179c3f8a14c30bf774ff77096ed6581e35981" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -1011,12 +1003,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "seahash" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" - [[package]] name = "serde" version = "1.0.210" @@ -1034,7 +1020,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn", ] [[package]] @@ -1102,17 +1088,6 @@ dependencies = [ "symbolic-common", ] -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "syn" version = "2.0.77" @@ -1124,12 +1099,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "tempfile" version = "3.12.0" @@ -1160,7 +1129,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn", ] [[package]] @@ -1259,7 +1228,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.77", + "syn", "wasm-bindgen-shared", ] @@ -1281,7 +1250,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1424,15 +1393,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - [[package]] name = "zerocopy" version = "0.7.35" @@ -1451,5 +1411,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn", ] diff --git a/Cargo.toml b/Cargo.toml index 739697e..0943d2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,9 +14,8 @@ keywords = ["memory-mapping", "synchronization", "interprocess", "wait-free", "z categories = ["os", "filesystem", "concurrency", "data-structures", "memory-management"] [dependencies] -bytecheck = { version = "~0.6.8", default-features = false } memmap2 = "0.9.4" -rkyv = { version = "0.7.40", features = ["validation", "strict"] } +rkyv = "0.8.9" thiserror = "1.0.30" wyhash = "0.5.0" diff --git a/examples/common/mod.rs b/examples/common/mod.rs index 96bae63..06eab7b 100644 --- a/examples/common/mod.rs +++ b/examples/common/mod.rs @@ -1,9 +1,8 @@ -use bytecheck::CheckBytes; use rkyv::{Archive, Deserialize, Serialize}; /// Example data-structure shared between writer and reader(s) #[derive(Archive, Deserialize, Serialize, Debug, PartialEq)] -#[archive_attr(derive(CheckBytes))] +#[rkyv(compare(PartialEq), derive(Debug))] pub struct HelloWorld { pub version: u32, pub messages: Vec, diff --git a/src/synchronizer.rs b/src/synchronizer.rs index 2cf87d2..de3023e 100644 --- a/src/synchronizer.rs +++ b/src/synchronizer.rs @@ -7,11 +7,15 @@ use std::ffi::OsStr; use std::hash::{BuildHasher, BuildHasherDefault, Hasher}; use std::time::Duration; -use bytecheck::CheckBytes; -use rkyv::ser::serializers::{AlignedSerializer, AllocSerializer}; -use rkyv::ser::Serializer; -use rkyv::validation::validators::DefaultValidator; -use rkyv::{archived_root, check_archived_root, AlignedVec, Archive, Serialize}; +use rkyv::{ + access, access_unchecked, + api::high::{to_bytes_with_alloc, HighSerializer, HighValidator}, + bytecheck::CheckBytes, + rancor::Error as RkyvErr, + ser::allocator::{Arena, ArenaHandle}, + util::AlignedVec, + Archive, Portable, Serialize, +}; use thiserror::Error; use wyhash::WyHash; @@ -123,25 +127,18 @@ where grace_duration: Duration, ) -> Result<(usize, bool), SynchronizerError> where - T: Serialize>, - T::Archived: for<'b> CheckBytes>, + T: for<'b> Serialize, RkyvErr>>, { let mut buf = self.serialize_buffer.take().ok_or(FailedEntityWrite)?; buf.clear(); // serialize given entity into bytes - let mut serializer = AllocSerializer::new( - AlignedSerializer::new(buf), - Default::default(), - Default::default(), - ); - let _ = serializer - .serialize_value(entity) - .map_err(|_| FailedEntityWrite)?; - let data = serializer.into_serializer().into_inner(); + let mut arena = Arena::new(); + let data = to_bytes_with_alloc::<_, RkyvErr>(entity, arena.acquire()) + .map_err(|_| SynchronizerError::FailedEntityWrite)?; // ensure that serialized bytes can be deserialized back to `T` struct successfully - check_archived_root::(&data).map_err(|_| FailedEntityRead)?; + // check_archived_root::(&data).map_err(|_| FailedEntityRead)?; // fetch current state from mapped memory let state = self.state_container.state::(true)?; @@ -175,8 +172,7 @@ where grace_duration: Duration, ) -> Result<(usize, bool), SynchronizerError> where - T: Serialize>, - T::Archived: for<'b> CheckBytes>, + T: for<'b> Serialize, RkyvErr>>, { // fetch current state from mapped memory let state = self.state_container.state::(true)?; @@ -222,7 +218,7 @@ where ) -> Result, SynchronizerError> where T: Archive, - T::Archived: for<'b> CheckBytes>, + T::Archived: Portable + for<'c> CheckBytes>, { // fetch current state from mapped memory let state = self.state_container.state::(false)?; @@ -238,8 +234,8 @@ where // fetch entity from data using zero-copy deserialization let entity = match check_bytes { - false => archived_root::(data), - true => check_archived_root::(data).map_err(|_| FailedEntityRead)?, + false => access::(data).map_err(|_| FailedEntityRead)?, + true => access_unchecked::(data), }; Ok(ReadResult::new(guard, entity, switched)) @@ -261,21 +257,24 @@ mod tests { use crate::instance::InstanceVersion; use crate::locks::SingleWriter; use crate::synchronizer::{Synchronizer, SynchronizerError}; - use bytecheck::CheckBytes; use rand::distributions::Uniform; use rand::prelude::*; - use rkyv::{Archive, Deserialize, Serialize}; - use std::collections::HashMap; + use rkyv::{ + with::{Identity, Map, MapKV}, + Archive, Deserialize, Serialize, + }; + use std::collections::BTreeMap; use std::fs; use std::path::Path; use std::time::Duration; use wyhash::WyHash; #[derive(Archive, Deserialize, Serialize, Debug, PartialEq)] - #[archive_attr(derive(CheckBytes))] + #[rkyv(derive(Debug))] struct MockEntity { - version: u32, - map: HashMap>, + version: u64, + #[rkyv(with = MapKV>)] + map: BTreeMap>, } struct MockEntityGenerator { @@ -292,7 +291,7 @@ mod tests { fn gen(&mut self, n: usize) -> MockEntity { let mut entity = MockEntity { version: self.rng.gen(), - map: HashMap::new(), + map: BTreeMap::new(), }; let range = Uniform::::from(0.0..100.0); for _ in 0..n { @@ -342,7 +341,7 @@ mod tests { assert!(!Path::new(&data_path_1).exists()); assert_eq!( reader.version().unwrap(), - InstanceVersion(8817430144856633152) + InstanceVersion(14199406521913192192) ); // check that first time scoped `read` works correctly and switches the data @@ -361,7 +360,7 @@ mod tests { assert!(Path::new(&data_path_1).exists()); assert_eq!( reader.version().unwrap(), - InstanceVersion(1441050725688826209) + InstanceVersion(13708579033715857729) ); // check that another scoped `read` works correctly and switches the data @@ -374,7 +373,7 @@ mod tests { assert_eq!(reset, false); assert_eq!( reader.version().unwrap(), - InstanceVersion(14058099486534675680) + InstanceVersion(17341169738818006304) ); let entity = entity_generator.gen(200); @@ -383,7 +382,7 @@ mod tests { assert_eq!(reset, false); assert_eq!( reader.version().unwrap(), - InstanceVersion(18228729609619266545) + InstanceVersion(1248068842828094129) ); fetch_and_assert_entity(&mut reader, &entity, true);