Skip to content

Commit

Permalink
fix: ensure checking the global cache before enabling stream cache (#592
Browse files Browse the repository at this point in the history
)

* 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.

* enhanced http response message for enabling/disabling cache

---------

Co-authored-by: Nikhil Sinha <[email protected]>
  • Loading branch information
nitisht and nikhilsinhaparseable authored Jan 3, 2024
1 parent a3f9ccb commit 9907a33
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ env-file
parseable
parseable_*
parseable-env-secret
cache
cache*

11 changes: 10 additions & 1 deletion server/src/handlers/http/logstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -249,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,
))
}
Expand Down Expand Up @@ -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}")]
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion server/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down

0 comments on commit 9907a33

Please sign in to comment.