@@ -26,13 +26,13 @@ use crate::event::{
26
26
error:: EventError ,
27
27
format:: { self , EventFormat } ,
28
28
} ;
29
- use crate :: handlers:: http:: cluster :: forward_create_stream_request ;
29
+ use crate :: handlers:: http:: modal :: utils :: logstream_utils :: create_stream_and_schema_from_storage ;
30
30
use crate :: handlers:: { LOG_SOURCE_KEY , LOG_SOURCE_OTEL , STREAM_NAME_HEADER_KEY } ;
31
31
use crate :: localcache:: CacheError ;
32
32
use crate :: metadata:: error:: stream_info:: MetadataError ;
33
- use crate :: metadata:: { self , STREAM_INFO } ;
33
+ use crate :: metadata:: STREAM_INFO ;
34
34
use crate :: option:: { Mode , CONFIG } ;
35
- use crate :: storage:: { LogStream , ObjectStorageError , StreamType } ;
35
+ use crate :: storage:: { ObjectStorageError , StreamType } ;
36
36
use crate :: utils:: header_parsing:: ParseHeaderError ;
37
37
use actix_web:: { http:: header:: ContentType , HttpRequest , HttpResponse } ;
38
38
use arrow_array:: RecordBatch ;
@@ -153,7 +153,17 @@ pub async fn post_event(req: HttpRequest, body: Bytes) -> Result<HttpResponse, P
153
153
) ) ) ;
154
154
}
155
155
if !STREAM_INFO . stream_exists ( & stream_name) {
156
- return Err ( PostError :: StreamNotFound ( stream_name) ) ;
156
+ // For distributed deployments, if the stream not found in memory map,
157
+ //check if it exists in the storage
158
+ //create stream and schema from storage
159
+ if CONFIG . parseable . mode != Mode :: All {
160
+ match create_stream_and_schema_from_storage ( & stream_name) . await {
161
+ Ok ( true ) => { }
162
+ Ok ( false ) | Err ( _) => return Err ( PostError :: StreamNotFound ( stream_name. clone ( ) ) ) ,
163
+ }
164
+ } else {
165
+ return Err ( PostError :: StreamNotFound ( stream_name. clone ( ) ) ) ;
166
+ }
157
167
}
158
168
159
169
flatten_and_push_logs ( req, body, stream_name) . await ?;
@@ -190,49 +200,25 @@ pub async fn create_stream_if_not_exists(
190
200
stream_exists = true ;
191
201
return Ok ( stream_exists) ;
192
202
}
193
- match & CONFIG . parseable . mode {
194
- Mode :: All | Mode :: Query => {
195
- super :: logstream:: create_stream (
196
- stream_name. to_string ( ) ,
197
- "" ,
198
- "" ,
199
- "" ,
200
- "" ,
201
- Arc :: new ( Schema :: empty ( ) ) ,
202
- stream_type,
203
- )
204
- . await ?;
205
- }
206
- Mode :: Ingest => {
207
- // here the ingest server has not found the stream
208
- // so it should check if the stream exists in storage
209
- let store = CONFIG . storage ( ) . get_object_store ( ) ;
210
- let streams = store. list_streams ( ) . await ?;
211
- if !streams. contains ( & LogStream {
212
- name : stream_name. to_owned ( ) ,
213
- } ) {
214
- match forward_create_stream_request ( stream_name) . await {
215
- Ok ( ( ) ) => log:: info!( "Stream {} created" , stream_name) ,
216
- Err ( e) => {
217
- return Err ( PostError :: Invalid ( anyhow:: anyhow!(
218
- "Unable to create stream: {} using query server. Error: {}" ,
219
- stream_name,
220
- e. to_string( ) ,
221
- ) ) )
222
- }
223
- } ;
224
- }
225
- metadata:: STREAM_INFO
226
- . upsert_stream_info (
227
- & * store,
228
- LogStream {
229
- name : stream_name. to_owned ( ) ,
230
- } ,
231
- )
232
- . await
233
- . map_err ( |_| PostError :: StreamNotFound ( stream_name. to_owned ( ) ) ) ?;
234
- }
203
+
204
+ // For distributed deployments, if the stream not found in memory map,
205
+ //check if it exists in the storage
206
+ //create stream and schema from storage
207
+ if CONFIG . parseable . mode != Mode :: All {
208
+ return Ok ( create_stream_and_schema_from_storage ( stream_name) . await ?) ;
235
209
}
210
+
211
+ super :: logstream:: create_stream (
212
+ stream_name. to_string ( ) ,
213
+ "" ,
214
+ "" ,
215
+ "" ,
216
+ "" ,
217
+ Arc :: new ( Schema :: empty ( ) ) ,
218
+ stream_type,
219
+ )
220
+ . await ?;
221
+
236
222
Ok ( stream_exists)
237
223
}
238
224
0 commit comments