Indexes 7: Adds a lock file around index generation and updates#1354
Indexes 7: Adds a lock file around index generation and updates#1354dcookspi wants to merge 1 commit intoindex-5-zplus-1-versionfilters-not-stringsfrom
Conversation
a0324cf to
85050e7
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
81fb685 to
f31a655
Compare
85050e7 to
d4d81db
Compare
f31a655 to
d9f7cef
Compare
d4d81db to
cddd514
Compare
d9f7cef to
7aa00a9
Compare
Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
cddd514 to
5ac3a7b
Compare
| if result.is_err() { | ||
| // Need to keep these if-statements separate | ||
| // to allow for two different error handling cases. | ||
| #[allow(clippy::collapsible_if)] |
| Ok(_file) => { | ||
| // Write any given contents to the lock file as well | ||
| if let Some(ref data) = contents | ||
| && let Err(err) = tokio::fs::write(&lock_file, data).await |
There was a problem hiding this comment.
| Ok(_file) => { | |
| // Write any given contents to the lock file as well | |
| if let Some(ref data) = contents | |
| && let Err(err) = tokio::fs::write(&lock_file, data).await | |
| Ok(mut file) => { | |
| // Write any given contents to the lock file as well | |
| if let Some(ref data) = contents | |
| && let Err(err) = tokio::io::AsyncWriteExt::write_all(&mut file, data).await |
Use the file handle already opened.
| // file for the lock data and add it to the returned error. | ||
| use std::io::Read; | ||
| let mut lock_data = String::new(); | ||
| let held_for = match std::fs::File::open(&lock_file) { |
There was a problem hiding this comment.
It's weird to switch to synchronous file apis here in an async function that was using async file apis earlier.
| /// # Safety: | ||
| /// File locks are used to ensure that only one process is writing |
There was a problem hiding this comment.
| /// # Safety: | |
| /// File locks are used to ensure that only one process is writing | |
| /// # Safety | |
| /// | |
| /// File locks are used to ensure that only one process is writing |
The style convention we're using almost consistently throughout the project.
| ); | ||
|
|
||
| return Err(unlock_error); | ||
| } |
There was a problem hiding this comment.
| } | |
| } else { | |
| self.has_been_deleted = true; | |
| } |
If the file didn't exist, then it had been deleted. Or does this variable mean to say was_deleted_by_us? Since this var is used to decide to attempt to delete the file in the drop handler then it should be set true here too, IMO.
| if !self.has_been_deleted | ||
| && let Err(err) = unsafe { self.unlock() } | ||
| { | ||
| // Can only the problem here. The unlock() method will |
There was a problem hiding this comment.
| // Can only the problem here. The unlock() method will | |
| // Can only <word> the problem here. The unlock() method will |
| let repo = &repos[0].1; | ||
|
|
||
| // Lock the index file until the data has been updated | ||
| let mut _lock = lock_index_file(repo).await?; |
There was a problem hiding this comment.
It will reduce programming bugs if the return value can be turned into a lock guard that is required as a parameter to the function call(s) that write to the index.
This adds a lock file around index generation and update processing. The lock for the index file is created, via a
FileLockobject, before the underlying repo is read and kept until the index has been generated and written out. The same duration of locking is done for updating the index.A
FileLockhas configurable settings for the maximum number of tries to get the lock before giving up, and the amound of time to sleep between tries, as well as the kind of file being locked (used in log messages). It also contains sentry integration when the sentry feature is enabled.This is the 7th of the chained PRs for adding indexes to spk solves:
new_unchecked()constructors to spk schema objects #1337spk repo indexsubcommand for index generation and updates #1340version_filterfield in index schema #1344