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

API break: Remove Lockfile.Locked #1399

Merged
merged 6 commits into from
Oct 25, 2022
Merged

API break: Remove Lockfile.Locked #1399

merged 6 commits into from
Oct 25, 2022

Conversation

mtrmac
Copy link
Collaborator

@mtrmac mtrmac commented Oct 18, 2022

As detailed in #1388, Lockfile.Locked() does not return the right values if there are multiple users of the same lock within a single process.

So, replace the users by callers correctly tracking locking state; and add LockFile.AssertLocked and Lockfile.AssertLockedForWriting purely for diagnostic purposes. These functions can trigger a panic in clearly invalid situations, but can’t be used by callers to avoid tracking state correctly. That’s a bit risky, so I’ll at least trigger Buildah and Podman CI runs with this change

Following the precedent of #1376 , this removes the Locked method, breaking API of c/storage.

See individual commit messages for details.

Fixes #1388 (and makes another small step towards fixing #1136; the relevant places are now annotated).

mtrmac added a commit to mtrmac/buildah that referenced this pull request Oct 18, 2022
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
@mtrmac
Copy link
Collaborator Author

mtrmac commented Oct 19, 2022

This should very slightly improve efficiency because we no longer take the lock’s state mutex to determine if we can write to the store.

mtrmac added a commit to mtrmac/buildah that referenced this pull request Oct 19, 2022
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
mtrmac added a commit to mtrmac/buildah that referenced this pull request Oct 19, 2022
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
mtrmac added a commit to mtrmac/libpod that referenced this pull request Oct 19, 2022
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
mtrmac added a commit to mtrmac/libpod that referenced this pull request Oct 19, 2022
DO NOT MERGE: Vendor containers/buildah#4350

Remove uses of Lockfile.Locked()

One of them is entirely unnecessary, and the other one
is avoidable.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
mtrmac added a commit to mtrmac/libpod that referenced this pull request Oct 19, 2022
DO NOT MERGE: Vendor containers/buildah#4350

Remove uses of Lockfile.Locked():
One of them is entirely unnecessary, and the other one
is avoidable.

[NO NEW TESTS NEEDED]

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
@@ -302,17 +307,19 @@ func (r *containerStore) Load() error {
r.bylayer = layers
r.byname = names
if needSave {
if !lockedForWriting {
// Eventually, the callers should be modified to retry with a write lock, instead.
return errors.New("container store is inconsistent and the current caller does not hold a write lock")
Copy link
Contributor

Choose a reason for hiding this comment

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

How can callers know when they need to try again? I mean how to distinguish this error (which requires retry) from any other? I see ErrDuplicateImageNames in layerStore.Load()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They can’t, currently.

I plan to add that (“try again”, instead of callers hard-coding specific error values) both to load and the callers simultaneously.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The retries will be added in #1407 .

@mtrmac
Copy link
Collaborator Author

mtrmac commented Oct 19, 2022

@mtrmac mtrmac marked this pull request as draft October 19, 2022 21:16
mtrmac added a commit to mtrmac/buildah that referenced this pull request Oct 19, 2022
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
mtrmac added a commit to mtrmac/libpod that referenced this pull request Oct 19, 2022
DO NOT MERGE: Vendor containers/buildah#4350

Remove uses of Lockfile.Locked():
One of them is entirely unnecessary, and the other one
is avoidable.

[NO NEW TESTS NEEDED]

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
mtrmac added a commit to mtrmac/buildah that referenced this pull request Oct 20, 2022
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
@mtrmac
Copy link
Collaborator Author

mtrmac commented Oct 20, 2022

Buildah tests succeeded; Podman failures seem unrelated.

@mtrmac mtrmac marked this pull request as ready for review October 20, 2022 18:03
This will replace Lockfile.Locked for the sanity-checking
purposes.

It is, just like Locked never was, NOT a way for a caller
to check the current state. Hence the panic() instead of an
error return.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
.Locked() will be going away.  These are just smoke-tests,
so use the .Assert* methods (which are not usable with other
concurrent users).

The AssertLockedForWriting() tests probably don't work on
Windows, but that was the case previously as well.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Instead, have the callers of ReloadIfChanged provide the
locking state.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Instead, have the callers of ReloadIfChanged provide the
locking state.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Instead, have the callers of ReloadIfChanged provide the
locking state.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
It is fundamentally incorrect, and no users are remaining.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
mtrmac added a commit to mtrmac/buildah that referenced this pull request Oct 21, 2022
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Copy link
Member

@rhatdan rhatdan left a comment

Choose a reason for hiding this comment

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

LGTM

@rhatdan
Copy link
Member

rhatdan commented Oct 24, 2022

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

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

LGTM

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.

lockfile.Locked() must not be used to make any decisions
4 participants