-
Notifications
You must be signed in to change notification settings - Fork 219
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
Add exclusive file locks to Wallet, Chain and Peer db’s #2403
Add exclusive file locks to Wallet, Chain and Peer db’s #2403
Conversation
This PR adds an exclusive file locking mechanism to the wallet databases, the chain storage LMDB database and the Peer database. This is done to prevent two processes from simultaneously accessing this databases which can cause data corruption. This was done using the fs2 crate which contains a cross platform method for acquiring an OS level write lock on a file. For all these database the first step in initialization is to attempt to acquire a firelock on the lock file in the path where the database is located. If the file is not locked then a lock is acquired and the db initialisation proceeds as normal. If the file cannot be locked because the lock is already held by another instance an error is thrown. If the process holding the lock panics the OS level lock is lost so it is not needed to clean up the file explicitly for this method to work. During testing this mechanism revealed that the wallet services were not being explicitly shutdown properly, we also plumb the shutdown signals into the services and their sub protocols. The `test_store_and_forward_send_tx` test was being particularly flakey in the PR so I have opted to ignore it for now and come back and examine it properly in the future. How was this tested: Tests were written for the wallet and chain storage db’s but it was not trivial to test the peer_manager addition as it is located in the p2p initialiser. The code was manually tested on: Mac OS X Windows 10 Ubuntu 20.01 Android
Can confirm it works on iOS sim and device as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on MacOS. LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! This should help a lot
Major changes since v0.6.0 --- - [#2431](#2431) Database refactor to remove checkpoints and more efficient calculation of MMR roots - [#2352](#2352) Add DNS seed support in base node Minor changes since v0.6.0 --- - [#2448](#2448) Add OpenSSL to Windows install, runtime - [#2434](#2434) Add supervisord setup notes - [#2439](#2439) Provide initial sync status to merge mining proxy - [#2377](#2377) Message malleability detect and ban - [#2447](#2447) Fix for xmrig powershell script - [#2440](#2440) Stagenet Setup Guide Corrections - [#2444](#2444) DHT connectivity waits for comms connectivity before starting - [#2427](#2427) Update merge mining runtime, README, Win install - [#2420](#2420) Show base node chain tip and sync status in the console wallet - [#2419](#2419) Add optional fee_per_gram field to console wallet Send Tx form - [#2421](#2421) Fix QR code rendering in the console wallet - [#2423](#2423) Plumb in the balance in the console wallet - [#2415](#2415) Prevent loop in peer sync by storing all peers attempted - [#2383](#2383) Implement daemon-mode in tari_base_node - [#2407](#2407) Simplify automated stress test - [#2397](#2397) Fix preset config files - [#2400](#2400) Implement wallet base node service - [#2403](#2403) Add exclusive file locks to Wallet, Chain and Peer db’s - [#2408](#2408) Fix wallet conversion error for a valid tx status - [#2356](#2356) Combine validation code to use same function in pruned and archive mode. - [#2371](#2371) Add configurable BN service request timeouts - [#2430](#2430) Implement entry and persistence of custom base node in console wallet
Description
This PR adds an exclusive file locking mechanism to the wallet databases, the chain storage LMDB database and the Peer database. This is done to prevent two processes from simultaneously accessing this databases which can cause data corruption.
This was done using the fs2 crate which contains a cross platform method for acquiring an OS level write lock on a file. For all these database the first step in initialization is to attempt to acquire a firelock on the lock file in the path where the database is located. If the file is not locked then a lock is acquired and the db initialisation proceeds as normal. If the file cannot be locked because the lock is already held by another instance an error is thrown. If the process holding the lock panics the OS level lock is lost so it is not needed to clean up the file explicitly for this method to work.
During testing this mechanism revealed that the wallet services were not being explicitly shutdown properly, we also plumb the shutdown signals into the services and their sub protocols.
The
test_store_and_forward_send_tx
test was being particularly flakey in the PR so I have opted to ignore it for now and come back and examine it properly in the future.How Has This Been Tested?
Tests were written for the wallet and chain storage db’s but it was not trivial to test the peer_manager addition as it is located in the p2p initialiser.
The code was manually tested on:
Mac OS X
Windows 10
Ubuntu 20.01
Android
Types of changes
Checklist:
development
branch.cargo-fmt --all
before pushing.cargo test
successfully before submitting my PR.