From 2dcfdd42050f0b4254e5f907cfa3ed98888a6626 Mon Sep 17 00:00:00 2001 From: Nitish Tiwari Date: Wed, 3 Jan 2024 11:58:56 +0530 Subject: [PATCH 1/2] fix: ensure checking the global cache status before enabling stream cache This PR adds a check to ensure global cache is enabled in the enable stream cache API. We don't allow enabling stream cache because it is misleading to enable cache if global cache is not enabled / configured. --- server/src/handlers/http/logstream.rs | 9 +++++++++ server/src/metadata.rs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/server/src/handlers/http/logstream.rs b/server/src/handlers/http/logstream.rs index 97ac52056..5885ce81b 100644 --- a/server/src/handlers/http/logstream.rs +++ b/server/src/handlers/http/logstream.rs @@ -241,6 +241,10 @@ pub async fn put_enable_cache( let stream_name: String = req.match_info().get("logstream").unwrap().parse().unwrap(); let storage = CONFIG.storage().get_object_store(); + if CONFIG.parseable.local_cache_path.is_none() { + return Err(StreamError::CacheNotEnabled(stream_name)); + } + let mut stream_metadata = storage.get_stream_metadata(&stream_name).await?; stream_metadata.cache_enabled = enable_cache; storage @@ -336,6 +340,10 @@ pub mod error { CreateStream(#[from] CreateStreamError), #[error("Log stream {0} does not exist")] StreamNotFound(String), + #[error( + "Caching not enabled at Parseable server config. Can't enable cache for stream {0}" + )] + CacheNotEnabled(String), #[error("Log stream is not initialized, send an event to this logstream and try again")] UninitializedLogstream, #[error("Storage Error {0}")] @@ -370,6 +378,7 @@ pub mod error { StreamError::CreateStream(CreateStreamError::Storage { .. }) => { StatusCode::INTERNAL_SERVER_ERROR } + StreamError::CacheNotEnabled(_) => StatusCode::BAD_REQUEST, StreamError::StreamNotFound(_) => StatusCode::NOT_FOUND, StreamError::Custom { status, .. } => *status, StreamError::UninitializedLogstream => StatusCode::METHOD_NOT_ALLOWED, diff --git a/server/src/metadata.rs b/server/src/metadata.rs index 5bdfdb515..e7fb32614 100644 --- a/server/src/metadata.rs +++ b/server/src/metadata.rs @@ -220,7 +220,7 @@ pub mod error { #[derive(Debug, thiserror::Error)] pub enum MetadataError { - #[error("Metadata for stream {0} not found. Maybe the stream does not exist")] + #[error("Metadata for stream {0} not found. Please create the stream and try again")] StreamMetaNotFound(String), } From 2d1be789a16a53ef3489ff29e3c449f5ee0cbe89 Mon Sep 17 00:00:00 2001 From: Nikhil Sinha <131262146+nikhilsinhacloudsurfex@users.noreply.github.com> Date: Wed, 3 Jan 2024 13:01:56 +0530 Subject: [PATCH 2/2] enhanced http response message for enabling/disabling cache --- .gitignore | 3 ++- server/src/handlers/http/logstream.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index c759f2831..c3994ec35 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ env-file parseable parseable_* parseable-env-secret -cache +cache* + diff --git a/server/src/handlers/http/logstream.rs b/server/src/handlers/http/logstream.rs index 5885ce81b..7fdfe61c3 100644 --- a/server/src/handlers/http/logstream.rs +++ b/server/src/handlers/http/logstream.rs @@ -253,7 +253,7 @@ pub async fn put_enable_cache( STREAM_INFO.set_stream_cache(&stream_name, enable_cache)?; Ok(( - format!("Cache setting updated for log stream {stream_name}"), + format!("Cache set to {enable_cache} for log stream {stream_name}"), StatusCode::OK, )) }