Skip to content

Commit 3b906aa

Browse files
committed
Permit access times for files after FilesystemStore startup
1 parent 8ae17ba commit 3b906aa

5 files changed

Lines changed: 75 additions & 5 deletions

File tree

Cargo.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nativelink-store/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ rust_library(
7575
"@crates//:http",
7676
"@crates//:http-body",
7777
"@crates//:http-body-util",
78+
"@crates//:humantime",
7879
"@crates//:hyper",
7980
"@crates//:hyper-rustls",
8081
"@crates//:hyper-util",
@@ -148,6 +149,7 @@ rust_test_suite(
148149
"@crates//:aws-smithy-types",
149150
"@crates//:bincode",
150151
"@crates//:bytes",
152+
"@crates//:fs-set-times",
151153
"@crates//:futures",
152154
"@crates//:hex",
153155
"@crates//:http",

nativelink-store/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ hex = { version = "0.4.3", default-features = false }
4949
http = { version = "1.3.1", default-features = false }
5050
http-body = { version = "1.0.1", default-features = false }
5151
http-body-util = { version = "0.1.3", default-features = false }
52+
humantime = { version = "2.3.0", default-features = false }
5253
hyper = { version = "1.6.0", default-features = false }
5354
hyper-rustls = { version = "0.27.5", default-features = false, features = [
5455
"http1",
@@ -126,6 +127,7 @@ aws-smithy-runtime-api = { version = "1.7.4", default-features = false }
126127
aws-smithy-types = { version = "1.3.0", default-features = false, features = [
127128
"http-body-1-x",
128129
] }
130+
fs-set-times = { version = "0.20.3", default-features = false }
129131
futures = { version = "0.3.31", default-features = false, features = [
130132
"executor",
131133
] }

nativelink-store/src/filesystem_store.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use core::fmt::{Debug, Formatter};
1616
use core::pin::Pin;
1717
use core::sync::atomic::{AtomicU64, Ordering};
18+
use core::time::Duration;
1819
use std::borrow::Cow;
1920
use std::ffi::{OsStr, OsString};
2021
use std::sync::{Arc, Weak};
@@ -26,7 +27,7 @@ use bytes::{Bytes, BytesMut};
2627
use futures::stream::{StreamExt, TryStreamExt};
2728
use futures::{Future, TryFutureExt};
2829
use nativelink_config::stores::FilesystemSpec;
29-
use nativelink_error::{Code, Error, ResultExt, make_err, make_input_err};
30+
use nativelink_error::{Code, Error, ResultExt, make_err};
3031
use nativelink_metric::MetricsComponent;
3132
use nativelink_util::background_spawn;
3233
use nativelink_util::buf_channel::{
@@ -452,9 +453,17 @@ async fn add_files_to_cache<Fe: FileEntry>(
452453
key: key.borrow().into_owned(),
453454
}),
454455
);
455-
let time_since_anchor = anchor_time
456-
.duration_since(atime)
457-
.map_err(|_| make_input_err!("File access time newer than now"))?;
456+
let time_since_anchor = if let Ok(d) = anchor_time.duration_since(atime) {
457+
d
458+
} else {
459+
warn!(
460+
%file_name,
461+
atime = %humantime::format_rfc3339(atime),
462+
anchor_time = %humantime::format_rfc3339(*anchor_time),
463+
"File access time newer than FilesystemStore start time",
464+
);
465+
Duration::ZERO
466+
};
458467
evicting_map
459468
.insert_with_time(
460469
key.into_owned().into(),

nativelink-store/tests/filesystem_store_test.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::env;
2020
use std::ffi::{OsStr, OsString};
2121
use std::path::Path;
2222
use std::sync::{Arc, LazyLock};
23+
use std::time::SystemTime;
2324

2425
use async_lock::RwLock;
2526
use bytes::Bytes;
@@ -49,7 +50,7 @@ use tokio::sync::{Barrier, Semaphore};
4950
use tokio::time::sleep;
5051
use tokio_stream::StreamExt;
5152
use tokio_stream::wrappers::ReadDirStream;
52-
use tracing::Instrument;
53+
use tracing::{Instrument, debug};
5354

5455
const VALID_HASH: &str = "0123456789abcdef000000000000000000010000000000000123456789abcdef";
5556

@@ -1465,3 +1466,40 @@ async fn safe_small_safe_eviction() -> Result<(), Error> {
14651466

14661467
Ok(())
14671468
}
1469+
1470+
#[nativelink_test]
1471+
async fn add_too_early_files() -> Result<(), Error> {
1472+
let content_path = make_temp_path("content_path");
1473+
let temp_path = make_temp_path("temp_path");
1474+
1475+
let demo_file_folder = format!("{content_path}/s");
1476+
fs::create_dir_all(&demo_file_folder).await?;
1477+
let demo_file_path = format!("{demo_file_folder}/foo");
1478+
std::fs::write(&demo_file_path, "demo text")
1479+
.err_tip(|| format!("writing to {demo_file_path}"))?;
1480+
debug!(%demo_file_path, "demo file path");
1481+
1482+
// Add 60 seconds to the access time to trigger the logging message about access times
1483+
fs_set_times::set_atime(
1484+
&demo_file_path,
1485+
SystemTime::now()
1486+
.checked_add(Duration::from_secs(60))
1487+
.unwrap()
1488+
.into(),
1489+
)?;
1490+
1491+
FilesystemStore::<FileEntryImpl>::new(&FilesystemSpec {
1492+
content_path: content_path.clone(),
1493+
temp_path: temp_path.clone(),
1494+
read_buffer_size: 1,
1495+
..Default::default()
1496+
})
1497+
.await
1498+
.err_tip(|| "during FileSystemStore::new")?;
1499+
1500+
assert!(logs_contain(
1501+
"File access time newer than FilesystemStore start time file_name=foo atime=20"
1502+
));
1503+
1504+
Ok(())
1505+
}

0 commit comments

Comments
 (0)