Skip to content

Commit

Permalink
Correct two bugs in the BucketQueueView. (linera-io#2541)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
MathieuDutSik authored Oct 22, 2024
1 parent fb2f26e commit 5c0359f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions linera-views/src/views/bucket_queue_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion linera-views/tests/random_container_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u8>();
view.queue.push_back(val);
Expand Down

0 comments on commit 5c0359f

Please sign in to comment.