pub struct StorageManager { /* private fields */ }Expand description
Manages rotating daily log files for multiple concurrent streams.
§Example
use digdigdig3::core::storage::{StorageManager, StorageConfig, StreamKey};
#[tokio::main]
async fn main() -> std::io::Result<()> {
let mgr = StorageManager::new(StorageConfig::default())?;
let key = StreamKey {
exchange: "binance".into(),
account: "spot".into(),
symbol: "BTCUSDT".into(),
stream_kind: "ticker".into(),
};
mgr.append(&key, 1_700_000_000_000, b"payload").await?;
Ok(())
}Implementations§
Source§impl StorageManager
impl StorageManager
Sourcepub fn new(config: StorageConfig) -> Result<Self>
pub fn new(config: StorageConfig) -> Result<Self>
Create a StorageManager. Creates config.root if it doesn’t exist.
Sourcepub async fn append(
&self,
key: &StreamKey,
ts_ms: i64,
payload: &[u8],
) -> Result<()>
pub async fn append( &self, key: &StreamKey, ts_ms: i64, payload: &[u8], ) -> Result<()>
Append one record to the stream identified by key.
Rotates to a new daily file automatically at UTC midnight.
Sourcepub async fn read_range(
&self,
key: &StreamKey,
from_ms: i64,
to_ms: i64,
) -> Result<Vec<(i64, Vec<u8>)>>
pub async fn read_range( &self, key: &StreamKey, from_ms: i64, to_ms: i64, ) -> Result<Vec<(i64, Vec<u8>)>>
Read records in [from_ms, to_ms] (inclusive) for key.
Spans multiple daily files automatically. Accepts any i64 (including
i64::MAX sentinel for “read to end”) — values outside the
representable date range are clamped to [0, MAX_SAFE_MS].
Sourcepub fn cleanup(&self, now: DateTime<Utc>) -> Result<usize>
pub fn cleanup(&self, now: DateTime<Utc>) -> Result<usize>
Run retention sweep — delete daily files older than config.default_retention_days.
Returns the count of deleted files.
Sourcepub fn stream_dir(&self, key: &StreamKey) -> PathBuf
pub fn stream_dir(&self, key: &StreamKey) -> PathBuf
Return the directory for a stream: {root}/{exchange}/{account}/{symbol}/{stream_kind}/
Sourcepub fn config(&self) -> &StorageConfig
pub fn config(&self) -> &StorageConfig
Return reference to config.
Auto Trait Implementations§
impl !RefUnwindSafe for StorageManager
impl !UnwindSafe for StorageManager
impl Freeze for StorageManager
impl Send for StorageManager
impl Sync for StorageManager
impl Unpin for StorageManager
impl UnsafeUnpin for StorageManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more