From 5c0359f8beb72b6f3f537f83884a570a3efb44d6 Mon Sep 17 00:00:00 2001 From: Mathieu Dutour Sikiric Date: Tue, 22 Oct 2024 20:14:11 +0200 Subject: [PATCH] Correct two bugs in the `BucketQueueView`. (#2541) * Correct one bug to the BucketQueueView where the `self.stored_position` was not updated. * Correct one bug for the dropping of entries when flushing. * Update the CI test to detect the problem. --- linera-views/src/views/bucket_queue_view.rs | 14 ++++++++------ linera-views/tests/random_container_tests.rs | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/linera-views/src/views/bucket_queue_view.rs b/linera-views/src/views/bucket_queue_view.rs index fb57f0904b3e..4df519ceae5e 100644 --- a/linera-views/src/views/bucket_queue_view.rs +++ b/linera-views/src/views/bucket_queue_view.rs @@ -55,9 +55,10 @@ enum KeyTag { /// The `StoredIndices` contains the description of the stored buckets. #[derive(Clone, Debug, Default, Serialize, Deserialize)] struct StoredIndices { - /// The stored buckets with the first index being the size at most N and the - /// second one is the index. If the index is 0 then it correspond to the Front, - /// otherwise to the Index. + /// The stored buckets with the first index being the size (at most N) and the + /// second one is the index in the storage. If the index is 0 then it corresponds + /// with the first value (entry `KeyTag::Front`), otherwise to the keys with + /// prefix `KeyTag::Index`. indices: Vec<(usize, usize)>, /// The position of the front in the first index. position: usize, @@ -231,15 +232,16 @@ where self.stored_data.clear(); self.stored_position = 0; } else if let Some((i_block, position)) = self.cursor.position { - for block in 0..i_block { - let index = self.stored_data[block].0; + for _ in 0..i_block { + let block = self.stored_data.pop_front().unwrap(); + let index = block.0; let key = self.get_index_key(index)?; batch.delete_key(key); - self.stored_data.pop_front(); } self.cursor = Cursor { position: Some((0, position)), }; + self.stored_position = position; // We need to ensure that the first index is in the front. let first_index = self.stored_data[0].0; if first_index != 0 { diff --git a/linera-views/tests/random_container_tests.rs b/linera-views/tests/random_container_tests.rs index 0bd6318d902c..577cbcdb1277 100644 --- a/linera-views/tests/random_container_tests.rs +++ b/linera-views/tests/random_container_tests.rs @@ -427,7 +427,7 @@ async fn bucket_queue_view_mutability_check() -> Result<()> { let count = view.queue.count(); if choice == 0 { // inserting random stuff - let n_ins = rng.gen_range(0..10); + let n_ins = rng.gen_range(0..100); for _ in 0..n_ins { let val = rng.gen::(); view.queue.push_back(val);