Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: just in time flags fix and epoch based storage flags #334

Merged
merged 15 commits into from
Aug 24, 2024
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ members = [
"visualize",
"path",
"grovedbg-types",
"grovedb-version"
"grovedb-version",
"grovedb-epoch-based-storage-flags"
]
2 changes: 1 addition & 1 deletion costs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grovedb-costs"
version = "1.0.0"
version = "1.1.0"
edition = "2021"
license = "MIT"
description = "Costs extension crate for GroveDB"
Expand Down
13 changes: 13 additions & 0 deletions grovedb-epoch-based-storage-flags/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "grovedb-epoch-based-storage-flags"
authors = ["Samuel Westrich <[email protected]>"]
description = "Epoch based storage flags for GroveDB"
version = "1.1.0"
edition = "2021"

[dependencies]
thiserror = { version = "1.0.63" }
grovedb-costs = { version = "1.1.0", path = "../costs" }
intmap = { version = "2.0.0", features = ["serde"]}
integer-encoding = { version = "4.0.0" }
hex = { version = "0.4.3" }
45 changes: 45 additions & 0 deletions grovedb-epoch-based-storage-flags/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/// Storage flag errors
#[derive(Debug, thiserror::Error)]
pub enum StorageFlagsError {
/// Error
#[error("deserialize unknown storage flags type error: {0}")]
DeserializeUnknownStorageFlagsType(String),
/// Error
#[error("storage flags wrong size error: {0}")]
StorageFlagsWrongSize(String),
/// Error
#[error("removing at epoch with no associated storage error: {0}")]
RemovingAtEpochWithNoAssociatedStorage(String),
/// Error
#[error("storage flags overflow error: {0}")]
StorageFlagsOverflow(String),
/// Error
#[error("removing flags error: {0}")]
RemovingFlagsError(String),
/// Error
#[error("merging storage flags from different owners error: {0}")]
MergingStorageFlagsFromDifferentOwners(String),
/// Error
#[error("merging storage flags with different base epoch: {0}")]
MergingStorageFlagsWithDifferentBaseEpoch(String),
}

impl StorageFlagsError {
/// Gets a mutable reference to the inner string of the error variant
pub(crate) fn get_mut_info(&mut self) -> &mut String {
match self {
StorageFlagsError::DeserializeUnknownStorageFlagsType(ref mut msg)
| StorageFlagsError::StorageFlagsWrongSize(ref mut msg)
| StorageFlagsError::RemovingAtEpochWithNoAssociatedStorage(ref mut msg)
| StorageFlagsError::StorageFlagsOverflow(ref mut msg)
| StorageFlagsError::RemovingFlagsError(ref mut msg)
| StorageFlagsError::MergingStorageFlagsFromDifferentOwners(ref mut msg)
| StorageFlagsError::MergingStorageFlagsWithDifferentBaseEpoch(ref mut msg) => msg,
}
}

/// adds info to the storage flags error
pub(crate) fn add_info(&mut self, info: &str) {
self.get_mut_info().push_str(format!(": {}", info).as_str());
}
}
Loading
Loading