Skip to content

Commit 28b984a

Browse files
fix: get schema for distributed (#1008)
current: querier checks if schema is available in STREAM_INFO if not, create schema from storage, load in STREAM_INFO and return STREAM_INFO cannot guarantee the latest state of the schema for distributed fix: merge schema from all ingestors and queriers and then load in STREAM_INFO and return
1 parent b31d46c commit 28b984a

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/handlers/http/logstream.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use super::ingest::create_stream_if_not_exists;
2323
use super::modal::utils::logstream_utils::{
2424
create_stream_and_schema_from_storage, create_update_stream,
2525
};
26+
use super::query::update_schema_when_distributed;
2627
use crate::alerts::Alerts;
2728
use crate::event::format::update_data_type_to_datetime;
2829
use crate::handlers::STREAM_TYPE_KEY;
@@ -117,23 +118,26 @@ pub async fn detect_schema(body: Bytes) -> Result<impl Responder, StreamError> {
117118

118119
pub async fn schema(req: HttpRequest) -> Result<impl Responder, StreamError> {
119120
let stream_name: String = req.match_info().get("logstream").unwrap().parse().unwrap();
120-
let schema = match STREAM_INFO.schema(&stream_name) {
121-
Ok(schema) => schema,
122121

123-
//if schema not found in memory map
124-
//create stream and schema from storage and memory
125-
//return from memory map
122+
match STREAM_INFO.schema(&stream_name) {
123+
Ok(_) => {}
126124
Err(_) if CONFIG.parseable.mode == Mode::Query => {
127-
if create_stream_and_schema_from_storage(&stream_name).await? {
128-
STREAM_INFO.schema(&stream_name)?
129-
} else {
125+
if !create_stream_and_schema_from_storage(&stream_name).await? {
130126
return Err(StreamError::StreamNotFound(stream_name.clone()));
131127
}
132128
}
133-
Err(_) => return Err(StreamError::StreamNotFound(stream_name)),
129+
Err(err) => return Err(StreamError::from(err)),
134130
};
135-
136-
Ok((web::Json(schema), StatusCode::OK))
131+
match update_schema_when_distributed(vec![stream_name.clone()]).await {
132+
Ok(_) => {
133+
let schema = STREAM_INFO.schema(&stream_name)?;
134+
Ok((web::Json(schema), StatusCode::OK))
135+
}
136+
Err(err) => Err(StreamError::Custom {
137+
msg: err.to_string(),
138+
status: StatusCode::EXPECTATION_FAILED,
139+
}),
140+
}
137141
}
138142

139143
pub async fn get_alert(req: HttpRequest) -> Result<impl Responder, StreamError> {

src/handlers/http/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use arrow_schema::Schema;
2121
use itertools::Itertools;
2222
use serde_json::Value;
2323

24-
use crate::option::CONFIG;
24+
use crate::{option::CONFIG, storage::STREAM_ROOT_DIRECTORY};
2525

2626
use self::{cluster::get_ingestor_info, query::Query};
2727

@@ -77,7 +77,7 @@ pub fn base_path_without_preceding_slash() -> String {
7777
/// An `anyhow::Result` containing the `arrow_schema::Schema` for the specified stream.
7878
pub async fn fetch_schema(stream_name: &str) -> anyhow::Result<arrow_schema::Schema> {
7979
let path_prefix =
80-
relative_path::RelativePathBuf::from(format!("{}/{}", stream_name, ".stream"));
80+
relative_path::RelativePathBuf::from(format!("{}/{}", stream_name, STREAM_ROOT_DIRECTORY));
8181
let store = CONFIG.storage().get_object_store();
8282
let res: Vec<Schema> = store
8383
.get_objects(

0 commit comments

Comments
 (0)