Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions nativelink-store/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ rust_library(
"@crates//:http",
"@crates//:http-body",
"@crates//:http-body-util",
"@crates//:humantime",
"@crates//:hyper",
"@crates//:hyper-rustls",
"@crates//:hyper-util",
Expand Down Expand Up @@ -165,6 +166,7 @@ rust_test_suite(
"@crates//:bytes",
"@crates//:dirs",
"@crates//:flate2",
"@crates//:fs-set-times",
"@crates//:futures",
"@crates//:hex",
"@crates//:http",
Expand Down
2 changes: 2 additions & 0 deletions nativelink-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ hex = { version = "0.4.3", default-features = false }
http = { version = "1.3.1", default-features = false }
http-body = { version = "1.0.1", default-features = false }
http-body-util = { version = "0.1.3", default-features = false }
humantime = { version = "2.3.0", default-features = false }
hyper = { version = "1.6.0", default-features = false }
hyper-rustls = { version = "0.27.5", default-features = false, features = [
"http1",
Expand Down Expand Up @@ -137,6 +138,7 @@ aws-smithy-types = { version = "1.3.0", default-features = false, features = [
] }
dirs = { version = "6.0.0", default-features = false }
flate2 = { version = "1.1.9", default-features = false, features = ["zlib-rs"] }
fs-set-times = { version = "0.20.3", default-features = false }
futures = { version = "0.3.31", default-features = false, features = [
"executor",
] }
Expand Down
17 changes: 13 additions & 4 deletions nativelink-store/src/filesystem_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use core::fmt::{Debug, Formatter};
use core::pin::Pin;
use core::sync::atomic::{AtomicU64, Ordering};
use core::time::Duration;
use std::borrow::Cow;
use std::ffi::{OsStr, OsString};
use std::sync::{Arc, Weak};
Expand All @@ -26,7 +27,7 @@ use bytes::{Bytes, BytesMut};
use futures::stream::{StreamExt, TryStreamExt};
use futures::{Future, TryFutureExt};
use nativelink_config::stores::FilesystemSpec;
use nativelink_error::{Code, Error, ResultExt, make_err, make_input_err};
use nativelink_error::{Code, Error, ResultExt, make_err};
use nativelink_metric::MetricsComponent;
use nativelink_util::background_spawn;
use nativelink_util::buf_channel::{
Expand Down Expand Up @@ -452,9 +453,17 @@ async fn add_files_to_cache<Fe: FileEntry>(
key: key.borrow().into_owned(),
}),
);
let time_since_anchor = anchor_time
.duration_since(atime)
.map_err(|_| make_input_err!("File access time newer than now"))?;
let time_since_anchor = if let Ok(d) = anchor_time.duration_since(atime) {
d
} else {
warn!(
%file_name,
atime = %humantime::format_rfc3339(atime),
anchor_time = %humantime::format_rfc3339(*anchor_time),
"File access time newer than FilesystemStore start time",
);
Duration::ZERO
};
evicting_map
.insert_with_time(
key.into_owned().into(),
Expand Down
40 changes: 39 additions & 1 deletion nativelink-store/tests/filesystem_store_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::env;
use std::ffi::{OsStr, OsString};
use std::path::Path;
use std::sync::{Arc, LazyLock};
use std::time::SystemTime;

use async_lock::RwLock;
use bytes::Bytes;
Expand Down Expand Up @@ -49,7 +50,7 @@ use tokio::sync::{Barrier, Semaphore};
use tokio::time::sleep;
use tokio_stream::StreamExt;
use tokio_stream::wrappers::ReadDirStream;
use tracing::Instrument;
use tracing::{Instrument, debug};

const VALID_HASH: &str = "0123456789abcdef000000000000000000010000000000000123456789abcdef";

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

Ok(())
}

#[nativelink_test]
async fn add_too_early_files() -> Result<(), Error> {
let content_path = make_temp_path("content_path");
let temp_path = make_temp_path("temp_path");

let demo_file_folder = format!("{content_path}/s");
fs::create_dir_all(&demo_file_folder).await?;
let demo_file_path = format!("{demo_file_folder}/foo");
std::fs::write(&demo_file_path, "demo text")
.err_tip(|| format!("writing to {demo_file_path}"))?;
debug!(%demo_file_path, "demo file path");

// Add 60 seconds to the access time to trigger the logging message about access times
fs_set_times::set_atime(
&demo_file_path,
SystemTime::now()
.checked_add(Duration::from_secs(60))
.unwrap()
.into(),
)?;

FilesystemStore::<FileEntryImpl>::new(&FilesystemSpec {
content_path: content_path.clone(),
temp_path: temp_path.clone(),
read_buffer_size: 1,
..Default::default()
})
.await
.err_tip(|| "during FileSystemStore::new")?;

assert!(logs_contain(
"File access time newer than FilesystemStore start time file_name=foo atime=20"
));

Ok(())
}
Loading