Skip to content

Commit 50499dc

Browse files
committed
Permit access times for files after FilesystemStore startup
1 parent 5d625c2 commit 50499dc

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
@@ -79,6 +79,7 @@ rust_library(
7979
"@crates//:http",
8080
"@crates//:http-body",
8181
"@crates//:http-body-util",
82+
"@crates//:humantime",
8283
"@crates//:hyper",
8384
"@crates//:hyper-rustls",
8485
"@crates//:hyper-util",
@@ -165,6 +166,7 @@ rust_test_suite(
165166
"@crates//:bytes",
166167
"@crates//:dirs",
167168
"@crates//:flate2",
169+
"@crates//:fs-set-times",
168170
"@crates//:futures",
169171
"@crates//:hex",
170172
"@crates//:http",

nativelink-store/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ hex = { version = "0.4.3", default-features = false }
5858
http = { version = "1.3.1", default-features = false }
5959
http-body = { version = "1.0.1", default-features = false }
6060
http-body-util = { version = "0.1.3", default-features = false }
61+
humantime = { version = "2.3.0", default-features = false }
6162
hyper = { version = "1.6.0", default-features = false }
6263
hyper-rustls = { version = "0.27.5", default-features = false, features = [
6364
"http1",
@@ -137,6 +138,7 @@ aws-smithy-types = { version = "1.3.0", default-features = false, features = [
137138
] }
138139
dirs = { version = "6.0.0", default-features = false }
139140
flate2 = { version = "1.1.9", default-features = false, features = ["zlib-rs"] }
141+
fs-set-times = { version = "0.20.3", default-features = false }
140142
futures = { version = "0.3.31", default-features = false, features = [
141143
"executor",
142144
] }

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)