Skip to content

Commit 123638c

Browse files
fixes
1. sync to storage issue - for regular scenario 2. server accepting request even after SIGTERM signal received - ingest handlers to check signal
1 parent 8ccd638 commit 123638c

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

server/src/handlers/http/health_check.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ use lazy_static::lazy_static;
2323
use std::sync::Arc;
2424
use tokio::signal::unix::{signal, SignalKind};
2525
use tokio::sync::{oneshot, Mutex};
26-
use tokio::time::{sleep, Duration};
2726

2827
// Create a global variable to store signal status
2928
lazy_static! {
30-
static ref SIGNAL_RECEIVED: Arc<Mutex<bool>> = Arc::new(Mutex::new(false));
29+
pub static ref SIGNAL_RECEIVED: Arc<Mutex<bool>> = Arc::new(Mutex::new(false));
3130
}
3231

3332
pub async fn liveness() -> HttpResponse {

server/src/handlers/http/ingest.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*
1717
*/
1818

19+
use super::health_check::SIGNAL_RECEIVED;
1920
use super::logstream::error::{CreateStreamError, StreamError};
2021
use super::modal::utils::ingest_utils::{flatten_and_push_logs, push_logs};
2122
use super::otel;
@@ -47,6 +48,13 @@ use std::sync::Arc;
4748
// ingests events by extracting stream name from header
4849
// creates if stream does not exist
4950
pub async fn ingest(req: HttpRequest, body: Bytes) -> Result<HttpResponse, PostError> {
51+
// Check if the application has received a shutdown signal
52+
let shutdown_flag = SIGNAL_RECEIVED.lock().await;
53+
if *shutdown_flag {
54+
return Err(PostError::CustomError(
55+
"Server is shutting down".to_string(),
56+
));
57+
}
5058
if let Some((_, stream_name)) = req
5159
.headers()
5260
.iter()
@@ -107,6 +115,13 @@ pub async fn ingest_internal_stream(stream_name: String, body: Bytes) -> Result<
107115
// ingests events by extracting stream name from header
108116
// creates if stream does not exist
109117
pub async fn ingest_otel_logs(req: HttpRequest, body: Bytes) -> Result<HttpResponse, PostError> {
118+
// Check if the application has received a shutdown signal
119+
let shutdown_flag = SIGNAL_RECEIVED.lock().await;
120+
if *shutdown_flag {
121+
return Err(PostError::CustomError(
122+
"Server is shutting down".to_string(),
123+
));
124+
}
110125
if let Some((_, stream_name)) = req
111126
.headers()
112127
.iter()
@@ -143,6 +158,13 @@ pub async fn ingest_otel_logs(req: HttpRequest, body: Bytes) -> Result<HttpRespo
143158
// only ingests events into the specified logstream
144159
// fails if the logstream does not exist
145160
pub async fn post_event(req: HttpRequest, body: Bytes) -> Result<HttpResponse, PostError> {
161+
// Check if the application has received a shutdown signal
162+
let shutdown_flag = SIGNAL_RECEIVED.lock().await;
163+
if *shutdown_flag {
164+
return Err(PostError::CustomError(
165+
"Server is shutting down".to_string(),
166+
));
167+
}
146168
let stream_name: String = req.match_info().get("logstream").unwrap().parse().unwrap();
147169
let internal_stream_names = STREAM_INFO.list_internal_streams();
148170
if internal_stream_names.contains(&stream_name) {

server/src/handlers/http/modal/server.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use crate::users::dashboards::DASHBOARDS;
4040
use crate::users::filters::FILTERS;
4141
use std::sync::Arc;
4242
use tokio::sync::{oneshot, Mutex};
43-
use tokio::time::{sleep, Duration};
4443

4544
use actix_web::web::resource;
4645
use actix_web::Resource;

server/src/storage/staging.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ impl StorageDir {
162162

163163
if !shutdown_signal {
164164
arrow_files.retain(|path| {
165-
path.file_name()
165+
!path
166+
.file_name()
166167
.unwrap()
167168
.to_str()
168169
.unwrap()

0 commit comments

Comments
 (0)