summaryrefslogtreecommitdiff
path: root/rola-utils
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-06-18 20:56:05 +0800
committer魏曹先生 <1992414357@qq.com>2026-06-18 20:56:05 +0800
commit68daa10abfe3015beca966825d32cf67c9f5d5d7 (patch)
treec28f0470240e7cdc3748cee57ef74353514c47b7 /rola-utils
parent669898193bebeadc975881bee496fe0239df76a0 (diff)
feat(bucket): implement bucket initialization and logging infrastructure
Add bucket init logic with directory structure creation and log macros for tracing
Diffstat (limited to 'rola-utils')
-rw-r--r--rola-utils/constants/src/bucket.rs38
-rw-r--r--rola-utils/constants/src/common.rs5
-rw-r--r--rola-utils/constants/src/lib.rs2
-rw-r--r--rola-utils/functions/Cargo.toml1
-rw-r--r--rola-utils/functions/src/lib.rs2
-rw-r--r--rola-utils/functions/src/log_macros.rs53
-rw-r--r--rola-utils/space-system/src/space/error.rs6
7 files changed, 106 insertions, 1 deletions
diff --git a/rola-utils/constants/src/bucket.rs b/rola-utils/constants/src/bucket.rs
new file mode 100644
index 0000000..e2ebff2
--- /dev/null
+++ b/rola-utils/constants/src/bucket.rs
@@ -0,0 +1,38 @@
+#[shared_macros::constants]
+mod consts {
+ /// Full object storage pool directory
+ pub const DIR_BUCKET_OBJ: &str = "./objects/";
+
+ /// Full compressed object storage pool directory
+ pub const DIR_BUCKET_COMPRESSED_OBJ: &str = "./compressed-objects/";
+
+ /// Incremental object fragment storage pool directory
+ pub const DIR_BUCKET_DELTA: &str = "./delta-objects/";
+
+ /// Version information storage directory
+ pub const DIR_BUCKET_ID_REVS: &str = "./revs/";
+
+ /// Tag storage directory, used to record tags for easy file location
+ pub const DIR_BUCKET_ID_TAGS: &str = "./tags/";
+
+ /// Full object file path template
+ pub const FILE_BUCKET_OBJ: &str = "./objects/{slice1}/{slice2}/{fullname}";
+
+ /// Full compressed object file path template
+ pub const FILE_BUCKET_COMPRESSED_OBJ: &str =
+ "./compressed-objects/{slice1}/{slice2}/{fullname}";
+
+ /// Incremental object file path template (records change info between the previous delta and the current delta)
+ pub const FILE_BUCKET_DELTA: &str = "./delta-objects/{slice1}/{slice2}/{fullname}";
+
+ /// Version information file, records the storage mode, pointed object, and its log offset for all versions of a given file ID (append-only)
+ pub const FILE_BUCKET_ID_REV: &str = "./revs/{file_id}.v";
+
+ /// Version log file, records all operation logs for a given file ID (append-only)
+ pub const FILE_BUCKET_ID_REV_LOG: &str = "./revs/{file_id}.log";
+
+ /// Tag file, internally points to a file_id
+ pub const FILE_BUCKET_ID_TAG: &str = "./tags/{tag_name}";
+}
+
+pub use consts::*;
diff --git a/rola-utils/constants/src/common.rs b/rola-utils/constants/src/common.rs
index 6ce6bd8..8b333e7 100644
--- a/rola-utils/constants/src/common.rs
+++ b/rola-utils/constants/src/common.rs
@@ -1,7 +1,10 @@
#[shared_macros::constants]
mod consts {
/// Directory name for Rorolala metadata storage in Workdraft
- pub const DRAFT_META_DIR: &str = ".rola";
+ pub const DIR_DRAFT_META: &str = ".rola";
+
+ /// Configuration file indicating the root directory of a bucket
+ pub const FILE_BUCKET_ROOT_CONFIG: &str = "bucket.toml";
}
pub use consts::*;
diff --git a/rola-utils/constants/src/lib.rs b/rola-utils/constants/src/lib.rs
index 566440d..ab8bd4a 100644
--- a/rola-utils/constants/src/lib.rs
+++ b/rola-utils/constants/src/lib.rs
@@ -3,3 +3,5 @@
//! This module records all constant information for Rorolala
pub mod common;
+
+pub mod bucket;
diff --git a/rola-utils/functions/Cargo.toml b/rola-utils/functions/Cargo.toml
index 564dc54..6ce5adf 100644
--- a/rola-utils/functions/Cargo.toml
+++ b/rola-utils/functions/Cargo.toml
@@ -7,3 +7,4 @@ license.workspace = true
[dependencies]
tokio.workspace = true
+log.workspace = true
diff --git a/rola-utils/functions/src/lib.rs b/rola-utils/functions/src/lib.rs
index 72d5b9c..92b4f03 100644
--- a/rola-utils/functions/src/lib.rs
+++ b/rola-utils/functions/src/lib.rs
@@ -6,3 +6,5 @@ pub use levenshtein_distance::*;
mod test_sandbox;
pub use test_sandbox::*;
+
+mod log_macros;
diff --git a/rola-utils/functions/src/log_macros.rs b/rola-utils/functions/src/log_macros.rs
new file mode 100644
index 0000000..4ee4e68
--- /dev/null
+++ b/rola-utils/functions/src/log_macros.rs
@@ -0,0 +1,53 @@
+//! Custom logging macros, with the same names as `log` crate's `trace!`, `debug!`, `info!`, `warn!`, `error!`,
+//! but different behavior: automatically prepend `file!()` information to the message.
+//!
+//! # Usage
+//! ```ignore
+//! trace!("value = {}", x);
+//! debug!("something happened");
+//! info!("user {} logged in", username);
+//! warn!("disk space low: {} GB", free);
+//! error!("failed to open file: {}", path);
+//! ```
+//!
+//! Expands to:
+//! ```ignore
+//! ::log::trace!("[{}]: {}", file!(), format!("value = {}", x));
+//! ::log::debug!("[{}]: {}", file!(), format!("something happened"));
+//! ...
+//! ```
+
+#[macro_export]
+macro_rules! trace {
+ ($($arg:tt)*) => {
+ ::log::trace!("[{}]: {}", file!(), format!($($arg)*));
+ };
+}
+
+#[macro_export]
+macro_rules! debug {
+ ($($arg:tt)*) => {
+ ::log::debug!("[{}]: {}", file!(), format!($($arg)*));
+ };
+}
+
+#[macro_export]
+macro_rules! info {
+ ($($arg:tt)*) => {
+ ::log::info!("[{}]: {}", file!(), format!($($arg)*));
+ };
+}
+
+#[macro_export]
+macro_rules! warn {
+ ($($arg:tt)*) => {
+ ::log::warn!("[{}]: {}", file!(), format!($($arg)*));
+ };
+}
+
+#[macro_export]
+macro_rules! error {
+ ($($arg:tt)*) => {
+ ::log::error!("[{}]: {}", file!(), format!($($arg)*));
+ };
+}
diff --git a/rola-utils/space-system/src/space/error.rs b/rola-utils/space-system/src/space/error.rs
index 33ee6e4..8e85010 100644
--- a/rola-utils/space-system/src/space/error.rs
+++ b/rola-utils/space-system/src/space/error.rs
@@ -11,6 +11,12 @@ pub enum SpaceError {
#[error("Other: {0}")]
Other(String),
+
+ #[error("Require empty directory")]
+ RequireEmptyDirectory,
+
+ #[error("Config file already exist")]
+ ConfigFileAlreadyExist,
}
impl PartialEq for SpaceError {