-
Notifications
You must be signed in to change notification settings - Fork 453
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
Visibility into and ability to limit number of encoders per block #2516
Changes from 8 commits
a811e7a
8a19a65
ed9ec58
4da6348
fcd69ca
631c485
2d79572
7cee5b7
2621b36
340b5ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// +build integration | ||
|
||
// Copyright (c) 2020 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package integration | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/m3db/m3/src/dbnode/client" | ||
"github.com/m3db/m3/src/x/ident" | ||
xtime "github.com/m3db/m3/src/x/time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestEncoderLimit(t *testing.T) { | ||
if testing.Short() { | ||
t.SkipNow() | ||
} | ||
|
||
// We don't want a tick to happen during this test, since that will | ||
// interfere with testing encoders due to the tick merging them. | ||
testOpts := NewTestOptions(t).SetTickMinimumInterval(time.Minute) | ||
testSetup, err := NewTestSetup(t, testOpts, nil) | ||
require.NoError(t, err) | ||
defer testSetup.Close() | ||
|
||
log := testSetup.StorageOpts().InstrumentOptions().Logger() | ||
require.NoError(t, testSetup.StartServer()) | ||
log.Info("server is now up") | ||
|
||
defer func() { | ||
require.NoError(t, testSetup.StopServer()) | ||
log.Info("server is now down") | ||
}() | ||
|
||
now := testSetup.NowFn()() | ||
|
||
db := testSetup.DB() | ||
mgr := db.Options().RuntimeOptionsManager() | ||
encoderLimit := 5 | ||
newRuntimeOpts := mgr.Get().SetEncodersPerBlockLimit(encoderLimit) | ||
mgr.Update(newRuntimeOpts) | ||
|
||
session, err := testSetup.M3DBClient().DefaultSession() | ||
require.NoError(t, err) | ||
nsID := testNamespaces[0] | ||
seriesID := ident.StringID("foo") | ||
|
||
for i := 0; i < encoderLimit+5; i++ { | ||
err = session.Write( | ||
nsID, seriesID, | ||
// Write backwards so that a new encoder gets created every write. | ||
now.Add(time.Duration(50-i)*time.Second), | ||
123, xtime.Second, nil, | ||
) | ||
|
||
if i >= encoderLimit { | ||
require.Error(t, err) | ||
// A rejected write due to hitting the max encoder limit should be | ||
// a bad request so that the client knows to not repeat the write | ||
// request, since that will exacerbate the problem. | ||
require.True(t, client.IsBadRequestError(err)) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
} | ||
|
||
for i := 0; i < 10; i++ { | ||
err = session.Write( | ||
nsID, seriesID, | ||
now.Add(time.Duration(51+i)*time.Second), | ||
123, xtime.Second, nil, | ||
) | ||
|
||
// Even though we're doing more writes, these can fit into existing | ||
// encoders since they are all ahead of existing writes, so expect | ||
// no errors writing. | ||
require.NoError(t, err) | ||
} | ||
|
||
// Now allow an unlimited number of encoders. | ||
encoderLimit = 0 | ||
newRuntimeOpts = mgr.Get().SetEncodersPerBlockLimit(encoderLimit) | ||
mgr.Update(newRuntimeOpts) | ||
|
||
for i := 0; i < 20; i++ { | ||
err = session.Write( | ||
nsID, seriesID, | ||
now.Add(time.Duration(20-i)*time.Second), | ||
123, xtime.Second, nil, | ||
) | ||
|
||
// Now there's no encoder limit, so no error even though each of these | ||
// additional writes create a new encoder. | ||
require.NoError(t, err) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,8 @@ const ( | |
var ( | ||
timeZero time.Time | ||
errIncompleteMerge = errors.New("bucket merge did not result in only one encoder") | ||
errTooManyEncoders = xerrors.NewInvalidParamsError(errors.New("too many encoders per block")) | ||
logger, _ = zap.NewProduction() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why create this here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch... not sure where that came from. |
||
) | ||
|
||
const ( | ||
|
@@ -506,6 +508,8 @@ func (b *dbBuffer) Tick(blockStates ShardBlockStateSnapshot, nsCtx namespace.Con | |
} | ||
} | ||
|
||
buckets.recordActiveEncoders() | ||
|
||
// Once we've evicted all eligible buckets, we merge duplicate encoders | ||
// in the remaining ones to try and reclaim memory. | ||
merges, err := buckets.merge(WarmWrite, nsCtx) | ||
|
@@ -1156,6 +1160,16 @@ func (b *BufferBucketVersions) mergeToStreams(ctx context.Context, opts streamsO | |
return res, nil | ||
} | ||
|
||
func (b *BufferBucketVersions) recordActiveEncoders() { | ||
var numActiveEncoders int | ||
for _, bucket := range b.buckets { | ||
if bucket.version == writableBucketVersion { | ||
numActiveEncoders += len(bucket.encoders) | ||
} | ||
} | ||
b.opts.Stats().RecordEncodersPerBlock(numActiveEncoders) | ||
} | ||
|
||
type streamsOptions struct { | ||
filterWriteType bool | ||
writeType WriteType | ||
|
@@ -1266,7 +1280,13 @@ func (b *BufferBucket) write( | |
return err == nil, err | ||
} | ||
|
||
// Need a new encoder, we didn't find an encoder to write to | ||
// Need a new encoder, we didn't find an encoder to write to. | ||
maxEncoders := b.opts.RuntimeOptionsManager().Get().EncodersPerBlockLimit() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be good to add tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
if maxEncoders != 0 && len(b.encoders) >= int(maxEncoders) { | ||
b.opts.Stats().IncEncoderLimitWriteRejected() | ||
return false, errTooManyEncoders | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one addition: a metric indicating a write was rejected due to this reason (can be done at this level) or you can make it ns/db level based on a check of an exported error, your call. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, that's what |
||
} | ||
|
||
b.opts.Stats().IncCreatedEncoders() | ||
bopts := b.opts.DatabaseBlockOptions() | ||
blockSize := b.opts.RetentionOptions().BlockSize() | ||
|
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.
nice test!