Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
add request id for debugging (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
OscarZhou0107 authored May 2, 2024
1 parent 47ef36d commit 20d3daa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
15 changes: 12 additions & 3 deletions server/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl DiskCache {
pub async fn get_file(
cache: Arc<Mutex<Self>>,
uid: PathBuf,
rid: String,
connector: Arc<dyn StorageConnector + Send + Sync>,
redis_read: &RwLockReadGuard<'_, RedisServer>,
) -> GetFileResult {
Expand Down Expand Up @@ -118,7 +119,8 @@ impl DiskCache {
let duration = end_time - start_time;

debug!(
"Request for {} started at {} and ended at {}, taking {:?}",
"Request id {} ask for {} started at {} and ended at {}, taking {:?}",
rid.clone(),
uid_str.clone(),
start_time.to_rfc3339(),
end_time.to_rfc3339(),
Expand Down Expand Up @@ -211,6 +213,7 @@ impl ConcurrentDiskCache {
pub async fn get_file(
&self,
uid: PathBuf,
rid: String,
connector: Arc<dyn StorageConnector + Send + Sync>,
) -> GetFileResult {
let uid = uid.into_os_string().into_string().unwrap();
Expand Down Expand Up @@ -238,8 +241,14 @@ impl ConcurrentDiskCache {
let shard = &self.shards[shard_index];
// Debug message showing shard selection
debug!("Selected shard index: {} for uid: {}", shard_index, &uid);
let result =
DiskCache::get_file(shard.clone(), uid.into(), connector.clone(), &redis_read).await;
let result = DiskCache::get_file(
shard.clone(),
uid.into(),
rid,
connector.clone(),
&redis_read,
)
.await;
drop(redis_read);
info!("{}", self.get_stats().await);
result
Expand Down
26 changes: 24 additions & 2 deletions server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::storage::mock_storage_connector::MockS3StorageConnector;
use crate::storage::s3_storage_connector::S3StorageConnector;
use crate::storage::storage_connector::StorageConnector;
use crate::util::hash;
use log::debug;
use rocket::State;
use rocket::{get, post, routes, Rocket};
use std::path::PathBuf;
Expand All @@ -27,14 +28,35 @@ async fn get_file(
cache: &State<Arc<ConcurrentDiskCache>>,
s3_connectors: &State<Vec<Arc<dyn StorageConnector + Send + Sync>>>,
) -> cache::GetFileResult {
let uid_str = uid.to_string_lossy().to_string(); // Convert PathBuf to String correctly
let full_uid_str = uid.to_string_lossy().to_string();
let parts: Vec<&str> = full_uid_str.split('?').collect();
let uid_str = parts[0].to_string();

// Default request ID
let mut request_id = "0".to_string();

// Check if there's a query part for request ID
if parts.len() == 2 {
let request_part = parts[1];
let rid_key_value: Vec<&str> = request_part.split('=').collect();
if rid_key_value.len() == 2 && rid_key_value[0] == "rid" {
request_id = rid_key_value[1].to_string();
} else {
return cache::GetFileResult::InitFailed(format!(
"Invalid request ID format: {}",
request_part
));
}
}

debug!("Handling request ID: {}", request_id);
let index = hash(&uid_str) % s3_connectors.len(); // Use the converted string
let s3_connector = &s3_connectors[index];

cache
.inner()
.clone()
.get_file(PathBuf::from(uid_str), s3_connector.clone()) // Use PathBuf from string
.get_file(PathBuf::from(uid_str), request_id, s3_connector.clone()) // Use PathBuf from string
.await
}

Expand Down

0 comments on commit 20d3daa

Please sign in to comment.