Skip to content

Commit 2f67f2a

Browse files
authored
Update rkyv and add strict feature for safer transport (#50)
1 parent 182194e commit 2f67f2a

28 files changed

Lines changed: 76 additions & 99 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "datacake"
3-
version = "0.7.0"
3+
version = "0.7.1"
44
edition = "2021"
55
description = "A batteries included framework for building fault-tolerance distributed data systems."
66
license = "MIT"

datacake-crdt/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "datacake-crdt"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
edition = "2021"
55
description = "A conflict free replicated datatype based on a hybrid logical clock implementation for building eventually consistent data stores."
66
license = "MIT"
@@ -14,9 +14,8 @@ readme = "README.md"
1414
[dependencies]
1515
thiserror = "1.0.33"
1616

17-
bytecheck = { version = "0.6.9", optional = true }
18-
rkyv = { version = "0.7.39", features = ["validation"], optional = true }
17+
rkyv = { version = "0.7.42", features = ["validation"], optional = true }
1918

2019
[features]
2120
# Enables (de)serialization support for all data types.
22-
rkyv-support = ["rkyv", "bytecheck"]
21+
rkyv-support = ["rkyv"]

datacake-crdt/src/orswot.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use std::fmt::Debug;
44
use std::time::Duration;
55
use std::{cmp, mem};
66

7-
#[cfg(feature = "rkyv-support")]
8-
use bytecheck::CheckBytes;
97
#[cfg(feature = "rkyv-support")]
108
use rkyv::{Archive, Deserialize, Serialize};
119

@@ -26,17 +24,16 @@ pub const FORGIVENESS_PERIOD: Duration = if cfg!(test) {
2624
Duration::from_secs(3_600)
2725
};
2826

29-
#[cfg(feature = "rkyv-support")]
27+
#[cfg(feature = "rkyv")]
3028
#[derive(Debug, thiserror::Error)]
3129
#[error("The set cannot be (de)serialized from the provided set of bytes.")]
3230
/// The set cannot be (de)serialized to or from the byte buffer.
3331
pub struct BadState;
3432

3533
#[derive(Debug, Clone)]
3634
#[repr(C)]
37-
#[cfg_attr(feature = "rkyv-support", derive(Serialize, Deserialize, Archive))]
38-
#[cfg_attr(feature = "rkyv-support", archive(compare(PartialEq)))]
39-
#[cfg_attr(feature = "rkyv-support", archive_attr(derive(CheckBytes)))]
35+
#[cfg_attr(feature = "rkyv", derive(Serialize, Deserialize, Archive))]
36+
#[cfg_attr(feature = "rkyv", archive(compare(PartialEq), check_bytes))]
4037
pub struct NodeVersions<const N: usize> {
4138
nodes_max_stamps: [BTreeMap<u8, HLCTimestamp>; N],
4239
safe_last_stamps: BTreeMap<u8, HLCTimestamp>,
@@ -140,8 +137,7 @@ impl<const N: usize> NodeVersions<N> {
140137
#[derive(Debug, Default, Clone)]
141138
#[repr(C)]
142139
#[cfg_attr(feature = "rkyv", derive(Serialize, Deserialize, Archive))]
143-
#[cfg_attr(feature = "rkyv", archive(compare(PartialEq)))]
144-
#[cfg_attr(feature = "rkyv", archive_attr(derive(CheckBytes)))]
140+
#[cfg_attr(feature = "rkyv", archive(compare(PartialEq), check_bytes))]
145141
/// A CRDT which supports purging of deleted entry tombstones.
146142
///
147143
/// This implementation is largely based on the Riak DB implementations

datacake-crdt/src/timestamp.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use std::fmt::{Display, Formatter};
33
use std::str::FromStr;
44
use std::time::{Duration, SystemTime, UNIX_EPOCH};
55

6-
#[cfg(feature = "rkyv-support")]
7-
use bytecheck::CheckBytes;
86
#[cfg(feature = "rkyv-support")]
97
use rkyv::{Archive, Deserialize, Serialize};
108

@@ -19,12 +17,9 @@ pub const DATACAKE_EPOCH: Duration = Duration::from_secs(1672534861);
1917

2018
#[derive(Debug, Hash, Copy, Clone, Eq, PartialEq, PartialOrd, Ord)]
2119
#[repr(C)]
22-
#[cfg_attr(feature = "rkyv-support", derive(Serialize, Deserialize, Archive))]
23-
#[cfg_attr(feature = "rkyv-support", archive(compare(PartialEq)))]
24-
#[cfg_attr(
25-
feature = "rkyv-support",
26-
archive_attr(repr(C), derive(CheckBytes, Debug))
27-
)]
20+
#[cfg_attr(feature = "rkyv", derive(Serialize, Deserialize, Archive))]
21+
#[cfg_attr(feature = "rkyv", archive(compare(PartialEq), check_bytes))]
22+
#[cfg_attr(feature = "rkyv", archive_attr(repr(C), derive(Debug)))]
2823
/// A HLC (Hybrid Logical Clock) timestamp implementation.
2924
///
3025
/// This implementation is largely a port of the JavaScript implementation

datacake-eventual-consistency/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "datacake-eventual-consistency"
3-
version = "0.5.0"
3+
version = "0.5.1"
44
edition = "2021"
55
description = "Eventually consistent state replication as a library (consensus, RPC and conflict resolution) for building your own eventually consistent databases."
66
license = "MIT"
@@ -25,13 +25,12 @@ crossbeam-utils = "0.8.14"
2525
async-trait = "0.1.58"
2626
anyhow = "1"
2727
rand = "0.8.5"
28-
bytecheck = "0.6.9"
2928
puppet = "0.4.0"
3029
smallvec = "1"
3130

3231
chitchat = { version = "0.5.1", package = "datacake-chitchat-fork" }
3332
tokio = { version = "1", default-features = false, features = ["sync", "time"] }
34-
rkyv = { version = "0.7.9", features = ["validation", "smallvec"] }
33+
rkyv = { version = "0.7.42", features = ["strict", "validation", "smallvec"] }
3534

3635
datacake-rpc = { path = "../datacake-rpc", version = "0.5" }
3736
datacake-node = { path = "../datacake-node", version = "0.4" }

datacake-eventual-consistency/src/core.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::fmt::{Debug, Formatter};
22
use std::hash::{Hash, Hasher};
33
use std::sync::Arc;
44

5-
use bytecheck::CheckBytes;
65
use datacake_crdt::{HLCTimestamp, Key};
76
use rkyv::with::CopyOptimize;
87
use rkyv::{Archive, Deserialize, Serialize};
@@ -12,7 +11,8 @@ pub(crate) type DocVec<T> = SmallVec<[T; 4]>;
1211

1312
#[repr(C)]
1413
#[derive(Serialize, Deserialize, Archive, Copy, Clone, Debug, PartialEq)]
15-
#[archive_attr(repr(C), derive(CheckBytes))]
14+
#[archive(check_bytes)]
15+
#[archive_attr(repr(C))]
1616
/// The metadata attached to each document.
1717
pub struct DocumentMetadata {
1818
/// The unique id of the document.
@@ -32,7 +32,8 @@ impl DocumentMetadata {
3232

3333
#[repr(C)]
3434
#[derive(Serialize, Deserialize, Archive, Clone)]
35-
#[archive_attr(repr(C), derive(CheckBytes))]
35+
#[archive(check_bytes)]
36+
#[archive_attr(repr(C))]
3637
/// A single document managed by the store.
3738
pub struct Document {
3839
/// The metadata associated with the document.
@@ -105,7 +106,8 @@ impl Debug for Document {
105106

106107
#[repr(C)]
107108
#[derive(Serialize, Deserialize, Archive, PartialEq, Clone)]
108-
#[archive_attr(repr(C), derive(CheckBytes))]
109+
#[archive(check_bytes)]
110+
#[archive_attr(repr(C))]
109111
/// A new type wrapper around a `Vec<u8>` to implement the
110112
/// [CopyOptimize] optimisations from [rkyv].
111113
pub struct Bytes {

datacake-eventual-consistency/src/keyspace/group.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::ops::{Deref, DerefMut};
55
use std::sync::Arc;
66
use std::time::{Duration, Instant};
77

8-
use bytecheck::CheckBytes;
98
use crossbeam_utils::atomic::AtomicCell;
109
use datacake_crdt::{HLCTimestamp, Key, OrSWotSet};
1110
use datacake_node::Clock;
@@ -261,7 +260,7 @@ where
261260

262261
#[repr(C)]
263262
#[derive(Serialize, Deserialize, Archive)]
264-
#[archive_attr(derive(CheckBytes))]
263+
#[archive(check_bytes)]
265264
pub struct KeyspaceInfo {
266265
pub timestamp: HLCTimestamp,
267266
pub keyspace_timestamps: BTreeMap<String, HLCTimestamp>,

datacake-eventual-consistency/src/rpc/services/consistency_impl.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::marker::PhantomData;
22
use std::net::SocketAddr;
33

4-
use bytecheck::CheckBytes;
54
use datacake_crdt::HLCTimestamp;
65
use datacake_node::{NodeId, RpcNetwork};
76
use datacake_rpc::{Handler, Request, RpcService, ServiceRegistry, Status};
@@ -228,7 +227,7 @@ where
228227

229228
#[repr(C)]
230229
#[derive(Serialize, Deserialize, Archive)]
231-
#[archive_attr(derive(CheckBytes))]
230+
#[archive(check_bytes)]
232231
pub struct PutPayload {
233232
pub keyspace: String,
234233
pub ctx: Option<Context>,
@@ -238,7 +237,7 @@ pub struct PutPayload {
238237

239238
#[repr(C)]
240239
#[derive(Serialize, Deserialize, Archive, Debug)]
241-
#[archive_attr(derive(CheckBytes))]
240+
#[archive(check_bytes)]
242241
pub struct MultiPutPayload {
243242
pub keyspace: String,
244243
pub ctx: Option<Context>,
@@ -248,7 +247,7 @@ pub struct MultiPutPayload {
248247

249248
#[repr(C)]
250249
#[derive(Serialize, Deserialize, Archive, Debug)]
251-
#[archive_attr(derive(CheckBytes))]
250+
#[archive(check_bytes)]
252251
pub struct RemovePayload {
253252
pub keyspace: String,
254253
pub document: DocumentMetadata,
@@ -257,7 +256,7 @@ pub struct RemovePayload {
257256

258257
#[repr(C)]
259258
#[derive(Serialize, Deserialize, Archive, Debug)]
260-
#[archive_attr(derive(CheckBytes))]
259+
#[archive(check_bytes)]
261260
pub struct MultiRemovePayload {
262261
pub keyspace: String,
263262
pub documents: DocVec<DocumentMetadata>,
@@ -266,7 +265,7 @@ pub struct MultiRemovePayload {
266265

267266
#[repr(C)]
268267
#[derive(Serialize, Deserialize, Archive, Debug)]
269-
#[archive_attr(derive(CheckBytes))]
268+
#[archive(check_bytes)]
270269
pub struct BatchPayload {
271270
pub timestamp: HLCTimestamp,
272271
pub modified: DocVec<MultiPutPayload>,
@@ -275,7 +274,7 @@ pub struct BatchPayload {
275274

276275
#[repr(C)]
277276
#[derive(Serialize, Deserialize, Archive, Debug)]
278-
#[archive_attr(derive(CheckBytes))]
277+
#[archive(check_bytes)]
279278
pub struct Context {
280279
pub node_id: NodeId,
281280
pub node_addr: SocketAddr,

datacake-eventual-consistency/src/rpc/services/replication_impl.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use bytecheck::CheckBytes;
21
use datacake_crdt::{HLCTimestamp, Key};
32
use datacake_rpc::{Handler, Request, RpcService, ServiceRegistry, Status};
43
use rkyv::{Archive, Deserialize, Serialize};
@@ -127,20 +126,20 @@ where
127126

128127
#[repr(C)]
129128
#[derive(Serialize, Deserialize, Archive)]
130-
#[archive_attr(derive(CheckBytes))]
129+
#[archive(check_bytes)]
131130
pub struct PollKeyspace(pub HLCTimestamp);
132131

133132
#[repr(C)]
134133
#[derive(Serialize, Deserialize, Archive)]
135-
#[archive_attr(derive(CheckBytes))]
134+
#[archive(check_bytes)]
136135
pub struct GetState {
137136
pub keyspace: String,
138137
pub timestamp: HLCTimestamp,
139138
}
140139

141140
#[repr(C)]
142141
#[derive(Serialize, Deserialize, Archive)]
143-
#[archive_attr(derive(CheckBytes))]
142+
#[archive(check_bytes)]
144143
pub struct KeyspaceOrSwotSet {
145144
pub timestamp: HLCTimestamp,
146145
pub last_updated: HLCTimestamp,
@@ -150,7 +149,7 @@ pub struct KeyspaceOrSwotSet {
150149

151150
#[repr(C)]
152151
#[derive(Serialize, Deserialize, Archive)]
153-
#[archive_attr(derive(CheckBytes))]
152+
#[archive(check_bytes)]
154153
pub struct FetchDocs {
155154
pub keyspace: String,
156155
#[with(rkyv::with::CopyOptimize)]
@@ -160,7 +159,7 @@ pub struct FetchDocs {
160159

161160
#[repr(C)]
162161
#[derive(Serialize, Deserialize, Archive)]
163-
#[archive_attr(derive(CheckBytes))]
162+
#[archive(check_bytes)]
164163
pub struct FetchedDocs {
165164
pub documents: Vec<Document>,
166165
pub timestamp: HLCTimestamp,

datacake-node/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "datacake-node"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
edition = "2021"
55
description = "The core cluster membership system built ontop of Quickwit's chitchat."
66
license = "MIT"
@@ -22,14 +22,13 @@ parking_lot = "0.12.1"
2222
rand = "0.8.5"
2323
futures = "0.3"
2424
crc32fast = "1.3.2"
25-
bytecheck = "0.6.9"
2625
smallvec = "1"
2726

2827
datacake-rpc = { version = "0.5", path = "../datacake-rpc" }
2928
datacake-crdt = { version = "0.4", path = "../datacake-crdt", features = ["rkyv-support"] }
3029
chitchat = { version = "0.5.1", package = "datacake-chitchat-fork" }
3130
tokio = { version = "1", default-features = false, features = ["sync", "time"] }
32-
rkyv = { version = "0.7.39", features = ["validation"] }
31+
rkyv = { version = "0.7.42", features = ["strict", "validation"] }
3332

3433
[dev-dependencies]
3534
tracing-subscriber = "0.3.16"

0 commit comments

Comments
 (0)