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
add a cache lock at SHA granularity #2612
base: main
Are you sure you want to change the base?
Conversation
Thanks for the PR here @senayuki! From the CI/CD tests it seems this is currently failing our
To fix this you will need to add the below boilerplate to the newly created files:
boilerplate to add at the beginning of those two files:
|
Sorry about that. I have added license headers. |
pkg/cache/lock.go
Outdated
return time.Now().After(expTime), nil | ||
} | ||
|
||
func ClearDeadlock(lockPath string) (cleared bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use of named return value cleared
here when value is not used IIUC. Should likely just be:
func ClearDeadlock(lockPath string) bool {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
pkg/cache/lock.go
Outdated
} | ||
|
||
func ClearDeadlock(lockPath string) (cleared bool) { | ||
expired, _ := isDeadlock(lockPath) // Ingore error and try again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Ingore -> Ignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
pkg/cache/warm.go
Outdated
@@ -152,13 +153,27 @@ func (w *Warmer) Warm(image string, opts *config.WarmerOptions) (v1.Hash, error) | |||
return v1.Hash{}, errors.Wrapf(err, "Failed to retrieve digest: %s", image) | |||
} | |||
|
|||
TRY_LOCAL: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not recommended in to use GOTO statements generally in Go as it can make code harder to follow/understand. In this situation, it might be more idiomatic in Go to use a for loop to retry the lock acquisition. Can you change this to use a retry loop instead? Additionally it likely makes sense to cap the amount of time the process can wait to acquire the file lock so that it cannot spin forever
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the GOTO and using for loop now.
I think it's okay not to set the maximum retry limits for the for loop here.
I designed the renewal and timeout of the lock, so there should be no deadlock here. If the holder of lock was died and cannot be renewed, other processes will have the right to unlock. And locking will continue through the entire download process, which may be very long and difficult to provide a suitable default value for timeout.
Hey, anything new about this? we also encounter this. |
Fixes #2589
Description
Add a file-lock before the warmer caching. Prevent concurrent downloading of the same image.
Resolve EOF caused by repeated write of cache files discovered in #2589.
Add a mechanism to clear expired locks. This may need to be discussed.
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
See the contribution guide for more details.
Reviewer Notes
Release Notes