Skip to content

feat(sdk): Improve ChunkIdentifierGenerator #3256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Mar 20, 2024

Follow up of #3251 (comment).

  1. As suggested by @poljar, it is possible that the
    value of the atomic changes between the fetch_add and the load (if
    and only if it is used in a concurrency model, which is not the case
    right now, but anyway… better being correct now!). The idea is not
    load but repeat the addition manually to compute the “current” value.
  2. Makes ChunkIdentifierGenerator::generate_next to panic
    if there is no more identifiers available. It was previously returning
    a Result but we were doing nothing with this Result except
    unwrapping it. To simplify the API: let's panic.

Hywan added 2 commits March 20, 2024 21:08
As suggested in https://github.com/matrix-org/matrix-rust-sdk/
pull/3251#discussion_r1532103818 by Poljar, it is possible that the
value of the atomic changes between the `fetch_add` and the `load` (if
and only if it is used in a concurrency model, which is not the case
right now, but anyway… better being correct now!). The idea is not
`load` but repeat the addition manually to compute the “current” value.
This patch makes `ChunkIdentifierGenerator::generate_next` to panic
if there is no more identifiers available. It was previously returning
a `Result` but we were doing nothing with this `Result` except
`unwrap`ping it. To simplify the API: let's panic.
@Hywan Hywan requested a review from a team as a code owner March 20, 2024 20:18
@Hywan Hywan requested review from bnjbvr and poljar and removed request for a team and bnjbvr March 20, 2024 20:18
Copy link

codecov bot commented Mar 20, 2024

Codecov Report

Attention: Patch coverage is 91.66667% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 83.72%. Comparing base (c120da7) to head (199275f).
Report is 12 commits behind head on main.

Files Patch % Lines
crates/matrix-sdk/src/event_cache/linked_chunk.rs 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3256      +/-   ##
==========================================
- Coverage   83.72%   83.72%   -0.01%     
==========================================
  Files         237      237              
  Lines       24560    24552       -8     
==========================================
- Hits        20564    20556       -8     
  Misses       3996     3996              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

if current < previous {
return Err(ChunkIdentifier(previous));
if previous == u64::MAX {
panic!("No more chunk identifiers available. Congrats, you did it. 2^64 identifiers have been consumed.")
Copy link
Member

Choose a reason for hiding this comment

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

easter eggs \o/

This patch renames `ChunkIdentifierGenerator::generate_next` to `next.

This patch also simplifies a `.saturating_add(1)` to a simple `+ 1`,
which is fine because we have checked for overflow just before.
@Hywan Hywan enabled auto-merge March 21, 2024 11:41
@Hywan Hywan merged commit f42c893 into matrix-org:main Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants