feat(tvix/store/directorysvc): add DirectoryService::get_recursive()
This moves the recursive BFS traversal of Directory closures from the GRPCDirectoryServiceWrapper out into a a DirectoryTraverser struct implementing Iterator. It is then used from various implementors of DirectoryService in the `get_recursive()` method. This allows distinguishing between recursive requests and non-recursive requests in the gRPC client trait implementation. Change-Id: I50bfd4a0d9eb11832847329b78c587ec7c9dc7b1 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8351 Autosubmit: flokli <flokli@flokli.de> Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
This commit is contained in:
parent
2d305fd5b3
commit
2fe53cce40
5 changed files with 316 additions and 97 deletions
|
|
@ -4,7 +4,7 @@ use std::collections::HashMap;
|
|||
use std::sync::{Arc, RwLock};
|
||||
use tracing::{instrument, warn};
|
||||
|
||||
use super::DirectoryService;
|
||||
use super::{DirectoryService, DirectoryTraverser};
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct MemoryDirectoryService {
|
||||
|
|
@ -12,6 +12,8 @@ pub struct MemoryDirectoryService {
|
|||
}
|
||||
|
||||
impl DirectoryService for MemoryDirectoryService {
|
||||
type DirectoriesIterator = DirectoryTraverser<Self>;
|
||||
|
||||
#[instrument(skip(self, digest), fields(directory.digest = BASE64.encode(digest)))]
|
||||
fn get(&self, digest: &[u8; 32]) -> Result<Option<proto::Directory>, Error> {
|
||||
let db = self.db.read()?;
|
||||
|
|
@ -33,6 +35,16 @@ impl DirectoryService for MemoryDirectoryService {
|
|||
)));
|
||||
}
|
||||
|
||||
// Validate the Directory itself is valid.
|
||||
if let Err(e) = directory.validate() {
|
||||
warn!("directory failed validation: {}", e.to_string());
|
||||
return Err(Error::StorageError(format!(
|
||||
"directory {} failed validation: {}",
|
||||
BASE64.encode(&actual_digest),
|
||||
e,
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(Some(directory.clone()))
|
||||
}
|
||||
}
|
||||
|
|
@ -57,4 +69,9 @@ impl DirectoryService for MemoryDirectoryService {
|
|||
|
||||
Ok(digest)
|
||||
}
|
||||
|
||||
#[instrument(skip_all, fields(directory.digest = BASE64.encode(root_directory_digest)))]
|
||||
fn get_recursive(&self, root_directory_digest: &[u8; 32]) -> Self::DirectoriesIterator {
|
||||
DirectoryTraverser::with(self.clone(), root_directory_digest)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue