Fix compressed spooling: compare decoded length against integer segment sizes - #624
Fix compressed spooling: compare decoded length against integer segment sizes#624arpitjain099 wants to merge 1 commit into
Conversation
|
Thanks for digging into this. I tried to reproduce the failure before merging and couldn't get it to happen against a real coordinator. Were you able to reproduce this? I checked out this branch reverted just the int(...) casts to get back to the old behavior and ran it against a coordinator with spooling and json+zstd/json+lz4 enabled. I didn't see any failures. I also printed type(metadata["segmentSize"]) directly in the decoder and it came back as int, not str. I think the existing int(...) cast in There might be a bug in trino/client.py has ignore_errors = true in mypy config so nothing catches this mismatch. We should instead fix the annotation and the test fixtures directly instead of adding casts around it. |
|
No, I could not reproduce it against a real coordinator. I do not have one with spooling enabled, and I should have said that in the PR rather than leaving it implied. My test built its metadata from Your diagnosis fits better: the annotation is wrong, the fixtures inherited the error, and Happy to redo this as the fix you described: correct |
|
yes, please adjust the PR to fix the incorrect fixtures and see if mypy can be enabled to catch this in the future. |
_SegmentMetadataTO declared segmentSize and uncompressedSize as str. A coordinator sends them as JSON numbers, so the annotation was wrong and the fixtures in test_client_spooling.py and test_client.py copied the error, which is what made this look like a str-vs-int bug at runtime. Correct the annotation, put integers in the fixtures, and drop the leftover int() in Lz4QueryDataDecoder.decompress that the wrong annotation made look necessary. trino.client has ignore_errors = true in the mypy config, so nothing flagged the mismatch. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
23813f5 to
deba88b
Compare
|
Done in deba88b, force-pushed over the branch and rebased onto current master. The change is now what you described:
The test I had added asserted the wrong premise, so I replaced it rather than adjusting it. There are now two: one that a zstd segment round-trips with integer sizes, and one that a mismatched On mypy, the short answer is that enabling it would not have caught this, and I would rather show you the numbers than assert that. Everything below is mypy 1.13.0, the version pinned in Dropping That is its own cleanup, not something to fold in here. But more to the point, none of those 85 is this bug. With the old What does catch it is which is exactly the two lines this PR started from, and both disappear with the corrected annotation. It is not free, though. Turning it on for this module also reports three things that are not bugs: I have that working locally and it comes out clean, but it is a long disable list that will drift, and it is a different change from this one. Happy to push it here, send it as a separate PR, or leave it. Your call. Unit tests: 376 passed. The 5 failures in |
Description
CompressedQueryDataDecoder.decodeguards the compressed spooling path by checking the segment length against the sizes the coordinator reports in the segment metadata. Those sizes arrive as strings (the_SegmentMetadataTOTypedDict typessegmentSizeanduncompressedSizeasstr, and the metadata built across the spooling tests uses string values like"10"), but the code compared them directly tolen(data), which is an int. An int is never equal to a decimal string, sonot len(data) == metadata["segmentSize"]is always true and every compressed segment raisedRuntimeErrorbefore it was ever decompressed. The error text gives it away, it reads "Expected to read 29 bytes but got 29" and still raises.This makes json+zstd and json+lz4 spooling unusable from the client even though both encodings are advertised in the
X-Trino-Encodingheader. The lz4 path already coerces the size withint(...)when callinglz4.block.decompress, so the two size checks here just needed the same treatment.The fix wraps both metadata sizes in
int()before comparing, matching the existing lz4 code. I also added a unit test that decodes a real zstd-compressed segment with the string-typed metadata the protocol actually sends. It fails against the old code with the "expected N, got N" RuntimeError and passes with the fix. The existing spooling tests missed this because they all decode withencoding="json"or mock the decoder, so the compressed decode path had no coverage.Non-technical explanation
Compressed results returned through the spooling protocol were always rejected with an error. This fixes the size check so compressed segments decode correctly.
Release notes
(x) Release notes are required, with the following suggested text: