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

Enforce lookup limit for storage #312

Merged
merged 6 commits into from
Sep 7, 2018
Merged

Enforce lookup limit for storage #312

merged 6 commits into from
Sep 7, 2018

Conversation

egonelbre
Copy link
Member

@egonelbre egonelbre commented Sep 6, 2018

Enforces lookup limits for store implementations.

I'm not sure whether to change the limit = 0 means as much as possible behavior. I think the reason for this approach is that when you don't specify a value in API requests it defaults to 0, and you are unlikely to want 0 items.


This change is Reviewable

@cla-bot cla-bot bot added the cla-signed label Sep 6, 2018
@coveralls
Copy link

coveralls commented Sep 6, 2018

Pull Request Test Coverage Report for Build 3335

  • 8 of 8 (100.0%) changed or added relevant lines in 3 files are covered.
  • 13 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.1%) to 67.13%

Files with Coverage Reduction New Missed Lines %
pkg/eestream/piecebuf.go 13 84.49%
Totals Coverage Status
Change from base Build 3333: -0.1%
Covered Lines: 4248
Relevant Lines: 6328

💛 - Coveralls

@kaloyan-raev
Copy link
Member

I think that semantically "no limit" is a good zero value for limit.

// TODO: this shouldn't be probably the case
limit = unlimited
if limit > LookupLimit {
return nil, ErrLimitExceeded
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it better to override the user-defined limit with the internal LookupLimit? This proposal is just for the list methods, not for GetAll.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not feeling in any particular direction.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@@ -30,7 +30,7 @@ var (
// ListPageLimit is the maximum number of items that will be returned by a list
// request.
// TODO(kaloyan): make it configurable
const ListPageLimit = 1000
const ListPageLimit = storage.LookupLimit
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we still need this const here and the check in the List method, if this limit check is now handled in the DB.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking about it, I also thought about how to configure it. There are a few roads we could take:

  1. Remove the limit from KeyValueStore and enforce it at service level.
  2. Add a wrapper around KeyValueStore that enforces such limits.

As usual with these things, since the cost of defensive programming here isn't high, it can be duplicated in both places.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I'll remove it for now and let's revisit the problem when making it configurable.

nfarah86
nfarah86 previously approved these changes Sep 6, 2018
@nfarah86
Copy link
Contributor

nfarah86 commented Sep 6, 2018

@kaloyan-raev do you approve as . well?

@nfarah86
Copy link
Contributor

nfarah86 commented Sep 6, 2018

pr 318 fixes the integration failure - once that is fixed, integration should pass here. I'll leave my approve, assuming the fix will be merged first.

@nfarah86 nfarah86 dismissed their stale review September 6, 2018 22:20

some change suggestions

@@ -19,6 +19,9 @@ var ErrKeyNotFound = errs.Class("key not found")
// ErrEmptyKey is returned when an empty key is used in Put
var ErrEmptyKey = errors.New("empty key")

// ErrLimitExceeded is returned when request limit is exceeded
var ErrLimitExceeded = errors.New("limit exceeded")
Copy link
Contributor

Choose a reason for hiding this comment

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

so i know we had this discussion in the golang channel (so feel free to ignore) if you wanted to add a . class here; jt mentions, if it seems right, he prefers zeebo/errs

Copy link
Member

Choose a reason for hiding this comment

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

yeah, my preferences are just preferences. i would prefer to not have to grep to find where "limit exceeded" is in the codebase if i hit this error to understand what went wrong, but i can be convinced that specific error cases like this are fine

@@ -10,6 +10,7 @@ import (
"storj.io/storj/storage"

"github.com/google/go-cmp/cmp"
Copy link
Member

Choose a reason for hiding this comment

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

oh i like this package!

@egonelbre egonelbre merged commit 79354bf into master Sep 7, 2018
@egonelbre egonelbre deleted the enforce-lookup-limit branch September 7, 2018 09:00
iglesiasbrandon pushed a commit that referenced this pull request Dec 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants