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

Add safer locking to CreateFieldIfNotExists #6462

Merged

Conversation

oldmantaiter
Copy link
Contributor

@oldmantaiter oldmantaiter commented Apr 25, 2016

Required for all non-trivial PRs
  • Rebased/mergable
  • Tests pass
  • CHANGELOG.md updated
  • Sign CLA (if not already signed)

A deadlock can occur if the field was created while we were waiting for the lock.

@mention-bot
Copy link

By analyzing the blame information on this pull request, we identified @jwilder, @benbjohnson and @pauldix to be potential reviewers

@oldmantaiter oldmantaiter force-pushed the measurement-fields-deadlock branch from 6cccab3 to bf33e0d Compare April 25, 2016 14:57
@oldmantaiter
Copy link
Contributor Author

oldmantaiter commented Apr 25, 2016

So far, this has stopped the issues I was seeing for #6096

@benbjohnson
Copy link
Contributor

@oldmantaiter That would make sense. It looks like the if block right after m.mu.Lock() isn't being unlocked before returning.

@jwilder We're already doing an RLock() to check the field existence. I'm ok with using defer here since it's not going to happen very often.

@jwilder
Copy link
Contributor

jwilder commented Apr 25, 2016

The defer was removed to avoid an allocation. This code is actually called very frequently now. I'd prefer to explicitly unlock in the place where we missed it.

@oldmantaiter oldmantaiter force-pushed the measurement-fields-deadlock branch from bf33e0d to ad3d201 Compare April 25, 2016 15:21
@oldmantaiter
Copy link
Contributor Author

oldmantaiter commented Apr 25, 2016

@jwilder Updated - on that note, let me rebase with a new subject line for the commit (so it makes more sense)

@oldmantaiter oldmantaiter force-pushed the measurement-fields-deadlock branch from ad3d201 to ba1ab03 Compare April 25, 2016 15:23
@benbjohnson
Copy link
Contributor

@jwilder The first lock seems like it would get called a lot:

https://github.com/influxdata/influxdb/pull/6462/files#diff-5794b17db5ab55866ed4ee776df9a0eaR561

The second one would only get called on new fields. It doesn't seem like that would happen very often.

@jwilder
Copy link
Contributor

jwilder commented Apr 25, 2016

@benbjohnson That's a good point. When I was looking at this code, it was in the context of speeding up shard loading when the DB starts up and new fields were getting created frequently. defer here might be fine since shard loading code has changed quite a bit and the contentious part should be the RLock now.

I'd still prefer the explicit unlock, but defer is also OK w/ me.

@benbjohnson
Copy link
Contributor

@jwilder I spent a full day trying to track this issue down (and was still unsuccessful). If we don't have a specific performance need for not using defer then I would strongly recommend using it.

@jwilder
Copy link
Contributor

jwilder commented Apr 25, 2016

@benbjohnson OK w/ me.

@mark-rushakoff
Copy link
Contributor

There's a bit of discussion on defer performance at golang/go#14939.

@jwilder
Copy link
Contributor

jwilder commented Apr 25, 2016

@oldmantaiter I didn't realize you had already updated the PR to remove the defer while we were discussing it. @benbjohnson would rather have your original change (using defer) and after discussing it, I'm OK w/ using the defer as well.

If you could switch the unlock back to using defer, then we can get this PR merged.

@oldmantaiter
Copy link
Contributor Author

@jwilder Sure, I'll bring back the defer.

@oldmantaiter oldmantaiter force-pushed the measurement-fields-deadlock branch from ba1ab03 to c531657 Compare April 25, 2016 16:31
A deadlock can occur if the field was created while we were waiting for the lock.
@oldmantaiter oldmantaiter force-pushed the measurement-fields-deadlock branch from c531657 to df0e16a Compare April 25, 2016 16:45
@benbjohnson benbjohnson merged commit f608e4c into influxdata:master Apr 25, 2016
@benbjohnson
Copy link
Contributor

Thanks @oldmantaiter! 👍

@oldmantaiter oldmantaiter deleted the measurement-fields-deadlock branch April 25, 2016 17:15
@timhallinflux timhallinflux added this to the 0.13.0 milestone Dec 20, 2016
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.

6 participants