-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Description
CliStoreManager::get_store in src/key_value.rs always returns Error::NoSuchStore when using KV stores with fastedge-run.
The StoreManager trait defines get_store with a param argument (the Redis URL):
// crates/key-value-store/src/lib.rs
pub trait StoreManager: Sync + Send {
/// Get a store by db url.
async fn get_store(
&self,
param: &str,
metric: Arc<dyn ReadStats>,
) -> Result<Arc<dyn Store>, Error>;
}StoreImpl::open passes the param (second element of the allowed_stores tuple — the Redis URL) to get_store:
// crates/key-value-store/src/lib.rs
pub async fn open(&mut self, name: &str) -> Result<u32, Error> {
if let Some(param) = self
.allowed_stores
.iter()
.find_map(|s| (s.0 == name).then_some(&s.1))
{
let store = self.manager.get_store(param, self.stats.clone()).await?;
// ...But CliStoreManager::get_store compares the received value against store.name instead of store.param:
// src/key_value.rs
impl StoreManager for CliStoreManager {
async fn get_store(
&self,
name: &str, // this is actually the `param` (Redis URL) from StoreImpl::open
_stats: Arc<dyn ReadStats>,
) -> Result<Arc<dyn Store>, Error> {
let Some(opts) = self.stores.iter().find(|store| store.name == name) else {
// ^^^^ should be store.param
return Err(Error::NoSuchStore);
};
let store = RedisStore::open(&opts.param).await?;
Ok(Arc::new(store))
}
}Steps to reproduce
fastedge-run http -p 8080 -w ./app.wasm --wasi-http true --kv-stores kv_all=redis://localhost:6379
Then call any endpoint that does KvStore.open('kv_all') — it returns Error::NoSuchStore.
Expected behavior
KV store opens successfully and connects to Redis.
Fix
Change store.name == name to store.param == name in src/key_value.rs line 18.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels