Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions server/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<StreamType> = Lazy::new(|| StreamType(RwLock::new(HashMap::new())));
pub static STREAM_INFO: Lazy<StreamInfo> = Lazy::new(StreamInfo::default);

#[derive(Debug)]
pub struct StreamType(RwLock<HashMap<String, LogStreamMetadata>>);

impl Deref for StreamType {
type Target = RwLock<HashMap<String, LogStreamMetadata>>;
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<HashMap<String, LogStreamMetadata>>);

#[derive(Debug)]
pub struct LogStreamMetadata {
Expand Down Expand Up @@ -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
Expand Down
33 changes: 7 additions & 26 deletions server/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -183,32 +183,13 @@ async fn create_remote_metadata(metadata: &StorageMetadata) -> Result<(), Object
client.put_metadata(metadata).await
}

pub static CACHED_FILES: Lazy<CachedFilesInnerType> =
Lazy::new(|| CachedFilesInnerType(Mutex::new(FileTable::new())));
pub static CACHED_FILES: Lazy<CachedFiles> =
Lazy::new(|| CachedFiles(Mutex::new(FileTable::new())));

pub struct CachedFilesInnerType(Mutex<FileTable<FileLink>>);
#[derive(Debug, Deref, DerefMut)]
pub struct CachedFiles(Mutex<FileTable<FileLink>>);

impl Deref for CachedFilesInnerType {
type Target = Mutex<FileTable<FileLink>>;

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
Expand Down
1 change: 1 addition & 0 deletions server/src/storage/file_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ impl Link for FileLink {
}
}

#[derive(Debug)]
pub struct FileTable<L: Link + Default> {
inner: HashMap<PathBuf, L>,
}
Expand Down