Skip to content

Commit

Permalink
[#22010] YSQL: Failed txn restarts with UPDATE ... RETURNING queries
Browse files Browse the repository at this point in the history
Summary:
### Issue

UPDATE ... REUTRNING queries fail txn restarts due to conflicts.

### Root Cause

yb_restart_portal does not reset the value of portal->holdContext to NULL.

This in turn fails the assertion in PortalCreateHoldStore.

### Impact

Only affects debug builds.

Backport-through: 2024.1
Jira: DB-10929

Test Plan:
Jenkins

yb_build.sh --java-test TestPgTransparentRestarts#testUpdateLong

Reviewers: pjain, smishra

Reviewed By: pjain

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D34242
  • Loading branch information
pao214 committed Apr 29, 2024
1 parent c86ec8d commit 0ee77be
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Expand Up @@ -496,6 +496,23 @@ public PreparedStatement createStatement(Connection conn) throws Exception {
}
}

/*
* Regression test for #22010
*
* We do not expect read restarts even in the long string case
* since the RETUNRING output is cached in a temporary table
* and only sent back to the client after the update is done.
*/
@Test
public void testUpdateLong() throws Exception {
new RegularDmlStatementTester(
getConnectionBuilder(),
"UPDATE test_rr set i=1 RETURNING *",
getLongString(),
false /* is_deadlock_possible */
).runTest();
}

//
// Helpers methods
//
Expand Down
3 changes: 3 additions & 0 deletions src/postgres/src/backend/tcop/postgres.c
Expand Up @@ -4477,7 +4477,10 @@ yb_restart_portal(const char* portal_name)

/* delete tuplestore storage, if any */
if (portal->holdContext)
{
MemoryContextDelete(portal->holdContext);
portal->holdContext = NULL;
}

/* the portal run context might not have been reset, so do it now */
MemoryContextReset(portal->ybRunContext);
Expand Down

0 comments on commit 0ee77be

Please sign in to comment.