Skip to content
This repository was archived by the owner on Nov 19, 2026. It is now read-only.

API break: Remove Lockfile.Locked - #1399

Merged
rhatdan merged 6 commits into
containers:mainfrom
mtrmac:no-Locked
Oct 25, 2022
Merged

rhatdan merged 6 commits into
containers:mainfrom
mtrmac:no-Locked

Conversation

@mtrmac

@mtrmac mtrmac commented Oct 18, 2022

Copy link
Copy Markdown
Collaborator

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
@mtrmac

mtrmac commented Oct 19, 2022

Copy link
Copy Markdown
Collaborator Author

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
mtrmac added a commit to mtrmac/buildah that referenced this pull request Oct 19, 2022
Comment thread containers.go
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
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
mtrmac added a commit to mtrmac/libpod that referenced this pull request Oct 19, 2022
DO NOT MERGE: Vendor podman-container-tools/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č <[email protected]>
mtrmac added a commit to mtrmac/buildah that referenced this pull request Oct 20, 2022
@mtrmac

mtrmac commented Oct 20, 2022

Copy link
Copy Markdown
Collaborator Author

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č <[email protected]>
.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č <[email protected]>
Instead, have the callers of ReloadIfChanged provide the
locking state.

Signed-off-by: Miloslav Trmač <[email protected]>
Instead, have the callers of ReloadIfChanged provide the
locking state.

Signed-off-by: Miloslav Trmač <[email protected]>
Instead, have the callers of ReloadIfChanged provide the
locking state.

Signed-off-by: Miloslav Trmač <[email protected]>
It is fundamentally incorrect, and no users are remaining.

Signed-off-by: Miloslav Trmač <[email protected]>
mtrmac added a commit to mtrmac/buildah that referenced this pull request Oct 21, 2022

@rhatdan rhatdan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@rhatdan

rhatdan commented Oct 24, 2022

Copy link
Copy Markdown
Member

@vrothberg vrothberg left a comment

Copy link
Copy Markdown
Member

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 subscribe to this conversation on GitHub. Already have an account? Sign in.

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