Skip to content

Commit 741b1ab

Browse files
committed
Move things around.
1 parent e98935c commit 741b1ab

19 files changed

Lines changed: 111 additions & 75 deletions

File tree

Cargo.lock

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cache-remote/src/grpc_remote_storage.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ use bazel_remote_apis::google::bytestream::{
1818
};
1919
use moon_blob::{BlobContent, BlobInput, BlobOutput, Bytes};
2020
use moon_cache_storage::{
21-
CacheCapabilities, CacheContext, Compressor, DigestFunction, ExternalDigestExt,
22-
InternalDigestExt, Manifest, StorageBackend, check_blob_integrity,
21+
CacheCapabilities, CacheContext, Compressor, DigestFunction, Manifest, StorageBackend,
22+
check_blob_integrity,
2323
};
2424
use moon_common::{Id, color, is_ci, is_remote};
2525
use moon_config::{RemoteCompression, RemoteConfig};
26-
use moon_hash::Digest;
26+
use moon_hash::{Digest, ExternalDigestExt, InternalDigestExt};
2727
use reqwest::header::HeaderMap;
2828
use std::fmt::Debug;
2929
use std::sync::{Arc, OnceLock};

crates/cache-storage/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ moon_blob = { path = "../blob" }
1313
moon_common = { path = "../common" }
1414
moon_config = { path = "../config" }
1515
moon_hash = { path = "../hash" }
16+
moon_manifest = { path = "../manifest" }
1617
moon_process = { path = "../process" }
1718
async-trait = { workspace = true }
1819
bazel-remote-apis = { workspace = true }

crates/cache-storage/src/helpers.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,7 @@
1-
use bazel_remote_apis::google::protobuf::Timestamp;
2-
use chrono::NaiveDateTime;
31
use moon_common::BLOCKING_THREAD_COUNT;
42
use moon_hash::Digest;
5-
use std::time::{Duration, SystemTime, UNIX_EPOCH};
63
use tracing::warn;
74

8-
pub fn create_timestamp(time: SystemTime) -> Option<Timestamp> {
9-
time.duration_since(UNIX_EPOCH)
10-
.ok()
11-
.map(|duration| Timestamp {
12-
seconds: duration.as_secs() as i64,
13-
nanos: duration.subsec_nanos() as i32,
14-
})
15-
}
16-
17-
pub fn create_timestamp_from_naive(time: NaiveDateTime) -> Option<Timestamp> {
18-
let utc = time.and_utc();
19-
20-
Some(Timestamp {
21-
seconds: utc.timestamp(),
22-
nanos: utc.timestamp_subsec_nanos() as i32,
23-
})
24-
}
25-
26-
pub fn create_from_timestamp(timestamp: Timestamp) -> SystemTime {
27-
UNIX_EPOCH + Duration::new(timestamp.seconds as u64, timestamp.nanos as u32)
28-
}
29-
305
pub fn check_blob_integrity(expected_digest: &Digest, bytes: &[u8]) -> miette::Result<bool> {
316
if bytes.len() != expected_digest.size as usize {
327
warn!(
@@ -302,20 +277,4 @@ mod tests {
302277
assert!(batches.iter().all(|batch| batch.items.len() == 3));
303278
}
304279
}
305-
306-
mod timestamps {
307-
use super::*;
308-
309-
#[test]
310-
fn round_trips_through_protobuf() {
311-
let now = SystemTime::now();
312-
313-
let restored = create_from_timestamp(create_timestamp(now).unwrap());
314-
315-
let original = now.duration_since(UNIX_EPOCH).unwrap();
316-
let after = restored.duration_since(UNIX_EPOCH).unwrap();
317-
assert_eq!(original.as_secs(), after.as_secs());
318-
assert_eq!(original.subsec_nanos(), after.subsec_nanos());
319-
}
320-
}
321280
}

crates/cache-storage/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
mod capabilities;
2-
mod digest_compat;
32
mod helpers;
4-
mod manifest;
53
mod storage;
64
mod storage_backend;
75

86
pub use capabilities::*;
9-
pub use digest_compat::*;
107
pub use helpers::*;
11-
pub use manifest::*;
128
pub use storage::*;
139
pub use storage_backend::*;
10+
11+
pub use moon_manifest::*;

crates/cache-storage/src/storage.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
use crate::manifest::{Manifest, ManifestSource};
21
use crate::storage_backend::{BoxedStorageBackend, StorageBackend};
2+
use miette::IntoDiagnostic;
33
use moon_blob::{BlobCleanStats, BlobContent, BlobInput, BlobOutput};
44
use moon_common::{Id, format_error_chain, is_daemon_env};
55
use moon_config::{CacheConfig, RemoteConfig};
66
use moon_hash::Digest;
7+
use moon_manifest::Manifest;
78
use rustc_hash::FxHashMap;
89
use std::collections::VecDeque;
910
use std::path::PathBuf;
1011
use std::sync::Arc;
11-
use std::sync::Mutex;
1212
use std::time::{Duration, SystemTime};
13+
use tokio::sync::Mutex;
1314
use tokio::task::{AbortHandle, JoinHandle, JoinSet};
1415
use tracing::{debug, warn};
1516

@@ -19,6 +20,12 @@ use tracing::{debug, warn};
1920
/// aborted and reported, and simply get re-uploaded on the next run.
2021
const BACKGROUND_FLUSH_TIMEOUT: Duration = Duration::from_secs(60);
2122

23+
pub struct ManifestSource {
24+
pub backend: BoxedStorageBackend,
25+
pub manifest: Manifest,
26+
pub remote: bool,
27+
}
28+
2229
#[derive(Clone, Debug)]
2330
pub struct CacheContext {
2431
pub cache_dir: PathBuf,
@@ -222,7 +229,7 @@ impl Storage {
222229
}
223230

224231
pub async fn store_blobs(&self, blobs: Vec<BlobInput>) -> miette::Result<()> {
225-
let mut background_tasks = self.background_tasks.lock().unwrap();
232+
let mut background_tasks = self.background_tasks.lock().await;
226233

227234
for backend in self.get_backends() {
228235
if !backend.is_writable() {
@@ -282,7 +289,7 @@ impl Storage {
282289
digest: &Digest,
283290
manifest: Manifest,
284291
) -> miette::Result<()> {
285-
let mut background_tasks = self.background_tasks.lock().unwrap();
292+
let mut background_tasks = self.background_tasks.lock().await;
286293

287294
debug!(
288295
hash = digest.hash.as_str(),
@@ -316,6 +323,10 @@ impl Storage {
316323
}
317324
}
318325

326+
while let Some(result) = set.join_next().await {
327+
result.into_diagnostic()??;
328+
}
329+
319330
debug!(
320331
hash = digest.hash.as_str(),
321332
files = manifest.files.len(),
@@ -403,7 +414,7 @@ impl Storage {
403414
/// backend, so the next run resolves locally instead of round-tripping to
404415
/// the remote.
405416
async fn warm_local_backends(&self, digest: &Digest, manifest: &Manifest) {
406-
let mut background_tasks = self.background_tasks.lock().unwrap();
417+
let mut background_tasks = self.background_tasks.lock().await;
407418

408419
for backend in self.get_local_backends() {
409420
if !backend.is_writable() {
@@ -432,7 +443,7 @@ impl Storage {
432443
let background_tasks = {
433444
self.background_tasks
434445
.lock()
435-
.unwrap()
446+
.await
436447
.drain(0..)
437448
.collect::<Vec<_>>()
438449
};

crates/cache-storage/src/storage_backend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::capabilities::CacheCapabilities;
22
use crate::helpers::{Batch, create_batches};
3-
use crate::manifest::Manifest;
43
use async_trait::async_trait;
54
use miette::IntoDiagnostic;
65
use moon_blob::{BlobCleanStats, BlobInput, BlobOutput};
76
use moon_common::{Id, format_error_chain};
87
use moon_hash::Digest;
8+
use moon_manifest::Manifest;
99
use moon_process::ProcessRegistry;
1010
use rustc_hash::FxHashSet;
1111
use std::fmt::Debug;

crates/cache-storage/tests/manifest_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use bazel_remote_apis::build::bazel::remote::execution::v2::{
33
};
44
use bazel_remote_apis::google::protobuf::Timestamp;
55
use moon_blob::{BlobContent, Bytes};
6-
use moon_cache_storage::{Manifest, ManifestFile};
76
use moon_hash::{ContentHash, Digest};
7+
use moon_manifest::{Manifest, ManifestFile};
88
use rustc_hash::FxHashMap;
99
use starbase_sandbox::create_empty_sandbox;
1010
use starbase_utils::json::serde_json;

crates/cache-storage/tests/storage_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use async_trait::async_trait;
22
use moon_blob::{BlobContent, BlobInput, BlobOutput, Bytes};
33
use moon_cache_storage::{
4-
CacheCapabilities, CacheContext, Manifest, ManifestFile, Storage, StorageBackend,
5-
StorageOptions,
4+
CacheCapabilities, CacheContext, Storage, StorageBackend, StorageOptions,
65
};
76
use moon_common::Id;
87
use moon_config::{CacheConfig, RemoteConfig};
98
use moon_hash::{ContentHash, Digest};
9+
use moon_manifest::{Manifest, ManifestFile};
1010
use rustc_hash::FxHashMap;
1111
use std::path::PathBuf;
1212
use std::sync::{Arc, Mutex};

crates/daemon-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ edition = "2024"
55
publish = false
66

77
[dependencies]
8-
moon_cache_storage = { path = "../cache-storage" }
98
moon_common = { path = "../common" }
109
moon_daemon_proto = { path = "../daemon-proto" }
1110
moon_daemon_utils = { path = "../daemon-utils" }
1211
moon_hash = { path = "../hash" }
12+
moon_manifest = { path = "../manifest" }
1313
hyper-util = "0.1.20"
1414
miette = { workspace = true }
1515
thiserror = { workspace = true }

0 commit comments

Comments
 (0)