milenkovicm commented on code in PR #2265: URL: https://github.com/apache/datafusion-ballista/pull/2265#discussion_r3745265614
########## ballista/scheduler/src/history/mod.rs: ########## @@ -0,0 +1,414 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Standalone history server: loads completed event logs and serves the same +//! `/api/*` responses the live scheduler does, from stored DTOs. + +use crate::api::SchedulerErrorResponse; +use axum::response::IntoResponse; +use axum::{ + Json, Router, + extract::{Path as AxumPath, State}, + routing::get, +}; +use ballista_api_types::dto::{JobConfig, JobResponse}; +use ballista_core::BALLISTA_VERSION; +use ballista_history::event::JobIndex; +use ballista_history::reader::{ReplayedJob, read_completed_job}; +use datafusion::DATAFUSION_VERSION; +use http::StatusCode; +use http::header::CONTENT_TYPE; +use serde_json::value::RawValue; +use std::collections::HashMap; +use std::path::Path; +use std::sync::Arc; + +/// In-memory store of completed jobs, loaded once at startup from a directory +/// of `<job_id>.eventlog` files. +#[derive(Default)] +pub struct HistoryStore { + /// Completed jobs keyed by job id. + pub jobs: HashMap<String, ReplayedJob>, +} + +impl HistoryStore { + /// Load every completed job found under `dir`. Missing directories yield + /// an empty store rather than an error. + /// + /// A single unreadable/corrupt `.eventlog` file (e.g. truncated by a + /// crash mid-write) is logged and skipped rather than failing the whole + /// load — one bad log must not hide every other completed job. Only a + /// failure to read the directory itself is propagated. + pub fn load(dir: &Path) -> std::io::Result<HistoryStore> { Review Comment: same like previous, why do we need to load it all instead of reading it on request ? ########## ballista/scheduler/src/history/mod.rs: ########## @@ -0,0 +1,414 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Standalone history server: loads completed event logs and serves the same +//! `/api/*` responses the live scheduler does, from stored DTOs. + +use crate::api::SchedulerErrorResponse; +use axum::response::IntoResponse; +use axum::{ + Json, Router, + extract::{Path as AxumPath, State}, + routing::get, +}; +use ballista_api_types::dto::{JobConfig, JobResponse}; +use ballista_core::BALLISTA_VERSION; +use ballista_history::event::JobIndex; +use ballista_history::reader::{ReplayedJob, read_completed_job}; +use datafusion::DATAFUSION_VERSION; +use http::StatusCode; +use http::header::CONTENT_TYPE; +use serde_json::value::RawValue; +use std::collections::HashMap; +use std::path::Path; +use std::sync::Arc; + +/// In-memory store of completed jobs, loaded once at startup from a directory +/// of `<job_id>.eventlog` files. +#[derive(Default)] +pub struct HistoryStore { + /// Completed jobs keyed by job id. + pub jobs: HashMap<String, ReplayedJob>, Review Comment: why do we want to keep them all in the memory? cant we just read file on request -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
