@@ -20,17 +20,19 @@ use self::error::{CreateStreamError, StreamError};
2020use super :: cluster:: utils:: { merge_quried_stats, IngestionStats , QueriedStats , StorageStats } ;
2121use super :: cluster:: { sync_streams_with_ingestors, INTERNAL_STREAM_NAME } ;
2222use super :: ingest:: create_stream_if_not_exists;
23- use super :: modal:: utils:: logstream_utils:: create_update_stream;
23+ use super :: modal:: utils:: logstream_utils:: {
24+ create_stream_and_schema_from_storage, create_update_stream,
25+ } ;
2426use crate :: alerts:: Alerts ;
2527use crate :: event:: format:: update_data_type_to_datetime;
2628use crate :: handlers:: STREAM_TYPE_KEY ;
2729use crate :: hottier:: { HotTierManager , StreamHotTier , CURRENT_HOT_TIER_VERSION } ;
2830use crate :: metadata:: STREAM_INFO ;
2931use crate :: metrics:: { EVENTS_INGESTED_DATE , EVENTS_INGESTED_SIZE_DATE , EVENTS_STORAGE_SIZE_DATE } ;
30- use crate :: option:: CONFIG ;
32+ use crate :: option:: { Mode , CONFIG } ;
3133use crate :: stats:: { event_labels_date, storage_size_labels_date, Stats } ;
3234use crate :: storage:: StreamType ;
33- use crate :: storage:: { retention:: Retention , LogStream , StorageDir , StreamInfo } ;
35+ use crate :: storage:: { retention:: Retention , StorageDir , StreamInfo } ;
3436use crate :: { catalog, event, stats} ;
3537
3638use crate :: { metadata, validator} ;
@@ -82,11 +84,12 @@ pub async fn delete(req: HttpRequest) -> Result<impl Responder, StreamError> {
8284}
8385
8486pub async fn list ( _: HttpRequest ) -> impl Responder {
85- let res: Vec < LogStream > = STREAM_INFO
87+ let res = CONFIG
88+ . storage ( )
89+ . get_object_store ( )
8690 . list_streams ( )
87- . into_iter ( )
88- . map ( |stream| LogStream { name : stream } )
89- . collect ( ) ;
91+ . await
92+ . unwrap ( ) ;
9093
9194 web:: Json ( res)
9295}
@@ -180,7 +183,11 @@ pub async fn put_alert(
180183 validator:: alert ( & alerts) ?;
181184
182185 if !STREAM_INFO . stream_initialized ( & stream_name) ? {
183- return Err ( StreamError :: UninitializedLogstream ) ;
186+ if CONFIG . parseable . mode == Mode :: Query {
187+ create_stream_and_schema_from_storage ( & stream_name) . await ?;
188+ } else {
189+ return Err ( StreamError :: UninitializedLogstream ) ;
190+ }
184191 }
185192
186193 let schema = STREAM_INFO . schema ( & stream_name) ?;
@@ -218,7 +225,11 @@ pub async fn put_alert(
218225pub async fn get_retention ( req : HttpRequest ) -> Result < impl Responder , StreamError > {
219226 let stream_name: String = req. match_info ( ) . get ( "logstream" ) . unwrap ( ) . parse ( ) . unwrap ( ) ;
220227 if !STREAM_INFO . stream_exists ( & stream_name) {
221- return Err ( StreamError :: StreamNotFound ( stream_name. to_string ( ) ) ) ;
228+ if CONFIG . parseable . mode == Mode :: Query {
229+ create_stream_and_schema_from_storage ( & stream_name) . await ?;
230+ } else {
231+ return Err ( StreamError :: StreamNotFound ( stream_name) ) ;
232+ }
222233 }
223234 let retention = STREAM_INFO . get_retention ( & stream_name) ;
224235
@@ -328,7 +339,11 @@ pub async fn get_stats(req: HttpRequest) -> Result<impl Responder, StreamError>
328339 let stream_name: String = req. match_info ( ) . get ( "logstream" ) . unwrap ( ) . parse ( ) . unwrap ( ) ;
329340
330341 if !metadata:: STREAM_INFO . stream_exists ( & stream_name) {
331- return Err ( StreamError :: StreamNotFound ( stream_name) ) ;
342+ if CONFIG . parseable . mode == Mode :: Query {
343+ create_stream_and_schema_from_storage ( & stream_name) . await ?;
344+ } else {
345+ return Err ( StreamError :: StreamNotFound ( stream_name) ) ;
346+ }
332347 }
333348
334349 let query_string = req. query_string ( ) ;
@@ -497,7 +512,11 @@ pub async fn create_stream(
497512pub async fn get_stream_info ( req : HttpRequest ) -> Result < impl Responder , StreamError > {
498513 let stream_name: String = req. match_info ( ) . get ( "logstream" ) . unwrap ( ) . parse ( ) . unwrap ( ) ;
499514 if !metadata:: STREAM_INFO . stream_exists ( & stream_name) {
500- return Err ( StreamError :: StreamNotFound ( stream_name) ) ;
515+ if CONFIG . parseable . mode == Mode :: Query {
516+ create_stream_and_schema_from_storage ( & stream_name) . await ?;
517+ } else {
518+ return Err ( StreamError :: StreamNotFound ( stream_name) ) ;
519+ }
501520 }
502521
503522 let store = CONFIG . storage ( ) . get_object_store ( ) ;
@@ -540,7 +559,11 @@ pub async fn put_stream_hot_tier(
540559) -> Result < impl Responder , StreamError > {
541560 let stream_name: String = req. match_info ( ) . get ( "logstream" ) . unwrap ( ) . parse ( ) . unwrap ( ) ;
542561 if !metadata:: STREAM_INFO . stream_exists ( & stream_name) {
543- return Err ( StreamError :: StreamNotFound ( stream_name) ) ;
562+ if CONFIG . parseable . mode == Mode :: Query {
563+ create_stream_and_schema_from_storage ( & stream_name) . await ?;
564+ } else {
565+ return Err ( StreamError :: StreamNotFound ( stream_name) ) ;
566+ }
544567 }
545568
546569 if STREAM_INFO . stream_type ( & stream_name) . unwrap ( ) == Some ( StreamType :: Internal . to_string ( ) ) {
@@ -590,7 +613,11 @@ pub async fn get_stream_hot_tier(req: HttpRequest) -> Result<impl Responder, Str
590613 let stream_name: String = req. match_info ( ) . get ( "logstream" ) . unwrap ( ) . parse ( ) . unwrap ( ) ;
591614
592615 if !metadata:: STREAM_INFO . stream_exists ( & stream_name) {
593- return Err ( StreamError :: StreamNotFound ( stream_name) ) ;
616+ if CONFIG . parseable . mode == Mode :: Query {
617+ create_stream_and_schema_from_storage ( & stream_name) . await ?;
618+ } else {
619+ return Err ( StreamError :: StreamNotFound ( stream_name) ) ;
620+ }
594621 }
595622
596623 if CONFIG . parseable . hot_tier_storage_path . is_none ( ) {
@@ -615,7 +642,11 @@ pub async fn delete_stream_hot_tier(req: HttpRequest) -> Result<impl Responder,
615642 let stream_name: String = req. match_info ( ) . get ( "logstream" ) . unwrap ( ) . parse ( ) . unwrap ( ) ;
616643
617644 if !metadata:: STREAM_INFO . stream_exists ( & stream_name) {
618- return Err ( StreamError :: StreamNotFound ( stream_name) ) ;
645+ if CONFIG . parseable . mode == Mode :: Query {
646+ create_stream_and_schema_from_storage ( & stream_name) . await ?;
647+ } else {
648+ return Err ( StreamError :: StreamNotFound ( stream_name) ) ;
649+ }
619650 }
620651
621652 if CONFIG . parseable . hot_tier_storage_path . is_none ( ) {
@@ -654,7 +685,7 @@ pub async fn create_internal_stream_if_not_exists() -> Result<(), StreamError> {
654685 header:: CONTENT_TYPE ,
655686 HeaderValue :: from_static ( "application/json" ) ,
656687 ) ;
657- sync_streams_with_ingestors ( header_map, Bytes :: new ( ) , INTERNAL_STREAM_NAME , None ) . await ?;
688+ sync_streams_with_ingestors ( header_map, Bytes :: new ( ) , INTERNAL_STREAM_NAME ) . await ?;
658689 }
659690 Ok ( ( ) )
660691}
0 commit comments