From 0ee77be23078517871825b6e7928ae688fbddccb Mon Sep 17 00:00:00 2001 From: Bvsk Patnaik Date: Wed, 17 Apr 2024 13:56:50 -0700 Subject: [PATCH] [#22010] YSQL: Failed txn restarts with UPDATE ... RETURNING queries 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 --- .../org/yb/pgsql/TestPgTransparentRestarts.java | 17 +++++++++++++++++ src/postgres/src/backend/tcop/postgres.c | 3 +++ 2 files changed, 20 insertions(+) diff --git a/java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgTransparentRestarts.java b/java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgTransparentRestarts.java index 243c9a4077a..f78b4ec6986 100644 --- a/java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgTransparentRestarts.java +++ b/java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgTransparentRestarts.java @@ -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 // diff --git a/src/postgres/src/backend/tcop/postgres.c b/src/postgres/src/backend/tcop/postgres.c index 1ab938db2b9..ab5b97fd8aa 100644 --- a/src/postgres/src/backend/tcop/postgres.c +++ b/src/postgres/src/backend/tcop/postgres.c @@ -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);