file_rwlock
commitff93c2382f878b226cfa269e0df93b9130f77aad
authorLucian Wischik <ljw@meta.com>
Tue, 25 Oct 2022 09:01:19 +0000 (25 02:01 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Tue, 25 Oct 2022 09:01:19 +0000 (25 02:01 -0700)
tree219d56da9d8eb8eb9c3f196cd88d23eb8027b908
parent8dd24b0a88e650e96abd1ac13070aad1f5519b7a
file_rwlock

Summary:
The re-architecture puts its state on disk and is concurrently accessed by multiple processes. We need a mechanism to control that concurrent access.

Currently:
* hh uses a load of methods in https://www.internalfb.com/code/fbsource/[f7ecd548b84b]/fbcode/hphp/hack/src/facebook/hh/lib/state_utils.rs
* hh_fanout uses https://www.internalfb.com/code/fbsource/[f7ecd548b84b]/fbcode/hphp/hack/src/facebook/hh_fanout/lib/state/mod.rs
* hh_decl didn't yet implement concurrency control because the available abstractions weren't there and it'd take a lot of work (i.e. this diff) to build them
* closest analogue in hh_server is https://www.internalfb.com/code/fbsource/[f7ecd548b84b]/fbcode/hphp/hack/src/utils/sys/lock.ml, but it really solves a different simpler set of concurrency problems

Writing lockfiles is jolly hard. I think this all merits a single central generic implementation.

This diff adds a new type `FileRwLock<T>`, backed by file and flock(LOCK_EX/LOCK_SH), which is usable as a synchronization primitive by multiple processes. It feels quite similar to `std::sync::RwLock<T>` which is backed by heap memory and is usable as a synchronization primitive by muliple threads. For instance, I used different error types to precisely list the errors relevant to each action, similar to std::sync::{Lock,TryLock}Result. I put in a load of comments, some on the API but most on the implementation, as befits tricky concurrency problems!

Reviewed By: edwinsmith, mjhostet

Differential Revision: D40572127

fbshipit-source-id: 6cf0a82547aeff030765efa6d9ab581ab0952198
hphp/hack/src/utils/rust/file_rwlock.rs [new file with mode: 0644]
hphp/hack/src/utils/rust/file_rwlock/Cargo.toml [new file with mode: 0644]