Refactor locking into repository package#4709
Merged
MichaelEischer merged 10 commits intorestic:masterfrom Mar 28, 2024
Merged
Conversation
…Lock The new functions much better convey the intent behind the lock request. This allows cleanly integrating noLock (for read) and dryRun (write/exclusive) handling. There are only minor changes to existing behavior with two exceptions: - `tag` no longer accepts the `--no-lock` flag. As it replaces files in the repository, this always requires an exclusive lock. - `debug examine` now returns an error if both `--extract-pack` and `--no-lock` are given.
Tests should use a helper from internal/repository/testing.go to construct a Repository object.
As `ls` reads data from the repository, it must acquire a read lock unless `--no-lock` was specified. The old behavior is equivalent to `ls --no-lock`.
1ea6d6f to
5e98f1e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR change? What problem does it solve?
The code to lock a repository was living in
cmd/restic. However, the allowed read or write access to a repository depends on the type of lock held by the current process. Therefore, locking must be centrally managed by the repository to guarantee integrity of the repository.The PR replaces the lockRepo and lockRepoExclusive functions with
openWithReadLock,openWithAppendLockandopenWithExclusiveLock. The code paths foropenWithReadLockandopenWithAppendLockare nearly identical, but the difference is in semantics: a read lock can be disabled by specifying--no-lock, whereas for a write lock the relevant question is whether the command is run in--dry-runmode or not.The unified lock handling leads to a few minor cosmetic changes and three actual changes in behavior:
tagno longer accepts the--no-lockflag. As it replaces files in the repository, this always requires an exclusive lock.debug examinenow returns an error if both--extract-packand--no-lockare given.lserroneously did not lock the repository. The old behavior is now available usingls --no-lock.The remaining changes are a mix of fewer global variables and test cleanups to correctly lock the repository. The latter are the result of an experiment to actually enforce the access requested together with the lock (i.e., a read lock blocks all modifications). However, that code is still too horrible to show anyone ^^ .
TODOs
repository.Lockfunction interfaceWas the change previously discussed in an issue or on the forum?
Part of the roadmap for restic 0.17
Checklist
changelog/unreleased/that describes the changes for our users (see template).gofmton the code in all commits.