diff --git a/server/src/metadata.rs b/server/src/metadata.rs index 7d876144d..2306ce6e9 100644 --- a/server/src/metadata.rs +++ b/server/src/metadata.rs @@ -19,7 +19,6 @@ use arrow_schema::Schema; use once_cell::sync::Lazy; use std::collections::HashMap; -use std::ops::{Deref, DerefMut}; use std::sync::{Arc, RwLock}; use crate::alerts::Alerts; @@ -29,25 +28,14 @@ use crate::stats::{Stats, StatsCounter}; use crate::storage::{MergedRecordReader, ObjectStorage, StorageDir}; use self::error::stream_info::{CheckAlertError, LoadError, MetadataError}; +use derive_more::{Deref, DerefMut}; // TODO: make return type be of 'static lifetime instead of cloning // A read-write lock to allow multiple reads while and isolated write -pub static STREAM_INFO: Lazy = Lazy::new(|| StreamType(RwLock::new(HashMap::new()))); +pub static STREAM_INFO: Lazy = Lazy::new(StreamInfo::default); -#[derive(Debug)] -pub struct StreamType(RwLock>); - -impl Deref for StreamType { - type Target = RwLock>; - fn deref(&self) -> &Self::Target { - &self.0 - } -} -impl DerefMut for StreamType { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} +#[derive(Debug, Deref, DerefMut, Default)] +pub struct StreamInfo(RwLock>); #[derive(Debug)] pub struct LogStreamMetadata { @@ -75,7 +63,7 @@ pub const LOCK_EXPECT: &str = "no method in metadata should panic while holding // 3. When a stream is deleted (remove the entry from the map) // 4. When first event is sent to stream (update the schema) // 5. When set alert API is called (update the alert) -impl StreamType { +impl StreamInfo { pub async fn check_alerts(&self, event: &Event) -> Result<(), CheckAlertError> { let map = self.read().expect(LOCK_EXPECT); let meta = map diff --git a/server/src/storage.rs b/server/src/storage.rs index 882e31ad9..f0bf16e64 100644 --- a/server/src/storage.rs +++ b/server/src/storage.rs @@ -26,12 +26,12 @@ use crate::utils; use chrono::{Local, NaiveDateTime, Timelike, Utc}; use datafusion::arrow::error::ArrowError; use datafusion::parquet::errors::ParquetError; +use derive_more::{Deref, DerefMut}; use once_cell::sync::Lazy; use std::collections::HashMap; -use std::fmt::{self, Debug, Formatter}; +use std::fmt::Debug; use std::fs::create_dir_all; -use std::ops::{Deref, DerefMut}; use std::path::{Path, PathBuf}; use std::sync::Mutex; @@ -183,32 +183,13 @@ async fn create_remote_metadata(metadata: &StorageMetadata) -> Result<(), Object client.put_metadata(metadata).await } -pub static CACHED_FILES: Lazy = - Lazy::new(|| CachedFilesInnerType(Mutex::new(FileTable::new()))); +pub static CACHED_FILES: Lazy = + Lazy::new(|| CachedFiles(Mutex::new(FileTable::new()))); -pub struct CachedFilesInnerType(Mutex>); +#[derive(Debug, Deref, DerefMut)] +pub struct CachedFiles(Mutex>); -impl Deref for CachedFilesInnerType { - type Target = Mutex>; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl DerefMut for CachedFilesInnerType { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} - -impl Debug for CachedFilesInnerType { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - f.write_str("CachedFilesInnerType { __private_field: () }") - } -} - -impl CachedFilesInnerType { +impl CachedFiles { pub fn track_parquet(&self) { let mut table = self.lock().expect("no poisoning"); STREAM_INFO diff --git a/server/src/storage/file_link.rs b/server/src/storage/file_link.rs index 90d2176a5..ebf38977f 100644 --- a/server/src/storage/file_link.rs +++ b/server/src/storage/file_link.rs @@ -70,6 +70,7 @@ impl Link for FileLink { } } +#[derive(Debug)] pub struct FileTable { inner: HashMap, }