Skip to content

Commit

Permalink
fix: dont return bool from kv delete (#1434)
Browse files Browse the repository at this point in the history
<!-- Please make sure there is an issue that this PR is correlated to. -->

## Changes

<!-- If there are frontend changes, please include screenshots. -->
  • Loading branch information
MasterPtato committed Nov 22, 2024
1 parent 8c45cbd commit b67e5dc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 38 deletions.
23 changes: 7 additions & 16 deletions packages/infra/client/actor-kv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Key>) -> Result<HashMap<Key, bool>> {
/// Deletes keys from the KV store.
pub async fn delete(&self, keys: Vec<Key>) -> Result<()> {
let subspace = self
.subspace
.as_ref()
Expand All @@ -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
Expand Down
21 changes: 4 additions & 17 deletions packages/infra/client/isolate-v8-runner/src/ext/kv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,34 +144,21 @@ pub fn op_rivet_kv_put_batch(
pub fn op_rivet_kv_delete(
state: &mut OpState,
#[serde] key: actor_kv::key::Key,
) -> Result<impl Future<Output = Result<bool, AnyError>>, AnyError> {
) -> Result<impl Future<Output = Result<(), AnyError>>, AnyError> {
let kv = state.borrow::<Arc<actor_kv::ActorKv>>().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)]
#[serde]
pub fn op_rivet_kv_delete_batch(
state: &mut OpState,
#[serde] keys: Vec<actor_kv::key::Key>,
) -> Result<impl Future<Output = Result<FakeMap<Key, bool>, AnyError>>, AnyError> {
) -> Result<impl Future<Output = Result<(), AnyError>>, AnyError> {
let kv = state.borrow::<Arc<actor_kv::ActorKv>>().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)]
Expand Down
11 changes: 6 additions & 5 deletions packages/infra/client/manager/src/actor/setup.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use std::{
collections::HashMap,
path::{Path, PathBuf},
process::Stdio,
result::Result::{Err, Ok},
};
use anyhow::*;
use futures_util::StreamExt;
use indoc::indoc;
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},
Expand Down

0 comments on commit b67e5dc

Please sign in to comment.