-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Use proper zstd decoder pool for binlog event compression handling #17042
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3124bf6
Use proper zstd decoder pool for binlog event compression handling
mattlord bf0e91d
Address review comment and cleanup
mattlord f2e6ad1
Add unit test
mattlord aa2d87f
Deflake unit test
mattlord 0340b02
Minor change from self review
mattlord 1d8db43
Address review comments
mattlord 3a12360
Address review comments part 2
mattlord e7191f0
Go back to logging on failed stateless decoder creation
mattlord File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
Copyright 2024 The Vitess Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package mysql | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"testing" | ||
|
||
"github.com/klauspost/compress/zstd" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDecoderPool(t *testing.T) { | ||
type args struct { | ||
r io.Reader | ||
} | ||
tests := []struct { | ||
name string | ||
reader io.Reader | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "happy path", | ||
reader: bytes.NewReader([]byte{0x68, 0x61, 0x70, 0x70, 0x79}), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
// It's not guaranteed that we get the same decoder back from the pool | ||
// that we just put in, so we use a loop and ensure that it worked at | ||
// least one of the times. Without doing this the test would be flaky. | ||
used := false | ||
|
||
for i := 0; i < 20; i++ { | ||
decoder, err := statefulDecoderPool.Get(tt.reader) | ||
require.NoError(t, err) | ||
require.NotNil(t, decoder) | ||
require.IsType(t, &zstd.Decoder{}, decoder) | ||
statefulDecoderPool.Put(decoder) | ||
|
||
decoder2, err := statefulDecoderPool.Get(tt.reader) | ||
require.NoError(t, err) | ||
require.NotNil(t, decoder2) | ||
require.IsType(t, &zstd.Decoder{}, decoder) | ||
if decoder2 == decoder { | ||
used = true | ||
} | ||
statefulDecoderPool.Put(decoder2) | ||
|
||
decoder3, err := statefulDecoderPool.Get(tt.reader) | ||
require.NoError(t, err) | ||
require.NotNil(t, &zstd.Decoder{}, decoder3) | ||
require.IsType(t, &zstd.Decoder{}, decoder3) | ||
if decoder3 == decoder || decoder3 == decoder2 { | ||
used = true | ||
} | ||
statefulDecoderPool.Put(decoder) | ||
} | ||
|
||
require.True(t, used) | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we panic here and prevent the process from launching? Option is for the
decompress()
to return an error ifstatefulDecoderPool
failed to initialize.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.
It's better to panic, I think, as this is only allocated once at init() time. If we can't initialize it, we won't be able to run properly. The way the code was previously, it would just continually log errors w/o being able to do much. This should only ever fail if you're very low on memory (ENOMEM). This isn't the decoder pool here, it's the global shared stateless decoder used for smaller payloads.
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 for compressed payloads, right? Is it documented that this failure can only happen for
ENOMEM
. In case there is some other issue withzstd
preventing the executable from launching seems excessive and risky.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.
Yeah, that's true.... maybe I'll just go back to logging like I was before then. It also has the benefit of limiting the changes.
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 went ahead and got rid of the panic and init(): e7191f0
No reason for us NOT to try initializing it again the next time we retry...