Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema merge #1008

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/handlers/http/logstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use super::ingest::create_stream_if_not_exists;
use super::modal::utils::logstream_utils::{
create_stream_and_schema_from_storage, create_update_stream,
};
use super::query::update_schema_when_distributed;
use crate::alerts::Alerts;
use crate::event::format::update_data_type_to_datetime;
use crate::handlers::STREAM_TYPE_KEY;
Expand Down Expand Up @@ -117,23 +118,26 @@ pub async fn detect_schema(body: Bytes) -> Result<impl Responder, StreamError> {

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

//if schema not found in memory map
//create stream and schema from storage and memory
//return from memory map
match STREAM_INFO.schema(&stream_name) {
Ok(_) => {}
Err(_) if CONFIG.parseable.mode == Mode::Query => {
if create_stream_and_schema_from_storage(&stream_name).await? {
STREAM_INFO.schema(&stream_name)?
} else {
if !create_stream_and_schema_from_storage(&stream_name).await? {
return Err(StreamError::StreamNotFound(stream_name.clone()));
}
}
Err(_) => return Err(StreamError::StreamNotFound(stream_name)),
Err(err) => return Err(StreamError::from(err)),
};

Ok((web::Json(schema), StatusCode::OK))
match update_schema_when_distributed(vec![stream_name.clone()]).await {
Ok(_) => {
let schema = STREAM_INFO.schema(&stream_name)?;
Ok((web::Json(schema), StatusCode::OK))
}
Err(err) => Err(StreamError::Custom {
msg: err.to_string(),
status: StatusCode::EXPECTATION_FAILED,
}),
}
}

pub async fn get_alert(req: HttpRequest) -> Result<impl Responder, StreamError> {
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use arrow_schema::Schema;
use itertools::Itertools;
use serde_json::Value;

use crate::option::CONFIG;
use crate::{option::CONFIG, storage::STREAM_ROOT_DIRECTORY};

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

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