-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
sql: Refactor TableDescriptor lease acquisition to use singleflight #18989
Conversation
be8a6d4
to
54a3bbc
Compare
@andreimatei PTAL. Took out the NB: I didn't use the Review status: 0 of 2 files reviewed at latest revision, all discussions resolved. Comments from Reviewable |
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.
Really nice change!
pkg/sql/lease.go
Outdated
// range of the actual lease duration will be | ||
// [(1-LeaseJitterFraction) * LeaseDuration, (1+LeaseJitterFraction) * LeaseDuration] | ||
// Exported for testing purposes only. | ||
LeaseJitterFraction = 0.25 |
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'd add this in the same PR that uses it. It makes sense to not make this change here.
pkg/sql/lease.go
Outdated
table, err := m.LeaseStore.acquire(ctx, t.id, minExpirationTime) | ||
t.mu.Lock() | ||
defer t.mu.Unlock() | ||
if err != nil { | ||
return err | ||
} |
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'd lock and defer unlock() after the err is checked.
pkg/sql/lease.go
Outdated
// underway. | ||
var err error | ||
hasAcquiredFreshest := false | ||
for !hasAcquiredFreshest { |
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.
for hasAcquiredFreshest := false; !hasAcquiredFreshest; {
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.
maybe not. See my comment below. Just break out of this loop once shared == false
pkg/sql/lease.go
Outdated
minExpirationTime = newestTable.expiration.Add(int64(time.Millisecond), 0) | ||
t.mu.Unlock() | ||
_, _, err = t.mu.group.Do("acquire", func() (interface{}, error) { | ||
hasAcquiredFreshest = true |
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 think we can do without this hasAcquiredFreshest boolean. Let's just used the shared boolean returned from Do(). It's not quite the same semantics but when set to false we are guaranteed we were the only caller of the method which means that the lease is the freshest.
54a3bbc
to
f59dacd
Compare
Review status: 0 of 2 files reviewed at latest revision, 4 unresolved discussions, some commit checks pending. pkg/sql/lease.go, line 59 at r2 (raw file): Previously, vivekmenezes wrote…
Done. pkg/sql/lease.go, line 714 at r2 (raw file): Previously, vivekmenezes wrote…
Done. pkg/sql/lease.go, line 727 at r2 (raw file): Previously, vivekmenezes wrote…
Done. pkg/sql/lease.go, line 797 at r2 (raw file): Previously, vivekmenezes wrote…
Done. Comments from Reviewable |
pkg/sql/lease.go
Outdated
t.acquireWait() | ||
|
||
// Move forward to acquire a fresh table lease. | ||
// Continue to attempt to call to acquireNodeLease until our call was the one |
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.
only one made by singleflight
pkg/sql/lease.go
Outdated
if err := t.acquireNodeLease(ctx, m, hlc.Timestamp{}); err != nil { | ||
// Acquire a lease if no lease exists or if the latest lease is about to | ||
// expire. Repeatedly check to ensure either a lease is acquired or we receive | ||
// an error. Checking we havea valid lease after acquisition is is required |
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.
s/havea/have a/
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.
s/is is/is/
pkg/sql/lease.go
Outdated
|
||
// Move forward to acquire a fresh table lease. | ||
// Continue to attempt to call to acquireNodeLease until our call was the one | ||
// made by singleflight. This busy-waits while another acquisitions are |
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.
s/another/other/
pkg/sql/lease.go
Outdated
|
||
// Set the min expiration time to guarantee that the lease acquired is the |
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.
// TODO(vivek): the expiration time is no longer needed to sort the tableVersionState. Get rid of this.
pkg/sql/lease.go
Outdated
t.mu.Lock() | ||
if !shared { | ||
return err | ||
} |
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.
if err != nil || !shared {
return err
}
Looks like you need to fix TestAcquireFreshestFromStoreRaces |
Aha, it appears we can't just use What ends up happening is an almost guaranteed livelock if we get two simultaneous calls to
The only thing that helps here is knowing whether it was our function that was called. |
db66684
to
2cb59c2
Compare
pkg/sql/lease.go
Outdated
hasAcquiredFreshest = true | ||
return nil, t.acquireNodeLease(ctx, m, minExpirationTime) | ||
}) | ||
t.mu.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.
before t.mu.Lock() is acquired t.mu.active.findNewest() can become nil again so we need to call
acquireFreshestFromStoreLocked() in a loop in acquireFreshestFromStore()
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.
Yep.
(Hmm, this is a common problem with all uses of acquireNodeLease
now that it's async and we're handing off the lock. I don't know if there's a better approach to this, but I don't know of one off the top of my head.)
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.
Regardless, I've added two tests which catch this problem for both acquireFreshestFromStore
and AcquireByName
/acquire
so I'm a lot more confident in that. The race happened ~50% of the time during testrace
locally but is now fixed.
Aside: How does teamcity compare to tests locally, when it comes to encountering race conditions? Is it more frequent because of some property of the execution speed?
pkg/sql/lease.go
Outdated
if err := t.acquireNodeLease(ctx, m, hlc.Timestamp{}); err != nil { | ||
// Acquire a lease if no lease exists or if the latest lease is about to | ||
// expire. Repeatedly check to ensure either a lease is acquired or we receive | ||
// an error. Checking we have a valid lease after acquisition is is required |
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.
s/is is /is/
ce5a44e
to
9a7473e
Compare
Isn't this what the bool return value of I don't know how to parse your last message. Has the bug you're talking about been fixed and so this is ready for a review (or do you want a review even if it hasn't been fixed)? Review status: 0 of 3 files reviewed at latest revision, 10 unresolved discussions, some commit checks pending. Comments from Reviewable |
The bug is fixed only by explicitly setting a bool, so we can't use the returned shared value (as previously suggested) Review status: 0 of 3 files reviewed at latest revision, 10 unresolved discussions, some commit checks pending. pkg/sql/lease.go, line 577 at r3 (raw file): Previously, vivekmenezes wrote…
Done. pkg/sql/lease.go, line 701 at r3 (raw file): Previously, vivekmenezes wrote…
Done. pkg/sql/lease.go, line 702 at r3 (raw file): Previously, vivekmenezes wrote…
Done. pkg/sql/lease.go, line 577 at r4 (raw file): Previously, vivekmenezes wrote…
Done. Comments from Reviewable |
3a2bf08
to
e3b0875
Compare
Following up from an in-person convo, I changed the Review status: 0 of 3 files reviewed at latest revision, 10 unresolved discussions. pkg/sql/lease.go, line 722 at r3 (raw file): Previously, vivekmenezes wrote…
Done. Comments from Reviewable |
A few comments; I'll check further when they're addressed. Review status: 0 of 3 files reviewed at latest revision, 13 unresolved discussions, some commit checks pending. pkg/sql/lease.go, line 701 at r3 (raw file): Previously, lego (Joey Pereira) wrote…
I don't know what "our call was the only one made by singleflight" means. What you want to say is that we wait until we didn't join an in-progress call. I suggest this comment:
pkg/sql/lease.go, line 548 at r6 (raw file):
needs a comment pkg/sql/lease.go, line 577 at r6 (raw file):
s//Looping is necessary because lease acquisition is done without holding the tableState lock, so anything can happen in between lease acquisition and us getting control again. pkg/sql/lease.go, line 725 at r6 (raw file):
as discussed offline, get rid of this capture and use Comments from Reviewable |
pkg/sql/lease.go
Outdated
// Continue to attempt to call to acquireNodeLease until our call was the only | ||
// one made by singleflight. This busy-waits while other acquisitions are | ||
// underway. | ||
for { |
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.
for wasCalled, s := false, t.mu.active.findNewest(); wasCalled && s != nil; s = t.mu.active.findNewest() {
and
s/newestTable/s/
Review status: 0 of 3 files reviewed at latest revision, 14 unresolved discussions, some commit checks pending. pkg/sql/lease.go, line 701 at r3 (raw file): Previously, andreimatei (Andrei Matei) wrote…
The expectation is that t.mu.active.findNewest() is non nil after the call so we potentially need to loop until that's true or we hit an error Comments from Reviewable |
Review status: 0 of 3 files reviewed at latest revision, 14 unresolved discussions, some commit checks pending. pkg/sql/lease.go, line 728 at r4 (raw file): Previously, lego (Joey Pereira) wrote…
teamcity tends to be slower than your own machine Comments from Reviewable |
Review status: 0 of 3 files reviewed at latest revision, 14 unresolved discussions, all commit checks successful. pkg/sql/lease.go, line 701 at r3 (raw file): Previously, vivekmenezes wrote…
OK. But actually it seems to me So, I think we should change the The main point of my comment remains: what we care is not specifically that we were the "leader" of a acquisition, but that the acquisition was started after a particular time. And since we're shaking things up, let me suggest something I see as related: I believe we're currently inserting leases in Comments from Reviewable |
Review status: 0 of 3 files reviewed at latest revision, 14 unresolved discussions, all commit checks successful. pkg/sql/lease.go, line 701 at r3 (raw file):
I don't think we can get away with a token since we will inevitably need to binary search If we return the least, we should be able to use
So, even after this change we still have to loop around if we aren't the leader to check if the lease is in That same logic you mentioned applies to Sidenote: I don't think Because methods are now conditionally incrementing the refcount, whether or not they were the leader I'm not sure how I feel about starting the More so, if we add async refreshing we do want to insert the lease with Comments from Reviewable |
Review status: 0 of 3 files reviewed at latest revision, 15 unresolved discussions, all commit checks successful. pkg/sql/lease.go, line 701 at r3 (raw file):
What I had in mind is the desire for a restricted interface: ideally, an API should make it impossible to break its assumptions. In this case, the API contract would be that, once you've received a result from
Correct.
Sure. I'm hoping we use the same protocol across acquire/acquireFreshest...
I don't fully follow this, but note that
I guess I don't have a strong opinion on this refcount increment. pkg/sql/lease.go, line 717 at r7 (raw file):
there's a race here. You want to release the lock after you've gotten the channel from Comments from Reviewable |
PTAL. They've been addressed. Review status: 0 of 3 files reviewed at latest revision, 15 unresolved discussions, all commit checks successful. pkg/sql/lease.go, line 701 at r3 (raw file): Previously, andreimatei (Andrei Matei) wrote…
The patch now covers the two cases you've mentioned (join an in-flight call, and when we don't). The condition also uses a token passed through to ensure the lease we expect is in I refrained from making the changes to how we handle pkg/sql/lease.go, line 577 at r6 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease.go, line 725 at r6 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease.go, line 704 at r7 (raw file): Previously, vivekmenezes wrote…
Done. pkg/sql/lease.go, line 717 at r7 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. Comments from Reviewable |
Addressed the comments. I'm still confused why this is failing on teamcity, and I'm almost positive it's a problem with the test. (https://teamcity.cockroachdb.com/viewLog.html?buildId=374164&buildTypeId=Cockroach_UnitTests_Test&tab=buildLog search The test is blocking on Review status: 0 of 3 files reviewed at latest revision, 18 unresolved discussions, some commit checks failed. pkg/sql/lease_internal_test.go, line 595 at r11 (raw file): Previously, andreimatei (Andrei Matei) wrote…
I've added more details (it's now below, just before The same problem "can" happen in another test ( pkg/sql/lease_internal_test.go, line 602 at r11 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done :). This may have been what was causing the test failures earlier. pkg/sql/lease_internal_test.go, line 605 at r11 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease_internal_test.go, line 640 at r11 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease_internal_test.go, line 645 at r11 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease_internal_test.go, line 769 at r11 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. Comments from Reviewable |
8ac91b0
to
5c24f5c
Compare
Review status: 0 of 3 files reviewed at latest revision, 13 unresolved discussions, some commit checks pending. pkg/sql/lease_internal_test.go, line 595 at r11 (raw file): Previously, lego (Joey Pereira) wrote…
Is checking the expiration really the only way to test that leases are "equal"? Can't we check the descriptor pointer? Comments from Reviewable |
559c14b
to
9484291
Compare
Huzza, tests finally work \o/. Turns out there were a few issues with the tests. I was underestimating concurrency here and didn't realize that during the test if the It's a bit unfortunate and that's made this test a little more brittle. Better than before but I'm a little less happy about the test. The other issue was failing tests on master. Right now #19180 is causing a failure. Review status: 0 of 3 files reviewed at latest revision, 13 unresolved discussions. pkg/sql/lease_internal_test.go, line 595 at r11 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Ah, thanks! I thought we had a value. Comments from Reviewable |
@andreimatei bump -- or were you 👍 earlier? just want to double check on that. Thanks again for the help on this one :) |
9484291
to
f620218
Compare
Review status: 0 of 3 files reviewed at latest revision, 33 unresolved discussions, all commit checks successful. pkg/sql/lease.go, line 50 at r14 (raw file):
does it need to be exported any more? See comment. pkg/sql/lease.go, line 51 at r14 (raw file):
this should now be called pkg/sql/lease.go, line 121 at r14 (raw file):
This comment is less than ideal, in my opinion. First of all, "constant" doesn't mean much if you say next that it can be modified. Second of all, all the members here (at least the pointers) are "constant", in that they're not changed after construction. Also, there's no particular need to spell out that a constructor sets this. Finally, this comment does not say the one thing that it should say - what is this member?
pkg/sql/lease.go, line 131 at r14 (raw file):
If possible, I'd make this a method on pkg/sql/lease.go, line 1109 at r14 (raw file):
If you're going through the pain of doing this (and I thank you that you are), please go all the way - make pkg/sql/lease.go, line 990 at r15 (raw file):
I don't see an error being passed. Is the comment correct? Same below. pkg/sql/lease.go, line 994 at r15 (raw file):
If possible, I'd keep just pkg/sql/lease_internal_test.go, line 596 at r15 (raw file):
I don't see the release part... Is this comment correct? pkg/sql/lease_internal_test.go, line 608 at r15 (raw file):
I think you can inline this one in the test case. pkg/sql/lease_internal_test.go, line 618 at r15 (raw file):
unnecessary. Also, missing final period. pkg/sql/lease_internal_test.go, line 622 at r15 (raw file):
pkg/sql/lease_internal_test.go, line 625 at r15 (raw file):
I don't think you need both this and the previous member. Choose one. pkg/sql/lease_internal_test.go, line 627 at r15 (raw file):
This phrasing is unfortunate. It would likely be read as "checks whether the race occurs", but you want "checks what happens when the race occurs". pkg/sql/lease_internal_test.go, line 644 at r15 (raw file):
if this pkg/sql/lease_internal_test.go, line 672 at r15 (raw file):
Also, I think using pkg/sql/lease_internal_test.go, line 672 at r15 (raw file):
"prelock" is stale? pkg/sql/lease_internal_test.go, line 705 at r15 (raw file):
is this comment still true about expiration being used to test equality? pkg/sql/lease_internal_test.go, line 726 at r15 (raw file):
routine's results. pkg/sql/lease_internal_test.go, line 757 at r15 (raw file):
nit: consider hinting to the pkg/sql/lease_internal_test.go, line 759 at r15 (raw file):
why is this necessary? pkg/sql/lease_internal_test.go, line 762 at r15 (raw file):
I don't know what "fully removed" means. pkg/sql/lease_internal_test.go, line 769 at r15 (raw file):
Comments from Reviewable |
f620218
to
f52f0b2
Compare
Review status: 0 of 10 files reviewed at latest revision, 33 unresolved discussions. pkg/sql/lease.go, line 50 at r14 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. 🎉 pkg/sql/lease.go, line 51 at r14 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease.go, line 121 at r14 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease.go, line 131 at r14 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease.go, line 1109 at r14 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. This plumbing has been amended to the first commit. pkg/sql/lease.go, line 990 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. (the comment was mistakenly added) pkg/sql/lease.go, line 994 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease_internal_test.go, line 596 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done, the comment wasn't correct as the "release" part was shuffled around quite a bit in trial and error. pkg/sql/lease_internal_test.go, line 608 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease_internal_test.go, line 618 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease_internal_test.go, line 622 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease_internal_test.go, line 625 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease_internal_test.go, line 627 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease_internal_test.go, line 644 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
I'm not sure what you mean by the LeaseManager's ctx. The need of the context is just for providing LeaseManager functions with a context, which is otherwise associated with the current request handling the lease. So then we won't have a LeaseManager context to plumb. pkg/sql/lease_internal_test.go, line 672 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Uh yea a lot of these logs were for walking through the tests while there were problems. Removing. pkg/sql/lease_internal_test.go, line 672 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Are you referring to the log or the waitgroup? (If it's the log, the logs are removed.) pkg/sql/lease_internal_test.go, line 705 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Expiration is still checked but in addition to the pointers. I'm more confident if it is, but if you insist it be removed I can. pkg/sql/lease_internal_test.go, line 726 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease_internal_test.go, line 757 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease_internal_test.go, line 759 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Releasing the second lease? It doesn't assist with what we're testing here. It was more about having the test clean up things (and if this errors, that's bad). pkg/sql/lease_internal_test.go, line 762 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Fixed. pkg/sql/lease_internal_test.go, line 769 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. Comments from Reviewable |
f52f0b2
to
082cf0c
Compare
Oof, didn't check back and notice the test failure. Fixed the problem where defaults weren't initialized in non-test contexts. |
Merge at will. Review status: 0 of 10 files reviewed at latest revision, 24 unresolved discussions, some commit checks failed. pkg/base/config.go, line 491 at r17 (raw file):
cconfigured pkg/base/config.go, line 491 at r17 (raw file):
I don't know what this sentence means. It suggests that Take it or leave it: I think it's unfortunate that this is a pointer, particularly since it looks like this pointer can be What I'd make pkg/base/test_server_args.go, line 39 at r17 (raw file):
please don't embed; I think that will only hurt readability. I see that other are, but I think that's unfortunate (also, others aren't!). More than one embedded thing is a bad idea, I think. pkg/server/config.go, line 124 at r17 (raw file):
please don't embed. pkg/sql/lease.go, line 123 at r18 (raw file):
exported comment is stale. pkg/sql/lease_internal_test.go, line 672 at r15 (raw file): Previously, lego (Joey Pereira) wrote…
the log pkg/sql/lease_internal_test.go, line 759 at r15 (raw file): Previously, lego (Joey Pereira) wrote…
but this cleanup clutters what's already a complicated test. Cleaning up this lease seems to me to not be any more needed than in every other test that directly and indirectly uses leases - failing to release in any of them would be bad. And yet we don't clutter all the tests with lease cleanup. Perhaps we should, but then the testing should be implicit -> the testserver cleanup (that does happen in every test, including in this one) should assert that the draining process managed to release all the leases. pkg/sql/lease_test.go, line 312 at r18 (raw file):
why 5? Comments from Reviewable |
Review status: 0 of 10 files reviewed at latest revision, 24 unresolved discussions, some commit checks failed. pkg/sql/lease_test.go, line 312 at r18 (raw file): Previously, andreimatei (Andrei Matei) wrote…
What I wanted to say here is that with a good config strategy, I think even 0 would work - which would perfectly express what you want. Comments from Reviewable |
b6e95ad
to
cbc7901
Compare
Previously, the global LeaseDuration value was modified during a test. If tests doing this are run in parallel, this would cause race problems. The global has now been modified to live on the LeaseStore where it is referenced from. It is also now configured during server initialization. A LeaseJitterFraction constant is also refactored out. This is used in later path.
This changes the acquisition of leases to use singleflight to reduce the complexity of handling concurrent acquisitions. The behaviour is kept the same as we block on the results of singleflight.DoChan. The change is in preparation for adding a new codepath which acquires leases asynchronously. This also refactors out the jitter multiplier into a constant.
cbc7901
to
899d08f
Compare
TFTR @andreimatei! I took the final tidbits of advice to clean things up :). Review status: 0 of 10 files reviewed at latest revision, 24 unresolved discussions, all commit checks successful. pkg/base/config.go, line 491 at r17 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/base/config.go, line 491 at r17 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Thanks for the suggestion! :) The code comment was a byproduct of exactly what you mentioned -- a tension between two desires and not knowing the right pattern, which was very dissatisfying. (In hindsight, I should have called this out to get advice.) I made the change to use a constructor instead of pkg/base/test_server_args.go, line 39 at r17 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/server/config.go, line 124 at r17 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease.go, line 123 at r18 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. pkg/sql/lease_internal_test.go, line 759 at r15 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Yea, I can agree with that. Related: it doesn't appear that there is any test server cleanup for leases. The lease cleanup doesn't appear to happen in server.Stopper().AddCloser(
stop.CloserFn(func() {
// ... clean up leases
})) pkg/sql/lease_test.go, line 312 at r18 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Huh, yea Comments from Reviewable |
Previously, the global LeaseDuration value was modified during a test.
If this test is run in parallel, this would cause problems. The global
has now been modified to live on the LeaseStore where it can be modified
in tests safely for the life of the test.
This changes the acquisition of leases to use singleflight to reduce the
complexity of handling concurrent acquisitions. The behaviour is kept
the same as we block on the results of singleflight.DoChan. The change
is in preparation for adding a new codepath which acquires leases
asynchronously.
This also refactors out the jitter multiplier into a constant.
cc: @vivekmenezes @andreimatei