-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
Receive packet after each block insert, so profile events are not missed #392
Merged
xzkostyan
merged 8 commits into
mymarilyn:master
from
insomnes:fix-long-insert-profile-events
Oct 19, 2023
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
015eac6
Receive packet after each block insert, so profile events are not missed
insomnes d52f4ab
Fix linter
insomnes 0cf555c
Extract receive_profile_events to Connection
insomnes 4ec897f
Use proper table in test for backward compatability
insomnes a1eeedc
Remove send_receive_timeot setting, add test and settings explaning c…
insomnes ce63ac6
Mock receive_end_of_query with 2 seconds sleep before call
insomnes 7bb9a63
Add receive_end_of_insert_query, move receive_profile_events to Clien…
insomnes a771321
Add extra packet types in receive_* methods according to server side …
insomnes 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
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,33 @@ | ||||||
from tests.testcase import BaseTestCase | ||||||
|
||||||
|
||||||
class LongInsertTestCase(BaseTestCase): | ||||||
client_kwargs = { | ||||||
'settings': { | ||||||
'insert_block_size': 1, | ||||||
'send_timeout': 1, | ||||||
'receive_timeout': 1, | ||||||
}, | ||||||
} | ||||||
|
||||||
def test_long_insert(self): | ||||||
""" | ||||||
In this test we are trying to emulate the situation, where we have a | ||||||
lot of insert blocks. From specific clickhouse version server would | ||||||
send ProfileEvents packet in response to each insert. | ||||||
|
||||||
This insert should work normally for all clickhouse versions, | ||||||
even without response ProfileEvents on each insert. | ||||||
The 100_000 rows used to provide somewaht consistent experience of | ||||||
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.
Suggested change
|
||||||
bug reproducability without too long test duration. | ||||||
|
||||||
`send_timeout` & `receive_timeout` are set to 1, | ||||||
so we can emulate the real world situation on synthetic data. | ||||||
The server will send exception and timeout if the client will not | ||||||
receive the ProfileEvent during this time. | ||||||
""" | ||||||
with self.create_table('x Int32'): | ||||||
data = [{'x': 1}] * 100_000 | ||||||
self.client.execute( | ||||||
'INSERT INTO test (x) VALUES', data | ||||||
) |
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.
I would say that this settings deserves some comments:
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.
@insomnes we have time limit of 10s for each test. Is 5s enough for reproducing? It seems that
pytest-timer
applies timeout to all test without any exceptions.Should we patch
connection.receive_profile_events
orread_varint
with following mock to ensure this test works?See
tests.test_connect.ConnectTestCase.test_alt_hosts
for inspiration.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.
@xzkostyan thank you for the clarification. I would need a bit of time to wrap my head around this. This test depends on server behavior and I can't come up with an appropriate mock from the get-go.
With the unpatched function and this synthetic data, this will for sure error in the first 5 seconds as
ServerException
if we were inserting quickly enough or as our socket'sConnectionResetError
.With the patched one it would take a long for the proper ending cause we process 100 000 ProfileEvents packets on new server versions.
Maybe a mock that passes if we don't catch
ServerException
orConnectionResetError
in the first 7 seconds would be ok.I will try to think about it a bit more and come back with a solution.
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.
@xzkostyan sorry for the long pause.
I've tried to emulate the situation of bug with adding of small sleep before calling
receive_end_of_query
inClient
.And lowered the row count. This configuration still reproduces the bug on unpatched version, but runs normally and under 7-8 seconds in patched one.
What do you think?
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.
Just out of curiosity I looked at this change, and this hack looks nice, though it was not clear how it works at first glance (when the driver do not receive profile events it will call receive_end_of_query, which will read all ProfileEvents and also EndOfStream, but it will sleep each time to 2 seconds, so eventually the server will timed out, and it does not timed out for EndOfStream, because it will be written to socket buffer)
But I think that it should be fixed differently, instead
receive_end_of_query
should not handleProfileEvents
forINSERT
(they still should be handled for SELECT though), so I think there should be separatereceive_end_of_insert_query
that will not handle them, and then it will be enough to send one block in this test, without any timeouts trickery.And this will match with how ClickHouse handle this protocol internally for INSERT, so this is preferable I would say.
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.
Something like this - https://gist.github.com/azat/da85ff0bde3f0da259144b0ba361cd64
BTW it also founds one problem in this patch - missing reading of ProfileEvents after empty block
P.S. @insomnes this patch is done on top of your latest 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.
@xzkostyan hello again!
I've applied @azat suggestion with a slight adjustment of moving method to client, and accepting possible Progress event in it (I found the possibility of Progress packet coming before ProfileEvents in test). Azat confirmed that it is normal and expected behavior from the server side.
There is only a simple insert test now. I have deleted the previous one, cause it still fails due to timeout inside github.
If you think, that some more direct test should be applied, maybe we can check that
receive_end_of_query
is not called andreceive_end_of_insert_query
has not get anyProfileEvents
packet in it.This breaks backward compatibility in some sens, so If you think this should be made other way, I would be happy to change code according to your vision.