Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
This PR brings RwLocks to blockchain methods.
As i know, Leveldb reads and writes are atomic, and creating additional lock will beat performance. Especially while write lock, no read operations will performe, but on the other hand, no other disc operations at the same time, that will increase block insertion time.
Disadvantages
Advantages
Possible problems
Imagine we have 2 methods
![Снимок экрана 2022-05-10 в 22 22 34](https://user-images.githubusercontent.com/355847/167706702-0adb184c-07a5-4a45-a3ca-ed0d10b4b032.png)
get
andcache
that atomic by itself but not together. In 2 different goroutines it could be:or
![image](https://user-images.githubusercontent.com/355847/167707010-69456f1b-6e56-47ea-86c5-d22abb2f6b55.png)
Second case has 2 problems:
IRL example
for example we proceed getting crosslinks with ReadCrosslinks, validating them and putting next with AddPendingCrosslinks. Even we don't lose crosslinks here, data can be duplicated. see node/node_cross_link.go:59
Test
Unit Test Coverage
Before:
After:
Test/Run Logs
Operational Checklist
Does this PR introduce backward-incompatible changes to the on-disk data structure and/or the over-the-wire protocol?. (If no, skip to question 8.)
NO
Does this PR introduce backward-incompatible changes NOT related to on-disk data structure and/or over-the-wire protocol? (If no, continue to question 11.)
NO
Does this PR introduce significant changes to the operational requirements of the node software, such as >20% increase in CPU, memory, and/or disk usage?
MAYBE, have to check
TODO