From 34e6e7a0e607989fae1a753e37d6769a0ad55dbf Mon Sep 17 00:00:00 2001 From: vpatibandla-yb Date: Tue, 23 Jul 2024 14:39:06 +0000 Subject: [PATCH] [#23250] YSQL: UT org.yb.pgsql.TestPgMemoryGC#testPgMemoryGcOrderBy is failing with connection manager Summary: During the connection setup with postgres, there is a startup message shared with the client, the message contains the details of the backend pid, cipher key. This info is persisted in the client side and can be used to cancel query if needed in the future. With connection manager, the above BackendKeyData packet is intercepted by connection manager and the info is persisted as part of server details. And, the client id info is shared with the client app. Propagating backend pid would not help as the client can be attached to a different backend across queries. So, in the case of connection manager, the connection manager client id is shared with the client app and this same id can be used to cancel the query if needed. As, the pid being shared with connection manager is not the true backend postgres id, I made the change to use `SELECT pg_backend_pid()` instead of `getPgBackendPid(connection)` which fetches the pid persisted in the client side. Follow up tickets for this change are: - Write a UT to test cancel query functionality with connection manager - https://yugabyte.atlassian.net/browse/DB-12241 - Document that the id persisted in JDBC is not the backend pid when connection manager is enabled - https://yugabyte.atlassian.net/browse/DB-12242 Jira: DB-12181 Test Plan: Run the test and check that the test `./yb_build.sh --java-test 'org.yb.pgsql.TestPgMemoryGC#testPgMemoryGcOrderBy'` is working as expected. Run the test and check that the test `./yb_build.sh --enable-ysql-conn-mgr-test --java-test 'org.yb.pgsql.TestPgMemoryGC#testPgMemoryGcOrderBy'` is working as expected. Verify that the cancel query is working with connection manager. Jenkins: test regex: .*TestPgMemoryGC.*, enable connection manager Reviewers: mkumar, rbarigidad, asrinivasan, nkumar, skumar Reviewed By: asrinivasan Differential Revision: https://phorge.dev.yugabyte.com/D36774 --- java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgMemoryGC.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgMemoryGC.java b/java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgMemoryGC.java index 3d47d5263645..2b3cf6749f22 100644 --- a/java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgMemoryGC.java +++ b/java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgMemoryGC.java @@ -10,6 +10,7 @@ import java.io.BufferedReader; import java.io.InputStreamReader; +import java.sql.ResultSet; import java.sql.Statement; import java.util.Collections; import java.util.Map; @@ -90,7 +91,9 @@ public void testPgMemoryGcOrderBy() throws Exception { try (Statement stmt = connection.createStatement()) { stmt.execute("SET work_mem='1GB'"); - final int pgPid = getPgBackendPid(connection); + ResultSet rs = stmt.executeQuery("SELECT pg_backend_pid()"); + rs.next(); + final int pgPid = rs.getInt("pg_backend_pid"); final long rssBefore = getRssForPid(pgPid); /*