Skip to content

Conversation

patrick-ogrady
Copy link
Contributor

Alternative: #1152

@patrick-ogrady patrick-ogrady marked this pull request as ready for review June 25, 2025 13:31
/// Pushes a `Record` to the end of `past`.
///
/// If the record has a `next`, this function cannot be called again.
fn past_push(&mut self, mut next: Box<Record<V>>) {
Copy link
Contributor Author

@patrick-ogrady patrick-ogrady Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactored past_push has the convenient byproduct of retaining the insertion order. I considered special casing next w/list insertion but seemed cleaner to just reduce the logic to one pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this simpler than the reverse list we were creating during iteration but it does use unsafe.

@patrick-ogrady patrick-ogrady changed the title [storage/index] Fix Middle Mutate [storage/index] Fix Middle Mutate Case Jun 25, 2025
@patrick-ogrady patrick-ogrady requested a review from Copilot June 25, 2025 13:38
@patrick-ogrady patrick-ogrady added this to the v0.0.55 milestone Jun 25, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses the middle mutate case in the storage index by updating the record linking logic and adjusting the test expectations accordingly.

  • Updated the Cursor struct with new fields (past_tail and past_pushed_list) and refactored the past_push method to support controlled list mutation.
  • Modified tests in mod.rs to reflect the new ordering of records and standardized test function naming.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
storage/src/index/storage.rs Introduces new raw pointer field and updates past_push logic.
storage/src/index/mod.rs Adjusts test expectations and renames test functions uniformly.
Comments suppressed due to low confidence (2)

storage/src/index/storage.rs:124

  • Consider adding a comment within the unsafe block to document the invariants that guarantee the validity of the raw pointer 'past_tail' to assist future maintainability and safety reviews.
            unsafe {

storage/src/index/mod.rs:79

  • The updated expected order of elements indicates a change in the underlying logic; consider adding a note in the test documentation explaining the rationale behind the new order.
        assert_eq!(index.get(key).copied().collect::<Vec<_>>(), vec![1, 4, 2]);

@patrick-ogrady
Copy link
Contributor Author

Ran cargo +nightly miri test -p commonware-storage 'index::tests':

running 37 tests
test index::tests::test_cursor_delete_after_done - should panic ... ok
test index::tests::test_cursor_delete_before_next_panics - should panic ... ok
test index::tests::test_cursor_delete_last_then_next ... ok
test index::tests::test_cursor_delete_then_next_returns_next ... ok
test index::tests::test_cursor_double_delete - should panic ... ok
test index::tests::test_cursor_insert_after_done_appends ... ok
test index::tests::test_cursor_insert_before_next - should panic ... ok
test index::tests::test_cursor_insert_with_next ... ok
test index::tests::test_cursor_update_after_done - should panic ... ok
test index::tests::test_cursor_update_before_next_panics - should panic ... ok
test index::tests::test_delete_first ... ok
test index::tests::test_delete_first_and_insert ... ok
test index::tests::test_delete_in_middle_then_continue ... ok
test index::tests::test_delete_last_then_insert_while_done ... ok
test index::tests::test_delete_then_insert_without_next - should panic ... ok
test index::tests::test_drop_mid_iteration_relinks ... ok
test index::tests::test_entry_replacement_not_a_collision ... ok
test index::tests::test_index_basic ... ok
test index::tests::test_index_empty_key ... ok
test index::tests::test_index_insert_and_remove_cursor ... ok
test index::tests::test_index_insert_through_iterator ... ok
test index::tests::test_index_key_lengths_and_key_item_metrics ... ok
test index::tests::test_index_many_keys ... ok
test index::tests::test_index_mutate_through_iterator ... ok
test index::tests::test_index_remove_middle_then_next ... ok
test index::tests::test_index_remove_specific ... ok
test index::tests::test_index_remove_through_iterator ... ok
test index::tests::test_index_remove_to_nothing ... ok
test index::tests::test_index_remove_to_nothing_then_add ... ok
test index::tests::test_index_value_order ... ok
test index::tests::test_insert_and_prune_dead_insert ... ok
test index::tests::test_insert_and_prune_replace_one ... ok
test index::tests::test_insert_and_prune_vacant ... ok
test index::tests::test_insert_at_entry_then_delete_head - should panic ... ok
test index::tests::test_insert_at_entry_then_next ... ok
test index::tests::test_inserts_without_next - should panic ... ok
test index::tests::test_update_before_next_panics - should panic ... ok

test result: ok. 37 passed; 0 failed; 0 ignored; 0 measured; 189 filtered out; finished in 335.72s

@patrick-ogrady patrick-ogrady merged commit 58c6fc4 into main Jun 25, 2025
16 checks passed
@patrick-ogrady patrick-ogrady deleted the fix-middle-mutate branch June 25, 2025 17:15
Copy link

codecov bot commented Jun 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.03%. Comparing base (fddae18) to head (19ce007).
Report is 1 commits behind head on main.

@@           Coverage Diff           @@
##             main    #1155   +/-   ##
=======================================
  Coverage   91.03%   91.03%           
=======================================
  Files         215      215           
  Lines       57425    57434    +9     
=======================================
+ Hits        52276    52285    +9     
  Misses       5149     5149           
Files with missing lines Coverage Δ
storage/src/index/mod.rs 87.50% <ø> (ø)
storage/src/index/storage.rs 99.32% <100.00%> (+0.02%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fddae18...19ce007. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants