Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YSQL] Failed txn restarts with UPDATE ... RETURNING queries #22010

Open
1 task done
pao214 opened this issue Apr 17, 2024 · 0 comments
Open
1 task done

[YSQL] Failed txn restarts with UPDATE ... RETURNING queries #22010

pao214 opened this issue Apr 17, 2024 · 0 comments
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue

Comments

@pao214
Copy link
Contributor

pao214 commented Apr 17, 2024

Jira Link: DB-10929

Description

Issue

Consider the following diff

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 43ab3c8f5a..f1b5211126 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
@@ -510,6 +510,19 @@ public class TestPgTransparentRestarts extends BasePgSQLTest {
     }
   }
 
+  /*
+   * Long strings shouldn't leak read restarts even when retuning.
+   */
+  @Test
+  public void testUpdateLong() throws Exception {
+    new RegularDmlStatementTester(
+        getConnectionBuilder(),
+        "UPDATE test_rr set i=1 RETURNING *",
+        getLongString(),
+        false /* is_deadlock_possible */
+    ).runTest();
+  }
+
   //
   // Helpers methods
   //

This is an update returning operation that has txn restarts because of txn conflicts with concurrent inserts.

Here is the log

ts1|pid96746|:29457|http://127.0.0.32:21406 	Query: UPDATE test_rr set i=1 RETURNING *
ts1|pid96746|:29457|http://127.0.0.32:21406 	Error: Restart read required at: { read: { days: 19829 time: 20:04:00.296831 } local_limit: { days: 19829 time: 20:04:00.296831 } global_limit: <min> in_txn_limit: <max> serial_no: 0 }
ts1|pid96746|:29457|http://127.0.0.32:21406 	Attempt No: 0
ts1|pid96746|:29457|http://127.0.0.32:21406 2024-04-16 20:04:00.302 PDT [96851] STATEMENT:  UPDATE test_rr set i=1 RETURNING *
ts1|pid96746|:29457|http://127.0.0.32:21406 TRAP: FailedAssertion("!(portal->holdContext == ((void*)0))", File: "../../../../../../../src/postgres/src/backend/utils/mmgr/portalmem.c", Line: 343)
ts1|pid96746|:29457|http://127.0.0.32:21406 2024-04-16 20:04:00.316 PDT [96852] LOG:  Restart is possible

Root Cause

When restarting a txn, we also restart the portal.

Below is an excerpt from yb_restart_portal

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

portal->holdContext is not assigned to NULL, making it a dangling reference.

Simply assign it to NULL.

Impact

Affects debug builds.

Issue Type

kind/bug

Warning: Please confirm that this issue does not contain any sensitive information

  • I confirm this issue does not contain any sensitive information.
@pao214 pao214 added area/ysql Yugabyte SQL (YSQL) status/awaiting-triage Issue awaiting triage labels Apr 17, 2024
@yugabyte-ci yugabyte-ci added kind/bug This issue is a bug priority/medium Medium priority issue labels Apr 17, 2024
@pao214 pao214 self-assigned this Apr 17, 2024
@pao214 pao214 changed the title [YSQL] YSQL crashes on txn restart with UPDATE ... RETURNING queries [YSQL] YSQL error on txn restart with UPDATE ... RETURNING queries Apr 17, 2024
@pao214 pao214 changed the title [YSQL] YSQL error on txn restart with UPDATE ... RETURNING queries [YSQL] Failed txn restarts with UPDATE ... RETURNING queries Apr 17, 2024
pao214 added a commit that referenced this issue Apr 29, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue
Projects
Status: In Review
Development

No branches or pull requests

3 participants