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

Problem: memiavl is not protected against concurrent writing #1100

Merged
merged 10 commits into from
Jul 13, 2023

Conversation

yihuang
Copy link
Collaborator

@yihuang yihuang commented Jul 13, 2023

Closes: #1055

Solution:

  • introduce exclusive file lock.
  • introduce read-only mode which can work concurrently.

👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻

PR Checklist:

  • Have you read the CONTRIBUTING.md?
  • Does your PR follow the C4 patch requirements?
  • Have you rebased your work on top of the latest master?
  • Have you checked your code compiles? (make)
  • Have you included tests for any non-trivial functionality?
  • Have you checked your code passes the unit tests? (make test)
  • Have you checked your code formatting is correct? (go fmt)
  • Have you checked your basic code style is fine? (golangci-lint run)
  • If you added any dependencies, have you checked they do not contain any known vulnerabilities? (go list -json -m all | nancy sleuth)
  • If your changes affect the client infrastructure, have you run the integration test?
  • If your changes affect public APIs, does your PR follow the C4 evolution of public contracts?
  • If your code changes public APIs, have you incremented the crate version numbers and documented your changes in the CHANGELOG.md?
  • If you are contributing for the first time, please read the agreement in CONTRIBUTING.md now and add a comment to this pull request stating that your PR is in accordance with the Developer's Certificate of Origin.

Thank you for your code, it's appreciated! :)

Solution:
- introduce exclusive file lock.
- introduce read-only mode which can work concurrently.
@yihuang yihuang requested a review from a team as a code owner July 13, 2023 01:40
@yihuang yihuang requested review from mmsqe and JayT106 and removed request for a team July 13, 2023 01:40
@yihuang yihuang marked this pull request as draft July 13, 2023 01:40
CHANGELOG.md Outdated Show resolved Hide resolved
Signed-off-by: yihuang <huang@crypto.com>
@@ -467,7 +467,7 @@
db := rs.db
if version != rs.lastCommitInfo.Version {
var err error
db, err = memiavl.Load(rs.dir, memiavl.Options{TargetVersion: uint32(version)})
db, err = memiavl.Load(rs.dir, memiavl.Options{TargetVersion: uint32(version), ReadOnly: true})

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion Error

Potential integer overflow by integer type conversion
memiavl/db.go Fixed Show fixed Hide fixed
@yihuang yihuang marked this pull request as ready for review July 13, 2023 02:26
memiavl/db.go Outdated Show resolved Hide resolved
memiavl/filelock.go Fixed Show fixed Hide fixed
yihuang and others added 2 commits July 13, 2023 10:45
Co-authored-by: mmsqe <mavis@crypto.com>
Signed-off-by: yihuang <huang@crypto.com>
memiavl/filelock.go Fixed Show fixed Hide fixed
@codecov
Copy link

codecov bot commented Jul 13, 2023

Codecov Report

Merging #1100 (3cfa7a4) into main (5e280e2) will decrease coverage by 0.01%.
The diff coverage is 67.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1100      +/-   ##
==========================================
- Coverage   46.49%   46.48%   -0.01%     
==========================================
  Files          80       81       +1     
  Lines        7152     7221      +69     
==========================================
+ Hits         3325     3357      +32     
- Misses       3476     3510      +34     
- Partials      351      354       +3     
Impacted Files Coverage Δ
memiavl/filelock.go 53.84% <53.84%> (ø)
memiavl/db.go 58.00% <70.00%> (+1.59%) ⬆️
memiavl/export.go 58.42% <100.00%> (+0.47%) ⬆️

... and 1 file with indirect coverage changes

@yihuang yihuang added this pull request to the merge queue Jul 13, 2023
Merged via the queue into crypto-org-chain:main with commit 50dc1d2 Jul 13, 2023
23 of 24 checks passed
@yihuang yihuang deleted the exclusive-lock branch July 13, 2023 09:10
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.

Problem: memiavl db is not protected against multi-processing opening
2 participants