Skip to content

Commit

Permalink
feat(etcd): implement purge_store and delete_range
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Sep 10, 2024
1 parent e65f7a8 commit b324a05
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions crates/store/src/backend/etcd/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/

use etcd_client::DeleteOptions;
use roaring::RoaringBitmap;

use super::{into_error, EtcdStore};

use crate::{
backend::deserialize_i64_le,
write::{key::DeserializeBigEndian, BitmapClass, ValueClass, AssignedIds, Batch},
BitmapKey, Deserialize, IterateParams, Key, ValueKey, U32_LEN, WITH_SUBSPACE
BitmapKey, Deserialize, IterateParams, Key, ValueKey, U32_LEN, WITH_SUBSPACE, SUBSPACE_QUOTA, SUBSPACE_COUNTER
};


Expand All @@ -22,10 +23,26 @@ impl EtcdStore {
}

pub(crate) async fn purge_store(&self) -> trc::Result<()> {
todo!()
for subspace in [SUBSPACE_QUOTA, SUBSPACE_COUNTER] {
let mut client = self.client.clone();
client.delete(vec![subspace], Some(DeleteOptions::new().with_prefix()))
.await
.map_err(into_error)?;
}

Ok(())
}

pub(crate) async fn delete_range(&self, from: impl Key, to: impl Key) -> trc::Result<()> {
todo!()
let key_subspace: u8 = from.subspace();
let from = from.serialize(0);
let to = to.serialize(0);

let mut client = self.get_prefix_client(key_subspace);

client.delete(from, Some(DeleteOptions::new().with_range(to)))
.await
.map_err(into_error)
.map(|_| ())
}
}

0 comments on commit b324a05

Please sign in to comment.