Skip to content
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

ledger: increase locks granularity in lookupWithoutRewards #5527

Merged
merged 1 commit into from Jul 28, 2023

Conversation

algorandskiy
Copy link
Contributor

Summary

Proposal for exclusion deltas iteration loop from trackers own lock.

  1. Take a state snapshot for a single iteration (the first part of the for {} loop in lookupWithoutRewards) - dbRound, deltas, offset, rewards, inDeltas check.
  2. make the nested loop over deltas lock free.

Why does it work:

say au.deltas has 10 elements that is backed by some array underneath. e make local deltas = au.deltas[0:len(au.deltas)], pointing to the same backing array. Then there are two options:

  1. when receiving a new block => add element
    • if backing array has space, it is not reallocated, just appended, our deltas keeps pointing on it
    • if not enough space, then realloc for au.deltas but our deltas keeps pointing to the old backing array
  2. when committing => remove elements
    • removal op is slicing, so au.deltas keeps pointing to the same backing array but to the right subset, our deltas is fine as well

The change would benefit from @icorderi work on making lru caches concurrency-safe.

Test Plan

Existing tests

@codecov
Copy link

codecov bot commented Jul 5, 2023

Codecov Report

Merging #5527 (d299733) into master (f54e7a7) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #5527      +/-   ##
==========================================
+ Coverage   55.83%   55.86%   +0.02%     
==========================================
  Files         446      446              
  Lines       63258    63265       +7     
==========================================
+ Hits        35321    35342      +21     
+ Misses      25561    25559       -2     
+ Partials     2376     2364      -12     
Impacted Files Coverage Δ
ledger/acctupdates.go 70.80% <100.00%> (-0.34%) ⬇️

... and 11 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@algonautshant algonautshant left a comment

Choose a reason for hiding this comment

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

Looks good.

@algorandskiy algorandskiy marked this pull request as ready for review July 28, 2023 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants