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

storage: Split storage.Stores #9014

Closed
bdarnell opened this issue Sep 1, 2016 · 7 comments
Closed

storage: Split storage.Stores #9014

bdarnell opened this issue Sep 1, 2016 · 7 comments
Assignees
Labels
C-cleanup Tech debt, refactors, loose ends, etc. Solution not expected to significantly change behavior.
Milestone

Comments

@bdarnell
Copy link
Contributor

bdarnell commented Sep 1, 2016

storage.Stores contains several methods which are only intended for use in tests (LookupReplica, FirstRange, RangeLookup). However, not all tests need them (ones that use a DistSender generally shouldn't, although I was surprised to learn in #8868 that the split snapshot race tests hit this code path), and because Stores.Send "helpfully" calls LookupReplica if RangeID is zero, we could call these methods in production too.

These methods should be removed from Stores and placed on a wrapper object that can be used explicitly by tests that need it, so we can ensure that tests that shouldn't use it don't end up accidentally relying on this behavior.

@bdarnell bdarnell added the C-cleanup Tech debt, refactors, loose ends, etc. Solution not expected to significantly change behavior. label Sep 1, 2016
@tamird
Copy link
Contributor

tamird commented Sep 1, 2016

Would it be sufficient to relocate these methods to helpers_test.go?

On Thu, Sep 1, 2016 at 2:12 AM, Ben Darnell [email protected]
wrote:

storage.Stores contains several methods which are only intended for use
in tests (LookupReplica, FirstRange, RangeLookup). However, not all tests
need them (ones that use a DistSender generally shouldn't, although I was
surprised to learn in #8868
#8868 that the split
snapshot race tests hit this code path), and because Stores.Send
"helpfully" calls LookupReplica if RangeID is zero, we could call these
methods in production too.

These methods should be removed from Stores and placed on a wrapper
object that can be used explicitly by tests that need it, so we can ensure
that tests that shouldn't use it don't end up accidentally relying on this
behavior.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#9014, or mute the thread
https://github.com/notifications/unsubscribe-auth/ABdsPAAXzG2SnTO9AQb4KmxeAe9THAg7ks5qlmzDgaJpZM4JyWT7
.

@bdarnell
Copy link
Contributor Author

bdarnell commented Sep 1, 2016

No; many tests rely on the fact that Stores.Send (prod code) calls Stores.LookupReplica (test code) in certain situations (which are not supposed to happen in prod, although there's nothing that guarantees this). We'll have to break up the type, not just move methods around.

I'm also not sure whether all the tests that rely on this are confined to the storage package. I think so, but again something outside the package could be using this.

@tamird
Copy link
Contributor

tamird commented Sep 1, 2016

I'm not sure I understand.

No; many tests rely on the fact that Stores.Send (prod code) calls Stores.LookupReplica (test code) in certain situations (which are not supposed to happen in prod, although there's nothing that guarantees this). We'll have to break up the type, not just move methods around.

Moving Stores.LookupReplica to helpers_test.go would make Stores.Send not compile as long as it calls Stores.LookupReplica.

I'm also not sure whether all the tests that rely on this are confined to the storage package. I think so, but again something outside the package could be using this.

If this is the case then indeed the only solution will be to have a test-only type that lives in a package which we validate is not imported into prod code.

@bdarnell
Copy link
Contributor Author

bdarnell commented Sep 1, 2016

It sounds to me like you've summed up the situation pretty well; what part do you not understand? We can't move LookupReplica to a test file as long as it's used in Send. We can't remove the call from Send because many tests will start failing.

@tamird
Copy link
Contributor

tamird commented Sep 1, 2016

My suggestion was to move these functions to a test file as a way of getting the compiler to help guide correcting the problem. In case those functions are called directly from test code, this approach will require less work than extracting a new type.

@bdarnell
Copy link
Contributor Author

bdarnell commented Jul 6, 2017

although I was surprised to learn in #8868 that the split snapshot race tests hit this code path

And I was surprised again in #16893 to re-learn that it was still going through this code path. That PR prevents the split snapshot race tests from using this code path, but many other tests in package storage still do.

benesch added a commit to benesch/cockroach that referenced this issue Apr 25, 2018
Thanks to the previous commit, Stores.LookupReplica is now unused save
for a few tests that can be trivially rewritten to call LookupReplica on
the one store within. Rewrite those tests and remove it.

We get to remove Stores.FirstRange, too, since its only caller was the
test for stores.LookupReplica.

Fix cockroachdb#9014.

Release note: None
benesch added a commit to benesch/cockroach that referenced this issue Apr 25, 2018
Thanks to the previous commit, Stores.LookupReplica is now unused save
for a few tests that can be trivially rewritten to call LookupReplica on
the one store within. Rewrite those tests and remove it.

We get to remove Stores.FirstRange, too, since its only caller was the
test for stores.LookupReplica.

Fix cockroachdb#9014.

Release note: None
@benesch benesch self-assigned this Apr 26, 2018
@benesch
Copy link
Contributor

benesch commented May 2, 2018

Fixed by #25061!

@benesch benesch closed this as completed May 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Tech debt, refactors, loose ends, etc. Solution not expected to significantly change behavior.
Projects
None yet
Development

No branches or pull requests

4 participants