@@ -23,7 +23,6 @@ use crate::event::format::override_data_type;
23
23
use crate :: hottier:: { HotTierManager , StreamHotTier , CURRENT_HOT_TIER_VERSION } ;
24
24
use crate :: metadata:: SchemaVersion ;
25
25
use crate :: metrics:: { EVENTS_INGESTED_DATE , EVENTS_INGESTED_SIZE_DATE , EVENTS_STORAGE_SIZE_DATE } ;
26
- use crate :: option:: Mode ;
27
26
use crate :: parseable:: { StreamNotFound , PARSEABLE } ;
28
27
use crate :: rbac:: role:: Action ;
29
28
use crate :: rbac:: Users ;
@@ -48,12 +47,7 @@ use tracing::warn;
48
47
pub async fn delete ( stream_name : Path < String > ) -> Result < impl Responder , StreamError > {
49
48
let stream_name = stream_name. into_inner ( ) ;
50
49
// Error out if stream doesn't exist in memory, or in the case of query node, in storage as well
51
- if !PARSEABLE . streams . contains ( & stream_name)
52
- && ( PARSEABLE . options . mode != Mode :: Query
53
- || !PARSEABLE
54
- . create_stream_and_schema_from_storage ( & stream_name)
55
- . await ?)
56
- {
50
+ if PARSEABLE . check_or_load_stream ( & stream_name) . await {
57
51
return Err ( StreamNotFound ( stream_name) . into ( ) ) ;
58
52
}
59
53
@@ -130,12 +124,7 @@ pub async fn get_schema(stream_name: Path<String>) -> Result<impl Responder, Str
130
124
let stream_name = stream_name. into_inner ( ) ;
131
125
132
126
// Ensure parseable is aware of stream in distributed mode
133
- if !PARSEABLE . streams . contains ( & stream_name)
134
- && ( PARSEABLE . options . mode != Mode :: Query
135
- || !PARSEABLE
136
- . create_stream_and_schema_from_storage ( & stream_name)
137
- . await ?)
138
- {
127
+ if PARSEABLE . check_or_load_stream ( & stream_name) . await {
139
128
return Err ( StreamNotFound ( stream_name. clone ( ) ) . into ( ) ) ;
140
129
}
141
130
@@ -171,12 +160,7 @@ pub async fn get_retention(stream_name: Path<String>) -> Result<impl Responder,
171
160
// For query mode, if the stream not found in memory map,
172
161
//check if it exists in the storage
173
162
//create stream and schema from storage
174
- if !PARSEABLE . streams . contains ( & stream_name)
175
- && ( PARSEABLE . options . mode != Mode :: Query
176
- || !PARSEABLE
177
- . create_stream_and_schema_from_storage ( & stream_name)
178
- . await ?)
179
- {
163
+ if PARSEABLE . check_or_load_stream ( & stream_name) . await {
180
164
return Err ( StreamNotFound ( stream_name. clone ( ) ) . into ( ) ) ;
181
165
}
182
166
@@ -196,12 +180,7 @@ pub async fn put_retention(
196
180
// For query mode, if the stream not found in memory map,
197
181
//check if it exists in the storage
198
182
//create stream and schema from storage
199
- if !PARSEABLE . streams . contains ( & stream_name)
200
- && ( PARSEABLE . options . mode != Mode :: Query
201
- || !PARSEABLE
202
- . create_stream_and_schema_from_storage ( & stream_name)
203
- . await ?)
204
- {
183
+ if PARSEABLE . check_or_load_stream ( & stream_name) . await {
205
184
return Err ( StreamNotFound ( stream_name) . into ( ) ) ;
206
185
}
207
186
@@ -252,12 +231,7 @@ pub async fn get_stats(
252
231
// For query mode, if the stream not found in memory map,
253
232
//check if it exists in the storage
254
233
//create stream and schema from storage
255
- if !PARSEABLE . streams . contains ( & stream_name)
256
- && ( PARSEABLE . options . mode != Mode :: Query
257
- || !PARSEABLE
258
- . create_stream_and_schema_from_storage ( & stream_name)
259
- . await ?)
260
- {
234
+ if PARSEABLE . check_or_load_stream ( & stream_name) . await {
261
235
return Err ( StreamNotFound ( stream_name. clone ( ) ) . into ( ) ) ;
262
236
}
263
237
@@ -353,12 +327,7 @@ pub async fn get_stream_info(stream_name: Path<String>) -> Result<impl Responder
353
327
// For query mode, if the stream not found in memory map,
354
328
//check if it exists in the storage
355
329
//create stream and schema from storage
356
- if !PARSEABLE . streams . contains ( & stream_name)
357
- && ( PARSEABLE . options . mode != Mode :: Query
358
- || !PARSEABLE
359
- . create_stream_and_schema_from_storage ( & stream_name)
360
- . await ?)
361
- {
330
+ if PARSEABLE . check_or_load_stream ( & stream_name) . await {
362
331
return Err ( StreamNotFound ( stream_name. clone ( ) ) . into ( ) ) ;
363
332
}
364
333
@@ -410,12 +379,7 @@ pub async fn put_stream_hot_tier(
410
379
// For query mode, if the stream not found in memory map,
411
380
//check if it exists in the storage
412
381
//create stream and schema from storage
413
- if !PARSEABLE . streams . contains ( & stream_name)
414
- && ( PARSEABLE . options . mode != Mode :: Query
415
- || !PARSEABLE
416
- . create_stream_and_schema_from_storage ( & stream_name)
417
- . await ?)
418
- {
382
+ if PARSEABLE . check_or_load_stream ( & stream_name) . await {
419
383
return Err ( StreamNotFound ( stream_name) . into ( ) ) ;
420
384
}
421
385
@@ -462,12 +426,7 @@ pub async fn get_stream_hot_tier(stream_name: Path<String>) -> Result<impl Respo
462
426
// For query mode, if the stream not found in memory map,
463
427
//check if it exists in the storage
464
428
//create stream and schema from storage
465
- if !PARSEABLE . streams . contains ( & stream_name)
466
- && ( PARSEABLE . options . mode != Mode :: Query
467
- || !PARSEABLE
468
- . create_stream_and_schema_from_storage ( & stream_name)
469
- . await ?)
470
- {
429
+ if PARSEABLE . check_or_load_stream ( & stream_name) . await {
471
430
return Err ( StreamNotFound ( stream_name. clone ( ) ) . into ( ) ) ;
472
431
}
473
432
@@ -487,12 +446,7 @@ pub async fn delete_stream_hot_tier(
487
446
// For query mode, if the stream not found in memory map,
488
447
//check if it exists in the storage
489
448
//create stream and schema from storage
490
- if !PARSEABLE . streams . contains ( & stream_name)
491
- && ( PARSEABLE . options . mode != Mode :: Query
492
- || !PARSEABLE
493
- . create_stream_and_schema_from_storage ( & stream_name)
494
- . await ?)
495
- {
449
+ if PARSEABLE . check_or_load_stream ( & stream_name) . await {
496
450
return Err ( StreamNotFound ( stream_name) . into ( ) ) ;
497
451
}
498
452
0 commit comments