Skip to content

Backport CI improvements and bug fixes to REL_2_STABLE - #2398

Open
Vlasdislav wants to merge 18 commits into
apache:REL_2_STABLEfrom
Vlasdislav:backport/rel2-ci-rat-batch
Open

Vlasdislav wants to merge 18 commits into
apache:REL_2_STABLEfrom
Vlasdislav:backport/rel2-ci-rat-batch

Conversation

@Vlasdislav

@Vlasdislav Vlasdislav commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Following the batch backports in #1936 and #2066, this PR backports 18 commits already merged into main to REL_2_STABLE. It includes the changes proposed in #2395, #2396, and #2397.

Cherry-picked commits

  • cd260a80358 enables WAL replication tests in Rocky Linux CI. The existing test code already matches the stable branch APIs.
  • df3a166f2a3 (Fix typo in RAT exclusion tag #2344) fixes the RAT exclusion for two distribution policy fixtures.
  • d4a669dc2fb (Run additional contrib regression tests in CI #2347) enables four contrib regression suites and makes the intarray distribution key explicit.
  • cba3cd5fb51 (Run gp_distribution_policy regression tests in CI #2345) enables gp_distribution_policy regression tests in Rocky Linux, Debian, and debug CI.
  • 5d30105f3df restores parallel regressions in debug CI, handles empty matrices, and reduces runner disk use.
  • 1c48a582e71 (Fix gzip external table reads #2338) keeps the gzip decoder alive across external-table row resets.
  • 6bff6d90a6f makes gpload report database errors in update and merge modes.
  • 394e7c5c6f3 keeps SegmentReconfigurer retrying after a connection failure.
  • 935af7475a5 fixes gpexpand tablespace detection by matching directory names to numeric OIDs.
  • 4fe60951b80 fixes an unaligned read of the UDP tuple chunk length.
  • b6104f71b22 fixes an unaligned word load in the HLL hash.
  • 4366425a51e serializes concurrent gpstop invocations with a shutdown lock.
  • 0d775034d76 fixes an unaligned read when decoding commit WAL.
  • e8aaef1b852 (Fix double KeyboardInterrupt on PL/Python cancel #2185) prevents duplicate PL/Python cancellation callbacks.
  • 1480f4f636c bounds UDP cursor history in read-only sessions by pruning on local transaction ID changes.
  • b83afbe00db serializes shared snapshot slot ID changes with directory scans.
  • 85b06fd9023 (Preserve parameterization in Append locus filters #2336) preserves parameterization in Append locus filters.
  • 757eeb18213 (Fix ORCA parameter dependencies and Material rescan shielding #2149) recalculates ORCA execution-parameter dependencies on the final plan and lets Material rescan children without Motion. This addresses stale rows in correlated subqueries such as the filtered unnest(a) in the intarray regression test. The backport includes the upstream ORCA regression tests.

Vlasdislav and others added 17 commits November 22, 2026 17:17
(cherry picked from commit df3a166)
Add the installcheck tests of fuzzystrmatch, intarray, isn, and
unaccent to the contrib test jobs in the Rocky Linux and Debian
workflows. The debug workflow gets these tests in a new
"ic-contrib-extra" job.

The intarray test creates the more__int table with CREATE TABLE AS
and does not set a distribution key. Cloudberry then selects a key
and writes a NOTICE and a HINT, which makes the expected output
fragile. Add "DISTRIBUTED BY (b)" to the statement and remove the
two messages from the expected output.

(cherry picked from commit d4a669d)
The debug workflow can generate an empty test matrix, which GitHub
Actions rejects before starting the test job. Skip the job when the
matrix is empty and report that no tests were configured, while still
reporting build, matrix preparation, and test failures.

Restore the parallel regression test in the debug workflow and free
disk space on the runner before testing. Disable profiling in debug
builds to reduce disk usage.

(cherry picked from commit 5d30105)
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)
When the UPDATE, DELETE or INSERT statement run by gpload in update or
merge mode failed, the error handler called

    str(str(e), errors = 'ignore')

This is a leftover of the Python 2 unicode(..., errors='ignore') idiom.
On Python 3, str() only accepts 'errors' when its argument is bytes, so
the handler raised "TypeError: decoding str is not supported". The real
database error was never logged; users only saw "unexpected error --
backtrace written to log file".

Both values are already str on Python 3, so use them directly.

Update the expected output of tests 497 (bad UPDATE_CONDITION) and 75
(merge with non-ASCII column names), which had captured the "unexpected
error" message instead of the database error.

(cherry picked from commit 6bff6d9)
reconfigure() tries to connect again until the mirrors are promoted.
When the connection fails, the except block closes conn.  But when the
first connection fails, conn has no value yet:

  UnboundLocalError: local variable 'conn' referenced before assignment

The error goes out of the retry loop, so gprecoverseg and gpstart stop
and do not wait for the promotion.  In later tries, conn is the closed
connection of the previous try.

Set conn to None before each try, and close it only if it is set.
Now test_unit_segment_reconfigurer passes 3 of 3, instead of 1.

Greenplum fixed this as part of the change to psycopg2 (b5920e061b4).
That change does not apply to Cloudberry, which still uses PyGreSQL.

Backpatch-through: REL_2_STABLE
Assisted-by: Claude Code
(cherry picked from commit 394e7c5)
Previously, gpexpand compared tablespace OIDs returned as strings by
os.listdir() against integer keys from the pg_tablespace query, so the
checks always evaluated to False. This skipped tablespace template
generation and left broken symlinks on new segments.

- read_tablespace_file() now casts the OID to int before the lookup
- generate_tablespace_inputfile() now casts the OID to int before the
  lookup
- generate_tablespace_inputfile() now skips entries in pg_tblspc without
  a pg_tablespace row instead of raising KeyError
- Added unit tests covering both methods, including an entry in pg_tblspc
  without a matching pg_tablespace row

Fixes apache#1885

(cherry picked from commit 935af74)
UBSan reported an unaligned uint16 load while parsing tuple chunks.
Copy the length into an aligned local with memcpy before adding the
header size, preserving the existing native-endian interpretation.

Sanitizer report (UBSan, instrumented build, distributed query with
Motion traffic over UDP):
  ic_udpifc.c:4572:39: runtime error: load of misaligned address
  0x52500016fa59 for type 'uint16', which requires 2 byte alignment
  #0 RecvTupleChunkUDPIFC ic_udpifc.c:4572
  #1 receiveChunksUDPIFCLoop ic_udpifc.c:4462
  #2 receiveChunksUDPIFC ic_udpifc.c:4406
  #3 RecvTupleChunkFromAnyUDPIFC ic_udpifc.c:4739
  apache#4 processIncomingChunks cdb/cdbmotion.c:653
  apache#5 RecvTupleFrom cdbmotion.c:607
  apache#6 execMotionUnsortedReceiver executor/nodeMotion.c:356
Reached whenever bytesProcessed walks the receive buffer past an
even offset while splitting a message into tuple chunks. Benign on
x86_64, but undefined behavior on strictly aligned targets.

(cherry picked from commit 4fe6095)
UBSan reported an unaligned uint64_t load in GpMurmurHash64A.
Read each word with memcpy so input need not have uint64_t alignment,
while preserving the little-endian hash computation.

Sanitizer report (UBSan, instrumented build, ANALYZE on a table with
short text values):
  gp_hyperloglog.c:897:11: runtime error: load of misaligned address
  0x529000093515 for type 'uint64_t', which requires 8 byte alignment
  #0 GpMurmurHash64A gp_hyperloglog.c:897
  #1 gp_hll_add_element gp_hyperloglog.c:471
  #2 gp_hyperloglog_add_item gp_hyperloglog.c:788
  #3 compute_scalar_stats commands/analyze.c:3968
  apache#4 do_analyze_rel commands/analyze.c:971
  apache#5 analyze_rel_internal commands/analyze.c:429
Triggered by ordinary ndistinct estimation during ANALYZE: short varlena
values hashed via VARDATA_ANY have a payload offset that is not a
multiple of 8. Benign on x86_64, but undefined behavior on strictly
aligned targets.

(cherry picked from commit b6104f7)
gpstop calls simple_main without mainOptions, so simple_main is never
told to hold a lock and nothing stops a second gpstop starting against a
cluster the first one is still shutting down. GPSTOPPID appears nowhere
in the tree.

The machinery is all here and in use: gprecoverseg asks for
gprecoverseg.lock the same way, gpmovemirrors for its own, and
SimpleMainLock builds the directory and writes the pid. Only gpstop's
half of it was lost.

gpstop.feature has covered this the whole time and could not pass:

    Then a sample gpstop.lock directory is created using the background
         pid in coordinator_data_directory
     And the user runs "gpstop -a"
     And gpstop should print "gpstop.lock indicates that an instance of
         gpstop is already running" to stdout

together with the scenario that a leftover empty lock directory is
cleaned up rather than treated as a live lock.

Split out of apache#1639 (originally 45a1155).

(cherry picked from commit 4366425)
UBSan reported a misaligned member access when decoding the
distributed-transaction field of commit WAL records during
crash-recovery redo. The WAL record payload has no alignment
guarantee; the neighboring xl_origin branch already copies onto the
stack for exactly this reason. Do the same for xl_xact_distrib.

Sanitizer report (UBSan, instrumented build, crash recovery):
  xactdesc.c:155:34: runtime error: member access within misaligned
  address 0x7b39d104de44 for type 'struct xl_xact_distrib', which
  requires 8 byte alignment
  #0 ParseCommitRecord xactdesc.c:155
  #1 xact_redo xactdesc.c:...
  #2 ApplyWalRecord xlogrecovery.c:2023
  #3 PerformWalRecovery xlogrecovery.c:1845
Undefined behavior at recovery time; harmless on x86_64 but
incorrect on strictly aligned targets.

(cherry picked from commit 0d77503)
statement_timeout, lock_timeout, and client cancel requests send
SIGINT both to the backend's process group and to the backend itself.
PLy_handle_cancel_interrupt() queued a KeyboardInterrupt callback for
each signal, so the second one aborted the except or finally block
handling the first, or failed the next PL/Python call in the session.

Keep at most one callback queued, and ignore a callback that runs
after the cancellation has already been processed.

Related to apache#2181

Co-authored-by: Leonid <63977577+leborchuk@users.noreply.github.com>
(cherry picked from commit e8aaef1)
…uted xid

SetupUDPIFCInterconnect_Internal() records one CursorICHistoryEntry per
interconnect instance on the QD and prunes old entries only when the
statement runs in a different transaction than the previous one, using
the distributed xid as the transaction identity.  Distributed xids are
assigned lazily (only for transactions that write or are dispatched
two-phase), so autocommit read-only statements always see
InvalidDistributedTransactionId on both sides of the comparison.  The
table is therefore never pruned on read-only sessions and grows by one
48-byte entry per Motion-containing statement for the life of the
backend (2.8 MB after 60000 statements, plus the heap fragmentation the
steady stream of small long-lived allocations induces).

Use MyProc->lxid instead: it is assigned to every top-level transaction,
including read-only ones, and stays constant within a transaction block,
so entries belonging to cursors that are still open in the current
transaction remain protected exactly as before.

Verified on a single long-lived session running the queries from apache#1947:
UdpInterconnectMemContext grew 0 -> 2814 KB over 60000 statements before
the change and stays at 12 KB after it; RssAnon went 12.7 -> 24.6 MB
before and is flat at 14.4 MB after.  Pruning still does not happen
inside an explicit transaction block or while a cursor is open, and
FETCH from an open cursor after 300 intervening statements works.

Related: apache#1947
(cherry picked from commit 1480f4f)
GpDropTempTables() updates slotid under the per-slot lock, while
SharedSnapshotAdd() and SharedSnapshotLookup() scan slot IDs under
SharedSnapshotLock. These locks do not serialize the update with
concurrent directory scans.

Acquire SharedSnapshotLock exclusively before the existing per-slot
lock when updating slotid during a session reset. Retain the per-slot
lock for slot-local readers and release the locks in reverse order.

Assisted-by: ChatGPT
(cherry picked from commit b83afbe)
Keep the child path parameterized when adding a segment-filter Result below a mixed-locus Append. Add a regression case for the replicated-parent and distributed-child path.

Reproduced in SQLLancer run

(cherry picked from commit 85b06fd)
@Vlasdislav

Copy link
Copy Markdown
Collaborator Author

@tuhaihe, I made as we discussed: #2397 (comment)

@Vlasdislav

Vlasdislav commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator Author

I see problem from contrib/intarray I'm trying to solve it, but perhaps we'll merge the change as it is, because this problem we need to solve in other PR.

…#2149)

* Fix ProjectSet parameter dependencies after SRF tree construction

Compute parameter dependency bitmaps only after ProjectSet target lists
and child links are complete. Otherwise correlated SRFs can lose rescan
notifications and a Sort can return rows from a previous invocation.

Recompute every generated ProjectSet and the optional top Result, so
nested SRFs inherit parameters referenced below an OUTER_VAR projection.
Add regression coverage for changing arrays, NULL/empty inputs,
duplicates, and nested SRFs on colocated outer rows.

* Compute ORCA parameter dependencies after final plan transformations

Replace translator-local SetParamIds calls with a final-plan walk in
optimize_query(), after redundant Results have been removed. Visit the
main tree and every subplan, and include only PARAM_EXEC dependencies.

Shield Material children from rescans only when their subtree contains a
Motion. Free the temporary Motion list after checking it.

Retain the ProjectSet regressions and cover a no-SRF Result with a
one-time filter above a parameterized Limit/Sort/ProjectSet. The original
PR returns 2,2,2,2 instead of 2,5,NULL,5 for changing inputs there.
Add Material rescan coverage and repeated generic prepared executions.

Adapted from the downstream patch shared in:
apache#2149 (comment)

Co-authored-by: Zhang Wenchao <zhangwenchao@apache.org>
Assisted-by: Codex

* Remove obsolete parameter setup from parallel Append

TranslateDXLParallelAppend still called SetParamIds after parameter
dependency computation moved to the final ORCA plan walk. Remove the
orphaned call so the current main-based PR builds again.

Assisted-by: Codex

---------

Co-authored-by: Zhang Wenchao <zhangwenchao@apache.org>
(cherry picked from commit 757eeb1)
@Vlasdislav

Copy link
Copy Markdown
Collaborator Author

I see problem from contrib/intarray I'm trying to solve it, but perhaps we'll merge the change as it is, because this problem we need to solve in other PR.

Cherry-pick 757eeb1 from main did help me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants