Repository navigation
Fix segment result handling in pg_lock_status() - #2424
Open
protectione055 wants to merge 1 commit into
Open
protectione055 wants to merge 1 commit into
protectione055 wants to merge 1 commit into
Conversation
In coordinator mode, pg_lock_status() previously parsed text-format segment rows manually with atoi()/atoll(), which corrupted timestamptz values (waitstart) and could mishandle unsigned OID/XID values. Use BuildTupleFromCStrings() to decode columns via their type input functions instead. Also fix two edge cases in segment result handling: - Skip empty segment result sets before reading the next row to avoid out-of-bounds access. - Register a MemoryContextCallback on multi_call_memory_ctx and clear results on column-count mismatch so libpq PGresults are not leaked on early termination or error. Also fix the error message in interpret_exec_location() to report "invalid exec location" instead of "invalid data access".
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Problem
Querying
pg_lockson the coordinator returns corruptedwaitstarttimestamps for waiting locks on segments.For example, when two sessions concurrently insert the same primary key so session 2 blocks on a segment:
Before :
Root Cause
In
pg_lock_status(), the coordinator dispatches a query to segments and receives rows in text format, then parses them manually withatoi()/atoll(). Forwaitstart(timestamptz),atoll()stops at the year prefix ("2026") and treats it as2026microseconds since the PostgreSQL epoch (2000-01-01). Similarly, unsignedoid/xidcolumns are parsed with signedatoi().Fix
atoi()/atoll()parsing withBuildTupleFromCStrings()so all segment columns are decoded via their type input functions.MemoryContextCallback(pg_lock_status_cleanup) and clearPGresulton column-count mismatch so libpq results are not leaked on early termination or error.interpret_exec_location()(src/backend/commands/functioncmds.c): report"invalid exec location"instead of"invalid data access".After :
Type of Change
Test Plan
src/test/isolation2/sql/pg_locks_segment.sql)make installcheckmake -C src/test installcheck-cbdb-parallelVerification details:
pg_locks_segmenton two independent 3-segment clusters comparing before vs after:waitstart_okfor the waiting lock on segment 0 changed fromftot.Checklist