From 705f4f0d0fb9289787337a328e622091601b3f9c Mon Sep 17 00:00:00 2001 From: Ryan Allen Date: Tue, 15 Sep 2020 20:54:45 -0400 Subject: [PATCH] [dbnode] query limits - missed commit with feedback (#2640) --- src/dbnode/server/server.go | 2 +- src/dbnode/storage/limits/noop_query_limits.go | 17 ----------------- src/dbnode/storage/limits/query_limits.go | 8 +++----- src/dbnode/storage/limits/query_limits_test.go | 4 ++-- src/dbnode/storage/limits/types.go | 2 +- 5 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/dbnode/server/server.go b/src/dbnode/server/server.go index b8f48cce49..4b9279f837 100644 --- a/src/dbnode/server/server.go +++ b/src/dbnode/server/server.go @@ -417,7 +417,7 @@ func Run(runOpts RunOptions) { bytesReadLimit.Limit = limitConfig.Value bytesReadLimit.Lookback = limitConfig.Lookback } - queryLimits, err := limits.NewQueryLimits(iopts, docsLimit, bytesReadLimit) + queryLimits, err := limits.NewQueryLimits(docsLimit, bytesReadLimit, iopts) if err != nil { logger.Fatal("could not construct docs query limits from config", zap.Error(err)) } diff --git a/src/dbnode/storage/limits/noop_query_limits.go b/src/dbnode/storage/limits/noop_query_limits.go index 533c7cd2d1..4d940de4f9 100644 --- a/src/dbnode/storage/limits/noop_query_limits.go +++ b/src/dbnode/storage/limits/noop_query_limits.go @@ -57,20 +57,3 @@ func (q *noOpQueryLimits) Start() { func (q *noOpLookbackLimit) Inc(int) error { return nil } - -func (q *noOpLookbackLimit) Exceeded() error { - return nil -} - -func (q *noOpLookbackLimit) Stop() { -} - -func (q *noOpLookbackLimit) Start() { -} - -func (q *noOpLookbackLimit) current() int64 { - return 0 -} - -func (q *noOpLookbackLimit) reset() { -} diff --git a/src/dbnode/storage/limits/query_limits.go b/src/dbnode/storage/limits/query_limits.go index 191669dc20..0c3b907993 100644 --- a/src/dbnode/storage/limits/query_limits.go +++ b/src/dbnode/storage/limits/query_limits.go @@ -25,6 +25,7 @@ import ( "time" "github.com/m3db/m3/src/x/instrument" + "github.com/uber-go/tally" "go.uber.org/atomic" ) @@ -67,9 +68,9 @@ func DefaultLookbackLimitOptions() LookbackLimitOptions { // NewQueryLimits returns a new query limits manager. func NewQueryLimits( - instrumentOpts instrument.Options, docsLimitOpts LookbackLimitOptions, bytesReadLimitOpts LookbackLimitOptions, + instrumentOpts instrument.Options, ) (QueryLimits, error) { if err := docsLimitOpts.validate(); err != nil { return nil, err @@ -133,10 +134,7 @@ func (q *queryLimits) AnyExceeded() error { if err := q.docsLimit.exceeded(); err != nil { return err } - if err := q.bytesReadLimit.exceeded(); err != nil { - return err - } - return nil + return q.bytesReadLimit.exceeded() } // Inc increments the current value and returns an error if above the limit. diff --git a/src/dbnode/storage/limits/query_limits_test.go b/src/dbnode/storage/limits/query_limits_test.go index 8e55458d3b..caf2949619 100644 --- a/src/dbnode/storage/limits/query_limits_test.go +++ b/src/dbnode/storage/limits/query_limits_test.go @@ -42,7 +42,7 @@ func TestQueryLimits(t *testing.T) { Limit: 1, Lookback: time.Second, } - queryLimits, err := NewQueryLimits(instrument.NewOptions(), docOpts, bytesOpts) + queryLimits, err := NewQueryLimits(docOpts, bytesOpts, instrument.NewOptions()) require.NoError(t, err) require.NotNil(t, queryLimits) @@ -53,7 +53,7 @@ func TestQueryLimits(t *testing.T) { queryLimits.DocsLimit().Inc(2) require.Error(t, queryLimits.AnyExceeded()) - queryLimits, err = NewQueryLimits(instrument.NewOptions(), docOpts, bytesOpts) + queryLimits, err = NewQueryLimits(docOpts, bytesOpts, instrument.NewOptions()) require.NoError(t, err) require.NotNil(t, queryLimits) diff --git a/src/dbnode/storage/limits/types.go b/src/dbnode/storage/limits/types.go index ebe027a2df..c187f35a60 100644 --- a/src/dbnode/storage/limits/types.go +++ b/src/dbnode/storage/limits/types.go @@ -28,7 +28,7 @@ import ( type QueryLimits interface { // DocsLimit limits queries by a global concurrent count of index docs matched. DocsLimit() LookbackLimit - // DocsLimit limits queries by a global concurrent count of bytes read from disk. + // BytesReadLimit limits queries by a global concurrent count of bytes read from disk. BytesReadLimit() LookbackLimit // AnyExceeded returns an error if any of the query limits are exceeded.