Skip to content

Commit 2505843

Browse files
committed
Makes it possible to register batching listeners
Upon reset_node and apply_update, we want to be able to react to a batch of changes rather than individual changes. In quickwit for instance, we want to be able to react to the reception of a batch of deleted shard and group this reaction into a single metastore call.
1 parent f783620 commit 2505843

File tree

6 files changed

+1023
-497
lines changed

6 files changed

+1023
-497
lines changed

chitchat-test/src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ impl Api {
3737
#[oai(path = "/set_kv/", method = "get")]
3838
async fn set_kv(&self, key: Query<String>, value: Query<String>) -> Json<serde_json::Value> {
3939
let mut chitchat_guard = self.chitchat.lock().await;
40-
41-
let cc_state = chitchat_guard.self_node_state();
40+
let mut cc_state = chitchat_guard.self_node_state();
4241
cc_state.set(key.as_str(), value.as_str());
4342

4443
Json(serde_json::to_value(&SetKeyValueResponse { status: true }).unwrap())
@@ -48,8 +47,7 @@ impl Api {
4847
#[oai(path = "/mark_for_deletion/", method = "get")]
4948
async fn mark_for_deletion(&self, key: Query<String>) -> Json<serde_json::Value> {
5049
let mut chitchat_guard = self.chitchat.lock().await;
51-
52-
let cc_state = chitchat_guard.self_node_state();
50+
let mut cc_state = chitchat_guard.self_node_state();
5351
cc_state.delete(key.as_str());
5452
Json(serde_json::to_value(&SetKeyValueResponse { status: true }).unwrap())
5553
}

chitchat/src/delta.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl Delta {
240240
pub(crate) fn num_tuples(&self) -> usize {
241241
self.node_deltas
242242
.iter()
243-
.map(|node_delta| node_delta.num_tuples())
243+
.map(|node_delta| node_delta.key_values.len())
244244
.sum()
245245
}
246246

@@ -323,10 +323,12 @@ pub(crate) struct NodeDelta {
323323
pub max_version: Option<Version>,
324324
}
325325

326-
#[cfg(test)]
327-
impl NodeDelta {
328-
pub fn num_tuples(&self) -> usize {
329-
self.key_values.len()
326+
impl IntoIterator for NodeDelta {
327+
type Item = KeyValueMutation;
328+
type IntoIter = std::vec::IntoIter<Self::Item>;
329+
330+
fn into_iter(self) -> Self::IntoIter {
331+
self.key_values.into_iter()
330332
}
331333
}
332334

0 commit comments

Comments
 (0)