-
Notifications
You must be signed in to change notification settings - Fork 1k
[WIP] Feature to disable file locking when DEPNOLOCK set #1206
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
having a look - but it seems like you may need to regenerate that commit with different git authorial metadata :) |
ya -- it needs lots of work. i was going to spend some time within the next couple of days getting it to pass code climate and working on agreeing to the cla. |
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.
somewhat superficial review, problems are mostly nittish.
i haven't really thought deeply about if there are problems that arise from this, but it's hard to imagine any off the top of my head. this seems like basically what we want.
internal/gps/source_manager.go
Outdated
GetOwner() (*os.Process, error) | ||
} | ||
|
||
type FalseLocker struct{} |
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.
also no need to export this, i don't think?
internal/gps/source_manager.go
Outdated
@@ -28,6 +28,26 @@ import ( | |||
// Used to compute a friendly filepath from a URL-shaped input. | |||
var sanitizer = strings.NewReplacer("-", "--", ":", "-", "/", "-", "+", "-") | |||
|
|||
type Locker interface { |
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.
shouldn't need to be exported. if there is a reason to, though, it'll need a comment.
internal/gps/source_manager.go
Outdated
Logger *log.Logger // Optional info/warn logger. Discards if nil. | ||
Cachedir string // Where to store local instances of upstream sources. | ||
Logger *log.Logger // Optional info/warn logger. Discards if nil. | ||
DisableLocking 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.
In keeping with the other items, let's have an inline explanatory comment.
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.
Okay -- will try to address these issues tonight. Thank you!
internal/gps/source_manager.go
Outdated
lf *lockfile.Lockfile // handle for the sm lock file on disk | ||
cachedir string // path to root of cache dir | ||
// lf *lockfile.Lockfile // handle for the sm lock file on disk | ||
lf Locker // handle for the sm lock file on disk |
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.
drop the old prop and update the comment
* Add DisableLocking bool members to Ctx and gps.SourceManagerConfig structs. This effectively communicates DEPNOLOCK from the shell, to Ctx, to SourceManager. The member is named DisableLocking to make its zero-value useful. * Add locker interface which implements TryLock(), Unlock(), and GetOwner() which lockfile.Lockfile alredy adheres to. This interface replaces the new type for the lf member of the SourceMgr struct. * Add a FalseLocker type which adheres to the Locker interface which does nothing. * Conditionally set the lf member of SourceMgr to either an instance of lockfile.Lockfile or FalseLocker depending on the value of SourceManagerConfig.DisableLocking. Signed-off-by: Ayan George <[email protected]>
CLAs look good, thanks! |
Signed-off-by: Ayan George <[email protected]>
context.go
Outdated
GOPATHs []string // Other Go paths. | ||
Out, Err *log.Logger // Required loggers. | ||
Verbose bool // Enables more verbose logging. | ||
DisableLocking bool // When set, disables locking. |
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.
we need a little more on this comment here. it's in reference to a rather obscure feature that most people don't know about. with just this context, i would probably expect people to assume that it referred to, say, not writing out Gopkg.lock
(which is not something we do at all). instead, maybe:
"When set, no lock file will be created to protect against multiple simultaneous dep processes."
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.
Absolutely. Frankly I wrote something similar originally and changed my mind (something about that comment being much longer than the others -- silly I know).
I'll fix immediately.
Signed-off-by: Ayan George <[email protected]>
Signed-off-by: Ayan George <[email protected]>
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.
just a couple typos. also, would you mind squashing this down?
internal/gps/source_manager.go
Outdated
@@ -28,6 +28,41 @@ import ( | |||
// Used to compute a friendly filepath from a URL-shaped input. | |||
var sanitizer = strings.NewReplacer("-", "--", ":", "-", "/", "-", "+", "-") | |||
|
|||
// A locker is responsible for preventing multiple instances of dep from interfereing |
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: s/interfereing/interfering/
internal/gps/source_manager.go
Outdated
Logger *log.Logger // Optional info/warn logger. Discards if nil. | ||
Cachedir string // Where to store local instances of upstream sources. | ||
Logger *log.Logger // Optional info/warn logger. Discards if nil. | ||
DisableLocking bool // True if dep SourceManager shoud NOT lock. |
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.
"shoud" typo here. also, let's rewrite this a bit, too:
"True if the SourceManager should NOT use a file lock to protect the Cachedir from multiple processes."
Signed-off-by: Ayan George <[email protected]>
* Disable file locking when DEPNOLOCK set * Add DisableLocking bool members to Ctx and gps.SourceManagerConfig structs. This effectively communicates DEPNOLOCK from the shell, to Ctx, to SourceManager. The member is named DisableLocking to make its zero-value useful. * Add locker interface which implements TryLock(), Unlock(), and GetOwner() which lockfile.Lockfile alredy adheres to. This interface replaces the new type for the lf member of the SourceMgr struct. * Add a FalseLocker type which adheres to the Locker interface which does nothing. * Conditionally set the lf member of SourceMgr to either an instance of lockfile.Lockfile or FalseLocker depending on the value of SourceManagerConfig.DisableLocking. Signed-off-by: Ayan George <[email protected]> * Revert stray edit. Signed-off-by: Ayan George <[email protected]> * Improve comment for DisableLocking Signed-off-by: Ayan George <[email protected]> * Fix comment type-os * Fix comment type-os Signed-off-by: Ayan George <[email protected]> * Fix yet more type-os. Signed-off-by: Ayan George <[email protected]>
Add DisableLocking bool members to Ctx and gps.SourceManagerConfig structs.
This effectively communicates DEPNOLOCK from the shell, to Ctx, to
SourceManager.
The member is named DisableLocking to make its zero-value useful.
Add Locker interface which implements TryLock(), Unlock(), and GetOwner()
which lockfile.Lockfile alredy adheres to. This interface replaces the new
type for the lf member of the SourceMgr struct.
Add a FalseLocker type which adheres to the Locker interface which does
nothing.
Conditionally set the lf member of SourceMgr to either an instance of
lockfile.Lockfile or FalseLocker depending on the value of
SourceManagerConfig.DisableLocking.
What does this do / why do we need it?
This pull request adds functionality that checks the DEPNOLOCK environment variable to determine if session manager should attempt to lock against multiple instances of dep runing.
This seems to be a problem particularly when building with CI systems in a Vagrant or Docker type container that uses union mount type file systems.
This environment variable allows us to work around this locking issue in these kind of systems where we can be sure there aren't concurrent runs of dep.
What should your reviewer look out for in this PR?
Do you need help or clarification on anything?
I'm interested to know if this is a reasonable approach and I'm open to suggestions of alternate ways to achieve this.
Which issue(s) does this PR fix?
fixes #947