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

Improve lockfiles #1193

Merged
merged 12 commits into from
Oct 7, 2021
Merged

Improve lockfiles #1193

merged 12 commits into from
Oct 7, 2021

Conversation

adriendelsalle
Copy link
Member

@adriendelsalle adriendelsalle commented Sep 30, 2021

Description

  • Handle files and directories locks
    • LockFile now takes the path to lock instead of the name of the supposed lock file
      • this allows to disambiguate a file path between the lock file or the file to be locked
      • an optional timeout argument can be specified to the constructorn defaulting to Context::lock_timeout value
  • Handle multiple locks acquired on the same path
    • from the same process -> raise a std::logic_error
    • from the another process: try lock in a blocking way and raise a std::runtime_error is a timeout is set
      • on Windows, implement a timeout calling _locking with _LK_LOCK every seconds
        • which is similar to _LK_NBLOCK but with control over the timeout
        • allows infinite loops as on Unix systems
      • on Unix, call fcntl with F_SETLKW in a separate thread and cancel it if timeout is met
      • we could change the default behavior to avoid infinite loops later (setting the timeout to some large number)
  • Improve logs
  • Add tests
    • add another testing CMake target mamba_test_lock to have a CLI for testing is_locked and lock paths for subprocesses
    • check creation of one or multiple locks on the same path from both current and foreign processes
  • Add micromamba CLI options/flags
    • -l,--locks to micromamba clean to remove lock files in caches
    • --lock-timeout to set the lock file timeout

src/core/util.cpp Outdated Show resolved Hide resolved
src/core/util.cpp Outdated Show resolved Hide resolved
src/core/util.cpp Outdated Show resolved Hide resolved
@adriendelsalle adriendelsalle force-pushed the improve-lockfile branch 5 times, most recently from e59195f to 9ef14d5 Compare October 6, 2021 09:48
handle multiple locks acquired from the same process
improve logs
add tests
refactor use of LockFile
forbid locking twice same path from same PID
improve windows lockfile to match unix one
split Lock and LockFile
use byte 21 to set lock status
enable reading locked file on windows
ensure closing of file descriptor in Lock and LockFile destructors
add timeout implementation for unix
add testing lock cli for subprocess tests
add subprocess tests
add --lock-timeout to umamba
add clean lock files
add a clean lock files flag -l,--locks to umamba clean command
add cpp-filesystem pins to enforce correct version on dev mode
src/core/util.cpp Outdated Show resolved Hide resolved
src/core/util.cpp Outdated Show resolved Hide resolved
src/core/util.cpp Outdated Show resolved Hide resolved
@@ -27,7 +27,7 @@ is_locked(const fs::path& path)
// From another process than the lockfile one, we can open/close
// a new file descriptor without risk to clear locks
int fd = open(path.c_str(), O_RDWR | O_CREAT, 0666);
bool is_locked = mamba::LockFile::is_locked(fd);
bool is_locked = mamba::Lock::is_locked(fd);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep the LockFile name -- because that's what it is. A "Lock" is a bit ambigous.

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.

2 participants