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

Add support for sys.sp_reset_connection stored procedure #2758

Conversation

sharathbp
Copy link
Contributor

@sharathbp sharathbp commented Jul 19, 2024

Description

Support sys.sp_reset_connection store procedure to reset tds connection

  1. At the moment babelfish doesn't support sys.sp_reset_connection to reset the connection state. With this change it supports reset connection stored procedure.
  2. This change is required for supporting RDS Proxy for Babelfish. RDS Proxy calls sys.sp_reset_connection before connection is reused by other clients.

Issues Resolved

BABEL-429

Test Scenarios Covered

  • Use case based - Yes

  • Boundary conditions - Yes

  • Arbitrary inputs - Yes

  • Negative test cases - Yes

  • Minor version upgrade tests - N/A

  • Major version upgrade tests - N/A

  • Performance tests - N/A

  • Tooling impact - N/A

  • Client tests - N/A

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@sharathbp sharathbp changed the title Adding support for sp_reset_connection stored procedure Adding support for sys.sp_reset_connection stored procedure Jul 19, 2024
@sharathbp sharathbp force-pushed the babel-429-rds-proxy-support branch from dffe0b3 to d1df741 Compare July 19, 2024 14:15
@sharathbp sharathbp changed the title Adding support for sys.sp_reset_connection stored procedure Add support for sys.sp_reset_connection stored procedure Jul 19, 2024
@coveralls
Copy link
Collaborator

coveralls commented Jul 19, 2024

Pull Request Test Coverage Report for Build 10990507023

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 16 of 16 (100.0%) changed or added relevant lines in 3 files are covered.
  • 1654 unchanged lines in 9 files lost coverage.
  • Overall coverage increased (+0.03%) to 74.465%

Files with Coverage Reduction New Missed Lines %
contrib/babelfishpg_tsql/src/pltsql_bulkcopy.c 4 91.57%
contrib/babelfishpg_tsql/src/pltsql_utils.c 37 91.93%
contrib/babelfishpg_tsql/src/multidb.c 91 80.03%
contrib/babelfishpg_tsql/src/dbcmds.c 104 75.15%
contrib/babelfishpg_tsql/src/rolecmds.c 115 83.52%
contrib/babelfishpg_tsql/src/pl_exec-2.c 122 81.64%
contrib/babelfishpg_tsql/src/catalog.c 228 87.18%
contrib/babelfishpg_tsql/src/hooks.c 285 84.2%
contrib/babelfishpg_tsql/src/pl_exec.c 668 44.2%
Totals Coverage Status
Change from base Build 10937107580: 0.03%
Covered Lines: 44939
Relevant Lines: 60349

💛 - Coveralls

@sharathbp sharathbp force-pushed the babel-429-rds-proxy-support branch from d1df741 to e048c94 Compare July 24, 2024 06:30
contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c Outdated Show resolved Hide resolved
@@ -276,6 +277,7 @@ GetTDSRequest(bool *resetProtocol)
ResetTDSConnection();
TdsErrorContext->err_text = "Fetching TDS Request";
*resetProtocol = true;
reset_tds_connection_flag = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to also put this in the catch block?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On error connection is not reset so we should not set the flag to false. right ?
otherwise TDS request after error will reuse the old connection resources ?

contrib/babelfishpg_tsql/src/procedures.c Outdated Show resolved Hide resolved
contrib/babelfishpg_tsql/src/procedures.c Outdated Show resolved Hide resolved
contrib/babelfishpg_tsql/src/procedures.c Outdated Show resolved Hide resolved
@sharathbp sharathbp requested a review from kuntalghosh July 25, 2024 06:36
@sharathbp sharathbp force-pushed the babel-429-rds-proxy-support branch 6 times, most recently from 7d70d95 to 933cbae Compare August 2, 2024 09:06
@@ -71,6 +71,8 @@ typedef ResetConnectionData *ResetConnection;
* Local structures
*/
TdsRequestCtrlData *TdsRequestCtrl = NULL;
bool resetTdsConnectionFlag;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we initialise resetTdsConnectionFlag as false, that is on backend startup ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets initialize both vars

@sharathbp sharathbp force-pushed the babel-429-rds-proxy-support branch 3 times, most recently from 6eea9b8 to 60589ef Compare August 4, 2024 16:49
SELECT * from #babel_temp_table
storedproc#!#prep#!#sys.sp_reset_connection#!#
SELECT * from #babel_temp_table
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not actually testing the RPC in this connection, can we also have an RPC after storedproc?

@@ -71,6 +71,8 @@ typedef ResetConnectionData *ResetConnection;
* Local structures
*/
TdsRequestCtrlData *TdsRequestCtrl = NULL;
bool resetTdsConnectionFlag;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets initialize both vars

contrib/babelfishpg_tds/src/include/tds_protocol.h Outdated Show resolved Hide resolved
@sharathbp sharathbp force-pushed the babel-429-rds-proxy-support branch from ec430c1 to 344acb5 Compare August 20, 2024 11:29
@sharathbp sharathbp closed this Aug 20, 2024
@sharathbp sharathbp force-pushed the babel-429-rds-proxy-support branch from 344acb5 to a66de39 Compare August 20, 2024 11:33
@sharathbp sharathbp reopened this Aug 20, 2024
@sharathbp sharathbp force-pushed the babel-429-rds-proxy-support branch 2 times, most recently from 8107191 to fa5c6dc Compare August 20, 2024 16:26
@sharathbp sharathbp force-pushed the babel-429-rds-proxy-support branch from fa5c6dc to 4ea70d8 Compare August 20, 2024 17:00
# Test (24): End

# Test (25): Test sys.sp_reset_connection stored procedure
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a new test file for sp_reset_connection

INSERT INTO #babel_temp_table (Data) VALUES (100), (200), (300)
SELECT * from #babel_temp_table
storedproc#!#prep#!#sys.sp_reset_connection#!#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must add tests for sp_prepexec, sp_execute as well. This test only uses sp_customtype

/*
* SetResetTDSConnectionFlag - Sets reset tds connection flag
*/
void SetResetTDSConnectionFlag()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On diving deep, Found 2 behaviour differences:

  1. sys.sp_reset_connection should not send Env change token and TDSResetConnection should send
  2. Isolation levels are reset for sp_reset_connection but retained for TDSResetConnection

We have not fixed this for sp_reset_connection and this is paramount for feature complete. Lets focus on testing and aligning TSQL Behaviour and using wireshark

contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c Outdated Show resolved Hide resolved

EXEC sys.sp_reset_connection
-- TODO: GUC is not resetting
SELECT @@lock_timeout;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming the default value was 0. How are we really testing the reset in this case?

~~END~~

DECLARE @handle int;
EXEC SP_PREPARE @handle output, NULL, N'exec sys.sp_reset_connection'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my previous comments, we have still not added RPC tests

~~END~~

DECLARE @handle int;
EXEC SP_PREPARE @handle output, NULL, N'exec sys.sp_reset_connection'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my previous comments, we have still not added RPC tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I see the these are added in .net

@KushaalShroff KushaalShroff merged commit 3997e2e into babelfish-for-postgresql:BABEL_4_X_DEV Sep 25, 2024
46 checks passed
@shardgupta shardgupta deleted the babel-429-rds-proxy-support branch September 25, 2024 06:21
sharathbp added a commit to amazon-aurora/babelfish_extensions that referenced this pull request Sep 25, 2024
…or-postgresql#2758)

Support sys.sp_reset_connection store procedure to reset tds connection

1. At the moment babelfish doesn't support sys.sp_reset_connection to reset the connection state. With this change it supports reset connection stored procedure.
2. This change is required for supporting RDS Proxy for Babelfish. RDS Proxy calls sys.sp_reset_connection before connection is reused by other clients.

Tasks:
BABEL-429

Signed off by: Sharath BP <[email protected]>

(cherry picked from commit 3997e2e)
sharathbp added a commit to amazon-aurora/babelfish_extensions that referenced this pull request Sep 25, 2024
…or-postgresql#2758)

Support sys.sp_reset_connection store procedure to reset tds connection

1. At the moment babelfish doesn't support sys.sp_reset_connection to reset the connection state. With this change it supports reset connection stored procedure.
2. This change is required for supporting RDS Proxy for Babelfish. RDS Proxy calls sys.sp_reset_connection before connection is reused by other clients.

Tasks:
BABEL-429

Signed off by: Sharath BP <[email protected]>

(cherry picked from commit 3997e2e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants