From b67e5dc612d2bacf6c07d9542a6c5129645567a3 Mon Sep 17 00:00:00 2001 From: MasterPtato <23087326+MasterPtato@users.noreply.github.com> Date: Fri, 22 Nov 2024 03:40:57 +0000 Subject: [PATCH] fix: dont return bool from kv delete (#1434) ## Changes --- packages/infra/client/actor-kv/src/lib.rs | 23 ++++++------------- .../client/isolate-v8-runner/src/ext/kv.rs | 21 ++++------------- .../infra/client/manager/src/actor/setup.rs | 11 +++++---- 3 files changed, 17 insertions(+), 38 deletions(-) diff --git a/packages/infra/client/actor-kv/src/lib.rs b/packages/infra/client/actor-kv/src/lib.rs index beeeb14e2b..c2f3ff920c 100644 --- a/packages/infra/client/actor-kv/src/lib.rs +++ b/packages/infra/client/actor-kv/src/lib.rs @@ -347,8 +347,8 @@ impl ActorKv { .map_err(Into::into) } - /// Deletes keys from the KV store. Returns true for keys that existed before deletion. - pub async fn delete(&self, keys: Vec) -> Result> { + /// Deletes keys from the KV store. + pub async fn delete(&self, keys: Vec) -> Result<()> { let subspace = self .subspace .as_ref() @@ -359,23 +359,14 @@ impl ActorKv { self.db .run(|tx, _mc| { let keys = keys.clone(); - async move { - futures_util::stream::iter(keys) - .map(|key| async { - let key_subspace = subspace.subspace(&key); + for key in keys { + let key_subspace = subspace.subspace(&key); - let existed = tx - .get(&key_subspace.pack(&"metadata"), false) - .await? - .is_some(); - tx.clear_subspace_range(&key_subspace); + tx.clear_subspace_range(&key_subspace); + } - Ok((key, existed)) - }) - .buffer_unordered(32) - .try_collect() - .await + Ok(()) } }) .await diff --git a/packages/infra/client/isolate-v8-runner/src/ext/kv.rs b/packages/infra/client/isolate-v8-runner/src/ext/kv.rs index 8f0e3a23ae..cc23b60e4c 100644 --- a/packages/infra/client/isolate-v8-runner/src/ext/kv.rs +++ b/packages/infra/client/isolate-v8-runner/src/ext/kv.rs @@ -144,14 +144,10 @@ pub fn op_rivet_kv_put_batch( pub fn op_rivet_kv_delete( state: &mut OpState, #[serde] key: actor_kv::key::Key, -) -> Result>, AnyError> { +) -> Result>, AnyError> { let kv = state.borrow::>().clone(); - Ok(async move { - let res = kv.delete(vec![key]).await?; - - Ok(res.into_values().next().unwrap_or_default()) - }) + Ok(async move { kv.delete(vec![key]).await }) } #[op2(async)] @@ -159,19 +155,10 @@ pub fn op_rivet_kv_delete( pub fn op_rivet_kv_delete_batch( state: &mut OpState, #[serde] keys: Vec, -) -> Result, AnyError>>, AnyError> { +) -> Result>, AnyError> { let kv = state.borrow::>().clone(); - Ok(async move { - let res = kv - .delete(keys) - .await? - .into_iter() - .map(|(k, v)| (k.into(), v.into())) - .collect(); - - Ok(res) - }) + Ok(async move { kv.delete(keys).await }) } #[op2(async)] diff --git a/packages/infra/client/manager/src/actor/setup.rs b/packages/infra/client/manager/src/actor/setup.rs index e30b6a5103..a1933dd92e 100644 --- a/packages/infra/client/manager/src/actor/setup.rs +++ b/packages/infra/client/manager/src/actor/setup.rs @@ -1,3 +1,9 @@ +use std::{ + collections::HashMap, + path::{Path, PathBuf}, + process::Stdio, + result::Result::{Err, Ok}, +}; use anyhow::*; use futures_util::StreamExt; use indoc::indoc; @@ -5,11 +11,6 @@ use pegboard::protocol; use pegboard_config::isolate_runner::actor as actor_config; use rand::Rng; use serde_json::json; -use std::{ - collections::HashMap, - path::{Path, PathBuf}, - process::Stdio, -}; use tokio::{ fs::{self, File}, io::{AsyncReadExt, AsyncWriteExt},