Skip to content

Commit 4bb230c

Browse files
committed
Comments, errors, etc.
Signed-off-by: itowlson <[email protected]>
1 parent 74449eb commit 4bb230c

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

crates/factor-blobstore/src/host.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,36 @@ mod outgoing_value;
1717

1818
pub(crate) use outgoing_value::OutgoingValue;
1919

20+
use crate::DelegatingContainerManager;
21+
2022
// TODO: I feel like the notions of "container" and "container manager" are muddled.
2123
// This was kinda modelled on the KV StoreManager but I am not sure it has worked.
2224
// A "container manager" actually manages only one container, making the `get` and
2325
// `is_defined` functions seemingly redundant. More clarity and better definition
2426
// is needed here, although the existing code does work!
25-
27+
//
28+
// Part of the trouble is, I think, that the WIT has operations for "create container"
29+
// etc. which implies a level above "container" but whose semantics are very poorly
30+
// defined (the implication in the WIT is that a `blobstore` implementation backs
31+
// onto exactly one provider, and if you need to deal with multiple providers then
32+
// you need to do some double-import trickery, which does not seem right). Clarification
33+
// sought via https://github.com/WebAssembly/wasi-blobstore/issues/27, so we may need
34+
// to do some rework once the authors define it more fully.
35+
36+
/// Allows obtaining a container. The only interesting implementation is
37+
/// [DelegatingContainerManager] (which is what [BlobStoreDispatch] uses);
38+
/// other implementations currently manage only one container. (See comments.)
2639
#[async_trait]
2740
pub trait ContainerManager: Sync + Send {
2841
async fn get(&self, name: &str) -> Result<Arc<dyn Container>, Error>;
2942
fn is_defined(&self, container_name: &str) -> bool;
3043
}
3144

45+
/// A container. This represents the system or network resource defined by
46+
/// a label mapping in the runtime config, e.g. a file system directory,
47+
/// Azure blob storage account, or S3 bucket. This trait is implemented
48+
/// by providers; it is the interface through which the [BlobStoreDispatch]
49+
/// WASI host talks to the different implementations.
3250
#[async_trait]
3351
pub trait Container: Sync + Send {
3452
async fn exists(&self) -> anyhow::Result<bool>;
@@ -54,22 +72,27 @@ pub trait Container: Sync + Send {
5472
async fn list_objects(&self) -> anyhow::Result<Box<dyn ObjectNames>>;
5573
}
5674

75+
/// An interface implemented by providers when listing objects.
5776
#[async_trait]
5877
pub trait ObjectNames: Send + Sync {
5978
async fn read(&mut self, len: u64) -> anyhow::Result<(Vec<String>, bool)>;
6079
async fn skip(&mut self, num: u64) -> anyhow::Result<(u64, bool)>;
6180
}
6281

82+
/// The content of a blob being read from a container. Called by the host to
83+
/// handle WIT incoming-value methods, and implemented by providers.
84+
/// providers
6385
#[async_trait]
6486
pub trait IncomingData: Send + Sync {
6587
async fn consume_sync(&mut self) -> anyhow::Result<Vec<u8>>;
6688
fn consume_async(&mut self) -> wasmtime_wasi::pipe::AsyncReadStream;
6789
async fn size(&mut self) -> anyhow::Result<u64>;
6890
}
6991

92+
/// Implements all the WIT host interfaces for wasi-blobstore.
7093
pub struct BlobStoreDispatch<'a> {
7194
allowed_containers: &'a HashSet<String>,
72-
manager: &'a dyn ContainerManager,
95+
manager: &'a DelegatingContainerManager,
7396
wasi_resources: &'a mut ResourceTable,
7497
containers: &'a RwLock<Table<Arc<dyn Container>>>,
7598
incoming_values: &'a RwLock<Table<Box<dyn IncomingData>>>,
@@ -80,7 +103,7 @@ pub struct BlobStoreDispatch<'a> {
80103
impl<'a> BlobStoreDispatch<'a> {
81104
pub(crate) fn new(
82105
allowed_containers: &'a HashSet<String>,
83-
manager: &'a dyn ContainerManager,
106+
manager: &'a DelegatingContainerManager,
84107
wasi_resources: &'a mut ResourceTable,
85108
containers: &'a RwLock<Table<Arc<dyn Container>>>,
86109
incoming_values: &'a RwLock<Table<Box<dyn IncomingData>>>,
@@ -131,7 +154,7 @@ impl bs::blobstore::Host for BlobStoreDispatch<'_> {
131154
let rep = self.containers.write().await.push(container).unwrap();
132155
Ok(Resource::new_own(rep))
133156
} else {
134-
Err("forbidden container".to_owned())
157+
Err(format!("Container {name:?} not defined or access denied"))
135158
}
136159
}
137160

0 commit comments

Comments
 (0)