Repository navigation
Fix gzip external table reads - #2338
Conversation
There was a problem hiding this comment.
Hi, @aartchik welcome!🎊 Thanks for taking the effort to make our project better! 🙌 Keep making such awesome contributions!
Vlasdislav
left a comment
There was a problem hiding this comment.
Thanks for your PR. We already review the changes in fork: open-gpdb/gpdb#447 so LGTM. But I suggest add to description stack trace about crash for clarity a very unobvious problem.
|
Thanks, the fix looks right to me. NextCopyFrom() runs in rowcontext, so when url_fread() moves to the next file of the glob, the zlib state that gfile allocates with palloc() lands in rowcontext, and the next MemoryContextReset() frees it. copycontext lives until the scan ends. gzip_reader passed in ic-gpcontrib. One thing before it can be merged: rat-check fails because the two new files, |
leborchuk
left a comment
There was a problem hiding this comment.
LGTM, thanks for the contribution!
RAT should be fixed, it was already pointed out
Fix backend crashes when reading gzip files through file:// external tables. Decoder memory can be allocated in the memory context of a single CSV record. Resetting that context frees memory that the decoder still references. On the tested revision, this caused SIGABRT with double free or corruption when finishing decompression. The fix switches to the scan's copycontext while reading external data, so decoder allocations survive per-row context resets. PG_FINALLY restores the caller's memory context on both success and error paths. --------- Co-authored-by: Artur Nasredinov <arturnasredin@yandex-team.ru> Co-authored-by: Leonid <63977577+leborchuk@users.noreply.github.com> (cherry picked from commit 1c48a58)
What does this PR do?
Fix backend crashes when reading gzip files through
file://external tables.Decoder memory can be allocated in the memory context of a single CSV record. Resetting that context frees memory that the decoder still references. On the tested revision, this caused
SIGABRTwithdouble free or corruptionwhen finishing decompression.The fix switches to the scan's
copycontextwhile reading external data, so decoder allocations survive per-row context resets.PG_FINALLYrestores the caller's memory context on both success and error paths.Type of Change
Test Plan
Add
gzip_readerto the existinggp_exttable_fdwregression suite. It generates a 1 MiB CSV containing 8,192 records and two gzip copies, then checks:The test verifies record counts, total message length, and decoded contents. It removes the generated files and tables afterward.
On the original revision:
After rebasing onto
mainatbb5d6931e00, the database was rebuilt and verified again:Validation used a local Linux ARM64 demo cluster with one coordinator and three primary segments, built without ORCA, gpcloud, PAX, or MDB locales. The new test reads files on the coordinator. No new failures attributable to the patch were identified.
Impact
User-facing changes: gzip external-table reads no longer crash in the reproduced scenarios.
Dependencies: No new dependencies.
AI assistance