Skip to content

Commit 9907a33

Browse files
fix: ensure checking the global cache before enabling stream cache (#592)
* 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]>
1 parent a3f9ccb commit 9907a33

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ env-file
1313
parseable
1414
parseable_*
1515
parseable-env-secret
16-
cache
16+
cache*
17+

server/src/handlers/http/logstream.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ pub async fn put_enable_cache(
241241
let stream_name: String = req.match_info().get("logstream").unwrap().parse().unwrap();
242242
let storage = CONFIG.storage().get_object_store();
243243

244+
if CONFIG.parseable.local_cache_path.is_none() {
245+
return Err(StreamError::CacheNotEnabled(stream_name));
246+
}
247+
244248
let mut stream_metadata = storage.get_stream_metadata(&stream_name).await?;
245249
stream_metadata.cache_enabled = enable_cache;
246250
storage
@@ -249,7 +253,7 @@ pub async fn put_enable_cache(
249253

250254
STREAM_INFO.set_stream_cache(&stream_name, enable_cache)?;
251255
Ok((
252-
format!("Cache setting updated for log stream {stream_name}"),
256+
format!("Cache set to {enable_cache} for log stream {stream_name}"),
253257
StatusCode::OK,
254258
))
255259
}
@@ -336,6 +340,10 @@ pub mod error {
336340
CreateStream(#[from] CreateStreamError),
337341
#[error("Log stream {0} does not exist")]
338342
StreamNotFound(String),
343+
#[error(
344+
"Caching not enabled at Parseable server config. Can't enable cache for stream {0}"
345+
)]
346+
CacheNotEnabled(String),
339347
#[error("Log stream is not initialized, send an event to this logstream and try again")]
340348
UninitializedLogstream,
341349
#[error("Storage Error {0}")]
@@ -370,6 +378,7 @@ pub mod error {
370378
StreamError::CreateStream(CreateStreamError::Storage { .. }) => {
371379
StatusCode::INTERNAL_SERVER_ERROR
372380
}
381+
StreamError::CacheNotEnabled(_) => StatusCode::BAD_REQUEST,
373382
StreamError::StreamNotFound(_) => StatusCode::NOT_FOUND,
374383
StreamError::Custom { status, .. } => *status,
375384
StreamError::UninitializedLogstream => StatusCode::METHOD_NOT_ALLOWED,

server/src/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub mod error {
220220

221221
#[derive(Debug, thiserror::Error)]
222222
pub enum MetadataError {
223-
#[error("Metadata for stream {0} not found. Maybe the stream does not exist")]
223+
#[error("Metadata for stream {0} not found. Please create the stream and try again")]
224224
StreamMetaNotFound(String),
225225
}
226226

0 commit comments

Comments
 (0)