From c02805d5e1021f760307f2f0e6c34cc95fd1b8a3 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 23 Oct 2026 21:25:57 +0530 Subject: [PATCH] fix(storage): connect to a host's shared storage service by name --- MODULE.md | 6 ++-- .../examples/verify_github_release.rs | 17 +++++++++- .../src/tinybus_module/README.md | 3 +- .../src/tinybus_module/settings.rs | 4 ++- .../src/tinybus_module/storage.rs | 33 +++++++++++-------- docs/specs/event-pipeline.md | 3 +- 6 files changed, 47 insertions(+), 19 deletions(-) diff --git a/MODULE.md b/MODULE.md index 9286043..0c58a04 100644 --- a/MODULE.md +++ b/MODULE.md @@ -23,8 +23,10 @@ scope the host bound it to, documents for its `teq.*` state and the queue port for the queues `queues.json` declares. `tinyeventqueues-bus` (feature `storage`) publishes `collection_specs()` for the module's document state and the shipped `queues.json`. The private module configuration must include the -host-provided `storage_callback` destination; setup fails closed if it is -missing or unavailable. +host-provided `storage_callback` destination: the unique name of the callback +binding admitted for this instance, or `ai.tinyhumans.tinystorage.Storage` for +a host that serves one storage service for every module. Setup fails closed if +it is missing or unavailable. The module takes a private configuration blob: `{"storage_callback": ":1.42", "queues": , "pipeline": , "timer": diff --git a/crates/tinyeventqueues/examples/verify_github_release.rs b/crates/tinyeventqueues/examples/verify_github_release.rs index 36eb877..d2ae3f5 100644 --- a/crates/tinyeventqueues/examples/verify_github_release.rs +++ b/crates/tinyeventqueues/examples/verify_github_release.rs @@ -10,6 +10,7 @@ //! ``` use std::io; +use std::sync::Arc; use std::time::Duration; use tinybus::Connection; @@ -17,6 +18,10 @@ use tinybus::broker::Broker; use tinybus::module::ModuleHost; use tinybus::transport::memory::MemoryBus; use tinyeventqueues::{StatsRequest, StatsResponse, names}; +use tinystoragedrivers_api::StorageBackend; +use tinystoragedrivers_busproxy::{HOST_NAME, PerCallerEndpoint, StorageServer, serve}; +use tinystoragedrivers_testkit::MemoryBackend; +use tinystoragedrivers_types::Scope; #[tokio::main] async fn main() -> Result<(), Box> { @@ -24,12 +29,22 @@ async fn main() -> Result<(), Box> { let bus = MemoryBus::new(); let broker = Broker::new(); let broker_task = broker.spawn(bus.clone()); + // The module refuses to start without host storage. Serve memory storage + // under the shared storage service name, as a host that serves one storage + // service for every module does. + let host = Connection::connect(bus.connect().await?).await?; + let backend = Arc::new(MemoryBackend::new()); + let endpoint = PerCallerEndpoint::new(move |_sender| { + let storage = backend.for_scope(&Scope::new("local").ok()?).ok()?; + Some(StorageServer::new(storage)) + }); + let _served = serve(&host, Arc::new(endpoint)).await?; let module_host = ModuleHost::new(broker); let info = module_host.load_github_release( &release_url, &archive, Some(&sha256), - serde_json::Value::default(), + serde_json::json!({ "storage_callback": HOST_NAME }), )?; if info.name != env!("CARGO_PKG_NAME") { diff --git a/crates/tinyeventqueues/src/tinybus_module/README.md b/crates/tinyeventqueues/src/tinybus_module/README.md index 9afdf4a..f58b365 100644 --- a/crates/tinyeventqueues/src/tinybus_module/README.md +++ b/crates/tinyeventqueues/src/tinybus_module/README.md @@ -25,7 +25,8 @@ both. the one scope the host bound the module to: documents for the `teq.*` state (declared by `tinyeventqueues_bus::storage::collection_specs()`) and the queue port for the manifest's queues. The host-provided `storage_callback` - setting names the unique callback binding admitted for this module instance; + setting names the unique callback binding admitted for this module instance, + or the shared storage service of a host that serves one for every module; missing or unusable host storage fails setup rather than starting with an ephemeral engine. - `host.rs`: `BusHost`, the pipeline's `Host`, calling the host's optional diff --git a/crates/tinyeventqueues/src/tinybus_module/settings.rs b/crates/tinyeventqueues/src/tinybus_module/settings.rs index 9842c78..46f1a1d 100644 --- a/crates/tinyeventqueues/src/tinybus_module/settings.rs +++ b/crates/tinyeventqueues/src/tinybus_module/settings.rs @@ -13,7 +13,9 @@ //! ``` //! //! `storage_callback` is the unique destination of the storage callback -//! admitted by the host for this module instance. `queues` is a `queues.json` +//! admitted by the host for this module instance, or the shared storage +//! service name (`ai.tinyhumans.tinystorage.Storage`) of a host that serves one +//! storage service for every module. `queues` is a `queues.json` //! document and `pipeline` a `pipeline.json` document, both parsed as strictly //! as the files are. A host that serves the module's queues should declare the //! same manifest it passes here: its queue port admits an `EnsureQueue` only diff --git a/crates/tinyeventqueues/src/tinybus_module/storage.rs b/crates/tinyeventqueues/src/tinybus_module/storage.rs index 9b86639..1b3d69b 100644 --- a/crates/tinyeventqueues/src/tinybus_module/storage.rs +++ b/crates/tinyeventqueues/src/tinybus_module/storage.rs @@ -36,20 +36,27 @@ pub(crate) async fn open(connection: Connection, callback: Option<&str>) -> Resu )) })?; let destination_display = destination.to_string(); - tinystoragedrivers_busproxy::connect_storage_at(connection, destination) - .await - .map_err(|error| { - Error::from( - StorageError::new( - error.kind(), - format!( - "storage_callback {destination_display} is unavailable: {}", - error.message() - ), - ) - .with_source(error), + // A host that serves one storage service for every module names + // that service instead of a per-instance callback binding. The + // name is exact: any other name is used as-is, an absent one still + // fails, and so does a service nobody owns. + let connected = if destination.as_str() == tinystoragedrivers_busproxy::HOST_NAME { + tinystoragedrivers_busproxy::connect_storage(connection).await + } else { + tinystoragedrivers_busproxy::connect_storage_at(connection, destination).await + }; + connected.map_err(|error| { + Error::from( + StorageError::new( + error.kind(), + format!( + "storage_callback {destination_display} is unavailable: {}", + error.message() + ), ) - })? + .with_source(error), + ) + })? } None => { return Err(Error::from( diff --git a/docs/specs/event-pipeline.md b/docs/specs/event-pipeline.md index 5f33749..eadba01 100644 --- a/docs/specs/event-pipeline.md +++ b/docs/specs/event-pipeline.md @@ -171,7 +171,8 @@ are in `tinyeventqueues-bus`. Without the callback destination, setup fails; there is no in-memory fallback. - Configuration: the host-provided private blob carries `storage_callback` - (the unique name for the admitted storage callback), plus `queues` (a `queues.json` + (the unique name for the admitted storage callback, or the shared storage + service name `ai.tinyhumans.tinystorage.Storage`), plus `queues` (a `queues.json` document), `pipeline` (a `pipeline.json` document) and `timer` bounds; absent fields run the shipped files. The manifest is applied through the queue port at setup.