Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

[WIP] Feature to disable file locking when DEPNOLOCK set #1206

Merged
merged 7 commits into from
Sep 29, 2017
Merged

[WIP] Feature to disable file locking when DEPNOLOCK set #1206

merged 7 commits into from
Sep 29, 2017

Conversation

ayang64
Copy link
Member

@ayang64 ayang64 commented Sep 22, 2017

  • 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

@ayang64 ayang64 requested a review from sdboyer as a code owner September 22, 2017 19:50
@googlebot
Copy link
Collaborator

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!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@ayang64
Copy link
Member Author

ayang64 commented Sep 22, 2017

I signed it!

@googlebot
Copy link
Collaborator

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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@sdboyer
Copy link
Member

sdboyer commented Sep 26, 2017

having a look - but it seems like you may need to regenerate that commit with different git authorial metadata :)

@ayang64
Copy link
Member Author

ayang64 commented Sep 26, 2017

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.

Copy link
Member

@sdboyer sdboyer left a 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.

GetOwner() (*os.Process, error)
}

type FalseLocker struct{}
Copy link
Member

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?

@@ -28,6 +28,26 @@ import (
// Used to compute a friendly filepath from a URL-shaped input.
var sanitizer = strings.NewReplacer("-", "--", ":", "-", "/", "-", "+", "-")

type Locker interface {
Copy link
Member

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.

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
Copy link
Member

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.

Copy link
Member Author

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!

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
Copy link
Member

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]>
@googlebot
Copy link
Collaborator

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.
Copy link
Member

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."

Copy link
Member Author

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.

Copy link
Member

@sdboyer sdboyer left a 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?

@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

nit: s/interfereing/interfering/

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.
Copy link
Member

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]>
@sdboyer sdboyer merged commit 3fd5bb3 into golang:master Sep 29, 2017
zknill pushed a commit to zknill/dep that referenced this pull request Oct 6, 2017
* 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]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dep init freeze for hours
3 participants