1919use arrow_schema:: Schema ;
2020use once_cell:: sync:: Lazy ;
2121use std:: collections:: HashMap ;
22- use std:: ops:: { Deref , DerefMut } ;
2322use std:: sync:: { Arc , RwLock } ;
2423
2524use crate :: alerts:: Alerts ;
@@ -29,25 +28,14 @@ use crate::stats::{Stats, StatsCounter};
2928use crate :: storage:: { MergedRecordReader , ObjectStorage , StorageDir } ;
3029
3130use self :: error:: stream_info:: { CheckAlertError , LoadError , MetadataError } ;
31+ use derive_more:: { Deref , DerefMut } ;
3232
3333// TODO: make return type be of 'static lifetime instead of cloning
3434// A read-write lock to allow multiple reads while and isolated write
35- pub static STREAM_INFO : Lazy < StreamType > = Lazy :: new ( || StreamType ( RwLock :: new ( HashMap :: new ( ) ) ) ) ;
35+ pub static STREAM_INFO : Lazy < StreamInfo > = Lazy :: new ( StreamInfo :: default ) ;
3636
37- #[ derive( Debug ) ]
38- pub struct StreamType ( RwLock < HashMap < String , LogStreamMetadata > > ) ;
39-
40- impl Deref for StreamType {
41- type Target = RwLock < HashMap < String , LogStreamMetadata > > ;
42- fn deref ( & self ) -> & Self :: Target {
43- & self . 0
44- }
45- }
46- impl DerefMut for StreamType {
47- fn deref_mut ( & mut self ) -> & mut Self :: Target {
48- & mut self . 0
49- }
50- }
37+ #[ derive( Debug , Deref , DerefMut , Default ) ]
38+ pub struct StreamInfo ( RwLock < HashMap < String , LogStreamMetadata > > ) ;
5139
5240#[ derive( Debug ) ]
5341pub struct LogStreamMetadata {
@@ -75,7 +63,7 @@ pub const LOCK_EXPECT: &str = "no method in metadata should panic while holding
7563// 3. When a stream is deleted (remove the entry from the map)
7664// 4. When first event is sent to stream (update the schema)
7765// 5. When set alert API is called (update the alert)
78- impl StreamType {
66+ impl StreamInfo {
7967 pub async fn check_alerts ( & self , event : & Event ) -> Result < ( ) , CheckAlertError > {
8068 let map = self . read ( ) . expect ( LOCK_EXPECT ) ;
8169 let meta = map
0 commit comments