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

Commit

Permalink
hot fix: lock early release
Browse files Browse the repository at this point in the history
  • Loading branch information
OscarZhou0107 committed May 1, 2024
1 parent 8fef90a commit 376db54
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
27 changes: 21 additions & 6 deletions server/src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// cache.rs
use chrono;
use chrono::{self, DateTime, Utc};
use log::{debug, info};
use rocket::{fs::NamedFile, response::Redirect};
use std::collections::VecDeque;
Expand Down Expand Up @@ -64,6 +64,7 @@ impl DiskCache {
redis_read: &RwLockReadGuard<'_, RedisServer>,
) -> GetFileResult {
let uid_str = uid.into_os_string().into_string().unwrap();
let start_time: DateTime<Utc> = Utc::now(); // Human-readable start time
let mut cache = cache.lock().await;
let redirect = redis_read.location_lookup(uid_str.clone()).await;
if let Some((x, p)) = redirect {
Expand Down Expand Up @@ -107,10 +108,24 @@ impl DiskCache {
debug!("get_file: {}", file_name_str);
cache.update_access(&file_name_str);
let cache_file_path = cache.cache_dir.join(file_name);
match NamedFile::open(cache_file_path).await {
Ok(x) => GetFileResult::Hit(x),
Err(_) => GetFileResult::NotFoundOnS3(uid_str),
}
drop(cache);
let result = match NamedFile::open(cache_file_path).await {
Ok(file) => GetFileResult::Hit(file),
Err(_) => GetFileResult::NotFoundOnS3(uid_str.clone()),
};

let end_time: DateTime<Utc> = Utc::now(); // Human-readable end time
let duration = end_time - start_time;

debug!(
"Request for {} started at {} and ended at {}, taking {:?}",
uid_str.clone(),
start_time.to_rfc3339(),
end_time.to_rfc3339(),
duration
);

result
}

async fn get_s3_file_to_cache(
Expand Down Expand Up @@ -226,7 +241,7 @@ impl ConcurrentDiskCache {
let result =
DiskCache::get_file(shard.clone(), uid.into(), connector.clone(), &redis_read).await;
drop(redis_read);
debug!("{}", self.get_stats().await);
info!("{}", self.get_stats().await);
result
}

Expand Down
4 changes: 0 additions & 4 deletions server/src/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ impl RedisServer {
}

self.slot_to_node_mapping = new_mapping;
debug!(
"Updated slot-to-node mapping: {:?}",
self.slot_to_node_mapping
);
Ok(())
}
// Location lookup function that uses the updated mapping
Expand Down
14 changes: 9 additions & 5 deletions server/src/storage/s3_storage_connector.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use async_trait::async_trait;
use aws_sdk_s3::{Client, Config, Credentials, Region};
use chrono::{DateTime, Utc};
use log::debug;
use rocket::futures::StreamExt;
use std::io;
Expand Down Expand Up @@ -53,6 +54,12 @@ impl StorageConnector for S3StorageConnector {
// Assemble the object key with the file name
let object_key = file_name;
let start = Instant::now();
let start_time: DateTime<Utc> = Utc::now(); // Record start time
debug!(
"Start fetching object '{}' at {}",
file_name,
start_time.to_rfc3339()
);
// Attempt to fetch the object from S3
let result = self
.client
Expand All @@ -77,11 +84,8 @@ impl StorageConnector for S3StorageConnector {
}
file.flush().await?;
let duration = start.elapsed();

debug!(
"Object '{}' fetched and cached successfully with size: {} bytes in {:?}",
file_name, file_size, duration
);
let end_time: DateTime<Utc> = Utc::now();
debug!("End fetching object '{}'. Started at: {}, Ended at: {}, Duration: {:?}, File size: {} bytes.", file_name, start_time.to_rfc3339(), end_time.to_rfc3339(), duration, file_size);
Ok((Path::new("").join(file_name), file_size))
}
Err(aws_sdk_s3::SdkError::ServiceError { err, .. }) => {
Expand Down

0 comments on commit 376db54

Please sign in to comment.